Skip to content

Commit b4becd4

Browse files
committed
Fix #8507: Consider UnknownSymbols values for import/export purposes
1 parent 33abdad commit b4becd4

35 files changed

+96
-19
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,9 +1133,8 @@ namespace ts {
11331133
const symbol = getSymbolOfNode(node);
11341134
const target = resolveAlias(symbol);
11351135
if (target) {
1136-
const markAlias =
1137-
(target === unknownSymbol && compilerOptions.isolatedModules) ||
1138-
(target !== unknownSymbol && (target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target));
1136+
const markAlias = target === unknownSymbol ||
1137+
((target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target));
11391138

11401139
if (markAlias) {
11411140
markAliasSymbolAsReferenced(symbol);
@@ -16983,14 +16982,12 @@ namespace ts {
1698316982

1698416983
function isAliasResolvedToValue(symbol: Symbol): boolean {
1698516984
const target = resolveAlias(symbol);
16986-
if (target === unknownSymbol && compilerOptions.isolatedModules) {
16985+
if (target === unknownSymbol) {
1698716986
return true;
1698816987
}
1698916988
// const enums and modules that contain only const enums are not considered values from the emit perspective
1699016989
// unless 'preserveConstEnums' option is set to true
16991-
return target !== unknownSymbol &&
16992-
target &&
16993-
target.flags & SymbolFlags.Value &&
16990+
return target.flags & SymbolFlags.Value &&
1699416991
(compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(target));
1699516992
}
1699616993

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,1): error TS2304: Cannot find name 'SomeNonExistingName'.
2+
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,14): error TS2304: Cannot find name 'SomeNonExistingName'.
23
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,14): error TS2503: Cannot find namespace 'SomeNonExistingName'.
34
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,14): error TS4000: Import declaration 'Foo' is using private name 'SomeNonExistingName'.
45

56

6-
==== tests/cases/compiler/declarationEmit_UnknownImport.ts (3 errors) ====
7+
==== tests/cases/compiler/declarationEmit_UnknownImport.ts (4 errors) ====
78

89
import Foo = SomeNonExistingName
910
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1011
!!! error TS2304: Cannot find name 'SomeNonExistingName'.
1112
~~~~~~~~~~~~~~~~~~~
13+
!!! error TS2304: Cannot find name 'SomeNonExistingName'.
14+
~~~~~~~~~~~~~~~~~~~
1215
!!! error TS2503: Cannot find namespace 'SomeNonExistingName'.
1316
~~~~~~~~~~~~~~~~~~~
1417
!!! error TS4000: Import declaration 'Foo' is using private name '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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,1): error TS2304: Cannot find name 'From'.
22
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS1005: '=' expected.
3+
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS2304: Cannot find name 'From'.
34
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS2503: Cannot find namespace 'From'.
45
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS4000: Import declaration 'Foo' is using private name 'From'.
56
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,17): error TS1005: ';' expected.
67

78

8-
==== tests/cases/compiler/declarationEmit_UnknownImport2.ts (5 errors) ====
9+
==== tests/cases/compiler/declarationEmit_UnknownImport2.ts (6 errors) ====
910

1011
import Foo From './Foo'; // Syntax error
1112
~~~~~~~~~~~~~~~
1213
!!! error TS2304: Cannot find name 'From'.
1314
~~~~
1415
!!! error TS1005: '=' expected.
1516
~~~~
17+
!!! error TS2304: Cannot find name 'From'.
18+
~~~~
1619
!!! error TS2503: Cannot find namespace 'From'.
1720
~~~~
1821
!!! 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)