diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 88847999a4b..09ae33c4edc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -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;