Enable await in ES6 and ES2015 script mode

Even though strictly generators are an ES6 feature the real world support
is large enough to use the feature in well known environments like
node.js or Electron app. Since the previous output was not working at
all anyway it feels like a good compromise to at least emit working code
while still having the warning in place. The user would also need to add
"use strict" on top of her .ts file to make it work with node.js.
This commit is contained in:
Dirk Holtwick 2015-12-01 10:26:14 +01:00
parent dac1874c38
commit 1fb8a249df

View file

@ -4514,32 +4514,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
convertedLoopState = undefined;
tempFlags = 0;
tempVariables = undefined;
tempParameters = undefined;
// When targeting ES6, emit arrow function natively in ES6
if (shouldEmitAsArrowFunction(node)) {
emitSignatureParametersForArrow(node);
write(" =>");
}
else {
emitSignatureParameters(node);
}
const isAsync = isAsyncFunctionLike(node);
if (isAsync && languageVersion === ScriptTarget.ES6) {
emitAsyncFunctionBodyForES6(node);
}
else {
emitFunctionBody(node);
}
if (!isES6ExportedDeclaration(node)) {
emitExportMemberAssignment(node);
}
Debug.assert(convertedLoopState === undefined);
convertedLoopState = saveConvertedLoopState;
tempVariables = undefined;
tempParameters = undefined;
// When targeting ES6, emit arrow function natively in ES6
if (shouldEmitAsArrowFunction(node)) {
emitSignatureParametersForArrow(node);
write(" =>");
}
else {
emitSignatureParameters(node);
}
// Even though generators are a ES6 only feature, the functionality is wiedely supported
// in current browsers and latest node, therefore showing some tolerance
const isAsync = isAsyncFunctionLike(node);
if (isAsync && (languageVersion === ScriptTarget.ES6 || languageVersion === ScriptTarget.ES2015 || languageVersion === ScriptTarget.ES5)) {
emitAsyncFunctionBodyForES6(node);
}
else {
emitFunctionBody(node);
}
if (!isES6ExportedDeclaration(node)) {
emitExportMemberAssignment(node);
}
Debug.assert(convertedLoopState === undefined);
convertedLoopState = saveConvertedLoopState;
tempFlags = saveTempFlags;
tempVariables = saveTempVariables;