update style end tag parsing to allow for whitespace after tag name

pull/5328/head
pngwn 5 years ago
parent e88191f285
commit 39c35e11c1

@ -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() {

@ -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('</style>', true);
parser.eat(matched, true);
const end = parser.index;
return {

@ -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('</script>', 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('</style>', 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<string>) {
}
// 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;

@ -0,0 +1,12 @@
<div>foo</div>
<style>
div {
color: red;
}
</style
>

@ -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"
}
}
}
Loading…
Cancel
Save