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;

tests/baselines/reference/es6ExportEqualsInterop.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ function_module_1.a;
275275
class_1.a;
276276
class_module_1.a;
277277
// named export
278+
var interface_2 = require("interface");
279+
exports.a1 = interface_2.a;
278280
var variable_2 = require("variable");
279281
exports.a2 = variable_2.a;
280282
var interface_variable_2 = require("interface-variable");
@@ -285,8 +287,12 @@ var interface_module_2 = require("interface-module");
285287
exports.a5 = interface_module_2.a;
286288
var variable_module_2 = require("variable-module");
287289
exports.a6 = variable_module_2.a;
290+
var function_2 = require("function");
291+
exports.a7 = function_2.a;
288292
var function_module_2 = require("function-module");
289293
exports.a8 = function_module_2.a;
294+
var class_2 = require("class");
295+
exports.a9 = class_2.a;
290296
var class_module_2 = require("class-module");
291297
exports.a0 = class_module_2.a;
292298
// export-star

tests/baselines/reference/importDeclWithClassModifiers.errors.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
tests/cases/compiler/importDeclWithClassModifiers.ts(5,8): error TS1044: 'public' modifier cannot appear on a module or namespace element.
2+
tests/cases/compiler/importDeclWithClassModifiers.ts(5,26): error TS2304: Cannot find name 'x'.
23
tests/cases/compiler/importDeclWithClassModifiers.ts(5,28): error TS2305: Module 'x' has no exported member 'c'.
34
tests/cases/compiler/importDeclWithClassModifiers.ts(6,8): error TS1044: 'private' modifier cannot appear on a module or namespace element.
5+
tests/cases/compiler/importDeclWithClassModifiers.ts(6,27): error TS2304: Cannot find name 'x'.
46
tests/cases/compiler/importDeclWithClassModifiers.ts(6,29): error TS2305: Module 'x' has no exported member 'c'.
57
tests/cases/compiler/importDeclWithClassModifiers.ts(7,8): error TS1044: 'static' modifier cannot appear on a module or namespace element.
8+
tests/cases/compiler/importDeclWithClassModifiers.ts(7,26): error TS2304: Cannot find name 'x'.
69
tests/cases/compiler/importDeclWithClassModifiers.ts(7,28): error TS2305: Module 'x' has no exported member 'c'.
710

811

9-
==== tests/cases/compiler/importDeclWithClassModifiers.ts (6 errors) ====
12+
==== tests/cases/compiler/importDeclWithClassModifiers.ts (9 errors) ====
1013
module x {
1114
interface c {
1215
}
1316
}
1417
export public import a = x.c;
1518
~~~~~~
1619
!!! error TS1044: 'public' modifier cannot appear on a module or namespace element.
20+
~
21+
!!! error TS2304: Cannot find name 'x'.
1722
~
1823
!!! error TS2305: Module 'x' has no exported member 'c'.
1924
export private import b = x.c;
2025
~~~~~~~
2126
!!! error TS1044: 'private' modifier cannot appear on a module or namespace element.
27+
~
28+
!!! error TS2304: Cannot find name 'x'.
2229
~
2330
!!! error TS2305: Module 'x' has no exported member 'c'.
2431
export static import c = x.c;
2532
~~~~~~
2633
!!! error TS1044: 'static' modifier cannot appear on a module or namespace element.
34+
~
35+
!!! error TS2304: Cannot find name 'x'.
2736
~
2837
!!! error TS2305: Module 'x' has no exported member 'c'.
2938
var b: a;

tests/baselines/reference/importDeclWithClassModifiers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ var b: a;
1212
//// [importDeclWithClassModifiers.js]
1313
define(["require", "exports"], function (require, exports) {
1414
"use strict";
15+
exports.a = x.c;
16+
exports.b = x.c;
17+
exports.c = x.c;
1518
var b;
1619
});

