Merge pull request #6563 from Microsoft/reExportUndefined

handle undefined entry as export specifier
This commit is contained in:
Vladimir Matveev 2016-01-21 15:40:34 -08:00
commit 4ce436714a
8 changed files with 90 additions and 1 deletions

View File

@ -14476,7 +14476,7 @@ namespace ts {
// find immediate value referenced by exported name (SymbolFlags.Alias is set so we don't chase down aliases)
const symbol = resolveName(exportedName, exportedName.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias,
/*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined);
if (symbol && isGlobalSourceFile(getDeclarationContainer(symbol.declarations[0]))) {
if (symbol && (symbol === undefinedSymbol || isGlobalSourceFile(getDeclarationContainer(symbol.declarations[0])))) {
error(exportedName, Diagnostics.Cannot_re_export_name_that_is_not_defined_in_the_module);
}
else {

View File

@ -0,0 +1,8 @@
tests/cases/compiler/a.ts(2,10): error TS2661: Cannot re-export name that is not defined in the module.
==== tests/cases/compiler/a.ts (1 errors) ====
export { undefined };
~~~~~~~~~
!!! error TS2661: Cannot re-export name that is not defined in the module.

View File

@ -0,0 +1,6 @@
//// [a.ts]
export { undefined };
//// [a.js]
"use strict";

View File

@ -0,0 +1,20 @@
//// [tests/cases/compiler/reExportUndefined2.ts] ////
//// [a.ts]
var undefined;
export { undefined };
//// [b.ts]
import { undefined } from "./a";
declare function use(a: number);
use(undefined);
//// [a.js]
"use strict";
var undefined;
exports.undefined = undefined;
//// [b.js]
"use strict";
var a_1 = require("./a");
use(a_1.undefined);

View File

@ -0,0 +1,20 @@
=== tests/cases/compiler/a.ts ===
var undefined;
>undefined : Symbol(undefined, Decl(a.ts, 1, 3))
export { undefined };
>undefined : Symbol(undefined, Decl(a.ts, 2, 8))
=== tests/cases/compiler/b.ts ===
import { undefined } from "./a";
>undefined : Symbol(undefined, Decl(b.ts, 0, 8))
declare function use(a: number);
>use : Symbol(use, Decl(b.ts, 0, 32))
>a : Symbol(a, Decl(b.ts, 1, 21))
use(undefined);
>use : Symbol(use, Decl(b.ts, 0, 32))
>undefined : Symbol(undefined, Decl(b.ts, 0, 8))

View File

@ -0,0 +1,21 @@
=== tests/cases/compiler/a.ts ===
var undefined;
>undefined : any
export { undefined };
>undefined : any
=== tests/cases/compiler/b.ts ===
import { undefined } from "./a";
>undefined : any
declare function use(a: number);
>use : (a: number) => any
>a : number
use(undefined);
>use(undefined) : any
>use : (a: number) => any
>undefined : any

View File

@ -0,0 +1,4 @@
// @module: commonjs
// @filename: a.ts
export { undefined };

View File

@ -0,0 +1,10 @@
// @module: commonjs
// @filename: a.ts
var undefined;
export { undefined };
// @filename: b.ts
import { undefined } from "./a";
declare function use(a: number);
use(undefined);