MCPcopy Index your code
hub / github.com/nodejs/node / transformAsyncFunctionBody

Function transformAsyncFunctionBody

test/fixtures/snapshot/typescript.js:96225–96296  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

96223 return false;
96224 }
96225 function transformAsyncFunctionBody(node) {
96226 resumeLexicalEnvironment();
96227 var original = ts.getOriginalNode(node, ts.isFunctionLike);
96228 var nodeType = original.type;
96229 var promiseConstructor = languageVersion < 2 /* ScriptTarget.ES2015 */ ? getPromiseConstructor(nodeType) : undefined;
96230 var isArrowFunction = node.kind === 214 /* SyntaxKind.ArrowFunction */;
96231 var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 8192 /* NodeCheckFlags.CaptureArguments */) !== 0;
96232 // An async function is emit as an outer function that calls an inner
96233 // generator function. To preserve lexical bindings, we pass the current
96234 // `this` and `arguments` objects to `__awaiter`. The generator function
96235 // passed to `__awaiter` is executed inside of the callback to the
96236 // promise constructor.
96237 var savedEnclosingFunctionParameterNames = enclosingFunctionParameterNames;
96238 enclosingFunctionParameterNames = new ts.Set();
96239 for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) {
96240 var parameter = _a[_i];
96241 recordDeclarationName(parameter, enclosingFunctionParameterNames);
96242 }
96243 var savedCapturedSuperProperties = capturedSuperProperties;
96244 var savedHasSuperElementAccess = hasSuperElementAccess;
96245 if (!isArrowFunction) {
96246 capturedSuperProperties = new ts.Set();
96247 hasSuperElementAccess = false;
96248 }
96249 var result;
96250 if (!isArrowFunction) {
96251 var statements = [];
96252 var statementOffset = factory.copyPrologue(node.body.statements, statements, /*ensureUseStrict*/ false, visitor);
96253 statements.push(factory.createReturnStatement(emitHelpers().createAwaiterHelper(inHasLexicalThisContext(), hasLexicalArguments, promiseConstructor, transformAsyncFunctionBodyWorker(node.body, statementOffset))));
96254 ts.insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment());
96255 // Minor optimization, emit `_super` helper to capture `super` access in an arrow.
96256 // This step isn't needed if we eventually transform this to ES5.
96257 var emitSuperHelpers = languageVersion >= 2 /* ScriptTarget.ES2015 */ && resolver.getNodeCheckFlags(node) & (4096 /* NodeCheckFlags.AsyncMethodWithSuperBinding */ | 2048 /* NodeCheckFlags.AsyncMethodWithSuper */);
96258 if (emitSuperHelpers) {
96259 enableSubstitutionForAsyncMethodsWithSuper();
96260 if (capturedSuperProperties.size) {
96261 var variableStatement = createSuperAccessVariableStatement(factory, resolver, node, capturedSuperProperties);
96262 substitutedSuperAccessors[ts.getNodeId(variableStatement)] = true;
96263 ts.insertStatementsAfterStandardPrologue(statements, [variableStatement]);
96264 }
96265 }
96266 var block = factory.createBlock(statements, /*multiLine*/ true);
96267 ts.setTextRange(block, node.body);
96268 if (emitSuperHelpers && hasSuperElementAccess) {
96269 // Emit helpers for super element access expressions (`super[x]`).
96270 if (resolver.getNodeCheckFlags(node) & 4096 /* NodeCheckFlags.AsyncMethodWithSuperBinding */) {
96271 ts.addEmitHelper(block, ts.advancedAsyncSuperHelper);
96272 }
96273 else if (resolver.getNodeCheckFlags(node) & 2048 /* NodeCheckFlags.AsyncMethodWithSuper */) {
96274 ts.addEmitHelper(block, ts.asyncSuperHelper);
96275 }
96276 }
96277 result = block;
96278 }
96279 else {
96280 var expression = emitHelpers().createAwaiterHelper(inHasLexicalThisContext(), hasLexicalArguments, promiseConstructor, transformAsyncFunctionBodyWorker(node.body));
96281 var declarations = endLexicalEnvironment();
96282 if (ts.some(declarations)) {

Callers 4

visitMethodDeclarationFunction · 0.85
visitFunctionDeclarationFunction · 0.85
visitFunctionExpressionFunction · 0.85
visitArrowFunctionFunction · 0.85

Calls 11

resumeLexicalEnvironmentFunction · 0.85
getPromiseConstructorFunction · 0.85
recordDeclarationNameFunction · 0.85
emitHelpersFunction · 0.85
inHasLexicalThisContextFunction · 0.85
endLexicalEnvironmentFunction · 0.85
someMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…