From cb24094963be2d3f0e516cf96bc26cf0068df6e6 Mon Sep 17 00:00:00 2001 From: pngwn Date: Mon, 31 Aug 2020 11:03:37 +0100 Subject: [PATCH] handle no closing match for script and style for eof and non-eof failures --- src/compiler/parse/index.ts | 4 ++-- src/compiler/parse/read/script.ts | 15 ++++++++------- src/compiler/parse/read/style.ts | 11 ++++++++--- .../samples/error-style-unclosed-eof/error.json | 10 ++++++++++ .../samples/error-style-unclosed-eof/input.svelte | 3 +++ .../samples/error-style-unclosed/error.json | 10 ++++++++++ .../samples/error-style-unclosed/input.svelte | 3 +++ 7 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 test/parser/samples/error-style-unclosed-eof/error.json create mode 100644 test/parser/samples/error-style-unclosed-eof/input.svelte create mode 100644 test/parser/samples/error-style-unclosed/error.json create mode 100644 test/parser/samples/error-style-unclosed/input.svelte diff --git a/src/compiler/parse/index.ts b/src/compiler/parse/index.ts index 04025ae0fc..f378fced41 100644 --- a/src/compiler/parse/index.ts +++ b/src/compiler/parse/index.ts @@ -177,9 +177,9 @@ export class Parser { return identifier; } - read_until(pattern: RegExp) { + read_until(pattern: RegExp, error?: {code: string; message: string}) { if (this.index >= this.template.length) - this.error({ + this.error(error || { code: `unexpected-eof`, message: 'Unexpected end of input' }); diff --git a/src/compiler/parse/read/script.ts b/src/compiler/parse/read/script.ts index 3fadab9fbe..6a719250ef 100644 --- a/src/compiler/parse/read/script.ts +++ b/src/compiler/parse/read/script.ts @@ -28,16 +28,15 @@ 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 = /<\/script\s*>/.exec(parser.template.slice(script_start)); - - if (!script_end) parser.error({ + const error_message ={ code: `unclosed-script`, message: `