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

Function getExternalRefs

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

Source from the content-addressed store, hash-verified

88 return scope.set.has(reference.identifier.name)
89 },
90 getExternalRefs(params: {
91 scopeManager: TSESLint.Scope.ScopeManager
92 sourceCode: Readonly<TSESLint.SourceCode>
93 node: TSESTree.Node
94 }): Array<TSESLint.Scope.Reference> {
95 const { scopeManager, sourceCode, node } = params
96 const scope = scopeManager.acquire(node)
97
98 if (scope === null) {
99 return []
100 }
101
102 const collectReferences = (
103 currentScope: TSESLint.Scope.Scope,
104 ): Array<TSESLint.Scope.Reference> => {
105 const references = [...currentScope.references]
106
107 for (const childScope of currentScope.childScopes) {
108 references.push(...collectReferences(childScope))
109 }
110
111 return references
112 }
113
114 const references = collectReferences(scope)
115 .filter((x) => x.isRead() && !scope.set.has(x.identifier.name))
116 .map((x) => {
117 const memberPath = ASTUtils.traverseUpMemberExpression(x.identifier)
118 const memberExpression = memberPath.parent
119 const isComputedCallProperty =
120 memberExpression !== undefined &&
121 memberExpression.type === AST_NODE_TYPES.MemberExpression &&
122 memberExpression.computed &&
123 memberExpression.property === memberPath &&
124 memberExpression.parent.type === AST_NODE_TYPES.CallExpression &&
125 memberExpression.parent.callee === memberExpression
126
127 const referenceNode = isComputedCallProperty
128 ? memberPath
129 : ASTUtils.traverseUpOnly(x.identifier, [
130 AST_NODE_TYPES.MemberExpression,
131 AST_NODE_TYPES.Identifier,
132 ])
133
134 return {
135 variable: x,
136 node: referenceNode,
137 text: sourceCode.getText(referenceNode),
138 }
139 })
140
141 const localRefIds = new Set(
142 [...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0])),
143 )
144
145 const externalRefs = references.filter(
146 (x) => x.variable.resolved === null || !localRefIds.has(x.text),
147 )

Callers

nothing calls this directly

Calls 2

uniqueByFunction · 0.90
collectReferencesFunction · 0.85

Tested by

no test coverage detected