pull/12335/head
Rich Harris 2 years ago
parent 65f8675b41
commit 65d2053aa3

@ -1610,6 +1610,10 @@ export const template_visitors = {
context.visit(node, state); context.visit(node, state);
} }
if (is_anchored) {
body.push(b.stmt(b.call('$.next')));
}
/** /**
* @param {import('estree').Identifier} template_name * @param {import('estree').Identifier} template_name
* @param {import('estree').Expression[]} args * @param {import('estree').Expression[]} args
@ -1668,11 +1672,7 @@ export const template_visitors = {
state state
}); });
body.push( body.push(b.var(id, b.call('$.text')), ...state.before_init, ...state.init);
b.var(id, b.call('$.text', is_anchored && b.true)),
...state.before_init,
...state.init
);
close = b.stmt(b.call('$.append', b.id('$$anchor'), id)); close = b.stmt(b.call('$.append', b.id('$$anchor'), id));
} else { } else {
if (is_standalone) { if (is_standalone) {

@ -1143,9 +1143,9 @@ const template_visitors = {
process_children(trimmed, { ...context, state }); process_children(trimmed, { ...context, state });
if (is_anchored) { // if (is_anchored) {
state.template.push(b.literal('<!---->')); // state.template.push(b.literal('<!---->'));
} // }
return b.block([...state.init, ...serialize_template(state.template)]); return b.block([...state.init, ...serialize_template(state.template)]);
}, },

@ -284,15 +284,10 @@ export function clean_nodes(
(attribute) => attribute.type === 'Attribute' && attribute.name.startsWith('--') (attribute) => attribute.type === 'Attribute' && attribute.name.startsWith('--')
))); )));
// if a component or snippet only contains text, we need to add an anchor comment // if a component or snippet starts with text, we need to add an anchor comment
// so that its text node doesn't get fused with its surroundings // so that its text node doesn't get fused with its surroundings
const is_dynamic_text = const is_anchored =
trimmed.every((node) => node.type === 'Text' || node.type === 'ExpressionTag') && parent.type === 'Fragment' && (first.type === 'Text' || first.type === 'ExpressionTag');
trimmed.some((node) => node.type === 'ExpressionTag');
const is_text = trimmed.length === 1 && first.type === 'Text';
const is_anchored = (is_dynamic_text || is_text) && parent.type === 'Fragment';
return { hoisted, trimmed, is_standalone: false, is_anchored }; return { hoisted, trimmed, is_standalone: false, is_anchored };
} }

@ -232,9 +232,9 @@ export function text(anchored) {
set_hydrate_node(node); set_hydrate_node(node);
} }
if (anchored) { // if (anchored) {
hydrate_next(); // hydrate_next();
} // }
assign_nodes(node, node); assign_nodes(node, node);
return node; return node;

Loading…
Cancel
Save