use proper discriminated unions (TODO replace args with node-specific properties)

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

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

@ -36,18 +36,31 @@ export interface ClientTransformState extends TransformState {
>;
}
type TemplateOperationsKind =
| 'create_element'
| 'create_text'
| 'create_anchor'
| 'set_prop'
| 'push_element'
| 'pop_element';
type TemplateOperations = Array<
| {
kind: 'create_element';
args: string[];
}
| {
kind: 'create_text';
args: string[];
}
| {
kind: 'create_anchor';
args?: string[];
}
| {
kind: 'set_prop';
args: string[];
}
| {
kind: 'push_element';
}
| {
kind: 'pop_element';
}
>;
type TemplateOperations = Array<{
kind: TemplateOperationsKind;
args?: Array<string>;
}>;
export interface ComponentClientTransformState extends ClientTransformState {
readonly analysis: ComponentAnalysis;
readonly options: ValidatedCompileOptions;

Loading…
Cancel
Save