fix: improve ssr template code generation (#10151)

* fix: improve ssr template code generation

* lint
pull/10148/head
Dominic Gannaway 1 year ago committed by GitHub
parent e2fc04d0d5
commit ff8dff993d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: improve ssr template code generation

@ -187,10 +187,12 @@ function process_children(nodes, parent, { visit, state }) {
const node = sequence[i];
if (node.type === 'Text' || node.type === 'Comment') {
let last = /** @type {import('estree').TemplateElement} */ (quasis.at(-1));
last.value.raw +=
node.type === 'Comment'
? `<!--${node.data}-->`
: sanitize_template_string(escape_html(node.data));
last.value.raw += node.type === 'Comment' ? `<!--${node.data}-->` : escape_html(node.data);
} else if (node.type === 'ExpressionTag' && node.expression.type === 'Literal') {
let last = /** @type {import('estree').TemplateElement} */ (quasis.at(-1));
if (node.expression.value != null) {
last.value.raw += escape_html(node.expression.value + '');
}
} else if (node.type === 'Anchor') {
expressions.push(node.id);
quasis.push(b.quasi('', i + 1 === sequence.length));

@ -14,7 +14,7 @@ export default function Each_string_template($$payload, $$props) {
const thing = each_array[$$index];
const anchor_1 = $.create_anchor($$payload);
$$payload.out += `${anchor_1}${$.escape(thing)},${$.escape(' ')}${anchor_1}`;
$$payload.out += `${anchor_1}${$.escape(thing)}, ${anchor_1}`;
}
$$payload.out += `${anchor}`;

Loading…
Cancel
Save