MCPcopy Create free account
hub / github.com/nodejs/node / finishCatchOrFinallyTransform

Function finishCatchOrFinallyTransform

test/fixtures/snapshot/typescript.js:151668–151691  ·  view source on GitHub ↗
(node, transformer, tryStatement, possibleNameForVarDecl, continuationArgName)

Source from the content-addressed store, hash-verified

151666 return possibleNameForVarDecl;
151667 }
151668 function finishCatchOrFinallyTransform(node, transformer, tryStatement, possibleNameForVarDecl, continuationArgName) {
151669 var statements = [];
151670 // In order to avoid an implicit any, we will synthesize a type for the declaration using the unions of the types of both paths (try block and catch block)
151671 var varDeclIdentifier;
151672 if (possibleNameForVarDecl && !shouldReturn(node, transformer)) {
151673 varDeclIdentifier = ts.getSynthesizedDeepClone(declareSynthIdentifier(possibleNameForVarDecl));
151674 var typeArray = possibleNameForVarDecl.types;
151675 var unionType = transformer.checker.getUnionType(typeArray, 2 /* UnionReduction.Subtype */);
151676 var unionTypeNode = transformer.isInJSFile ? undefined : transformer.checker.typeToTypeNode(unionType, /*enclosingDeclaration*/ undefined, /*flags*/ undefined);
151677 var varDecl = [ts.factory.createVariableDeclaration(varDeclIdentifier, /*exclamationToken*/ undefined, unionTypeNode)];
151678 var varDeclList = ts.factory.createVariableStatement(/*modifiers*/ undefined, ts.factory.createVariableDeclarationList(varDecl, 1 /* NodeFlags.Let */));
151679 statements.push(varDeclList);
151680 }
151681 statements.push(tryStatement);
151682 if (continuationArgName && varDeclIdentifier && isSynthBindingPattern(continuationArgName)) {
151683 statements.push(ts.factory.createVariableStatement(
151684 /*modifiers*/ undefined, ts.factory.createVariableDeclarationList([
151685 ts.factory.createVariableDeclaration(ts.getSynthesizedDeepClone(declareSynthBindingPattern(continuationArgName)),
151686 /*exclamationToken*/ undefined,
151687 /*type*/ undefined, varDeclIdentifier)
151688 ], 2 /* NodeFlags.Const */)));
151689 }
151690 return statements;
151691 }
151692 /**
151693 * @param hasContinuation Whether another `then`, `catch`, or `finally` continuation follows this continuation.
151694 * @param continuationArgName The argument name for the continuation that follows this call.

Callers 2

transformFinallyFunction · 0.85
transformCatchFunction · 0.85

Calls 5

shouldReturnFunction · 0.85
declareSynthIdentifierFunction · 0.85
isSynthBindingPatternFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected