Skip to content

Commit 2add7b3

Browse files
committed
explicit type narrowing lets us avoid coercion
1 parent 3f402c6 commit 2add7b3

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ export function CallExpression(node, context) {
4747
parent?.left?.type === 'MemberExpression' &&
4848
context.state.in_constructor
4949
) {
50-
/** @type {ClassDeclaration | ClassExpression} */
51-
const constructor = /** @type {ClassDeclaration | ClassExpression} */ (
52-
context.path.findLast((parent) => parent.type.match(/^Class(Declaration|Expression)$/))
50+
const constructor = context.path.findLast(
51+
(parent) => parent.type === 'ClassDeclaration' || parent.type === 'ClassExpression'
5352
);
5453
const property = get_name(parent.left.property);
5554
source_tag = `${constructor?.id?.name ?? '[class]'}.${property}`;
@@ -70,9 +69,8 @@ export function CallExpression(node, context) {
7069
parent?.left?.type === 'MemberExpression' &&
7170
context.state.in_constructor
7271
) {
73-
/** @type {ClassDeclaration | ClassExpression} */
74-
const constructor = /** @type {ClassDeclaration | ClassExpression} */ (
75-
context.path.findLast((parent) => parent.type.match(/^Class(Declaration|Expression)$/))
72+
const constructor = context.path.findLast(
73+
(parent) => parent.type === 'ClassDeclaration' || parent.type === 'ClassExpression'
7674
);
7775
const property = get_name(parent.left.property);
7876
source_tag = `${constructor?.id?.name ?? '[class]'}.${property}`;

0 commit comments

Comments
 (0)