Skip to content

Commit 3ca76ca

Browse files
committed
Add null check when querying for exports from a module
1 parent c53b0a5 commit 3ca76ca

File tree

7 files changed

+241
-1
lines changed

7 files changed

+241
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ module ts {
929929
// The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example,
930930
// module 'a' can 'export * from "b"' and 'b' can 'export * from "a"' without error.
931931
function visit(symbol: Symbol) {
932-
if (symbol.flags & SymbolFlags.HasExports && !contains(visitedSymbols, symbol)) {
932+
if (symbol && symbol.flags & SymbolFlags.HasExports && !contains(visitedSymbols, symbol)) {
933933
visitedSymbols.push(symbol);
934934
if (symbol !== moduleSymbol) {
935935
if (!result) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
tests/cases/compiler/exportDeclarationInInternalModule.ts(14,19): error TS1141: String literal expected.
2+
3+
4+
==== tests/cases/compiler/exportDeclarationInInternalModule.ts (1 errors) ====
5+
6+
class Bbb {
7+
}
8+
9+
class Aaa extends Bbb { }
10+
11+
module Aaa {
12+
export class SomeType { }
13+
}
14+
15+
module Bbb {
16+
export class SomeType { }
17+
18+
export * from Aaa; // this line causes the nullref
19+
~~~
20+
!!! error TS1141: String literal expected.
21+
}
22+
23+
var a: Bbb.SomeType;
24+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//// [exportDeclarationInInternalModule.ts]
2+
3+
class Bbb {
4+
}
5+
6+
class Aaa extends Bbb { }
7+
8+
module Aaa {
9+
export class SomeType { }
10+
}
11+
12+
module Bbb {
13+
export class SomeType { }
14+
15+
export * from Aaa; // this line causes the nullref
16+
}
17+
18+
var a: Bbb.SomeType;
19+
20+
21+
//// [exportDeclarationInInternalModule.js]
22+
var __extends = this.__extends || function (d, b) {
23+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
24+
function __() { this.constructor = d; }
25+
__.prototype = b.prototype;
26+
d.prototype = new __();
27+
};
28+
var Bbb = (function () {
29+
function Bbb() {
30+
}
31+
return Bbb;
32+
})();
33+
var Aaa = (function (_super) {
34+
__extends(Aaa, _super);
35+
function Aaa() {
36+
_super.apply(this, arguments);
37+
}
38+
return Aaa;
39+
})(Bbb);
40+
var Aaa;
41+
(function (Aaa) {
42+
var SomeType = (function () {
43+
function SomeType() {
44+
}
45+
return SomeType;
46+
})();
47+
Aaa.SomeType = SomeType;
48+
})(Aaa || (Aaa = {}));
49+
var Bbb;
50+
(function (Bbb) {
51+
var SomeType = (function () {
52+
function SomeType() {
53+
}
54+
return SomeType;
55+
})();
56+
Bbb.SomeType = SomeType;
57+
__export(require()); // this line causes the nullref
58+
})(Bbb || (Bbb = {}));
59+
var a;
60+
61+
62+
//// [exportDeclarationInInternalModule.d.ts]
63+
declare class Bbb {
64+
}
65+
declare class Aaa extends Bbb {
66+
}
67+
declare module Aaa {
68+
class SomeType {
69+
}
70+
}
71+
declare module Bbb {
72+
class SomeType {
73+
}
74+
export * from Aaa;
75+
}
76+
declare var a: Bbb.SomeType;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
tests/cases/compiler/exportStarFromEmptyModule_module3.ts(1,15): error TS2306: File 'tests/cases/compiler/exportStarFromEmptyModule_module2.ts' is not an external module.
2+
tests/cases/compiler/exportStarFromEmptyModule_module4.ts(4,5): error TS2339: Property 'r' does not exist on type 'typeof A'.
3+
4+
5+
==== tests/cases/compiler/exportStarFromEmptyModule_module1.ts (0 errors) ====
6+
7+
export class A {
8+
static r;
9+
}
10+
11+
==== tests/cases/compiler/exportStarFromEmptyModule_module2.ts (0 errors) ====
12+
// empty
13+
14+
==== tests/cases/compiler/exportStarFromEmptyModule_module3.ts (1 errors) ====
15+
export * from "exportStarFromEmptyModule_module2";
16+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17+
!!! error TS2306: File 'exportStarFromEmptyModule_module2.ts' is not an external module.
18+
export * from "exportStarFromEmptyModule_module1";
19+
20+
export class A {
21+
static q;
22+
}
23+
24+
==== tests/cases/compiler/exportStarFromEmptyModule_module4.ts (1 errors) ====
25+
import * as X from "exportStarFromEmptyModule_module3";
26+
var s: X.A;
27+
X.A.q;
28+
X.A.r; // Error
29+
~
30+
!!! error TS2339: Property 'r' does not exist on type 'typeof A'.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//// [tests/cases/compiler/exportStarFromEmptyModule.ts] ////
2+
3+
//// [exportStarFromEmptyModule_module1.ts]
4+
5+
export class A {
6+
static r;
7+
}
8+
9+
//// [exportStarFromEmptyModule_module2.ts]
10+
// empty
11+
12+
//// [exportStarFromEmptyModule_module3.ts]
13+
export * from "exportStarFromEmptyModule_module2";
14+
export * from "exportStarFromEmptyModule_module1";
15+
16+
export class A {
17+
static q;
18+
}
19+
20+
//// [exportStarFromEmptyModule_module4.ts]
21+
import * as X from "exportStarFromEmptyModule_module3";
22+
var s: X.A;
23+
X.A.q;
24+
X.A.r; // Error
25+
26+
//// [exportStarFromEmptyModule_module1.js]
27+
var A = (function () {
28+
function A() {
29+
}
30+
return A;
31+
})();
32+
exports.A = A;
33+
//// [exportStarFromEmptyModule_module2.js]
34+
// empty
35+
//// [exportStarFromEmptyModule_module3.js]
36+
function __export(m) {
37+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
38+
}
39+
__export(require("exportStarFromEmptyModule_module2"));
40+
__export(require("exportStarFromEmptyModule_module1"));
41+
var A = (function () {
42+
function A() {
43+
}
44+
return A;
45+
})();
46+
exports.A = A;
47+
//// [exportStarFromEmptyModule_module4.js]
48+
var X = require("exportStarFromEmptyModule_module3");
49+
var s;
50+
X.A.q;
51+
X.A.r; // Error
52+
53+
54+
//// [exportStarFromEmptyModule_module1.d.ts]
55+
export declare class A {
56+
static r: any;
57+
}
58+
//// [exportStarFromEmptyModule_module2.d.ts]
59+
//// [exportStarFromEmptyModule_module3.d.ts]
60+
export * from "exportStarFromEmptyModule_module2";
61+
export * from "exportStarFromEmptyModule_module1";
62+
export declare class A {
63+
static q: any;
64+
}
65+
//// [exportStarFromEmptyModule_module4.d.ts]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @target: es5
2+
// @module: commonjs
3+
// @declaration: true
4+
5+
class Bbb {
6+
}
7+
8+
class Aaa extends Bbb { }
9+
10+
module Aaa {
11+
export class SomeType { }
12+
}
13+
14+
module Bbb {
15+
export class SomeType { }
16+
17+
export * from Aaa; // this line causes the nullref
18+
}
19+
20+
var a: Bbb.SomeType;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @target: es5
2+
// @module: commonjs
3+
// @declaration: true
4+
5+
// @filename: exportStarFromEmptyModule_module1.ts
6+
export class A {
7+
static r;
8+
}
9+
10+
// @filename:exportStarFromEmptyModule_module2.ts
11+
// empty
12+
13+
// @filename: exportStarFromEmptyModule_module3.ts
14+
export * from "exportStarFromEmptyModule_module2";
15+
export * from "exportStarFromEmptyModule_module1";
16+
17+
export class A {
18+
static q;
19+
}
20+
21+
// @filename: exportStarFromEmptyModule_module4.ts
22+
import * as X from "exportStarFromEmptyModule_module3";
23+
var s: X.A;
24+
X.A.q;
25+
X.A.r; // Error

0 commit comments

Comments
 (0)