make process_children unaware of templating mode - the less visitors know about this, the better

pull/15538/head
Rich Harris 4 months ago
parent 4a3fc9d9cb
commit 76d05e065c

@ -28,7 +28,6 @@ export function template_to_functions(items) {
}
for (let instruction of items) {
const args = instruction.args ?? [];
const last_element_stack = /** @type {Element} */ (elements_stack.at(-1));
/**
* @param {Expression | null | void} value
@ -56,7 +55,7 @@ export function template_to_functions(items) {
push(last_current_element);
break;
case 'create_text':
push(create_text(last_element_stack, args[0]));
push(create_text(last_element_stack, instruction.nodes.map((node) => node.data).join('')));
break;
case 'create_anchor':
push(create_anchor(last_element_stack, instruction.data));
@ -138,13 +137,13 @@ function create_text(element, value) {
*
* @param {Element} element
* @param {string} prop
* @param {string} value
* @param {string | undefined} value
*/
function set_prop(element, prop, value) {
const p = get_or_create_prop(element, 'p', b.object([]));
if (prop === 'is') {
element.properties.push(b.prop('init', b.id(prop), b.literal(value)));
element.properties.push(b.prop('init', b.id(prop), b.literal(/** @type {string} */ (value))));
return;
}

@ -55,7 +55,7 @@ export function template_to_string(items) {
case 'create_text':
insert({
kind: 'text',
value: instruction.args[0]
value: instruction.nodes.map((node) => node.raw).join('')
});
break;
case 'create_anchor':

@ -43,7 +43,7 @@ type TemplateOperations = Array<
}
| {
kind: 'create_text';
args: string[];
nodes: AST.Text[];
}
| {
kind: 'create_anchor';

@ -66,17 +66,13 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
skipped += 1;
state.template.push({
kind: 'create_text',
args: [
sequence
.map((node) => (state.is_functional_template_mode ? node.data : node.raw))
.join('')
]
nodes: sequence
});
return;
}
state.template.push({
kind: 'create_text',
args: [' ']
nodes: [{ type: 'Text', data: ' ', raw: ' ', start: -1, end: -1 }]
});
const { has_state, value } = build_template_chunk(sequence, visit, state);

Loading…
Cancel
Save