Skip to content

Commit fb1eb23

Browse files
committed
tweak
1 parent 9f61a3b commit fb1eb23

File tree

2 files changed

+13
-36
lines changed

2 files changed

+13
-36
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,8 @@ export function EachBlock(node, context) {
240240
id.name = context.state.scope.generate('$$array');
241241
child_state.transform[id.name] = { read: get_value };
242242

243-
declarations.push(
244-
b.var(
245-
id,
246-
b.call(
247-
'$.derived',
248-
/** @type {Expression} */ (context.visit(b.thunk(value), child_state))
249-
)
250-
)
251-
);
243+
const expression = /** @type {Expression} */ (context.visit(b.thunk(value), child_state));
244+
declarations.push(b.var(id, b.call('$.derived', expression)));
252245
}
253246

254247
for (const path of paths) {

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

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,10 @@ export function VariableDeclaration(node, context) {
138138
};
139139

140140
if (declarator.id.type === 'Identifier') {
141+
const expression = /** @type {Expression} */ (context.visit(value));
142+
141143
declarations.push(
142-
b.declarator(
143-
declarator.id,
144-
create_state_declarator(
145-
declarator.id,
146-
/** @type {Expression} */ (context.visit(value))
147-
)
148-
)
144+
b.declarator(declarator.id, create_state_declarator(declarator.id, expression))
149145
);
150146
} else {
151147
const tmp = b.id(context.state.scope.generate('tmp'));
@@ -157,10 +153,8 @@ export function VariableDeclaration(node, context) {
157153
id.name = context.state.scope.generate('$$array');
158154
context.state.transform[id.name] = { read: get_value };
159155

160-
return b.declarator(
161-
id,
162-
b.call('$.derived', /** @type {Expression} */ (context.visit(b.thunk(value))))
163-
);
156+
const expression = /** @type {Expression} */ (context.visit(b.thunk(value)));
157+
return b.declarator(id, b.call('$.derived', expression));
164158
}),
165159
...paths.map((path) => {
166160
const value = /** @type {Expression} */ (context.visit(path.expression));
@@ -205,12 +199,8 @@ export function VariableDeclaration(node, context) {
205199
id.name = context.state.scope.generate('$$array');
206200
context.state.transform[id.name] = { read: get_value };
207201

208-
declarations.push(
209-
b.declarator(
210-
id,
211-
b.call('$.derived', /** @type {Expression} */ (context.visit(b.thunk(value))))
212-
)
213-
);
202+
const expression = /** @type {Expression} */ (context.visit(b.thunk(value)));
203+
declarations.push(b.declarator(id, b.call('$.derived', expression)));
214204
}
215205

216206
for (const path of paths) {
@@ -261,12 +251,8 @@ export function VariableDeclaration(node, context) {
261251
id.name = context.state.scope.generate('$$array');
262252
context.state.transform[id.name] = { read: get_value };
263253

264-
declarations.push(
265-
b.declarator(
266-
id,
267-
b.call('$.derived', /** @type {Expression} */ (context.visit(b.thunk(value))))
268-
)
269-
);
254+
const expression = /** @type {Expression} */ (context.visit(b.thunk(value)));
255+
declarations.push(b.declarator(id, b.call('$.derived', expression)));
270256
}
271257

272258
for (const path of paths) {
@@ -349,10 +335,8 @@ function create_state_declarators(declarator, context, value) {
349335
id.name = context.state.scope.generate('$$array');
350336
context.state.transform[id.name] = { read: get_value };
351337

352-
return b.declarator(
353-
id,
354-
b.call('$.derived', /** @type {Expression} */ (context.visit(b.thunk(value))))
355-
);
338+
const expression = /** @type {Expression} */ (context.visit(b.thunk(value)));
339+
return b.declarator(id, b.call('$.derived', expression));
356340
}),
357341
...paths.map((path) => {
358342
const value = /** @type {Expression} */ (context.visit(path.expression));

0 commit comments

Comments
 (0)