From 2efd532563aaaf7162a3cf43ff17ebad48f482cd Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 1 Mar 2017 18:02:23 -0500 Subject: [PATCH] better error for unmatched closing tag (#321) --- src/parse/state/tag.js | 2 ++ test/parser/error-unmatched-closing-tag/error.json | 8 ++++++++ test/parser/error-unmatched-closing-tag/input.html | 1 + 3 files changed, 11 insertions(+) create mode 100644 test/parser/error-unmatched-closing-tag/error.json create mode 100644 test/parser/error-unmatched-closing-tag/input.html diff --git a/src/parse/state/tag.js b/src/parse/state/tag.js index 3b79ad8406..11177514b5 100644 --- a/src/parse/state/tag.js +++ b/src/parse/state/tag.js @@ -90,6 +90,8 @@ export default function tag ( parser ) { // close any elements that don't have their own closing tags, e.g.

while ( parent.name !== name ) { + if ( parent.type !== 'Element' ) parser.error( ` attempted to close an element that was not open`, start ); + parent.end = start; parser.stack.pop(); diff --git a/test/parser/error-unmatched-closing-tag/error.json b/test/parser/error-unmatched-closing-tag/error.json new file mode 100644 index 0000000000..3dd72b28da --- /dev/null +++ b/test/parser/error-unmatched-closing-tag/error.json @@ -0,0 +1,8 @@ +{ + "message": " attempted to close an element that was not open", + "loc": { + "line": 1, + "column": 0 + }, + "pos": 0 +} diff --git a/test/parser/error-unmatched-closing-tag/input.html b/test/parser/error-unmatched-closing-tag/input.html new file mode 100644 index 0000000000..7f5eaa32ef --- /dev/null +++ b/test/parser/error-unmatched-closing-tag/input.html @@ -0,0 +1 @@ + \ No newline at end of file