Skip to content

fix(typescript): allow catch/return/throw as legitimate method names - #2282

Merged
squid-protocol merged 2 commits into
mainfrom
fix/typescript-2276-catch-return-shield
Aug 26, 2026
Merged

fix(typescript): allow catch/return/throw as legitimate method names#2282
squid-protocol merged 2 commits into
mainfrom
fix/typescript-2276-catch-return-shield

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #2276. func_start's reserved-keyword shield unconditionally excluded catch/return/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()).

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

  • Isolated regex tests: catch<TResult=never>(...) and return: () => {...} 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.
  • Full 23-file typescript corpus diff against tree-sitter (tri_comparison_gatherer.gather_language): missing-function count went from 131 to 130 (the targeted catch case fixed, zero new regressions introduced anywhere else in the corpus). A second return-named occurrence in the same file remains a separate, pre-existing same-name dedup gap in detector.py -- unrelated to this change, unaffected either way.
  • tests/ruff_audit.py --ci / tests/mypy_audit.py --ci -- no new findings beyond baseline.
  • ReDoS pathological-input timing probe -- no slowdown (bounded conditional exclusion, no new unbounded quantifiers).

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

  • Regex-level positive/negative tests
  • test_typescript.py / test_typescript_strict.py / test_detector.py
  • Full-corpus tri-comparison diff (before/after)
  • ruff/mypy baseline audits
  • ReDoS sanity check

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>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

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>
@squid-protocol
squid-protocol merged commit 7337da1 into main Aug 26, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the fix/typescript-2276-catch-return-shield branch August 26, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TypeScript] func_start's reserved-keyword shield excludes legitimate catch method name

1 participant