Skip to content

Commit ae5f778

Browse files
authored
fix(language-core): walk identifiers correctly within type nodes in interpolation (#5501)
1 parent 211b1f7 commit ae5f778

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/language-core/lib/codegen/template/interpolation.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ function walkIdentifiers(
231231
processFunction(ts, prop, ast, cb, ctx);
232232
}
233233
}
234-
} else if (ts.isTypeReferenceNode(node)) {
234+
} else if (ts.isTypeNode(node)) {
235235
// fix https://github.com/vuejs/language-tools/issues/1422
236-
ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
236+
walkIdentifiersInTypeNode(ts, node, cb);
237237
} else {
238238
const _blockVars = blockVars;
239239
if (ts.isBlock(node)) {
@@ -280,15 +280,19 @@ function processFunction(
280280
}
281281
}
282282

283-
function walkIdentifiersInTypeReference(
283+
function walkIdentifiersInTypeNode(
284284
ts: typeof import('typescript'),
285285
node: ts.Node,
286286
cb: (varNode: ts.Identifier, isShorthand: boolean) => void,
287287
) {
288-
if (ts.isTypeQueryNode(node) && ts.isIdentifier(node.exprName)) {
289-
cb(node.exprName, false);
288+
if (ts.isTypeQueryNode(node)) {
289+
let id = node.exprName;
290+
while (!ts.isIdentifier(id)) {
291+
id = id.left;
292+
}
293+
cb(id, false);
290294
} else {
291-
ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
295+
ts.forEachChild(node, node => walkIdentifiersInTypeNode(ts, node, cb));
292296
}
293297
}
294298

0 commit comments

Comments
 (0)