Skip to content

Commit 448cff1

Browse files
committed
remove indirection
1 parent 8c819e5 commit 448cff1

File tree

15 files changed

+35
-119
lines changed

15 files changed

+35
-119
lines changed

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

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/** @import { AST } from '#compiler' */
2-
/** @import { TemplateOperation } from '../types.js' */
32
/** @import { Node, Element } from './types'; */
43

54
export class Template {
@@ -14,43 +13,6 @@ export class Template {
1413

1514
#fragment = this.nodes;
1615

17-
/**
18-
* @param {...TemplateOperation} nodes
19-
* @deprecated
20-
*/
21-
push(...nodes) {
22-
for (const node of nodes) {
23-
switch (node.kind) {
24-
case 'create_element':
25-
this.create_element(node.name);
26-
break;
27-
28-
case 'create_anchor':
29-
this.create_anchor(node.data);
30-
break;
31-
32-
case 'create_text':
33-
this.create_text(node.nodes);
34-
break;
35-
36-
case 'push_element': {
37-
this.push_element();
38-
break;
39-
}
40-
41-
case 'pop_element': {
42-
this.pop_element();
43-
break;
44-
}
45-
46-
case 'set_prop': {
47-
this.set_prop(node.key, node.value);
48-
break;
49-
}
50-
}
51-
}
52-
}
53-
5416
/** @param {string} name */
5517
create_element(name) {
5618
this.#element = {
@@ -63,7 +25,7 @@ export class Template {
6325
this.#fragment.push(this.#element);
6426
}
6527

66-
/** @param {string | undefined} data */
28+
/** @param {string} [data] */
6729
create_anchor(data) {
6830
this.#fragment.push({ type: 'anchor', data });
6931
}

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,6 @@ export interface ClientTransformState extends TransformState {
3737
>;
3838
}
3939

40-
type TemplateOperation =
41-
| {
42-
kind: 'create_element';
43-
name: string;
44-
}
45-
| {
46-
kind: 'create_text';
47-
nodes: AST.Text[];
48-
}
49-
| {
50-
kind: 'create_anchor';
51-
data?: string;
52-
}
53-
| {
54-
kind: 'set_prop';
55-
key: string;
56-
value: string | undefined;
57-
}
58-
| {
59-
kind: 'push_element';
60-
}
61-
| {
62-
kind: 'pop_element';
63-
};
64-
6540
export interface ComponentClientTransformState extends ClientTransformState {
6641
readonly analysis: ComponentAnalysis;
6742
readonly options: ValidatedCompileOptions;

packages/svelte/src/compiler/phases/3-transform/client/visitors/AwaitBlock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { get_value } from './shared/declarations.js';
1111
* @param {ComponentContext} context
1212
*/
1313
export function AwaitBlock(node, context) {
14-
context.state.template.push({ kind: 'create_anchor' });
14+
context.state.template.create_anchor();
1515

1616
// Visit {#await <expression>} first to ensure that scopes are in the correct order
1717
const expression = b.thunk(/** @type {Expression} */ (context.visit(node.expression)));

packages/svelte/src/compiler/phases/3-transform/client/visitors/Comment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
*/
88
export function Comment(node, context) {
99
// We'll only get here if comments are not filtered out, which they are unless preserveComments is true
10-
context.state.template.push({ kind: 'create_anchor', data: node.data });
10+
context.state.template.create_anchor(node.data);
1111
}

packages/svelte/src/compiler/phases/3-transform/client/visitors/EachBlock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function EachBlock(node, context) {
3232
);
3333

3434
if (!each_node_meta.is_controlled) {
35-
context.state.template.push({ kind: 'create_anchor' });
35+
context.state.template.create_anchor();
3636
}
3737

3838
let flags = 0;

packages/svelte/src/compiler/phases/3-transform/client/visitors/HtmlTag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as b from '#compiler/builders';
99
* @param {ComponentContext} context
1010
*/
1111
export function HtmlTag(node, context) {
12-
context.state.template.push({ kind: 'create_anchor' });
12+
context.state.template.create_anchor();
1313

1414
const expression = /** @type {Expression} */ (context.visit(node.expression));
1515

packages/svelte/src/compiler/phases/3-transform/client/visitors/IfBlock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as b from '#compiler/builders';
88
* @param {ComponentContext} context
99
*/
1010
export function IfBlock(node, context) {
11-
context.state.template.push({ kind: 'create_anchor' });
11+
context.state.template.create_anchor();
1212
const statements = [];
1313

1414
const consequent = /** @type {BlockStatement} */ (context.visit(node.consequent));

packages/svelte/src/compiler/phases/3-transform/client/visitors/KeyBlock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as b from '#compiler/builders';
88
* @param {ComponentContext} context
99
*/
1010
export function KeyBlock(node, context) {
11-
context.state.template.push({ kind: 'create_anchor' });
11+
context.state.template.create_anchor();
1212

1313
const key = /** @type {Expression} */ (context.visit(node.expression));
1414
const body = /** @type {Expression} */ (context.visit(node.fragment));

packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ export function RegularElement(node, context) {
5252
}
5353

5454
if (node.name === 'noscript') {
55-
context.state.template.push({
56-
kind: 'create_element',
57-
name: 'noscript'
58-
});
55+
context.state.template.create_element('noscript');
5956
return;
6057
}
6158

@@ -75,10 +72,7 @@ export function RegularElement(node, context) {
7572
context.state.metadata.context.template_contains_script_tag = true;
7673
}
7774

78-
context.state.template.push({
79-
kind: 'create_element',
80-
name: node.name
81-
});
75+
context.state.template.create_element(node.name);
8276

8377
/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
8478
const attributes = [];
@@ -116,11 +110,7 @@ export function RegularElement(node, context) {
116110
const { value } = build_attribute_value(attribute.value, context);
117111

118112
if (value.type === 'Literal' && typeof value.value === 'string') {
119-
context.state.template.push({
120-
kind: 'set_prop',
121-
key: 'is',
122-
value: value.value
123-
});
113+
context.state.template.set_prop('is', value.value);
124114
continue;
125115
}
126116
}
@@ -300,12 +290,10 @@ export function RegularElement(node, context) {
300290
}
301291

302292
if (name !== 'class' || value) {
303-
context.state.template.push({
304-
kind: 'set_prop',
305-
key: attribute.name,
306-
value:
307-
is_boolean_attribute(name) && value === true ? undefined : value === true ? '' : value
308-
});
293+
context.state.template.set_prop(
294+
attribute.name,
295+
is_boolean_attribute(name) && value === true ? undefined : value === true ? '' : value
296+
);
309297
}
310298
} else if (name === 'autofocus') {
311299
let { value } = build_attribute_value(attribute.value, context);
@@ -337,7 +325,8 @@ export function RegularElement(node, context) {
337325
) {
338326
context.state.after_update.push(b.stmt(b.call('$.replay_events', node_id)));
339327
}
340-
context.state.template.push({ kind: 'push_element' });
328+
329+
context.state.template.push_element();
341330

342331
const metadata = {
343332
...context.state.metadata,
@@ -458,7 +447,7 @@ export function RegularElement(node, context) {
458447
// @ts-expect-error
459448
location.push(state.locations);
460449
}
461-
context.state.template.push({ kind: 'pop_element' });
450+
context.state.template.pop_element();
462451
}
463452

464453
/**

packages/svelte/src/compiler/phases/3-transform/client/visitors/RenderTag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as b from '#compiler/builders';
99
* @param {ComponentContext} context
1010
*/
1111
export function RenderTag(node, context) {
12-
context.state.template.push({ kind: 'create_anchor' });
12+
context.state.template.create_anchor();
1313

1414
const expression = unwrap_optional(node.expression);
1515

0 commit comments

Comments
 (0)