Skip to content

Commit ec2bb95

Browse files
committed
replace 'undefined' with 'void 0'
1 parent 5d3aa2b commit ec2bb95

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

.changeset/curvy-countries-flow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: replace `undefined` with `void 0` to avoid edge case

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function VariableDeclaration(node, context) {
117117

118118
const args = /** @type {CallExpression} */ (init).arguments;
119119
const value =
120-
args.length === 0 ? b.id('undefined') : /** @type {Expression} */ (context.visit(args[0]));
120+
args.length === 0 ? b.unary('void', b.literal(0)) : /** @type {Expression} */ (context.visit(args[0]));
121121

122122
if (rune === '$state' || rune === '$state.raw') {
123123
/**

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

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

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

1919
if (rune === '$effect.tracking') {

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

Lines changed: 2 additions & 2 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.id('undefined');
48+
: b.unary('void', b.literal(0));
4949
return b.assignment_pattern(node.left, right);
5050
}
5151
}
@@ -76,7 +76,7 @@ export function VariableDeclaration(node, context) {
7676

7777
const args = /** @type {CallExpression} */ (init).arguments;
7878
const value =
79-
args.length === 0 ? b.id('undefined') : /** @type {Expression} */ (context.visit(args[0]));
79+
args.length === 0 ? b.unary('void', b.literal(0)) : /** @type {Expression} */ (context.visit(args[0]));
8080

8181
if (rune === '$derived.by') {
8282
declarations.push(

0 commit comments

Comments
 (0)