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); last_current_element = elements_stack.at(-1);
break; break;
case 'create_element': case 'create_element':
last_current_element = create_element(args[0]); last_current_element = create_element(instruction.name);
push(last_current_element); push(last_current_element);
break; break;
case 'create_text': case 'create_text':
push(create_text(last_element_stack, args[0])); push(create_text(last_element_stack, args[0]));
break; break;
case 'create_anchor': case 'create_anchor':
push(create_anchor(last_element_stack, args[0])); push(create_anchor(last_element_stack, instruction.data));
break; break;
case 'set_prop': 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; break;
} }
} }

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

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

@ -7,5 +7,5 @@
*/ */
export function Comment(node, context) { export function Comment(node, context) {
// We'll only get here if comments are not filtered out, which they are unless preserveComments is true // 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') { if (node.name === 'noscript') {
context.state.template.push({ context.state.template.push({
kind: 'create_element', kind: 'create_element',
args: ['noscript'] name: 'noscript'
}); });
return; return;
} }
@ -77,7 +77,7 @@ export function RegularElement(node, context) {
context.state.template.push({ context.state.template.push({
kind: 'create_element', kind: 'create_element',
args: [node.name] name: node.name
}); });
/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */ /** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
@ -118,7 +118,8 @@ export function RegularElement(node, context) {
if (value.type === 'Literal' && typeof value.value === 'string') { if (value.type === 'Literal' && typeof value.value === 'string') {
context.state.template.push({ context.state.template.push({
kind: 'set_prop', kind: 'set_prop',
args: ['is', value.value] key: 'is',
value: value.value
}); });
continue; continue;
} }
@ -301,9 +302,9 @@ export function RegularElement(node, context) {
if (name !== 'class' || value) { if (name !== 'class' || value) {
context.state.template.push({ context.state.template.push({
kind: 'set_prop', kind: 'set_prop',
args: [attribute.name].concat( key: attribute.name,
is_boolean_attribute(name) && value === true ? [] : [value === true ? '' : value] value:
) is_boolean_attribute(name) && value === true ? undefined : value === true ? '' : value
}); });
} }
} else if (name === 'autofocus') { } else if (name === 'autofocus') {

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

Loading…
Cancel
Save