Skip to content

Commit db74d1d

Browse files
committed
Merge branch 'Kovensky-allow-export-specifier-reference'
2 parents e5416b5 + 0292f58 commit db74d1d

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,15 @@ namespace ts {
760760

761761

762762
// declaration is after usage, but it can still be legal if usage is deferred:
763-
// 1. inside a function
764-
// 2. inside an instance property initializer, a reference to a non-instance property
765-
// 3. inside a static property initializer, a reference to a static method in the same class
763+
// 1. inside an export specifier
764+
// 2. inside a function
765+
// 3. inside an instance property initializer, a reference to a non-instance property
766+
// 4. inside a static property initializer, a reference to a static method in the same class
767+
if (usage.parent.kind === SyntaxKind.ExportSpecifier) {
768+
// export specifiers do not use the variable, they only make it available for use
769+
return true;
770+
}
771+
766772
const container = getEnclosingBlockScopeContainer(declaration);
767773
return isUsedInFunctionOrInstanceProperty(usage, declaration, container);
768774

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [exportBinding.ts]
2+
export { x }
3+
const x = 'x'
4+
5+
export { Y as Z }
6+
class Y {}
7+
8+
9+
//// [exportBinding.js]
10+
"use strict";
11+
exports.__esModule = true;
12+
var x = 'x';
13+
exports.x = x;
14+
var Y = (function () {
15+
function Y() {
16+
}
17+
return Y;
18+
}());
19+
exports.Z = Y;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/es6/modules/exportBinding.ts ===
2+
export { x }
3+
>x : Symbol(x, Decl(exportBinding.ts, 0, 8))
4+
5+
const x = 'x'
6+
>x : Symbol(x, Decl(exportBinding.ts, 1, 5))
7+
8+
export { Y as Z }
9+
>Y : Symbol(Z, Decl(exportBinding.ts, 3, 8))
10+
>Z : Symbol(Z, Decl(exportBinding.ts, 3, 8))
11+
12+
class Y {}
13+
>Y : Symbol(Y, Decl(exportBinding.ts, 3, 17))
14+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/conformance/es6/modules/exportBinding.ts ===
2+
export { x }
3+
>x : "x"
4+
5+
const x = 'x'
6+
>x : "x"
7+
>'x' : "x"
8+
9+
export { Y as Z }
10+
>Y : typeof Y
11+
>Z : typeof Y
12+
13+
class Y {}
14+
>Y : Y
15+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { x }
2+
const x = 'x'
3+
4+
export { Y as Z }
5+
class Y {}

0 commit comments

Comments
 (0)