replace 'undefined' with 'void 0'

pull/15511/head
ComputerGuy 1 year ago
parent 5d3aa2bda4
commit ec2bb952b2

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

@ -117,7 +117,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]));
args.length === 0 ? b.unary('void', b.literal(0)) : /** @type {Expression} */ (context.visit(args[0]));
if (rune === '$state' || rune === '$state.raw') {
/**

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

@ -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.unary('void', b.literal(0));
return b.assignment_pattern(node.left, right);
}
}
@ -76,7 +76,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]));
args.length === 0 ? b.unary('void', b.literal(0)) : /** @type {Expression} */ (context.visit(args[0]));
if (rune === '$derived.by') {
declarations.push(

Loading…
Cancel
Save