@@ -128,21 +128,21 @@ class TreeBuilder {
128128 attrs . push ( this . _consumeAttr ( this . _advance ( ) ) ) ;
129129 }
130130 var fullName = getElementFullName ( prefix , name , this . _getParentElement ( ) ) ;
131- var voidElement = false ;
131+ var selfClosing = false ;
132132 // Note: There could have been a tokenizer error
133133 // so that we don't get a token for the end tag...
134134 if ( this . peek . type === HtmlTokenType . TAG_OPEN_END_VOID ) {
135135 this . _advance ( ) ;
136- voidElement = true ;
136+ selfClosing = true ;
137137 } else if ( this . peek . type === HtmlTokenType . TAG_OPEN_END ) {
138138 this . _advance ( ) ;
139- voidElement = false ;
139+ selfClosing = false ;
140140 }
141141 var end = this . peek . sourceSpan . start ;
142142 var el = new HtmlElementAst ( fullName , attrs , [ ] ,
143143 new ParseSourceSpan ( startTagToken . sourceSpan . start , end ) ) ;
144144 this . _pushElement ( el ) ;
145- if ( voidElement ) {
145+ if ( selfClosing ) {
146146 this . _popElement ( fullName ) ;
147147 }
148148 }
@@ -172,18 +172,27 @@ class TreeBuilder {
172172 var fullName =
173173 getElementFullName ( endTagToken . parts [ 0 ] , endTagToken . parts [ 1 ] , this . _getParentElement ( ) ) ;
174174 if ( ! this . _popElement ( fullName ) ) {
175- this . errors . push ( HtmlTreeError . create ( fullName , endTagToken . sourceSpan . start ,
176- `Unexpected closing tag "${ endTagToken . parts [ 1 ] } "` ) ) ;
175+ let msg ;
176+
177+ if ( getHtmlTagDefinition ( fullName ) . isVoid ) {
178+ msg =
179+ `Void elements do not have end tags (they can not have content) "${ endTagToken . parts [ 1 ] } "` ;
180+ } else {
181+ msg = `Unexpected closing tag "${ endTagToken . parts [ 1 ] } "` ;
182+ }
183+
184+ this . errors . push ( HtmlTreeError . create ( fullName , endTagToken . sourceSpan . start , msg ) ) ;
177185 }
178186 }
179187
180188 private _popElement ( fullName : string ) : boolean {
181189 for ( let stackIndex = this . elementStack . length - 1 ; stackIndex >= 0 ; stackIndex -- ) {
182- var el = this . elementStack [ stackIndex ] ;
190+ let el = this . elementStack [ stackIndex ] ;
183191 if ( el . name . toLowerCase ( ) == fullName . toLowerCase ( ) ) {
184192 ListWrapper . splice ( this . elementStack , stackIndex , this . elementStack . length - stackIndex ) ;
185193 return true ;
186194 }
195+
187196 if ( ! getHtmlTagDefinition ( el . name ) . closedByParent ) {
188197 return false ;
189198 }
0 commit comments