diff --git a/src/parse/index.js b/src/parse/index.js index 30b88ae53125..ee0c1d8dfb58 100644 --- a/src/parse/index.js +++ b/src/parse/index.js @@ -123,7 +123,14 @@ export default function parse ( template, options = {} ) { state = state( parser ) || fragment; } - if ( state !== fragment || parser.stack.length > 1 ) { + if ( parser.stack.length > 1 ) { + const current = parser.current(); + + const type = current.type === 'Element' ? `<${current.name}>` : 'Block'; + parser.error( `${type} was left open`, current.start ); + } + + if ( state !== fragment ) { parser.error( 'Unexpected end of input' ); } diff --git a/test/parse.js b/test/parse.js index caa132bbdf65..68e3d18664d8 100644 --- a/test/parse.js +++ b/test/parse.js @@ -45,7 +45,7 @@ describe( 'parse', () => { svelte.compile( `

unclosed`, { onerror ( err ) { errored = true; - assert.equal( err.message, `Unexpected end of input` ); + assert.equal( err.message, `

was left open` ); } }); @@ -55,6 +55,6 @@ describe( 'parse', () => { it( 'throws without options.onerror', () => { assert.throws( () => { svelte.compile( `

unclosed` ); - }, /Unexpected end of input/ ); + }, /

was left open/ ); }); }); diff --git a/test/parser/error-unexpected-end-of-input-d/error.json b/test/parser/error-unexpected-end-of-input-d/error.json new file mode 100644 index 000000000000..8a78bbf50110 --- /dev/null +++ b/test/parser/error-unexpected-end-of-input-d/error.json @@ -0,0 +1,8 @@ +{ + "message": "Block was left open", + "loc": { + "line": 1, + "column": 0 + }, + "pos": 0 +} diff --git a/test/parser/error-unexpected-end-of-input-d/input.html b/test/parser/error-unexpected-end-of-input-d/input.html new file mode 100644 index 000000000000..3f73b869118c --- /dev/null +++ b/test/parser/error-unexpected-end-of-input-d/input.html @@ -0,0 +1,2 @@ +{{#if foo}} +

foo

\ No newline at end of file diff --git a/test/parser/error-unexpected-end-of-input/error.json b/test/parser/error-unexpected-end-of-input/error.json index e171d2a2e812..87ecce83bc2e 100644 --- a/test/parser/error-unexpected-end-of-input/error.json +++ b/test/parser/error-unexpected-end-of-input/error.json @@ -1,8 +1,8 @@ { - "message": "Unexpected end of input", + "message": "
was left open", "loc": { "line": 1, - "column": 5 + "column": 0 }, - "pos": 5 + "pos": 0 }