MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / isBuiltInOrExternal

Method isBuiltInOrExternal

src/resolution/index.ts:1966–2073  ·  view source on GitHub ↗

* Check if reference is to a built-in or external symbol

(ref: UnresolvedRef)

Source from the content-addressed store, hash-verified

1964 * Check if reference is to a built-in or external symbol
1965 */
1966 private isBuiltInOrExternal(ref: UnresolvedRef): boolean {
1967 const name = ref.referenceName;
1968 const isJsTs = ref.language === 'typescript' || ref.language === 'javascript'
1969 || ref.language === 'tsx' || ref.language === 'jsx' || ref.language === 'arkts';
1970
1971 // JavaScript/TypeScript built-ins
1972 if (isJsTs && JS_BUILT_INS.has(name)) {
1973 return true;
1974 }
1975
1976 // ArkTS resource-reference intrinsics — `$r('app.string.x')` /
1977 // `$rawfile('x.png')` are framework-provided and appear dozens of times
1978 // per UI file; without this they can resolve to a stray same-named
1979 // symbol (e.g. a checked-in hvigor wrapper's `$r`).
1980 if (ref.language === 'arkts' && (name === '$r' || name === '$rawfile')) {
1981 return true;
1982 }
1983
1984 // Common JS/TS library calls (console.log, Math.floor, JSON.parse)
1985 if (isJsTs && (name.startsWith('console.') || name.startsWith('Math.') || name.startsWith('JSON.'))) {
1986 return true;
1987 }
1988
1989 // React hooks from React itself
1990 if (isJsTs && REACT_HOOKS.has(name)) {
1991 return true;
1992 }
1993
1994 // Python built-ins (bare calls only — dotted calls like console.print are method calls)
1995 if (ref.language === 'python' && PYTHON_BUILT_INS.has(name)) {
1996 return true;
1997 }
1998
1999 // Python built-in method calls (e.g., list.extend, dict.update)
2000 if (ref.language === 'python') {
2001 const dotIdx = name.indexOf('.');
2002 if (dotIdx > 0) {
2003 const receiver = name.substring(0, dotIdx);
2004 const method = name.substring(dotIdx + 1);
2005 // Filter calls on built-in types (list.append, dict.update, etc.)
2006 if (PYTHON_BUILT_IN_TYPES.has(receiver)) {
2007 return true;
2008 }
2009 // Filter built-in methods on non-class receivers
2010 // (e.g., items.append where items is a local list variable)
2011 // But allow if the capitalized receiver matches a known codebase class
2012 if (PYTHON_BUILT_IN_METHODS.has(method)) {
2013 const capitalized = receiver.charAt(0).toUpperCase() + receiver.slice(1);
2014 if (!this.knownNames?.has(capitalized)) {
2015 return true;
2016 }
2017 }
2018 }
2019 // A bare name colliding with a builtin method (index, get, update, count…)
2020 // is only a builtin when NOTHING in the codebase declares it. A declared
2021 // symbol with that exact name — e.g. a Flask/FastAPI view `def index()` or
2022 // `def get()` — is a real reference target. Mirrors the knownNames guard on
2023 // the dotted branch above; without it, every handler named after a builtin

Callers 1

resolveOneMethod · 0.95

Calls 2

hasAnyPossibleMatchMethod · 0.95
hasMethod · 0.80

Tested by

no test coverage detected