Skip to content

Commit 94ea388

Browse files
author
Andy
authored
Disable import fix for method of 'export =' value (#20208)
* Disable import fix for method of 'export =' value * Exclude primitives, but allow other interfaces * Use type.flags * Fix comment
1 parent 5ee640d commit 94ea388

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,13 +1898,17 @@ namespace ts {
18981898

18991899
function tryGetMemberInModuleExportsAndProperties(memberName: __String, moduleSymbol: Symbol): Symbol | undefined {
19001900
const symbol = tryGetMemberInModuleExports(memberName, moduleSymbol);
1901-
if (!symbol) {
1902-
const exportEquals = resolveExternalModuleSymbol(moduleSymbol);
1903-
if (exportEquals !== moduleSymbol) {
1904-
return getPropertyOfType(getTypeOfSymbol(exportEquals), memberName);
1905-
}
1901+
if (symbol) {
1902+
return symbol;
19061903
}
1907-
return symbol;
1904+
1905+
const exportEquals = resolveExternalModuleSymbol(moduleSymbol);
1906+
if (exportEquals === moduleSymbol) {
1907+
return undefined;
1908+
}
1909+
1910+
const type = getTypeOfSymbol(exportEquals);
1911+
return type.flags & TypeFlags.Primitive ? undefined : getPropertyOfType(type, memberName);
19081912
}
19091913

19101914
function getExportsOfSymbol(symbol: Symbol): SymbolTable {

src/compiler/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2766,7 +2766,10 @@ namespace ts {
27662766
getAmbientModules(): Symbol[];
27672767

27682768
tryGetMemberInModuleExports(memberName: string, moduleSymbol: Symbol): Symbol | undefined;
2769-
/** Unlike `tryGetMemberInModuleExports`, this includes properties of an `export =` value. */
2769+
/**
2770+
* Unlike `tryGetMemberInModuleExports`, this includes properties of an `export =` value.
2771+
* Does *not* return properties of primitive types.
2772+
*/
27702773
/* @internal */ tryGetMemberInModuleExportsAndProperties(memberName: string, moduleSymbol: Symbol): Symbol | undefined;
27712774
getApparentType(type: Type): Type;
27722775
getSuggestionForNonexistentProperty(node: Identifier, containingType: Type): string | undefined;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////[|valueOf/*0*/();|]
4+
5+
// @Filename: foo.ts
6+
////declare var x: number;
7+
////export = x;
8+
9+
verify.not.codeFixAvailable(); // See GH#20191

tests/cases/fourslash/importNameCodeFixNewImportFile5.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//// declare var x: MyStatic;
1010
//// export = x;
1111

12-
verify.importFixAtPosition([
12+
-verify.importFixAtPosition([
1313
`import { bar } from "./foo";
1414
1515
bar();`
16-
]);
16+
]);

0 commit comments

Comments
 (0)