Skip to content

Fixes emitExpressionIdentifier when combining --target ES6 with --module. #5343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 20, 2015
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
55 changes: 30 additions & 25 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1769,34 +1769,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(".");
}
}
else if (modulekind !== ModuleKind.ES6) {
let declaration = resolver.getReferencedImportDeclaration(node);
if (declaration) {
if (declaration.kind === SyntaxKind.ImportClause) {
// Identifier references default import
write(getGeneratedNameForNode(<ImportDeclaration>declaration.parent));
write(languageVersion === ScriptTarget.ES3 ? "[\"default\"]" : ".default");
return;
}
else if (declaration.kind === SyntaxKind.ImportSpecifier) {
// Identifier references named import
write(getGeneratedNameForNode(<ImportDeclaration>declaration.parent.parent.parent));
let name = (<ImportSpecifier>declaration).propertyName || (<ImportSpecifier>declaration).name;
let identifier = getSourceTextOfNodeFromSourceFile(currentSourceFile, name);
if (languageVersion === ScriptTarget.ES3 && identifier === "default") {
write(`["default"]`);
else {
if (modulekind !== ModuleKind.ES6) {
let declaration = resolver.getReferencedImportDeclaration(node);
if (declaration) {
if (declaration.kind === SyntaxKind.ImportClause) {
// Identifier references default import
write(getGeneratedNameForNode(<ImportDeclaration>declaration.parent));
write(languageVersion === ScriptTarget.ES3 ? "[\"default\"]" : ".default");
return;
}
else {
write(".");
write(identifier);
else if (declaration.kind === SyntaxKind.ImportSpecifier) {
// Identifier references named import
write(getGeneratedNameForNode(<ImportDeclaration>declaration.parent.parent.parent));
let name = (<ImportSpecifier>declaration).propertyName || (<ImportSpecifier>declaration).name;
let identifier = getSourceTextOfNodeFromSourceFile(currentSourceFile, name);
if (languageVersion === ScriptTarget.ES3 && identifier === "default") {
write(`["default"]`);
}
else {
write(".");
write(identifier);
}
return;
}
return;
}
}
declaration = resolver.getReferencedNestedRedeclaration(node);
if (declaration) {
write(getGeneratedNameForNode(declaration.name));
return;

if (languageVersion !== ScriptTarget.ES6) {
let declaration = resolver.getReferencedNestedRedeclaration(node);
if (declaration) {
write(getGeneratedNameForNode(declaration.name));
return;
}
}
}

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

/**
* Emit ES7 exponentiation operator downlevel using Math.pow
* @param node a binary expression node containing exponentiationOperator (**, **=)
* @param node a binary expression node containing exponentiationOperator (**, **=)
*/
function emitExponentiationOperator(node: BinaryExpression) {
let leftHandSideExpression = node.left;
Expand Down
15 changes: 15 additions & 0 deletions tests/baselines/reference/nestedRedeclarationInES6AMD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [nestedRedeclarationInES6AMD.ts]
function a() {
{
let status = 1;
status = 2;
}
}

//// [nestedRedeclarationInES6AMD.js]
function a() {
{
let status = 1;
status = 2;
}
}
11 changes: 11 additions & 0 deletions tests/baselines/reference/nestedRedeclarationInES6AMD.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=== tests/cases/compiler/nestedRedeclarationInES6AMD.ts ===
function a() {
>a : Symbol(a, Decl(nestedRedeclarationInES6AMD.ts, 0, 0))
{
let status = 1;
>status : Symbol(status, Decl(nestedRedeclarationInES6AMD.ts, 2, 11))

status = 2;
>status : Symbol(status, Decl(nestedRedeclarationInES6AMD.ts, 2, 11))
}
}
14 changes: 14 additions & 0 deletions tests/baselines/reference/nestedRedeclarationInES6AMD.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/compiler/nestedRedeclarationInES6AMD.ts ===
function a() {
>a : () => void
{
let status = 1;
>status : number
>1 : number

status = 2;
>status = 2 : number
>status : number
>2 : number
}
}
8 changes: 8 additions & 0 deletions tests/cases/compiler/nestedRedeclarationInES6AMD.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @target: ES6
// @module: AMD
function a() {
{
let status = 1;
status = 2;
}
}