mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 02:35:48 -05:00
use downlevel destructuring for exported variables for target=ES6 if module kind is not ES6
This commit is contained in:
@@ -4218,12 +4218,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
|
||||
function emitVariableDeclaration(node: VariableDeclaration) {
|
||||
if (isBindingPattern(node.name)) {
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
emitDestructuring(node, /*isAssignmentExpressionStatement*/ false);
|
||||
}
|
||||
else {
|
||||
const isExported = getCombinedNodeFlags(node) & NodeFlags.Export;
|
||||
if (languageVersion >= ScriptTarget.ES6 && (!isExported || modulekind === ModuleKind.ES6)) {
|
||||
// emit ES6 destructuring only if target module is ES6 or variable is not exported
|
||||
// exported variables in CJS\AMD are prefixed with 'exports.' so result javascript { exports.toString } = 1; is illegal
|
||||
|
||||
const isTopLevelDeclarationInSystemModule =
|
||||
modulekind === ModuleKind.System &&
|
||||
shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/true);
|
||||
|
||||
if (isTopLevelDeclarationInSystemModule) {
|
||||
// is system modules top level variables are hoisted
|
||||
write("(");
|
||||
}
|
||||
|
||||
emit(node.name);
|
||||
emitOptional(" = ", node.initializer);
|
||||
|
||||
if (isTopLevelDeclarationInSystemModule) {
|
||||
write(")");
|
||||
}
|
||||
}
|
||||
else {
|
||||
emitDestructuring(node, /*isAssignmentExpressionStatement*/ false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user