Skip to content

Commit 85e587e

Browse files
committed
Fixes issue in emitExpressionIdentifier when combining --target ES6 with --module.
Fixes #5315.
1 parent 5b94698 commit 85e587e

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-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;

0 commit comments

Comments
 (0)