Skip to content

Commit 4ce4367

Browse files
committed
Merge pull request #6563 from Microsoft/reExportUndefined
handle undefined entry as export specifier
2 parents 4b284ab + f252b9d commit 4ce4367

File tree

8 files changed

+90
-1
lines changed

8 files changed

+90
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14476,7 +14476,7 @@ namespace ts {
1447614476
// find immediate value referenced by exported name (SymbolFlags.Alias is set so we don't chase down aliases)
1447714477
const symbol = resolveName(exportedName, exportedName.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias,
1447814478
/*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined);
14479-
if (symbol && isGlobalSourceFile(getDeclarationContainer(symbol.declarations[0]))) {
14479+
if (symbol && (symbol === undefinedSymbol || isGlobalSourceFile(getDeclarationContainer(symbol.declarations[0])))) {
1448014480
error(exportedName, Diagnostics.Cannot_re_export_name_that_is_not_defined_in_the_module);
1448114481
}
1448214482
else {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/compiler/a.ts(2,10): error TS2661: Cannot re-export name that is not defined in the module.
2+
3+
4+
==== tests/cases/compiler/a.ts (1 errors) ====
5+
6+
export { undefined };
7+
~~~~~~~~~
8+
!!! error TS2661: Cannot re-export name that is not defined in the module.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [a.ts]
2+
3+
export { undefined };
4+
5+
//// [a.js]
6+
"use strict";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [tests/cases/compiler/reExportUndefined2.ts] ////
2+
3+
//// [a.ts]
4+
5+
var undefined;
6+
export { undefined };
7+
8+
//// [b.ts]
9+
import { undefined } from "./a";
10+
declare function use(a: number);
11+
use(undefined);
12+
13+
//// [a.js]
14+
"use strict";
15+
var undefined;
16+
exports.undefined = undefined;
17+
//// [b.js]
18+
"use strict";
19+
var a_1 = require("./a");
20+
use(a_1.undefined);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/a.ts ===
2+
3+
var undefined;
4+
>undefined : Symbol(undefined, Decl(a.ts, 1, 3))
5+
6+
export { undefined };
7+
>undefined : Symbol(undefined, Decl(a.ts, 2, 8))
8+
9+
=== tests/cases/compiler/b.ts ===
10+
import { undefined } from "./a";
11+
>undefined : Symbol(undefined, Decl(b.ts, 0, 8))
12+
13+
declare function use(a: number);
14+
>use : Symbol(use, Decl(b.ts, 0, 32))
15+
>a : Symbol(a, Decl(b.ts, 1, 21))
16+
17+
use(undefined);
18+
>use : Symbol(use, Decl(b.ts, 0, 32))
19+
>undefined : Symbol(undefined, Decl(b.ts, 0, 8))
20+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/compiler/a.ts ===
2+
3+
var undefined;
4+
>undefined : any
5+
6+
export { undefined };
7+
>undefined : any
8+
9+
=== tests/cases/compiler/b.ts ===
10+
import { undefined } from "./a";
11+
>undefined : any
12+
13+
declare function use(a: number);
14+
>use : (a: number) => any
15+
>a : number
16+
17+
use(undefined);
18+
>use(undefined) : any
19+
>use : (a: number) => any
20+
>undefined : any
21+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @module: commonjs
2+
3+
// @filename: a.ts
4+
export { undefined };
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @module: commonjs
2+
3+
// @filename: a.ts
4+
var undefined;
5+
export { undefined };
6+
7+
// @filename: b.ts
8+
import { undefined } from "./a";
9+
declare function use(a: number);
10+
use(undefined);

0 commit comments

Comments
 (0)