mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #5343 from Microsoft/fixES6LetInModule
Fixes emitExpressionIdentifier when combining --target ES6 with --module.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
15
tests/baselines/reference/nestedRedeclarationInES6AMD.js
Normal file
15
tests/baselines/reference/nestedRedeclarationInES6AMD.js
Normal file
@@ -0,0 +1,15 @@
|
||||
//// [nestedRedeclarationInES6AMD.ts]
|
||||
function a() {
|
||||
{
|
||||
let status = 1;
|
||||
status = 2;
|
||||
}
|
||||
}
|
||||
|
||||
//// [nestedRedeclarationInES6AMD.js]
|
||||
function a() {
|
||||
{
|
||||
let status = 1;
|
||||
status = 2;
|
||||
}
|
||||
}
|
||||
@@ -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
tests/baselines/reference/nestedRedeclarationInES6AMD.types
Normal file
14
tests/baselines/reference/nestedRedeclarationInES6AMD.types
Normal file
@@ -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
tests/cases/compiler/nestedRedeclarationInES6AMD.ts
Normal file
8
tests/cases/compiler/nestedRedeclarationInES6AMD.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// @target: ES6
|
||||
// @module: AMD
|
||||
function a() {
|
||||
{
|
||||
let status = 1;
|
||||
status = 2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user