Skip to content

Commit 3eeb548

Browse files
author
Andy
authored
Fix invalid cast (microsoft#18821)
1 parent 67a6a94 commit 3eeb548

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/compiler/binder.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,16 +2271,13 @@ namespace ts {
22712271
function isExportsOrModuleExportsOrAlias(node: Node): boolean {
22722272
return isExportsIdentifier(node) ||
22732273
isModuleExportsPropertyAccessExpression(node) ||
2274-
isNameOfExportsOrModuleExportsAliasDeclaration(node);
2274+
isIdentifier(node) && isNameOfExportsOrModuleExportsAliasDeclaration(node);
22752275
}
22762276

2277-
function isNameOfExportsOrModuleExportsAliasDeclaration(node: Node) {
2278-
if (isIdentifier(node)) {
2279-
const symbol = lookupSymbolForName(node.escapedText);
2280-
return symbol && symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration) &&
2281-
symbol.valueDeclaration.initializer && isExportsOrModuleExportsOrAliasOrAssignment(symbol.valueDeclaration.initializer);
2282-
}
2283-
return false;
2277+
function isNameOfExportsOrModuleExportsAliasDeclaration(node: Identifier): boolean {
2278+
const symbol = lookupSymbolForName(node.escapedText);
2279+
return symbol && symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration) &&
2280+
symbol.valueDeclaration.initializer && isExportsOrModuleExportsOrAliasOrAssignment(symbol.valueDeclaration.initializer);
22842281
}
22852282

22862283
function isExportsOrModuleExportsOrAliasOrAssignment(node: Node): boolean {
@@ -2354,20 +2351,22 @@ namespace ts {
23542351
// Look up the function in the local scope, since prototype assignments should
23552352
// follow the function declaration
23562353
const leftSideOfAssignment = node.left as PropertyAccessExpression;
2357-
const target = leftSideOfAssignment.expression as Identifier;
2354+
const target = leftSideOfAssignment.expression;
23582355

2359-
// Fix up parent pointers since we're going to use these nodes before we bind into them
2360-
leftSideOfAssignment.parent = node;
2361-
target.parent = leftSideOfAssignment;
2356+
if (isIdentifier(target)) {
2357+
// Fix up parent pointers since we're going to use these nodes before we bind into them
2358+
leftSideOfAssignment.parent = node;
2359+
target.parent = leftSideOfAssignment;
23622360

2363-
if (isNameOfExportsOrModuleExportsAliasDeclaration(target)) {
2364-
// This can be an alias for the 'exports' or 'module.exports' names, e.g.
2365-
// var util = module.exports;
2366-
// util.property = function ...
2367-
bindExportsPropertyAssignment(node);
2368-
}
2369-
else {
2370-
bindPropertyAssignment(target.escapedText, leftSideOfAssignment, /*isPrototypeProperty*/ false);
2361+
if (isNameOfExportsOrModuleExportsAliasDeclaration(target)) {
2362+
// This can be an alias for the 'exports' or 'module.exports' names, e.g.
2363+
// var util = module.exports;
2364+
// util.property = function ...
2365+
bindExportsPropertyAssignment(node);
2366+
}
2367+
else {
2368+
bindPropertyAssignment(target.escapedText, leftSideOfAssignment, /*isPrototypeProperty*/ false);
2369+
}
23712370
}
23722371
}
23732372

0 commit comments

Comments
 (0)