Created
April 18, 2025 23:05
-
-
Save souporserious/513547e11ff0965e821d507c57fb840d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Identifier } from 'ts-morph' | |
const referenceCache = new WeakMap<Identifier, boolean>() | |
/** Determines if an identifier is a reference. */ | |
export function isReferenceIdentifier(node: Identifier) { | |
const cached = referenceCache.get(node) | |
if (cached !== undefined) { | |
return cached | |
} | |
const parentNode = node.getParent() | |
let isReference = true | |
for (const definitionNode of node.getDefinitionNodes()) { | |
if (definitionNode === parentNode) { | |
isReference = false | |
break | |
} | |
} | |
referenceCache.set(node, isReference) | |
return isReference | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment