remove instruction.args

pull/15538/head
Rich Harris 4 months ago
parent 324bd8a7a3
commit 4a3fc9d9cb

@ -52,17 +52,17 @@ export function template_to_functions(items) {
last_current_element = elements_stack.at(-1);
break;
case 'create_element':
last_current_element = create_element(args[0]);
last_current_element = create_element(instruction.name);
push(last_current_element);
break;
case 'create_text':
push(create_text(last_element_stack, args[0]));
break;
case 'create_anchor':
push(create_anchor(last_element_stack, args[0]));
push(create_anchor(last_element_stack, instruction.data));
break;
case 'set_prop':
set_prop(/** @type {Element} */ (last_current_element), args[0], args[1]);
set_prop(/** @type {Element} */ (last_current_element), instruction.key, instruction.value);
break;
}
}

@ -49,7 +49,7 @@ export function template_to_string(items) {
case 'create_element':
last_current_element = insert({
kind: 'element',
element: instruction.args[0]
element: instruction.name
});
break;
case 'create_text':
@ -61,14 +61,13 @@ export function template_to_string(items) {
case 'create_anchor':
insert({
kind: 'anchor',
data: instruction.args?.[0]
data: instruction.data
});
break;
case 'set_prop': {
const el = /** @type {Element} */ (last_current_element);
const [prop, value] = instruction.args;
el.props ??= {};
el.props[prop] = escape_html(value, true);
el.props[instruction.key] = escape_html(instruction.value, true);
break;
}
}

@ -39,7 +39,7 @@ export interface ClientTransformState extends TransformState {
type TemplateOperations = Array<
| {
kind: 'create_element';
args: string[];
name: string;
}
| {
kind: 'create_text';
@ -47,11 +47,12 @@ type TemplateOperations = Array<
}
| {
kind: 'create_anchor';
args?: string[];
data?: string;
}
| {
kind: 'set_prop';
args: string[];
key: string;
value: string | undefined;
}
| {
kind: 'push_element';

@ -7,5 +7,5 @@
*/
export function Comment(node, context) {
// We'll only get here if comments are not filtered out, which they are unless preserveComments is true
context.state.template.push({ kind: 'create_anchor', args: [node.data] });
context.state.template.push({ kind: 'create_anchor', data: node.data });
}

@ -54,7 +54,7 @@ export function RegularElement(node, context) {
if (node.name === 'noscript') {
context.state.template.push({
kind: 'create_element',
args: ['noscript']
name: 'noscript'
});
return;
}
@ -77,7 +77,7 @@ export function RegularElement(node, context) {
context.state.template.push({
kind: 'create_element',
args: [node.name]
name: node.name
});
/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
@ -118,7 +118,8 @@ export function RegularElement(node, context) {
if (value.type === 'Literal' && typeof value.value === 'string') {
context.state.template.push({
kind: 'set_prop',
args: ['is', value.value]
key: 'is',
value: value.value
});
continue;
}
@ -301,9 +302,9 @@ export function RegularElement(node, context) {
if (name !== 'class' || value) {
context.state.template.push({
kind: 'set_prop',
args: [attribute.name].concat(
is_boolean_attribute(name) && value === true ? [] : [value === true ? '' : value]
)
key: attribute.name,
value:
is_boolean_attribute(name) && value === true ? undefined : value === true ? '' : value
});
}
} else if (name === 'autofocus') {

@ -446,14 +446,14 @@ export function build_component(node, component_name, context, anchor = context.
const template_operations = [];
if (context.state.metadata.namespace === 'svg') {
// this boils down to <g><!></g>
template_operations.push({ kind: 'create_element', args: ['g'] });
template_operations.push({ kind: 'create_element', name: 'g' });
template_operations.push({ kind: 'push_element' });
template_operations.push({ kind: 'create_anchor' });
template_operations.push({ kind: 'pop_element' });
} else {
// this boils down to <svelte-css-wrapper style='display: contents'><!></svelte-css-wrapper>
template_operations.push({ kind: 'create_element', args: ['svelte-css-wrapper'] });
template_operations.push({ kind: 'set_prop', args: ['style', 'display: contents'] });
template_operations.push({ kind: 'create_element', name: 'svelte-css-wrapper' });
template_operations.push({ kind: 'set_prop', key: 'style', value: 'display: contents' });
template_operations.push({ kind: 'push_element' });
template_operations.push({ kind: 'create_anchor' });
template_operations.push({ kind: 'pop_element' });

Loading…
Cancel
Save