Simplifying the pre ES6 async/await change

This commit is contained in:
Dirk Holtwick 2015-12-01 20:26:20 +01:00
parent 1fb8a249df
commit c12d29bda5

View File

@ -2978,7 +2978,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
else {
// this is top level converted loop so we need to create an alias for 'this' here
// NOTE:
// NOTE:
// if converted loops were all nested in arrow function then we'll always emit '_this' so convertedLoopState.thisName will not be set.
// If it is set this means that all nested loops are not nested in arrow function and it is safe to capture 'this'.
write(`var ${convertedLoopState.thisName} = this;`);
@ -4369,7 +4369,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
function emitAsyncFunctionBodyForES6(node: FunctionLikeDeclaration) {
const promiseConstructor = getEntityNameFromTypeNode(node.type);
const isArrowFunction = node.kind === SyntaxKind.ArrowFunction;
const isArrowFunction = node.kind === SyntaxKind.ArrowFunction;
const hasLexicalArguments = (resolver.getNodeCheckFlags(node) & NodeCheckFlags.CaptureArguments) !== 0;
// An async function is emit as an outer function that calls an inner
@ -4514,34 +4514,32 @@ 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);
}
// 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;
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) {
emitAsyncFunctionBodyForES6(node);
}
else {
emitFunctionBody(node);
}
if (!isES6ExportedDeclaration(node)) {
emitExportMemberAssignment(node);
}
Debug.assert(convertedLoopState === undefined);
convertedLoopState = saveConvertedLoopState;
tempFlags = saveTempFlags;
tempVariables = saveTempVariables;