@@ -2439,10 +2439,11 @@ namespace ts {
2439
2439
}
2440
2440
2441
2441
function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration | VariableDeclaration, dontResolveAlias: boolean): Symbol | undefined {
2442
- if (isVariableDeclaration(node) && node.initializer && isPropertyAccessExpression(node.initializer)) {
2443
- const name = (getLeftmostAccessExpression(node.initializer.expression) as CallExpression).arguments[0] as StringLiteral;
2444
- return isIdentifier(node.initializer.name)
2445
- ? resolveSymbol(getPropertyOfType(resolveExternalModuleTypeByLiteral(name), node.initializer.name.escapedText))
2442
+ const commonJSPropertyAccess = getCommonJSPropertyAccess(node)
2443
+ if (commonJSPropertyAccess) {
2444
+ const name = (getLeftmostAccessExpression(commonJSPropertyAccess.expression) as CallExpression).arguments[0] as StringLiteral;
2445
+ return isIdentifier(commonJSPropertyAccess.name)
2446
+ ? resolveSymbol(getPropertyOfType(resolveExternalModuleTypeByLiteral(name), commonJSPropertyAccess.name.escapedText))
2446
2447
: undefined;
2447
2448
}
2448
2449
if (isVariableDeclaration(node) || node.moduleReference.kind === SyntaxKind.ExternalModuleReference) {
@@ -2637,15 +2638,17 @@ namespace ts {
2637
2638
return result;
2638
2639
}
2639
2640
2640
- function getExportOfModule(symbol: Symbol, specifier: ImportOrExportSpecifier | BindingElement, dontResolveAlias: boolean): Symbol | undefined {
2641
+ function getExportOfModule(symbol: Symbol, specifier: ImportOrExportSpecifier | BindingElement | PropertyAccessExpression , dontResolveAlias: boolean): Symbol | undefined {
2641
2642
if (symbol.flags & SymbolFlags.Module) {
2642
- const name = specifier.propertyName ?? specifier.name;
2643
+ const name = !isPropertyAccessExpression( specifier) && specifier .propertyName || specifier.name;
2643
2644
if (!isIdentifier(name)) {
2644
2645
return undefined;
2645
2646
}
2646
2647
const exportSymbol = getExportsOfSymbol(symbol).get(name.escapedText);
2647
2648
const resolved = resolveSymbol(exportSymbol, dontResolveAlias);
2648
- markSymbolOfAliasDeclarationIfTypeOnly(specifier, exportSymbol, resolved, /*overwriteEmpty*/ false);
2649
+ if (!isPropertyAccessExpression(specifier)) {
2650
+ markSymbolOfAliasDeclarationIfTypeOnly(specifier, exportSymbol, resolved, /*overwriteEmpty*/ false);
2651
+ }
2649
2652
return resolved;
2650
2653
}
2651
2654
}
@@ -2659,6 +2662,12 @@ namespace ts {
2659
2662
}
2660
2663
}
2661
2664
2665
+ function getCommonJSPropertyAccess(node: Node) {
2666
+ if(isVariableDeclaration(node) && node.initializer && isPropertyAccessExpression(node.initializer)) {
2667
+ return node.initializer;
2668
+ }
2669
+ }
2670
+
2662
2671
function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration | VariableDeclaration, specifier: ImportOrExportSpecifier | BindingElement, dontResolveAlias = false): Symbol | undefined {
2663
2672
const moduleSpecifier = getExternalModuleRequireArgument(node) || (node as ImportDeclaration | ExportDeclaration).moduleSpecifier!;
2664
2673
const moduleSymbol = resolveExternalModuleName(node, moduleSpecifier)!; // TODO: GH#18217
@@ -2682,10 +2691,14 @@ namespace ts {
2682
2691
else {
2683
2692
symbolFromVariable = getPropertyOfVariable(targetSymbol, name.escapedText);
2684
2693
}
2685
-
2686
2694
// if symbolFromVariable is export - get its final target
2687
2695
symbolFromVariable = resolveSymbol(symbolFromVariable, dontResolveAlias);
2688
- let symbolFromModule = getExportOfModule(targetSymbol, specifier, dontResolveAlias);
2696
+
2697
+ const commonJSPropertyAccess = getCommonJSPropertyAccess(node)
2698
+ let symbolFromModule = getExportOfModule(targetSymbol, commonJSPropertyAccess || specifier, dontResolveAlias);
2699
+ if (commonJSPropertyAccess && symbolFromModule) {
2700
+ symbolFromModule = getPropertyOfType(getTypeOfSymbol(symbolFromModule), name.escapedText);
2701
+ }
2689
2702
if (symbolFromModule === undefined && name.escapedText === InternalSymbolName.Default) {
2690
2703
const file = find(moduleSymbol.declarations, isSourceFile);
2691
2704
if (canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias)) {
0 commit comments