diff --git a/src/compiler/parse/index.ts b/src/compiler/parse/index.ts index c41bd04518..04025ae0fc 100644 --- a/src/compiler/parse/index.ts +++ b/src/compiler/parse/index.ts @@ -189,11 +189,11 @@ export class Parser { if (match) { this.index = start + match.index; - return this.template.slice(start, this.index); + return [this.template.slice(start, this.index), match[0]]; } this.index = this.template.length; - return this.template.slice(start); + return [this.template.slice(start)]; } require_whitespace() { diff --git a/src/compiler/parse/read/style.ts b/src/compiler/parse/read/style.ts index 3b9502c01c..349110ec6c 100644 --- a/src/compiler/parse/read/style.ts +++ b/src/compiler/parse/read/style.ts @@ -6,7 +6,7 @@ import { Style } from '../../interfaces'; export default function read_style(parser: Parser, start: number, attributes: Node[]): Style { const content_start = parser.index; - const styles = parser.read_until(/<\/style>/); + const [styles, matched] = parser.read_until(/<\/style\s*>/); const content_end = parser.index; let ast; @@ -69,7 +69,7 @@ export default function read_style(parser: Parser, start: number, attributes: No } }); - parser.eat('', true); + parser.eat(matched, true); const end = parser.index; return { diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index d6294d4a5c..e7b5fa3efe 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -56,7 +56,7 @@ export default function tag(parser: Parser) { let parent = parser.current(); if (parser.eat('!--')) { - const data = parser.read_until(/-->/); + const [data] = parser.read_until(/-->/); parser.eat('-->', true, 'comment was left open, expected -->'); parser.current().children.push({ @@ -226,7 +226,7 @@ export default function tag(parser: Parser) { } else if (name === 'script') { // special case const start = parser.index; - const data = parser.read_until(/<\/script>/); + const [data] = parser.read_until(/<\/script>/); const end = parser.index; element.children.push({ start, end, type: 'Text', data }); parser.eat('', true); @@ -234,7 +234,7 @@ export default function tag(parser: Parser) { } else if (name === 'style') { // special case const start = parser.index; - const data = parser.read_until(/<\/style>/); + const [data] = parser.read_until(/<\/style>/); const end = parser.index; element.children.push({ start, end, type: 'Text', data }); parser.eat('', true); @@ -272,7 +272,7 @@ function read_tag_name(parser: Parser) { if (parser.read(COMPONENT)) return 'svelte:component'; - const name = parser.read_until(/(\s|\/|>)/); + const [name] = parser.read_until(/(\s|\/|>)/); if (meta_tags.has(name)) return name; @@ -356,7 +356,7 @@ function read_attribute(parser: Parser, unique_names: Set) { } // eslint-disable-next-line no-useless-escape - const name = parser.read_until(/[\s=\/>"']/); + const [name] = parser.read_until(/[\s=\/>"']/); if (!name) return null; let end = parser.index; diff --git a/test/parser/samples/css-whitespace-after-tagname/input.svelte b/test/parser/samples/css-whitespace-after-tagname/input.svelte new file mode 100644 index 0000000000..ae4277b697 --- /dev/null +++ b/test/parser/samples/css-whitespace-after-tagname/input.svelte @@ -0,0 +1,12 @@ +
foo
+ + \ No newline at end of file diff --git a/test/parser/samples/css-whitespace-after-tagname/output.json b/test/parser/samples/css-whitespace-after-tagname/output.json new file mode 100644 index 0000000000..b57401b213 --- /dev/null +++ b/test/parser/samples/css-whitespace-after-tagname/output.json @@ -0,0 +1,97 @@ +{ + "html": { + "start": 0, + "end": 14, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 14, + "type": "Element", + "name": "div", + "attributes": [], + "children": [ + { + "start": 5, + "end": 8, + "type": "Text", + "raw": "foo", + "data": "foo" + } + ] + }, + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "\n\n", + "data": "\n\n" + } + ] + }, + "css": { + "type": "Style", + "start": 16, + "end": 66, + "attributes": [], + "children": [ + { + "type": "Rule", + "selector": { + "type": "SelectorList", + "children": [ + { + "type": "Selector", + "children": [ + { + "type": "TypeSelector", + "name": "div", + "start": 25, + "end": 28 + } + ], + "start": 25, + "end": 28 + } + ], + "start": 25, + "end": 28 + }, + "block": { + "type": "Block", + "children": [ + { + "type": "Declaration", + "important": false, + "property": "color", + "value": { + "type": "Value", + "children": [ + { + "type": "Identifier", + "name": "red", + "start": 40, + "end": 43 + } + ], + "start": 39, + "end": 43 + }, + "start": 33, + "end": 43 + } + ], + "start": 29, + "end": 47 + }, + "start": 25, + "end": 47 + } + ], + "content": { + "start": 23, + "end": 48, + "styles": "\n\tdiv {\n\t\tcolor: red;\n\t}\n" + } + } +} \ No newline at end of file