diff --git a/src/generators/nodes/Element.ts b/src/generators/nodes/Element.ts index 48852c27ea9b..1882b1b77ae8 100644 --- a/src/generators/nodes/Element.ts +++ b/src/generators/nodes/Element.ts @@ -433,7 +433,7 @@ export default class Element extends Node { if (isVoidElementName(node.name)) return open + '>'; - if (node.name === 'script' || node.name === 'style') { + if (node.name === 'script') { return `${open}>${node.data}`; } diff --git a/src/generators/server-side-rendering/visitors/Element.ts b/src/generators/server-side-rendering/visitors/Element.ts index 486f0f01a307..7ea2b3a7cde3 100644 --- a/src/generators/server-side-rendering/visitors/Element.ts +++ b/src/generators/server-side-rendering/visitors/Element.ts @@ -68,7 +68,7 @@ export default function visitElement( if (node.name === 'textarea' && textareaContents !== undefined) { generator.append(textareaContents); - } else if (node.name === 'script' || node.name === 'style') { + } else if (node.name === 'script') { generator.append(escape(node.data)); } else { node.children.forEach((child: Node) => { diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index a659dc6d3d76..1b55617c3310 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -224,11 +224,20 @@ export default function tag(parser: Parser) { ); parser.read(/<\/textarea>/); element.end = parser.index; - } else if (name === 'script' || name === 'style') { + } else if (name === 'script') { // special case element.data = parser.readUntil(new RegExp(``)); parser.eat(``, true); element.end = parser.index; + } else if (name === 'style') { + // special case + element.children = readSequence( + parser, + () => + parser.template.slice(parser.index, parser.index + 8) === '' + ); + parser.read(/<\/style>/); + element.end = parser.index; } else { parser.stack.push(element); } diff --git a/test/runtime/samples/non-root-style-interpolation/_config.js b/test/runtime/samples/non-root-style-interpolation/_config.js new file mode 100644 index 000000000000..326d17e3b17b --- /dev/null +++ b/test/runtime/samples/non-root-style-interpolation/_config.js @@ -0,0 +1,15 @@ +export default { + data: { + color: 'red', + }, + + html: ` +
+ + foo +
`, +}; diff --git a/test/runtime/samples/non-root-style-interpolation/main.html b/test/runtime/samples/non-root-style-interpolation/main.html new file mode 100644 index 000000000000..b49fc101a70f --- /dev/null +++ b/test/runtime/samples/non-root-style-interpolation/main.html @@ -0,0 +1,8 @@ +
+ + foo +