mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Merge pull request #6597 from plantain-00/use_const_rather_than_var_when_target_es6
Use const rather than var when target es6
This commit is contained in:
@@ -6100,6 +6100,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
if (contains(externalImports, node)) {
|
||||
const isExportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0;
|
||||
const namespaceDeclaration = getNamespaceDeclarationNode(node);
|
||||
const varOrConst = (languageVersion <= ScriptTarget.ES5) ? "var " : "const ";
|
||||
|
||||
if (modulekind !== ModuleKind.AMD) {
|
||||
emitLeadingComments(node);
|
||||
@@ -6107,7 +6108,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
if (namespaceDeclaration && !isDefaultImport(node)) {
|
||||
// import x = require("foo")
|
||||
// import * as x from "foo"
|
||||
if (!isExportedImport) write("var ");
|
||||
if (!isExportedImport) {
|
||||
write(varOrConst);
|
||||
};
|
||||
emitModuleMemberName(namespaceDeclaration);
|
||||
write(" = ");
|
||||
}
|
||||
@@ -6119,7 +6122,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
// import d, { x, y } from "foo"
|
||||
const isNakedImport = SyntaxKind.ImportDeclaration && !(<ImportDeclaration>node).importClause;
|
||||
if (!isNakedImport) {
|
||||
write("var ");
|
||||
write(varOrConst);
|
||||
write(getGeneratedNameForNode(<ImportDeclaration>node));
|
||||
write(" = ");
|
||||
}
|
||||
@@ -6146,7 +6149,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
}
|
||||
else if (namespaceDeclaration && isDefaultImport(node)) {
|
||||
// import d, * as x from "foo"
|
||||
write("var ");
|
||||
write(varOrConst);
|
||||
emitModuleMemberName(namespaceDeclaration);
|
||||
write(" = ");
|
||||
write(getGeneratedNameForNode(<ImportDeclaration>node));
|
||||
|
||||
Reference in New Issue
Block a user