fix(extraction): capture top-level initializer and inline-object-method calls (#465)

The variable / method-definition extractors never walked top-level
initializer values or inline-object method bodies, so calls like
`const token = getTokenMp()` and `methods: { save() { getTokenMp() } }`
showed up nowhere in `codegraph_callers`. The variable extractor now
walks any non-object initializer value; the method-definition extractor
still skips synthetic nodes for inline-object methods (noise rationale
unchanged) but now walks their bodies for calls. Surfaces in plain
`.ts`/`.js` files as well as Vue SFCs (`<script setup>` initializers +
Options API `methods: {...}` / `setup()`), which is where the bug was
originally reported.

Closes #425.
This commit is contained in:
Nandhis
2026-05-26 19:15:32 -05:00
committed by GitHub
parent 2f93af5d89
commit 893256b88e
3 changed files with 73 additions and 0 deletions
+61
View File
@@ -518,6 +518,20 @@ export const authMachine = createMachine({
expect(varNode).toBeDefined();
expect(varNode?.isExported).toBe(true);
});
it('should extract calls from a top-level variable initializer (issue #425)', () => {
const code = `
import { getTokenMp } from './api/upload';
const token = getTokenMp();
`;
const result = extractFromSource('app.ts', code);
const call = result.unresolvedReferences.find(
(ref) => ref.referenceKind === 'calls' && ref.referenceName === 'getTokenMp'
);
expect(call).toBeDefined();
});
});
describe('File Node Extraction', () => {
@@ -3600,6 +3614,53 @@ function increment(): void {
}
});
it('should extract calls from top-level <script setup> initializers', () => {
const code = `<template>
<div>{{ token }}</div>
</template>
<script setup lang="ts">
import { getTokenMp } from './api/upload';
const token = getTokenMp();
</script>
`;
const result = extractFromSource('Issue425Setup.vue', code);
const call = result.unresolvedReferences.find(
(ref) => ref.referenceKind === 'calls' && ref.referenceName === 'getTokenMp'
);
expect(call).toBeDefined();
});
it('should extract calls from Vue Options API object methods', () => {
const code = `<template>
<button @click="save">Save</button>
</template>
<script>
import { getTokenMp } from './api/upload';
export default {
methods: {
save() {
return getTokenMp();
}
},
setup() {
return getTokenMp();
}
}
</script>
`;
const result = extractFromSource('Issue425Options.vue', code);
const calls = result.unresolvedReferences.filter(
(ref) => ref.referenceKind === 'calls' && ref.referenceName === 'getTokenMp'
);
expect(calls).toHaveLength(2);
});
it('should extract from both <script> and <script setup> blocks', () => {
const code = `<template>
<div>{{ msg }}</div>