Skip to content

Commit c3f36e1

Browse files
committed
Merge pull request #5343 from Microsoft/fixES6LetInModule
Fixes emitExpressionIdentifier when combining --target ES6 with --module.
2 parents 1b36407 + c627802 commit c3f36e1

File tree

5 files changed

+78
-25
lines changed

5 files changed

+78
-25
lines changed

src/compiler/emitter.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,34 +1769,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
17691769
write(".");
17701770
}
17711771
}
1772-
else if (modulekind !== ModuleKind.ES6) {
1773-
let declaration = resolver.getReferencedImportDeclaration(node);
1774-
if (declaration) {
1775-
if (declaration.kind === SyntaxKind.ImportClause) {
1776-
// Identifier references default import
1777-
write(getGeneratedNameForNode(<ImportDeclaration>declaration.parent));
1778-
write(languageVersion === ScriptTarget.ES3 ? "[\"default\"]" : ".default");
1779-
return;
1780-
}
1781-
else if (declaration.kind === SyntaxKind.ImportSpecifier) {
1782-
// Identifier references named import
1783-
write(getGeneratedNameForNode(<ImportDeclaration>declaration.parent.parent.parent));
1784-
let name = (<ImportSpecifier>declaration).propertyName || (<ImportSpecifier>declaration).name;
1785-
let identifier = getSourceTextOfNodeFromSourceFile(currentSourceFile, name);
1786-
if (languageVersion === ScriptTarget.ES3 && identifier === "default") {
1787-
write(`["default"]`);
1772+
else {
1773+
if (modulekind !== ModuleKind.ES6) {
1774+
let declaration = resolver.getReferencedImportDeclaration(node);
1775+
if (declaration) {
1776+
if (declaration.kind === SyntaxKind.ImportClause) {
1777+
// Identifier references default import
1778+
write(getGeneratedNameForNode(<ImportDeclaration>declaration.parent));
1779+
write(languageVersion === ScriptTarget.ES3 ? "[\"default\"]" : ".default");
1780+
return;
17881781
}
1789-
else {
1790-
write(".");
1791-
write(identifier);
1782+
else if (declaration.kind === SyntaxKind.ImportSpecifier) {
1783+
// Identifier references named import
1784+
write(getGeneratedNameForNode(<ImportDeclaration>declaration.parent.parent.parent));
1785+
let name = (<ImportSpecifier>declaration).propertyName || (<ImportSpecifier>declaration).name;
1786+
let identifier = getSourceTextOfNodeFromSourceFile(currentSourceFile, name);
1787+
if (languageVersion === ScriptTarget.ES3 && identifier === "default") {
1788+
write(`["default"]`);
1789+
}
1790+
else {
1791+
write(".");
1792+
write(identifier);
1793+
}
1794+
return;
17921795
}
1793-
return;
17941796
}
17951797
}
1796-
declaration = resolver.getReferencedNestedRedeclaration(node);
1797-
if (declaration) {
1798-
write(getGeneratedNameForNode(declaration.name));
1799-
return;
1798+
1799+
if (languageVersion !== ScriptTarget.ES6) {
1800+
let declaration = resolver.getReferencedNestedRedeclaration(node);
1801+
if (declaration) {
1802+
write(getGeneratedNameForNode(declaration.name));
1803+
return;
1804+
}
18001805
}
18011806
}
18021807

@@ -2785,7 +2790,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
27852790

27862791
/**
27872792
* Emit ES7 exponentiation operator downlevel using Math.pow
2788-
* @param node a binary expression node containing exponentiationOperator (**, **=)
2793+
* @param node a binary expression node containing exponentiationOperator (**, **=)
27892794
*/
27902795
function emitExponentiationOperator(node: BinaryExpression) {
27912796
let leftHandSideExpression = node.left;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [nestedRedeclarationInES6AMD.ts]
2+
function a() {
3+
{
4+
let status = 1;
5+
status = 2;
6+
}
7+
}
8+
9+
//// [nestedRedeclarationInES6AMD.js]
10+
function a() {
11+
{
12+
let status = 1;
13+
status = 2;
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/nestedRedeclarationInES6AMD.ts ===
2+
function a() {
3+
>a : Symbol(a, Decl(nestedRedeclarationInES6AMD.ts, 0, 0))
4+
{
5+
let status = 1;
6+
>status : Symbol(status, Decl(nestedRedeclarationInES6AMD.ts, 2, 11))
7+
8+
status = 2;
9+
>status : Symbol(status, Decl(nestedRedeclarationInES6AMD.ts, 2, 11))
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/nestedRedeclarationInES6AMD.ts ===
2+
function a() {
3+
>a : () => void
4+
{
5+
let status = 1;
6+
>status : number
7+
>1 : number
8+
9+
status = 2;
10+
>status = 2 : number
11+
>status : number
12+
>2 : number
13+
}
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: ES6
2+
// @module: AMD
3+
function a() {
4+
{
5+
let status = 1;
6+
status = 2;
7+
}
8+
}

0 commit comments

Comments
 (0)