MCPcopy Create free account
hub / github.com/TanStack/query / getExternalRefs

Function getExternalRefs

packages/eslint-plugin-query/src/utils/ast-utils.ts:160–208  ·  view source on GitHub ↗
(params: {
    scopeManager: TSESLint.Scope.ScopeManager
    sourceCode: Readonly<TSESLint.SourceCode>
    node: TSESTree.Node
  })

Source from the content-addressed store, hash-verified

158 return scope.set.has(reference.identifier.name)
159 },
160 getExternalRefs(params: {
161 scopeManager: TSESLint.Scope.ScopeManager
162 sourceCode: Readonly<TSESLint.SourceCode>
163 node: TSESTree.Node
164 }): Array<TSESLint.Scope.Reference> {
165 const { scopeManager, sourceCode, node } = params
166 const scope = scopeManager.acquire(node)
167
168 if (scope === null) {
169 return []
170 }
171
172 const collectReferences = (
173 currentScope: TSESLint.Scope.Scope,
174 ): Array<TSESLint.Scope.Reference> => {
175 const references = [...currentScope.references]
176
177 for (const childScope of currentScope.childScopes) {
178 references.push(...collectReferences(childScope))
179 }
180
181 return references
182 }
183
184 const references = collectReferences(scope)
185 .filter((x) => x.isRead() && !scope.set.has(x.identifier.name))
186 .map((x) => {
187 const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [
188 AST_NODE_TYPES.MemberExpression,
189 AST_NODE_TYPES.Identifier,
190 ])
191
192 return {
193 variable: x,
194 node: referenceNode,
195 text: sourceCode.getText(referenceNode),
196 }
197 })
198
199 const localRefIds = new Set(
200 [...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0])),
201 )
202
203 const externalRefs = references.filter(
204 (x) => x.variable.resolved === null || !localRefIds.has(x.text),
205 )
206
207 return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable)
208 },
209 mapKeyNodeToText(
210 node: TSESTree.Node,
211 sourceCode: Readonly<TSESLint.SourceCode>,

Callers

nothing calls this directly

Calls 2

uniqueByFunction · 0.90
collectReferencesFunction · 0.85

Tested by

no test coverage detected