Skip to content

Commit

Permalink
add missing end AST property to non-top-level <style> tags (sveltejs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ehrencrona authored and taylorzane committed Dec 17, 2020
1 parent 3ba8ed1 commit 2f91899
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/compiler/parse/state/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('</script>', true);
parser.eat(`</${name}>`, 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('</style>', true);
} else {
parser.stack.push(element);
}
Expand Down
1 change: 1 addition & 0 deletions test/parser/samples/style-inside-head/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<svelte:head><style></style></svelte:head>
33 changes: 33 additions & 0 deletions test/parser/samples/style-inside-head/output.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
]
}
]
}
]
}
}

0 comments on commit 2f91899

Please sign in to comment.