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

Function useOuterVariableScopeInParameter

test/fixtures/snapshot/typescript.js:49575–49633  ·  view source on GitHub ↗
(result, location, lastLocation)

Source from the content-addressed store, hash-verified

49573 }
49574 }
49575 function useOuterVariableScopeInParameter(result, location, lastLocation) {
49576 var target = ts.getEmitScriptTarget(compilerOptions);
49577 var functionLocation = location;
49578 if (ts.isParameter(lastLocation)
49579 && functionLocation.body
49580 && result.valueDeclaration
49581 && result.valueDeclaration.pos >= functionLocation.body.pos
49582 && result.valueDeclaration.end <= functionLocation.body.end) {
49583 // check for several cases where we introduce temporaries that require moving the name/initializer of the parameter to the body
49584 // - static field in a class expression
49585 // - optional chaining pre-es2020
49586 // - nullish coalesce pre-es2020
49587 // - spread assignment in binding pattern pre-es2017
49588 if (target >= 2 /* ScriptTarget.ES2015 */) {
49589 var links = getNodeLinks(functionLocation);
49590 if (links.declarationRequiresScopeChange === undefined) {
49591 links.declarationRequiresScopeChange = ts.forEach(functionLocation.parameters, requiresScopeChange) || false;
49592 }
49593 return !links.declarationRequiresScopeChange;
49594 }
49595 }
49596 return false;
49597 function requiresScopeChange(node) {
49598 return requiresScopeChangeWorker(node.name)
49599 || !!node.initializer && requiresScopeChangeWorker(node.initializer);
49600 }
49601 function requiresScopeChangeWorker(node) {
49602 switch (node.kind) {
49603 case 214 /* SyntaxKind.ArrowFunction */:
49604 case 213 /* SyntaxKind.FunctionExpression */:
49605 case 256 /* SyntaxKind.FunctionDeclaration */:
49606 case 171 /* SyntaxKind.Constructor */:
49607 // do not descend into these
49608 return false;
49609 case 169 /* SyntaxKind.MethodDeclaration */:
49610 case 172 /* SyntaxKind.GetAccessor */:
49611 case 173 /* SyntaxKind.SetAccessor */:
49612 case 296 /* SyntaxKind.PropertyAssignment */:
49613 return requiresScopeChangeWorker(node.name);
49614 case 167 /* SyntaxKind.PropertyDeclaration */:
49615 // static properties in classes introduce temporary variables
49616 if (ts.hasStaticModifier(node)) {
49617 return target < 99 /* ScriptTarget.ESNext */ || !useDefineForClassFields;
49618 }
49619 return requiresScopeChangeWorker(node.name);
49620 default:
49621 // null coalesce and optional chain pre-es2020 produce temporary variables
49622 if (ts.isNullishCoalesce(node) || ts.isOptionalChain(node)) {
49623 return target < 7 /* ScriptTarget.ES2020 */;
49624 }
49625 if (ts.isBindingElement(node) && node.dotDotDotToken && ts.isObjectBindingPattern(node.parent)) {
49626 return target < 4 /* ScriptTarget.ES2017 */;
49627 }
49628 if (ts.isTypeNode(node))
49629 return false;
49630 return ts.forEachChild(node, requiresScopeChangeWorker) || false;
49631 }
49632 }

Callers 1

resolveNameHelperFunction · 0.85

Calls 2

getNodeLinksFunction · 0.85
forEachMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…