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

Function forEachRelatedSymbol

test/fixtures/snapshot/typescript.js:138694–138801  ·  view source on GitHub ↗

* @param allowBaseTypes return true means it would try to find in base class or interface.

(symbol, location, checker, isForRenamePopulateSearchSymbolSet, onlyIncludeBindingElementAtReferenceLocation, 
            /**
             * @param baseSymbol This symbol means one property/mehtod from base class or interface when it is not null or undefined,
             */
            cbSymbol, allowBaseTypes)

Source from the content-addressed store, hash-verified

138692 * @param allowBaseTypes return true means it would try to find in base class or interface.
138693 */
138694 function forEachRelatedSymbol(symbol, location, checker, isForRenamePopulateSearchSymbolSet, onlyIncludeBindingElementAtReferenceLocation,
138695 /**
138696 * @param baseSymbol This symbol means one property/mehtod from base class or interface when it is not null or undefined,
138697 */
138698 cbSymbol, allowBaseTypes) {
138699 var containingObjectLiteralElement = ts.getContainingObjectLiteralElement(location);
138700 if (containingObjectLiteralElement) {
138701 /* Because in short-hand property assignment, location has two meaning : property name and as value of the property
138702 * When we do findAllReference at the position of the short-hand property assignment, we would want to have references to position of
138703 * property name and variable declaration of the identifier.
138704 * Like in below example, when querying for all references for an identifier 'name', of the property assignment, the language service
138705 * should show both 'name' in 'obj' and 'name' in variable declaration
138706 * const name = "Foo";
138707 * const obj = { name };
138708 * In order to do that, we will populate the search set with the value symbol of the identifier as a value of the property assignment
138709 * so that when matching with potential reference symbol, both symbols from property declaration and variable declaration
138710 * will be included correctly.
138711 */
138712 var shorthandValueSymbol = checker.getShorthandAssignmentValueSymbol(location.parent); // gets the local symbol
138713 if (shorthandValueSymbol && isForRenamePopulateSearchSymbolSet) {
138714 // When renaming 'x' in `const o = { x }`, just rename the local variable, not the property.
138715 return cbSymbol(shorthandValueSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 3 /* EntryKind.SearchedLocalFoundProperty */);
138716 }
138717 // If the location is in a context sensitive location (i.e. in an object literal) try
138718 // to get a contextual type for it, and add the property symbol from the contextual
138719 // type to the search set
138720 var contextualType = checker.getContextualType(containingObjectLiteralElement.parent);
138721 var res_1 = contextualType && ts.firstDefined(ts.getPropertySymbolsFromContextualType(containingObjectLiteralElement, checker, contextualType, /*unionSymbolOk*/ true), function (sym) { return fromRoot(sym, 4 /* EntryKind.SearchedPropertyFoundLocal */); });
138722 if (res_1)
138723 return res_1;
138724 // If the location is name of property symbol from object literal destructuring pattern
138725 // Search the property symbol
138726 // for ( { property: p2 } of elems) { }
138727 var propertySymbol = getPropertySymbolOfDestructuringAssignment(location, checker);
138728 var res1 = propertySymbol && cbSymbol(propertySymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 4 /* EntryKind.SearchedPropertyFoundLocal */);
138729 if (res1)
138730 return res1;
138731 var res2 = shorthandValueSymbol && cbSymbol(shorthandValueSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 3 /* EntryKind.SearchedLocalFoundProperty */);
138732 if (res2)
138733 return res2;
138734 }
138735 var aliasedSymbol = getMergedAliasedSymbolOfNamespaceExportDeclaration(location, symbol, checker);
138736 if (aliasedSymbol) {
138737 // In case of UMD module and global merging, search for global as well
138738 var res_2 = cbSymbol(aliasedSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 1 /* EntryKind.Node */);
138739 if (res_2)
138740 return res_2;
138741 }
138742 var res = fromRoot(symbol);
138743 if (res)
138744 return res;
138745 if (symbol.valueDeclaration && ts.isParameterPropertyDeclaration(symbol.valueDeclaration, symbol.valueDeclaration.parent)) {
138746 // For a parameter property, now try on the other symbol (property if this was a parameter, parameter if this was a property).
138747 var paramProps = checker.getSymbolsOfParameterPropertyDeclaration(ts.cast(symbol.valueDeclaration, ts.isParameter), symbol.name);
138748 ts.Debug.assert(paramProps.length === 2 && !!(paramProps[0].flags & 1 /* SymbolFlags.FunctionScopedVariable */) && !!(paramProps[1].flags & 4 /* SymbolFlags.Property */)); // is [parameter, property]
138749 return fromRoot(symbol.flags & 1 /* SymbolFlags.FunctionScopedVariable */ ? paramProps[1] : paramProps[0]);
138750 }
138751 var exportSpecifier = ts.getDeclarationOfKind(symbol, 275 /* SyntaxKind.ExportSpecifier */);

Callers 2

populateSearchSymbolSetFunction · 0.85
getRelatedSymbolFunction · 0.85

Tested by

no test coverage detected