From 2add7b3d1eda54f7ff9d1e9256a11ae63b9d1175 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 2 Jun 2025 15:17:59 -0400 Subject: [PATCH] explicit type narrowing lets us avoid coercion --- .../3-transform/client/visitors/CallExpression.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/CallExpression.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/CallExpression.js index 8394002adf..2bceeef6af 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/CallExpression.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/CallExpression.js @@ -47,9 +47,8 @@ export function CallExpression(node, context) { parent?.left?.type === 'MemberExpression' && context.state.in_constructor ) { - /** @type {ClassDeclaration | ClassExpression} */ - const constructor = /** @type {ClassDeclaration | ClassExpression} */ ( - context.path.findLast((parent) => parent.type.match(/^Class(Declaration|Expression)$/)) + const constructor = context.path.findLast( + (parent) => parent.type === 'ClassDeclaration' || parent.type === 'ClassExpression' ); const property = get_name(parent.left.property); source_tag = `${constructor?.id?.name ?? '[class]'}.${property}`; @@ -70,9 +69,8 @@ export function CallExpression(node, context) { parent?.left?.type === 'MemberExpression' && context.state.in_constructor ) { - /** @type {ClassDeclaration | ClassExpression} */ - const constructor = /** @type {ClassDeclaration | ClassExpression} */ ( - context.path.findLast((parent) => parent.type.match(/^Class(Declaration|Expression)$/)) + const constructor = context.path.findLast( + (parent) => parent.type === 'ClassDeclaration' || parent.type === 'ClassExpression' ); const property = get_name(parent.left.property); source_tag = `${constructor?.id?.name ?? '[class]'}.${property}`;