Skip to content

Commit

Permalink
provide useful feedback on encountering void element closing tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 24, 2016
1 parent 5801df8 commit fc977a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/parse/state/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export default function tag ( parser ) {
parser.allowWhitespace();

if ( isClosingTag ) {
if ( voidElementNames.test( name ) ) {
parser.error( `<${name}> is a void element and cannot have children, or a closing tag`, start );
}

if ( !parser.eat( '>' ) ) parser.error( `Expected '>'` );

const element = parser.current();
Expand Down
8 changes: 8 additions & 0 deletions test/parser/error-void-closing/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"message": "<input> is a void element and cannot have children, or a closing tag",
"loc": {
"line": 1,
"column": 23
},
"pos": 23
}
1 change: 1 addition & 0 deletions test/parser/error-void-closing/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input>this is illegal!</input>

0 comments on commit fc977a2

Please sign in to comment.