tests/baselines/reference/importDeclWithDeclareModifier.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
tests/cases/compiler/importDeclWithDeclareModifier.ts(5,9): error TS1029: 'export' modifier must precede 'declare' modifier.
2+
tests/cases/compiler/importDeclWithDeclareModifier.ts(5,27): error TS2304: Cannot find name 'x'.
23
tests/cases/compiler/importDeclWithDeclareModifier.ts(5,29): error TS2305: Module 'x' has no exported member 'c'.
34

45

5-
==== tests/cases/compiler/importDeclWithDeclareModifier.ts (2 errors) ====
6+
==== tests/cases/compiler/importDeclWithDeclareModifier.ts (3 errors) ====
67
module x {
78
interface c {
89
}
910
}
1011
declare export import a = x.c;
1112
~~~~~~
1213
!!! error TS1029: 'export' modifier must precede 'declare' modifier.
14+
~
15+
!!! error TS2304: Cannot find name 'x'.
1316
~
1417
!!! error TS2305: Module 'x' has no exported member 'c'.
1518
var b: a;

tests/baselines/reference/importDeclWithExportModifier.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
tests/cases/compiler/importDeclWithExportModifier.ts(5,19): error TS2304: Cannot find name 'x'.
12
tests/cases/compiler/importDeclWithExportModifier.ts(5,21): error TS2305: Module 'x' has no exported member 'c'.
23

34

4-
==== tests/cases/compiler/importDeclWithExportModifier.ts (1 errors) ====
5+
==== tests/cases/compiler/importDeclWithExportModifier.ts (2 errors) ====
56
module x {
67
interface c {
78
}
89
}
910
export import a = x.c;
11+
~
12+
!!! error TS2304: Cannot find name 'x'.
1013
~
1114
!!! error TS2305: Module 'x' has no exported member 'c'.
1215
var b: a;

tests/baselines/reference/importDeclWithExportModifier.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ var b: a;
1010
//// [importDeclWithExportModifier.js]
1111
define(["require", "exports"], function (require, exports) {
1212
"use strict";
13+
exports.a = x.c;
1314
var b;
1415
});

