mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Add null check when querying for exports from a module
This commit is contained in:
parent
c53b0a5016
commit
3ca76ca53b
@ -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) {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
@ -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
tests/baselines/reference/exportStarFromEmptyModule.js
Normal file
65
tests/baselines/reference/exportStarFromEmptyModule.js
Normal file
@ -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
tests/cases/compiler/exportDeclarationInInternalModule.ts
Normal file
20
tests/cases/compiler/exportDeclarationInInternalModule.ts
Normal file
@ -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
tests/cases/compiler/exportStarFromEmptyModule.ts
Normal file
25
tests/cases/compiler/exportStarFromEmptyModule.ts
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user