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

Function getPossibleNameForVarDecl

test/fixtures/snapshot/typescript.js:151642–151667  ·  view source on GitHub ↗
(node, transformer, continuationArgName)

Source from the content-addressed store, hash-verified

151640 return createSynthIdentifier(renamedPrevArg);
151641 }
151642 function getPossibleNameForVarDecl(node, transformer, continuationArgName) {
151643 var possibleNameForVarDecl;
151644 // If there is another call in the chain after the .catch() or .finally() we are transforming, we will need to save the result of both paths
151645 // (try block and catch/finally block). To do this, we will need to synthesize a variable that we were not aware of while we were adding
151646 // identifiers to the synthNamesMap. We will use the continuationArgName and then update the synthNamesMap with a new variable name for
151647 // the next transformation step
151648 if (continuationArgName && !shouldReturn(node, transformer)) {
151649 if (isSynthIdentifier(continuationArgName)) {
151650 possibleNameForVarDecl = continuationArgName;
151651 transformer.synthNamesMap.forEach(function (val, key) {
151652 if (val.identifier.text === continuationArgName.identifier.text) {
151653 var newSynthName = createUniqueSynthName(continuationArgName);
151654 transformer.synthNamesMap.set(key, newSynthName);
151655 }
151656 });
151657 }
151658 else {
151659 possibleNameForVarDecl = createSynthIdentifier(ts.factory.createUniqueName("result", 16 /* GeneratedIdentifierFlags.Optimistic */), continuationArgName.types);
151660 }
151661 // We are about to write a 'let' variable declaration, but `transformExpression` for both
151662 // the try block and catch/finally block will assign to this name. Setting this flag indicates
151663 // that future assignments should be written as `name = value` instead of `const name = value`.
151664 declareSynthIdentifier(possibleNameForVarDecl);
151665 }
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)

Callers 2

transformFinallyFunction · 0.85
transformCatchFunction · 0.85

Calls 7

shouldReturnFunction · 0.85
isSynthIdentifierFunction · 0.85
createUniqueSynthNameFunction · 0.85
createSynthIdentifierFunction · 0.85
declareSynthIdentifierFunction · 0.85
forEachMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected