Skip to content

Commit 977a7ec

Browse files
committed
Merge pull request microsoft#8509 from Microsoft/Fix8507
Fix microsoft#8507: Consider UnknownSymbols values for import/export purposes
2 parents d9657b4 + 5e9fc58 commit 977a7ec

35 files changed

+94
-23
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,9 +1136,8 @@ namespace ts {
11361136
const symbol = getSymbolOfNode(node);
11371137
const target = resolveAlias(symbol);
11381138
if (target) {
1139-
const markAlias =
1140-
(target === unknownSymbol && compilerOptions.isolatedModules) ||
1141-
(target !== unknownSymbol && (target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target));
1139+
const markAlias = target === unknownSymbol ||
1140+
((target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target));
11421141

11431142
if (markAlias) {
11441143
markAliasSymbolAsReferenced(symbol);
@@ -2633,7 +2632,7 @@ namespace ts {
26332632
const internalModuleReference = <Identifier | QualifiedName>(<ImportEqualsDeclaration>declaration).moduleReference;
26342633
const firstIdentifier = getFirstIdentifier(internalModuleReference);
26352634
const importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace,
2636-
Diagnostics.Cannot_find_name_0, firstIdentifier);
2635+
undefined, undefined);
26372636
if (importSymbol) {
26382637
buildVisibleNodeList(importSymbol.declarations);
26392638
}
@@ -17113,14 +17112,12 @@ namespace ts {
1711317112

1711417113
function isAliasResolvedToValue(symbol: Symbol): boolean {
1711517114
const target = resolveAlias(symbol);
17116-
if (target === unknownSymbol && compilerOptions.isolatedModules) {
17115+
if (target === unknownSymbol) {
1711717116
return true;
1711817117
}
1711917118
// const enums and modules that contain only const enums are not considered values from the emit perspective
1712017119
// unless 'preserveConstEnums' option is set to true
17121-
return target !== unknownSymbol &&
17122-
target &&
17123-
target.flags & SymbolFlags.Value &&
17120+
return target.flags & SymbolFlags.Value &&
1712417121
(compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(target));
1712517122
}
1712617123

tests/baselines/reference/ExportAssignment7.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ var C = (function () {
1212
return C;
1313
}());
1414
exports.C = C;
15+
module.exports = B;

tests/baselines/reference/ExportAssignment8.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ var C = (function () {
1212
return C;
1313
}());
1414
exports.C = C;
15+
module.exports = B;

tests/baselines/reference/aliasErrors.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ var foo;
5555
var provide = foo;
5656
var booz = foo.bar.baz;
5757
var beez = foo.bar;
58+
var m = no;
59+
var m2 = no.mod;
5860
5;
5961
"s";
6062
null;
63+
var r = undefined;
6164
var p = new provide.Provide();
6265
function use() {
6366
beez.baz.boo;

tests/baselines/reference/blockScopedFunctionDeclarationInStrictModule.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ define(["require", "exports"], function (require, exports) {
1313
function foo() { }
1414
foo(); // ok
1515
}
16+
return foo;
1617
});

tests/baselines/reference/classAbstractManyKeywords.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import abstract class D {}
66

77
//// [classAbstractManyKeywords.js]
88
"use strict";
9+
exports.__esModule = true;
10+
exports["default"] = abstract;
911
var A = (function () {
1012
function A() {
1113
}
@@ -22,6 +24,7 @@ var C = (function () {
2224
}
2325
return C;
2426
}());
27+
var abstract = ;
2528
var D = (function () {
2629
function D() {
2730
}

tests/baselines/reference/declarationEmit_UnknownImport.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,1): error TS2304: Cannot find name 'SomeNonExistingName'.
1+
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,14): error TS2304: Cannot find name 'SomeNonExistingName'.
22
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,14): error TS2503: Cannot find namespace 'SomeNonExistingName'.
33
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,14): error TS4000: Import declaration 'Foo' is using private name 'SomeNonExistingName'.
44

55

66
==== tests/cases/compiler/declarationEmit_UnknownImport.ts (3 errors) ====
77

88
import Foo = SomeNonExistingName
9-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
~~~~~~~~~~~~~~~~~~~
1010
!!! error TS2304: Cannot find name 'SomeNonExistingName'.
1111
~~~~~~~~~~~~~~~~~~~
1212
!!! error TS2503: Cannot find namespace 'SomeNonExistingName'.

tests/baselines/reference/declarationEmit_UnknownImport.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ export {Foo}
55

66
//// [declarationEmit_UnknownImport.js]
77
"use strict";
8+
var Foo = SomeNonExistingName;
9+
exports.Foo = Foo;

tests/baselines/reference/declarationEmit_UnknownImport2.errors.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,1): error TS2304: Cannot find name 'From'.
21
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS1005: '=' expected.
2+
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS2304: Cannot find name 'From'.
33
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS2503: Cannot find namespace 'From'.
44
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS4000: Import declaration 'Foo' is using private name 'From'.
55
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,17): error TS1005: ';' expected.
@@ -8,11 +8,11 @@ tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,17): error TS1005: ';'
88
==== tests/cases/compiler/declarationEmit_UnknownImport2.ts (5 errors) ====
99

1010
import Foo From './Foo'; // Syntax error
11-
~~~~~~~~~~~~~~~
12-
!!! error TS2304: Cannot find name 'From'.
1311
~~~~
1412
!!! error TS1005: '=' expected.
1513
~~~~
14+
!!! error TS2304: Cannot find name 'From'.
15+
~~~~
1616
!!! error TS2503: Cannot find namespace 'From'.
1717
~~~~
1818
!!! error TS4000: Import declaration 'Foo' is using private name 'From'.

tests/baselines/reference/declarationEmit_UnknownImport2.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ export default Foo
55

66
//// [declarationEmit_UnknownImport2.js]
77
"use strict";
8+
var Foo = From;
89
'./Foo'; // Syntax error
10+
Object.defineProperty(exports, "__esModule", { value: true });
11+
exports.default = Foo;

0 commit comments

Comments
 (0)