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

Function resolveNameHelper

test/fixtures/snapshot/typescript.js:49650–50084  ·  view source on GitHub ↗
(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggestions, lookup)

Source from the content-addressed store, hash-verified

49648 return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggstions, getSymbol);
49649 }
49650 function resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggestions, lookup) {
49651 var _a, _b, _c;
49652 var originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
49653 var result;
49654 var lastLocation;
49655 var lastSelfReferenceLocation;
49656 var propertyWithInvalidInitializer;
49657 var associatedDeclarationForContainingInitializerOrBindingName;
49658 var withinDeferredContext = false;
49659 var errorLocation = location;
49660 var grandparent;
49661 var isInExternalModule = false;
49662 loop: while (location) {
49663 if (name === "const" && isConstAssertion(location)) {
49664 // `const` in an `as const` has no symbol, but issues no error because there is no *actual* lookup of the type
49665 // (it refers to the constant type of the expression instead)
49666 return undefined;
49667 }
49668 // Locals of a source file are not in scope (because they get merged into the global symbol table)
49669 if (location.locals && !isGlobalSourceFile(location)) {
49670 if (result = lookup(location.locals, name, meaning)) {
49671 var useResult = true;
49672 if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) {
49673 // symbol lookup restrictions for function-like declarations
49674 // - Type parameters of a function are in scope in the entire function declaration, including the parameter
49675 // list and return type. However, local types are only in scope in the function body.
49676 // - parameters are only in the scope of function body
49677 // This restriction does not apply to JSDoc comment types because they are parented
49678 // at a higher level than type parameters would normally be
49679 if (meaning & result.flags & 788968 /* SymbolFlags.Type */ && lastLocation.kind !== 320 /* SyntaxKind.JSDoc */) {
49680 useResult = result.flags & 262144 /* SymbolFlags.TypeParameter */
49681 // type parameters are visible in parameter list, return type and type parameter list
49682 ? lastLocation === location.type ||
49683 lastLocation.kind === 164 /* SyntaxKind.Parameter */ ||
49684 lastLocation.kind === 340 /* SyntaxKind.JSDocParameterTag */ ||
49685 lastLocation.kind === 341 /* SyntaxKind.JSDocReturnTag */ ||
49686 lastLocation.kind === 163 /* SyntaxKind.TypeParameter */
49687 // local types not visible outside the function body
49688 : false;
49689 }
49690 if (meaning & result.flags & 3 /* SymbolFlags.Variable */) {
49691 // expression inside parameter will lookup as normal variable scope when targeting es2015+
49692 if (useOuterVariableScopeInParameter(result, location, lastLocation)) {
49693 useResult = false;
49694 }
49695 else if (result.flags & 1 /* SymbolFlags.FunctionScopedVariable */) {
49696 // parameters are visible only inside function body, parameter list and return type
49697 // technically for parameter list case here we might mix parameters and variables declared in function,
49698 // however it is detected separately when checking initializers of parameters
49699 // to make sure that they reference no variables declared after them.
49700 useResult =
49701 lastLocation.kind === 164 /* SyntaxKind.Parameter */ ||
49702 (lastLocation === location.type &&
49703 !!ts.findAncestor(result.valueDeclaration, ts.isParameter));
49704 }
49705 }
49706 }
49707 else if (location.kind === 189 /* SyntaxKind.ConditionalType */) {

Callers 2

resolveNameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…