fix: replace `undefined` with `void 0` to avoid edge case (#15511)

* replace 'undefined' with 'void 0'

* lint

* YALF

* reuse expression

* oops

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/15513/head
ComputerGuy 6 months ago committed by GitHub
parent 5d3aa2bda4
commit 489f463d7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: replace `undefined` with `void 0` to avoid edge case

@ -116,8 +116,7 @@ export function VariableDeclaration(node, context) {
}
const args = /** @type {CallExpression} */ (init).arguments;
const value =
args.length === 0 ? b.id('undefined') : /** @type {Expression} */ (context.visit(args[0]));
const value = args.length > 0 ? /** @type {Expression} */ (context.visit(args[0])) : b.void0;
if (rune === '$state' || rune === '$state.raw') {
/**

@ -13,11 +13,11 @@ export function CallExpression(node, context) {
const rune = get_rune(node, context.state.scope);
if (rune === '$host') {
return b.id('undefined');
return b.void0;
}
if (rune === '$effect.tracking') {
return b.literal(false);
return b.false;
}
if (rune === '$effect.root') {

@ -45,7 +45,7 @@ export function VariableDeclaration(node, context) {
) {
const right = node.right.arguments.length
? /** @type {Expression} */ (context.visit(node.right.arguments[0]))
: b.id('undefined');
: b.void0;
return b.assignment_pattern(node.left, right);
}
}
@ -75,8 +75,7 @@ export function VariableDeclaration(node, context) {
}
const args = /** @type {CallExpression} */ (init).arguments;
const value =
args.length === 0 ? b.id('undefined') : /** @type {Expression} */ (context.visit(args[0]));
const value = args.length > 0 ? /** @type {Expression} */ (context.visit(args[0])) : b.void0;
if (rune === '$derived.by') {
declarations.push(

@ -154,6 +154,8 @@ export function unary(operator, argument) {
return { type: 'UnaryExpression', argument, operator, prefix: true };
}
export const void0 = unary('void', literal(0));
/**
* @param {ESTree.Expression} test
* @param {ESTree.Expression} consequent

Loading…
Cancel
Save