Skip to content

fix: resolve computed string-literal keys in object-literal extraction#1885

Closed
carlos-alm wants to merge 2 commits into
fix/issue-1763-busytimeout-readonly-wiringfrom
fix/issue-1764-computed-key-object-literal
Closed

fix: resolve computed string-literal keys in object-literal extraction#1885
carlos-alm wants to merge 2 commits into
fix/issue-1763-busytimeout-readonly-wiringfrom
fix/issue-1764-computed-key-object-literal

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

  • extractObjectLiteralFunctions's pair branch only stripped quotes for plain string-typed keys; a computed string-literal key like { ['foo']: () => {} } fell through to raw keyNode.text, emitting obj.['foo'] instead of obj.foo, so obj.foo() call sites could never resolve to it. Reproduced identically on both engines.
  • Extracted the existing computed_property_name-unwrapping logic (already correct in the adjacent method_definition branch's resolveMethodDefinitionName) into a shared resolveComputedKeyName helper, reused by the pair branch. Rust mirror needed two fix sites (const path and let/var path, which Rust splits into separate functions where TS uses one).

Closes #1764

Test plan

  • npm test — full suite green (3533 passed, 0 failed)
  • npm run lint / npm run typecheck — clean
  • cargo test --release — 448 passed
  • Native addon rebuilt, codesigned, verified directly
  • Exact repro confirmed fixed on both engines: obj.foo/obj.bar now resolve correctly (verified via where and query showing identical caller edges on both engines)
  • [Symbol.iterator] computed key confirmed skipped (no garbage definition) on both engines, matching method_definition's existing precedent; let/var parity confirmed separately

Filed #1884 for an out-of-scope finding: the same unwrapping gap exists in several adjacent typeMap-seeding functions (affecting typeMap seeding, not Definition.name, so they don't reproduce this issue's symptom).

Stacked on #1883 (base branch fix/issue-1763-busytimeout-readonly-wiring) — only the extractor/test diff is this issue's change.

…n (docs check acknowledged)

extractObjectLiteralFunctions's pair branch only stripped quotes for
plain string-typed keys, so a computed string-literal key like
{ ['foo']: () => {} } fell through to the raw bracket/quote text,
emitting a definition named obj.['foo'] instead of obj.foo. This
broke resolution of obj.foo() call sites.

Extract the computed_property_name-unwrapping logic already used by
resolveMethodDefinitionName into a shared resolveComputedKeyName
helper and reuse it in the pair branch, skipping the pair (like the
adjacent method_definition branch already does) when the computed key
isn't a resolvable string literal (e.g. [Symbol.iterator]).

Mirrors the same fix in the Rust native engine: extract_object_literal_functions
(const) and match_js_objlit_qualified_method_defs (let/var) both had the
identical gap, now routed through shared resolve_computed_key_name /
resolve_pair_key_name helpers alongside resolve_method_def_name.

No README/CLAUDE.md/ROADMAP.md changes needed — internal extractor bug
fix, no new language, command, or architecture surface.

Fixes #1764

Impact: 3 functions changed, 17 affected
@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a resolution bug where computed string-literal object-literal keys like { ['foo']: () => {} } produced the malformed qualified name obj.['foo'] instead of obj.foo, preventing call-site edges from resolving. The fix extracts the existing computed-key unwrapping logic already present in resolveMethodDefinitionName / resolve_method_def_name into a shared helper, then routes the pair branch through that helper in both the TypeScript and Rust extractors.

  • TypeScript: resolveComputedKeyName is extracted and reused by both resolveMethodDefinitionName and the pair branch in extractObjectLiteralFunctions.
  • Rust: Two fix sites updated (extract_object_literal_functions for const, match_js_objlit_qualified_method_defs for let/var), with resolve_pair_key_name providing the same three-case dispatch as the TS ternary.
  • Tests: Four new TS tests and three new Rust tests cover the plain computed key, non-string computed key skip, variable computed key skip, and let/var parity paths.

Confidence Score: 5/5

Safe to merge — targeted bug fix that adds a shared helper with no behavior change for existing key types, backed by comprehensive tests on both engines.

The change is a clean extraction and reuse of logic already proven correct in the method_definition branch. Both fix sites in Rust are patched, implementations are symmetric across TS and Rust, and tests cover the full matrix of cases. No existing code paths are altered in behavior.

No files require special attention.

Important Files Changed

Filename Overview
src/extractors/javascript.ts Extracts resolveComputedKeyName from resolveMethodDefinitionName and applies it to the pair branch in extractObjectLiteralFunctions, fixing computed string-literal key handling.
crates/codegraph-core/src/extractors/javascript.rs Adds resolve_computed_key_name and resolve_pair_key_name helpers, applies them at both const and let/var fix sites; resolve_method_def_name delegates to the shared helper.
tests/parsers/javascript.test.ts Adds four new test cases covering the exact bug (bracketed key, non-string computed key, variable computed key, let/var path) — good parity with the Rust test suite.

Reviews (2): Last reviewed commit: "Merge branch 'fix/issue-1763-busytimeout..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

3 functions changed17 callers affected across 1 files

  • extractObjectLiteralFunctions in src/extractors/javascript.ts:1287 (8 transitive callers)
  • resolveComputedKeyName in src/extractors/javascript.ts:2087 (14 transitive callers)
  • resolveMethodDefinitionName in src/extractors/javascript.ts:2101 (16 transitive callers)

@carlos-alm

Copy link
Copy Markdown
Contributor Author

Auto-closed when its stacked base PR #1943 was merged with --delete-branch (GitHub closes rather than retargets dependents in this case). No commits lost — recreated against main directly as #1954.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant