From 277c07692644fdbc9803d51433af2b279c95ad55 Mon Sep 17 00:00:00 2001 From: Andreas Ehrencrona Date: Fri, 2 Oct 2020 12:14:02 +0200 Subject: [PATCH 1/2] Style tags that were not at top level were missing end attribute --- src/compiler/parse/state/tag.ts | 13 ++------ .../samples/style-inside-head/input.svelte | 1 + .../samples/style-inside-head/output.json | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 test/parser/samples/style-inside-head/input.svelte create mode 100644 test/parser/samples/style-inside-head/output.json diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 7d7a3384bea5..ffbd48e4fe25 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -223,21 +223,14 @@ export default function tag(parser: Parser) { ); parser.read(/<\/textarea>/); element.end = parser.index; - } else if (name === 'script') { + } else if (name === 'script' || name === 'style') { // special case const start = parser.index; - const data = parser.read_until(/<\/script>/); + const data = parser.read_until(new RegExp(`<\\/${name}>`)); const end = parser.index; element.children.push({ start, end, type: 'Text', data }); - parser.eat('', true); + parser.eat(``, true); element.end = parser.index; - } else if (name === 'style') { - // special case - const start = parser.index; - const data = parser.read_until(/<\/style>/); - const end = parser.index; - element.children.push({ start, end, type: 'Text', data }); - parser.eat('', true); } else { parser.stack.push(element); } diff --git a/test/parser/samples/style-inside-head/input.svelte b/test/parser/samples/style-inside-head/input.svelte new file mode 100644 index 000000000000..512e5b2fb4f7 --- /dev/null +++ b/test/parser/samples/style-inside-head/input.svelte @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/parser/samples/style-inside-head/output.json b/test/parser/samples/style-inside-head/output.json new file mode 100644 index 000000000000..ae972c5fa858 --- /dev/null +++ b/test/parser/samples/style-inside-head/output.json @@ -0,0 +1,33 @@ +{ + "html": { + "start": 0, + "end": 42, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 42, + "type": "Head", + "name": "svelte:head", + "attributes": [], + "children": [ + { + "start": 13, + "end": 28, + "type": "Element", + "name": "style", + "attributes": [], + "children": [ + { + "start": 20, + "end": 20, + "type": "Text", + "data": "" + } + ] + } + ] + } + ] + } +} \ No newline at end of file From 2f1f7097a417d4a71e957de79f0bacf6f19844ba Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 2 Oct 2020 09:27:54 -0400 Subject: [PATCH 2/2] remove unneeded escaping of / --- src/compiler/parse/state/tag.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index ffbd48e4fe25..efeb9433bc8e 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -226,7 +226,7 @@ export default function tag(parser: Parser) { } else if (name === 'script' || name === 'style') { // special case const start = parser.index; - const data = parser.read_until(new RegExp(`<\\/${name}>`)); + const data = parser.read_until(new RegExp(``)); const end = parser.index; element.children.push({ start, end, type: 'Text', data }); parser.eat(``, true);