tests/baselines/reference/importDeclWithExportModifierAndExportAssignment.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
tests/cases/compiler/importDeclWithExportModifierAndExportAssignment.ts(5,19): error TS2304: Cannot find name 'x'.
12
tests/cases/compiler/importDeclWithExportModifierAndExportAssignment.ts(5,21): error TS2305: Module 'x' has no exported member 'c'.
23
tests/cases/compiler/importDeclWithExportModifierAndExportAssignment.ts(6,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
34

45

5-
==== tests/cases/compiler/importDeclWithExportModifierAndExportAssignment.ts (2 errors) ====
6+
==== tests/cases/compiler/importDeclWithExportModifierAndExportAssignment.ts (3 errors) ====
67
module x {
78
interface c {
89
}
910
}
1011
export import a = x.c;
12+
~
13+
!!! error TS2304: Cannot find name 'x'.
1114
~
1215
!!! error TS2305: Module 'x' has no exported member 'c'.
1316
export = x;

tests/baselines/reference/importDeclWithExportModifierAndExportAssignment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export = x;
88

99
//// [importDeclWithExportModifierAndExportAssignment.js]
1010
"use strict";
11+
exports.a = x.c;

tests/baselines/reference/invalidImportAliasIdentifiers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ import i = I;
2727
//// [invalidImportAliasIdentifiers.js]
2828
// none of these should work, since non are actually modules
2929
var V = 12;
30+
var v = V;
3031
var C = (function () {
3132
function C() {
3233
}
3334
return C;
3435
}());
36+
var c = C;
3537
var E;
3638
(function (E) {
3739
E[E["Red"] = 0] = "Red";
3840
E[E["Blue"] = 1] = "Blue";
3941
})(E || (E = {}));
42+
var e = E;
43+
var i = I;

tests/baselines/reference/moduleElementsInWrongContext.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
{
3535
var v;
3636
function foo() { }
37+
var ambient_2 = require("ambient");
38+
exports.b = ambient_2.baz;
3739
exports["default"] = v;
3840
var C = (function () {
3941
function C() {

tests/baselines/reference/moduleElementsInWrongContext2.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ function blah () {
3434
function blah() {
3535
var v;
3636
function foo() { }
37+
var ambient_2 = require("ambient");
38+
exports.b = ambient_2.baz;
3739
exports["default"] = v;
3840
var C = (function () {
3941
function C() {

tests/baselines/reference/moduleElementsInWrongContext3.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ var P;
3737
{
3838
var v;
3939
function foo() { }
40+
var ambient_2 = require("ambient");
41+
P.b = ambient_2.baz;
4042
P["default"] = v;
4143
var C = (function () {
4244
function C() {

tests/baselines/reference/parserExportAssignment1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export = foo
33

44
//// [parserExportAssignment1.js]
55
"use strict";
6+
module.exports = foo;

tests/baselines/reference/parserExportAssignment2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export = foo;
33

44
//// [parserExportAssignment2.js]
55
"use strict";
6+
module.exports = foo;

tests/baselines/reference/parserExportAssignment3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export =
33

44
//// [parserExportAssignment3.js]
55
"use strict";
6+
module.exports = ;

tests/baselines/reference/parserExportAssignment4.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export = ;
33

44
//// [parserExportAssignment4.js]
55
"use strict";
6+
module.exports = ;

tests/baselines/reference/parserExportAssignment7.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/parserExportAssignment8.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/parserImportDeclaration1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
import TypeScript = TypeScriptServices.TypeScript;
33

44
//// [parserImportDeclaration1.js]
5+
var TypeScript = TypeScriptServices.TypeScript;

tests/baselines/reference/privacyImportParseErrors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ var glo_im4_private_v4_private = glo_im4_private.f1();
560560
// Parse error to export module
561561
exports.glo_im1_public = glo_M1_public;
562562
exports.glo_im2_public = glo_M3_private;
563+
exports.glo_im3_public = require("glo_M2_public");
564+
exports.glo_im4_public = require("glo_M4_private");
563565
var m2;
564566
(function (m2_1) {
565567
var m4;

tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType4.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import ClassB = require("recursiveExportAssignmentAndFindAliasedType4_moduleB");
1414
export var b: ClassB; // This should result in type ClassB
1515

1616
//// [recursiveExportAssignmentAndFindAliasedType4_moduleC.js]
17-
define(["require", "exports"], function (require, exports) {
17+
define(["require", "exports", "recursiveExportAssignmentAndFindAliasedType4_moduleC"], function (require, exports, self) {
1818
"use strict";
19+
return self;
1920
});
2021
//// [recursiveExportAssignmentAndFindAliasedType4_moduleB.js]
2122
define(["require", "exports"], function (require, exports) {

tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType5.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ import ClassB = require("recursiveExportAssignmentAndFindAliasedType5_moduleB");
1818
export var b: ClassB; // This should result in type ClassB
1919

2020
//// [recursiveExportAssignmentAndFindAliasedType5_moduleD.js]
21-
define(["require", "exports"], function (require, exports) {
21+
define(["require", "exports", "recursiveExportAssignmentAndFindAliasedType5_moduleC"], function (require, exports, self) {
2222
"use strict";
23+
return self;
2324
});
2425
//// [recursiveExportAssignmentAndFindAliasedType5_moduleC.js]
25-
define(["require", "exports"], function (require, exports) {
26+
define(["require", "exports", "recursiveExportAssignmentAndFindAliasedType5_moduleD"], function (require, exports, self) {
2627
"use strict";
28+
return self;
2729
});
2830
//// [recursiveExportAssignmentAndFindAliasedType5_moduleB.js]
2931
define(["require", "exports"], function (require, exports) {

0 commit comments

Comments
 (0)