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
7 changes: 7 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,13 @@ namespace ts {
// declaration is after usage, but it can still be legal if usage is deferred:
// 1. inside a function
// 2. inside an instance property initializer, a reference to a non-instance property
// 3. inside an export specifier

if (usage.parent.kind === SyntaxKind.ExportSpecifier) {
// export specifiers do not use the variable, they only make it available for use
return true;
}

const container = getEnclosingBlockScopeContainer(declaration);
const isInstanceProperty = declaration.kind === SyntaxKind.PropertyDeclaration && !(getModifierFlags(declaration) & ModifierFlags.Static);
return isUsedInFunctionOrInstanceProperty(usage, isInstanceProperty, container);
Expand Down
19 changes: 19 additions & 0 deletions tests/baselines/reference/exportBinding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [exportBinding.ts]
export { x }
const x = 'x'

export { Y as Z }
class Y {}


//// [exportBinding.js]
"use strict";
exports.__esModule = true;
var x = 'x';
exports.x = x;
var Y = (function () {
function Y() {
}
return Y;
}());
exports.Z = Y;
14 changes: 14 additions & 0 deletions tests/baselines/reference/exportBinding.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/conformance/es6/modules/exportBinding.ts ===
export { x }
>x : Symbol(x, Decl(exportBinding.ts, 0, 8))

const x = 'x'
>x : Symbol(x, Decl(exportBinding.ts, 1, 5))

export { Y as Z }
>Y : Symbol(Z, Decl(exportBinding.ts, 3, 8))
>Z : Symbol(Z, Decl(exportBinding.ts, 3, 8))

class Y {}
>Y : Symbol(Y, Decl(exportBinding.ts, 3, 17))

15 changes: 15 additions & 0 deletions tests/baselines/reference/exportBinding.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=== tests/cases/conformance/es6/modules/exportBinding.ts ===
export { x }
>x : "x"

const x = 'x'
>x : "x"
>'x' : "x"

export { Y as Z }
>Y : typeof Y
>Z : typeof Y

class Y {}
>Y : Y

5 changes: 5 additions & 0 deletions tests/cases/conformance/es6/modules/exportBinding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { x }
const x = 'x'

export { Y as Z }
Copy link
Copy Markdown
Author

@Jessidhia Jessidhia Mar 17, 2017

Choose a reason for hiding this comment

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

Strangely, this was not an error; only const and let were errors, even though class Foo {} has the exact same behavior as let Foo = class {} (no hoisting, has TDZ).

class Y {}