Skip to content

Commit 324bd8a

Browse files
committed
use proper discriminated unions (TODO replace args with node-specific properties)
1 parent e81c669 commit 324bd8a

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

packages/svelte/src/compiler/phases/3-transform/client/transform-template/to-string.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ export function template_to_string(items) {
4949
case 'create_element':
5050
last_current_element = insert({
5151
kind: 'element',
52-
element: /** @type {string[]} */ (instruction.args)[0]
52+
element: instruction.args[0]
5353
});
5454
break;
5555
case 'create_text':
5656
insert({
5757
kind: 'text',
58-
value: /** @type {string[]} */ (instruction.args)[0]
58+
value: instruction.args[0]
5959
});
6060
break;
6161
case 'create_anchor':
@@ -66,7 +66,7 @@ export function template_to_string(items) {
6666
break;
6767
case 'set_prop': {
6868
const el = /** @type {Element} */ (last_current_element);
69-
const [prop, value] = /** @type {string[]} */ (instruction.args);
69+
const [prop, value] = instruction.args;
7070
el.props ??= {};
7171
el.props[prop] = escape_html(value, true);
7272
break;

packages/svelte/src/compiler/phases/3-transform/client/types.d.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,31 @@ export interface ClientTransformState extends TransformState {
3636
>;
3737
}
3838

39-
type TemplateOperationsKind =
40-
| 'create_element'
41-
| 'create_text'
42-
| 'create_anchor'
43-
| 'set_prop'
44-
| 'push_element'
45-
| 'pop_element';
39+
type TemplateOperations = Array<
40+
| {
41+
kind: 'create_element';
42+
args: string[];
43+
}
44+
| {
45+
kind: 'create_text';
46+
args: string[];
47+
}
48+
| {
49+
kind: 'create_anchor';
50+
args?: string[];
51+
}
52+
| {
53+
kind: 'set_prop';
54+
args: string[];
55+
}
56+
| {
57+
kind: 'push_element';
58+
}
59+
| {
60+
kind: 'pop_element';
61+
}
62+
>;
4663

47-
type TemplateOperations = Array<{
48-
kind: TemplateOperationsKind;
49-
args?: Array<string>;
50-
}>;
5164
export interface ComponentClientTransformState extends ClientTransformState {
5265
readonly analysis: ComponentAnalysis;
5366
readonly options: ValidatedCompileOptions;

0 commit comments

Comments
 (0)