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

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

Loading…
Cancel
Save