diff --git a/src/compiler/parse/read/script.ts b/src/compiler/parse/read/script.ts index 130c346ba1..297d5d941b 100644 --- a/src/compiler/parse/read/script.ts +++ b/src/compiler/parse/read/script.ts @@ -31,13 +31,16 @@ function get_context(parser: Parser, attributes: any[], start: number): string { export default function read_script(parser: Parser, start: number, attributes: Node[]): Script { const script_start = parser.index; const script_end = parser.template.indexOf(script_closing_tag, script_start); + const script_start_line = parser.template.slice(0, script_start).split('\n').length - 1; if (script_end === -1) parser.error({ code: `unclosed-script`, message: ` + +{foo.bar.baz} diff --git a/test/sourcemaps/samples/script-after-comment/test.js b/test/sourcemaps/samples/script-after-comment/test.js new file mode 100644 index 0000000000..b473970112 --- /dev/null +++ b/test/sourcemaps/samples/script-after-comment/test.js @@ -0,0 +1,16 @@ +export function test({ assert, smc, locateInSource, locateInGenerated }) { + const expected = locateInSource( 'assertThisLine' ); + const start = locateInGenerated( 'assertThisLine' ); + + const actual = smc.originalPositionFor({ + line: start.line + 1, + column: start.column + }); + + assert.deepEqual( actual, { + source: 'input.svelte', + name: null, + line: expected.line + 1, + column: expected.column + }); +} diff --git a/test/sourcemaps/samples/two-scripts/input.svelte b/test/sourcemaps/samples/two-scripts/input.svelte new file mode 100644 index 0000000000..4c869827c0 --- /dev/null +++ b/test/sourcemaps/samples/two-scripts/input.svelte @@ -0,0 +1,9 @@ + + + + +{foo.bar.baz} diff --git a/test/sourcemaps/samples/two-scripts/test.js b/test/sourcemaps/samples/two-scripts/test.js new file mode 100644 index 0000000000..b473970112 --- /dev/null +++ b/test/sourcemaps/samples/two-scripts/test.js @@ -0,0 +1,16 @@ +export function test({ assert, smc, locateInSource, locateInGenerated }) { + const expected = locateInSource( 'assertThisLine' ); + const start = locateInGenerated( 'assertThisLine' ); + + const actual = smc.originalPositionFor({ + line: start.line + 1, + column: start.column + }); + + assert.deepEqual( actual, { + source: 'input.svelte', + name: null, + line: expected.line + 1, + column: expected.column + }); +}