diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 54d722f53b0..1b87578a26d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -929,7 +929,7 @@ module ts { // The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example, // module 'a' can 'export * from "b"' and 'b' can 'export * from "a"' without error. function visit(symbol: Symbol) { - if (symbol.flags & SymbolFlags.HasExports && !contains(visitedSymbols, symbol)) { + if (symbol && symbol.flags & SymbolFlags.HasExports && !contains(visitedSymbols, symbol)) { visitedSymbols.push(symbol); if (symbol !== moduleSymbol) { if (!result) { diff --git a/tests/baselines/reference/exportDeclarationInInternalModule.errors.txt b/tests/baselines/reference/exportDeclarationInInternalModule.errors.txt new file mode 100644 index 00000000000..58973f2a096 --- /dev/null +++ b/tests/baselines/reference/exportDeclarationInInternalModule.errors.txt @@ -0,0 +1,24 @@ +tests/cases/compiler/exportDeclarationInInternalModule.ts(14,19): error TS1141: String literal expected. + + +==== tests/cases/compiler/exportDeclarationInInternalModule.ts (1 errors) ==== + + class Bbb { + } + + class Aaa extends Bbb { } + + module Aaa { + export class SomeType { } + } + + module Bbb { + export class SomeType { } + + export * from Aaa; // this line causes the nullref + ~~~ +!!! error TS1141: String literal expected. + } + + var a: Bbb.SomeType; + \ No newline at end of file diff --git a/tests/baselines/reference/exportDeclarationInInternalModule.js b/tests/baselines/reference/exportDeclarationInInternalModule.js new file mode 100644 index 00000000000..97011f2425f --- /dev/null +++ b/tests/baselines/reference/exportDeclarationInInternalModule.js @@ -0,0 +1,76 @@ +//// [exportDeclarationInInternalModule.ts] + +class Bbb { +} + +class Aaa extends Bbb { } + +module Aaa { + export class SomeType { } +} + +module Bbb { + export class SomeType { } + + export * from Aaa; // this line causes the nullref +} + +var a: Bbb.SomeType; + + +//// [exportDeclarationInInternalModule.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Bbb = (function () { + function Bbb() { + } + return Bbb; +})(); +var Aaa = (function (_super) { + __extends(Aaa, _super); + function Aaa() { + _super.apply(this, arguments); + } + return Aaa; +})(Bbb); +var Aaa; +(function (Aaa) { + var SomeType = (function () { + function SomeType() { + } + return SomeType; + })(); + Aaa.SomeType = SomeType; +})(Aaa || (Aaa = {})); +var Bbb; +(function (Bbb) { + var SomeType = (function () { + function SomeType() { + } + return SomeType; + })(); + Bbb.SomeType = SomeType; + __export(require()); // this line causes the nullref +})(Bbb || (Bbb = {})); +var a; + + +//// [exportDeclarationInInternalModule.d.ts] +declare class Bbb { +} +declare class Aaa extends Bbb { +} +declare module Aaa { + class SomeType { + } +} +declare module Bbb { + class SomeType { + } + export * from Aaa; +} +declare var a: Bbb.SomeType; diff --git a/tests/baselines/reference/exportStarFromEmptyModule.errors.txt b/tests/baselines/reference/exportStarFromEmptyModule.errors.txt new file mode 100644 index 00000000000..598eb8bc029 --- /dev/null +++ b/tests/baselines/reference/exportStarFromEmptyModule.errors.txt @@ -0,0 +1,30 @@ +tests/cases/compiler/exportStarFromEmptyModule_module3.ts(1,15): error TS2306: File 'tests/cases/compiler/exportStarFromEmptyModule_module2.ts' is not an external module. +tests/cases/compiler/exportStarFromEmptyModule_module4.ts(4,5): error TS2339: Property 'r' does not exist on type 'typeof A'. + + +==== tests/cases/compiler/exportStarFromEmptyModule_module1.ts (0 errors) ==== + + export class A { + static r; + } + +==== tests/cases/compiler/exportStarFromEmptyModule_module2.ts (0 errors) ==== + // empty + +==== tests/cases/compiler/exportStarFromEmptyModule_module3.ts (1 errors) ==== + export * from "exportStarFromEmptyModule_module2"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2306: File 'exportStarFromEmptyModule_module2.ts' is not an external module. + export * from "exportStarFromEmptyModule_module1"; + + export class A { + static q; + } + +==== tests/cases/compiler/exportStarFromEmptyModule_module4.ts (1 errors) ==== + import * as X from "exportStarFromEmptyModule_module3"; + var s: X.A; + X.A.q; + X.A.r; // Error + ~ +!!! error TS2339: Property 'r' does not exist on type 'typeof A'. \ No newline at end of file diff --git a/tests/baselines/reference/exportStarFromEmptyModule.js b/tests/baselines/reference/exportStarFromEmptyModule.js new file mode 100644 index 00000000000..9b486af4eae --- /dev/null +++ b/tests/baselines/reference/exportStarFromEmptyModule.js @@ -0,0 +1,65 @@ +//// [tests/cases/compiler/exportStarFromEmptyModule.ts] //// + +//// [exportStarFromEmptyModule_module1.ts] + +export class A { + static r; +} + +//// [exportStarFromEmptyModule_module2.ts] +// empty + +//// [exportStarFromEmptyModule_module3.ts] +export * from "exportStarFromEmptyModule_module2"; +export * from "exportStarFromEmptyModule_module1"; + +export class A { + static q; +} + +//// [exportStarFromEmptyModule_module4.ts] +import * as X from "exportStarFromEmptyModule_module3"; +var s: X.A; +X.A.q; +X.A.r; // Error + +//// [exportStarFromEmptyModule_module1.js] +var A = (function () { + function A() { + } + return A; +})(); +exports.A = A; +//// [exportStarFromEmptyModule_module2.js] +// empty +//// [exportStarFromEmptyModule_module3.js] +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +__export(require("exportStarFromEmptyModule_module2")); +__export(require("exportStarFromEmptyModule_module1")); +var A = (function () { + function A() { + } + return A; +})(); +exports.A = A; +//// [exportStarFromEmptyModule_module4.js] +var X = require("exportStarFromEmptyModule_module3"); +var s; +X.A.q; +X.A.r; // Error + + +//// [exportStarFromEmptyModule_module1.d.ts] +export declare class A { + static r: any; +} +//// [exportStarFromEmptyModule_module2.d.ts] +//// [exportStarFromEmptyModule_module3.d.ts] +export * from "exportStarFromEmptyModule_module2"; +export * from "exportStarFromEmptyModule_module1"; +export declare class A { + static q: any; +} +//// [exportStarFromEmptyModule_module4.d.ts] diff --git a/tests/cases/compiler/exportDeclarationInInternalModule.ts b/tests/cases/compiler/exportDeclarationInInternalModule.ts new file mode 100644 index 00000000000..0b9ba7600a4 --- /dev/null +++ b/tests/cases/compiler/exportDeclarationInInternalModule.ts @@ -0,0 +1,20 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +class Bbb { +} + +class Aaa extends Bbb { } + +module Aaa { + export class SomeType { } +} + +module Bbb { + export class SomeType { } + + export * from Aaa; // this line causes the nullref +} + +var a: Bbb.SomeType; diff --git a/tests/cases/compiler/exportStarFromEmptyModule.ts b/tests/cases/compiler/exportStarFromEmptyModule.ts new file mode 100644 index 00000000000..163576f1c08 --- /dev/null +++ b/tests/cases/compiler/exportStarFromEmptyModule.ts @@ -0,0 +1,25 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: exportStarFromEmptyModule_module1.ts +export class A { + static r; +} + +// @filename:exportStarFromEmptyModule_module2.ts +// empty + +// @filename: exportStarFromEmptyModule_module3.ts +export * from "exportStarFromEmptyModule_module2"; +export * from "exportStarFromEmptyModule_module1"; + +export class A { + static q; +} + +// @filename: exportStarFromEmptyModule_module4.ts +import * as X from "exportStarFromEmptyModule_module3"; +var s: X.A; +X.A.q; +X.A.r; // Error \ No newline at end of file