fix(typescript): allow catch/return/throw as legitimate method names - #2282
Merged
Conversation
func_start's reserved-keyword shield unconditionally excluded catch,
return, and throw to stop `} catch (e) {` control-flow blocks from
being misidentified as method definitions -- but that also permanently
hid a real method/property legitimately named one of those words (a
Promise-like thenable's catch<T>(), an AsyncIterator protocol's
return()).
Moved to a conditional exclusion: only excluded when immediately
followed by whitespace then `(`/`<`, the shape idiomatic control-flow
and statement syntax always has (`catch (e)`, `return <expr`) but a
real method/property definition never does (`catch<T>(...)`,
`return: () => {...}`).
Verified via the full 23-file typescript corpus diff against
tree-sitter: the targeted catch case is fixed, zero new regressions
introduced anywhere else in the corpus (131 -> 130 missing). A second
`return`-named occurrence in the same file remains a separate,
pre-existing same-name dedup gap in detector.py, unrelated to this
regex change (unaffected either way).
Fixes #2276.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
Structural drift is fully attributable to the fix: async.ts now correctly extracts `catch` as a real method (253 -> 254 function/ method declarations), with the expected downstream ripple into topological coordinates and structural-magnitude aggregates for the same file/directory group -- CLAUDE.md's documented, expected class of drift when a function count changes. The tree-sitter-accuracy-audit baseline needed a reviewed (not blind) regeneration: `catch` is now correctly reported as a real function (verified directly against source, see #2276), but this tool's own tree-sitter walker filters reserved-control-flow-keyword-shaped names defensively (the same class of tooling blind spot already documented in this tool's own module docstring for cpp/c's macro-shield precedent) -- so it counted GitGalaxy's new, correct find as "extra_functions: 12 -> 13" against a ground truth that's itself wrong here. Regenerated per that same documented precedent ("reviewed rather than treated as a real regression"), not force-overridden blind. python tests/tools/audit_check.py --ci: all clear. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2276.
func_start's reserved-keyword shield unconditionally excludedcatch/return/throwto stop} catch (e) {control-flow blocks from being misidentified as method definitions -- but that also permanently hid a real method/property legitimately named one of those words (a Promise-like thenable'scatch<T>(), an AsyncIterator protocol'sreturn()).Fix
Moved to a conditional exclusion: only excluded when immediately followed by whitespace then
(/<-- the shape idiomatic control-flow/statement syntax always has (catch (e),return <expr), while a real method/property definition never does (catch<T>(...),return: () => {...}).Verification
catch<TResult=never>(...)andreturn: () => {...}now match;} catch (e) {(control-flow) still correctly does not.pytest tests/extraction/languages/test_typescript.py tests/extraction/languages/test_typescript_strict.py tests/core_engine/test_detector.py-- 333 passed, no stale expectations needed updating.tri_comparison_gatherer.gather_language): missing-function count went from 131 to 130 (the targetedcatchcase fixed, zero new regressions introduced anywhere else in the corpus). A secondreturn-named occurrence in the same file remains a separate, pre-existing same-name dedup gap indetector.py-- unrelated to this change, unaffected either way.tests/ruff_audit.py --ci/tests/mypy_audit.py --ci-- no new findings beyond baseline.Implemented by a dispatched Gemini/agy subagent per this repo's
tree-sitter-accuracy-sweep-style workflow; independently re-verified in the main session (diff read, corpus-wide regression check, ReDoS probe) before this push, per that skill's step 7.Test plan
test_typescript.py/test_typescript_strict.py/test_detector.py