Skip to content

Commit e0f1daf

Browse files
committed
reuse expression
1 parent c06b252 commit e0f1daf

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ export function VariableDeclaration(node, context) {
116116
}
117117

118118
const args = /** @type {CallExpression} */ (init).arguments;
119-
const value =
120-
args.length === 0
121-
? b.unary('void', b.literal(0))
122-
: /** @type {Expression} */ (context.visit(args[0]));
119+
const value = args.length > 0 ? /** @type {Expression} */ (context.visit(args[0])) : b.void0;
123120

124121
if (rune === '$state' || rune === '$state.raw') {
125122
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ export function CallExpression(node, context) {
1313
const rune = get_rune(node, context.state.scope);
1414

1515
if (rune === '$host') {
16-
return b.unary('void', b.literal(0));
16+
return b.void0;
1717
}
1818

1919
if (rune === '$effect.tracking') {
20-
return b.literal(false);
20+
return b.false;
2121
}
2222

2323
if (rune === '$effect.root') {

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function VariableDeclaration(node, context) {
4545
) {
4646
const right = node.right.arguments.length
4747
? /** @type {Expression} */ (context.visit(node.right.arguments[0]))
48-
: b.unary('void', b.literal(0));
48+
: b.void0;
4949
return b.assignment_pattern(node.left, right);
5050
}
5151
}
@@ -75,10 +75,7 @@ export function VariableDeclaration(node, context) {
7575
}
7676

7777
const args = /** @type {CallExpression} */ (init).arguments;
78-
const value =
79-
args.length === 0
80-
? b.unary('void', b.literal(0))
81-
: /** @type {Expression} */ (context.visit(args[0]));
78+
const value = args.length > 0 ? /** @type {Expression} */ (context.visit(args[0])) : b.void0;
8279

8380
if (rune === '$derived.by') {
8481
declarations.push(

packages/svelte/src/compiler/utils/builders.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ export function unary(operator, argument) {
154154
return { type: 'UnaryExpression', argument, operator, prefix: true };
155155
}
156156

157+
export const void0 = unary('void', b.literal(0));
158+
157159
/**
158160
* @param {ESTree.Expression} test
159161
* @param {ESTree.Expression} consequent

0 commit comments

Comments
 (0)