Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the check on the initial symbol; none of the others should ever be undefined, should they?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we later on call visit(resolveExternalModuleName(node, (<ExportDeclaration>node).moduleSpecifier)); and that can be undefined if the module is empty. see my second test case.

visitedSymbols.push(symbol);
if (symbol !== moduleSymbol) {
if (!result) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

76 changes: 76 additions & 0 deletions tests/baselines/reference/exportDeclarationInInternalModule.js
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 30 additions & 0 deletions tests/baselines/reference/exportStarFromEmptyModule.errors.txt
Original file line number Diff line number Diff line change
@@ -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'.
65 changes: 65 additions & 0 deletions tests/baselines/reference/exportStarFromEmptyModule.js
Original file line number Diff line number Diff line change
@@ -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]
20 changes: 20 additions & 0 deletions tests/cases/compiler/exportDeclarationInInternalModule.ts
Original file line number Diff line number Diff line change
@@ -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;
25 changes: 25 additions & 0 deletions tests/cases/compiler/exportStarFromEmptyModule.ts
Original file line number Diff line number Diff line change
@@ -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