Skip to content

Commit 30d3479

Browse files
committed
chore: simplify build_template
1 parent d26fb1f commit 30d3479

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

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

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

4747
if (node.fallback) {
48-
const open = b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), block_open));
48+
const open = b.stmt(b.call(b.id('$$payload.push'), block_open));
4949

5050
const fallback = /** @type {BlockStatement} */ (context.visit(node.fallback));
5151

packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/utils.js

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,9 @@ function is_statement(node) {
103103

104104
/**
105105
* @param {Array<Statement | Expression>} template
106-
* @param {Identifier} out
107-
* @param {AssignmentOperator | 'push'} operator
108106
* @returns {Statement[]}
109107
*/
110-
export function build_template(template, out = b.id('$$payload'), operator = 'push') {
108+
export function build_template(template) {
111109
/** @type {string[]} */
112110
let strings = [];
113111

@@ -118,32 +116,18 @@ export function build_template(template, out = b.id('$$payload'), operator = 'pu
118116
const statements = [];
119117

120118
const flush = () => {
121-
if (operator === 'push') {
122-
statements.push(
123-
b.stmt(
124-
b.call(
125-
b.member(out, b.id('push')),
126-
b.template(
127-
strings.map((cooked, i) => b.quasi(cooked, i === strings.length - 1)),
128-
expressions
129-
)
130-
)
131-
)
132-
);
133-
} else {
134-
statements.push(
135-
b.stmt(
136-
b.assignment(
137-
operator,
138-
out,
139-
b.template(
140-
strings.map((cooked, i) => b.quasi(cooked, i === strings.length - 1)),
141-
expressions
142-
)
119+
statements.push(
120+
b.stmt(
121+
b.call(
122+
b.id('$$payload.push'),
123+
b.template(
124+
strings.map((cooked, i) => b.quasi(cooked, i === strings.length - 1)),
125+
expressions
143126
)
144127
)
145-
);
146-
}
128+
)
129+
);
130+
147131
strings = [];
148132
expressions = [];
149133
};

0 commit comments

Comments
 (0)