Skip to content

fix(typescript): recognize negation-body arrows, optional method signatures, and fix TS audit ground-truth filter - #2245

Merged
squid-protocol merged 34 commits into
mainfrom
fix/tri-comparison-sweep-final-issues
Aug 26, 2026
Merged

squid-protocol merged 34 commits into
mainfrom
fix/tri-comparison-sweep-final-issues

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

  • func_start's arrow-body-start lookahead had no allowance for a bare unary ! (const predicate = (e: T) => !e.newDocument;), so negation-body arrow functions were silently dropped. Added ! as a literal alternative in both assignment-style branches.
  • func_start's two zero-generic-prefix lookaheads had no allowance for TypeScript's optional-member ? between a name and its parameter list (copy?(source: Uri): void;, flush?(), handleDrag?()), so these interface/ambient signatures were never matched. Added \?? immediately against the name capture in both the modifier-prefixed and zero-prefix branches — placed with zero whitespace tolerance before the ? so it can't be satisfied by a spaced ternary (isEnabled ? (a + b) : c;), verified explicitly.
  • tests/tools/tree_sitter_accuracy_audit.py's ground-truth filter for GitGalaxy's intentional, correct exclusion of reserved-word method names (catch, etc. — indistinguishable from a control-flow statement without scope-awareness) was scoped to lang == "javascript" only, even though TypeScript's method_definition nodes are the identical tree-sitter-inherited shape and TS's func_start carries the same keyword blacklist. This made real catch/return-named methods in vscode/async.ts show up as phantom false-negative gaps in the accuracy audit. Widened the filter to cover typescript, and added "return" to the shared reserved-keyword set (it was missing alongside catch). The JS-only Flow-hallucination half of the filter is untouched.
  • Regenerated both golden masters (tests/golden_master_audit.json, tests/golden_master_zero_dep_audit.json) via update_golden_master.py — the 62-entry drift in each is expected: newly-recovered TypeScript functions/methods in the crucible corpus (playwright/frames.ts, vscode/vscode.d.ts, vscode/ipc.ts) plus small downstream ripples in global topology/aggregate metrics that depend on the whole-corpus function graph.
  • Renamed the three [TS]-tagged issues to [TypeScript] for future search discoverability.

Closes #2231, #2232, #2233.

Test plan

  • pytest tests/extraction/languages/test_typescript.py — 88 passed
  • pytest tests/extraction/languages/test_typescript_strict.py (ReDoS/precision harness) — 101 passed
  • pytest tests/core_engine/test_language_standards_strict.py — 21 passed
  • Full suite: pytest tests/ — 7035 passed, 2 skipped, 10 xfailed, 3 xpassed
  • python tests/tools/crucible_check.py (both full-precision and zero-dependency modes) — PASS against regenerated golden masters
  • Manually verified each issue's exact reproduction snippet plus the spaced-ternary collision edge case against the new regex

🤖 Generated with Claude Code

squid-protocol and others added 30 commits August 23, 2026 18:39
… Obj-C, Swift, Tcl, TS

This commit resolves a batch of unvalidated tri-comparison shapes by improving extraction accuracy:
- **Objective-C**: Updated `func_start` to correctly match unparenthesized return types (e.g., `- unsigned char next_input_block`).
- **Swift**: Modified `detector.py` normalizer to preserve standard operator characters (e.g., `==`), preventing them from collapsing into `Unknown_Block`.
- **Tcl**: Updated `func_start` to optionally consume the inline brace-wrapped argument list so it isn't mistaken for the function body by the balanced-brace finder.
- **TypeScript**: Fixed arrow function `func_start` branch to permit up to 3 levels of nested parentheses in the return type, enabling extraction of `const fn = <T>(): (returnType<...>) => {`.

Closes #2214
Closes #2217
Closes #2218
Closes #2220

Also updates all relevant baselines (Tree-sitter accuracy, Crucible Golden Masters, Tri-comparison Ledger/Chart).
…baseline

Resolves #2230 by ignoring multi-character operators like <=, <<, and => in the detector's backward scanner. Also adds tri_comparison baseline for typescript.
…eep-final-issues

# Conflicts:
#	docs/self_scan/tree_sitter_accuracy_chart.svg
#	docs/self_scan/tree_sitter_accuracy_history.csv
#	docs/self_scan/tri_comparison_chart.svg
#	docs/self_scan/tri_comparison_ledger.json
#	docs/self_scan/tri_comparison_points_of_interest.md
#	tests/golden_master_audit.json
#	tests/golden_master_zero_dep_audit.json
#	tests/tree_sitter_accuracy_baseline_typescript.json
objective-c/function/existence/agree[ctags,gitgalaxy]_vs[tree_sitter] (2
occurrences, worldwideweb/HyperText.m:1147,1289) confirmed: both are real
methods using old unparenthesized-return-type syntax ('- ReturnType name')
that ctags and GitGalaxy both handle correctly. tree-sitter-objc cannot
parse this form under any node type at all (confirmed via a direct parse:
the leading '-' gets read as a unary-minus operator once the return type
isn't parenthesized, corrupting the rest of the construct). No
credit/debit -- ctags+gitgalaxy are already an agreeing pair.

Logged as Claim 13 in why_gitgalaxy_beats_ast_here.md: a distinct
mechanism from Claim 2 (grammar has no concept of a dialect/extension) and
Claim 3 (grammar supports the construct but a parse bug cascades into
unrelated code) -- here the grammar never supported the looser historical
form of the SAME base language at all, and the misparse stays local.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…avascript, typescript, rust, perl, php, haskell)

Full ledger sweep after a proper regen with real Universal Ctags + tree-sitter
(the prior committed ledger had 48 unvalidated shapes, 47 of them stale
artifacts of two dated incidents: PR #2111's regen without real ctags on
PATH, degrading many languages to a 2-tool comparison, and an earlier
ctags-availability gap on the ledger's first-ever gather).

Validated 25 shapes across 9 languages:
- Most (18) are stale/superseded duplicates: the real, current disagreement
  is already captured and validated under a sibling 3-tool shape key; these
  are the same occurrences observed mid-incident with a tool missing from
  the reading set, not a separate cause.
- 3 are confirmed-fixed historical GitGalaxy defects (csharp bodyless
  interface/abstract methods, #2036; typescript curried arrow functions
  with nested-paren return types, #2220).
- 1 corrects a previously mis-validated live entry
  (perl/function/existence/agree[gitgalaxy]_vs[ctags,tree_sitter]) that
  credited GitGalaxy for a false positive -- mojo/Promise.pm's `get_p` is
  inside a POD SYNOPSIS documentation block, not real code. Same
  "Antigravity (direct sweep)" error pattern already caught twice before
  (dd496a5, 2af9219).
- 3 new confirmed engine defects filed as issues (#2237 csharp args on
  doubly-nested-paren attributes, #2238 python args on cdef/cpdef with a
  C return type, #2239 perl func_start matching POD code examples as real
  subroutines -- the false-positive mirror of closed #1606).

Also closed #2216 (php anonymous-class recall) as based on a
since-corrected ledger premise -- ctags fabricates a synthetic name for
these, GitGalaxy is right to skip them, not the other way around.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…powershell, objc, tcl)

Completes the full ledger sweep -- 0 unvalidated shapes remain (from 49 at
the start of this sweep).

10 of these 13 are stale/superseded duplicates of already-validated sibling
shapes (same underlying occurrences, observed with a tool missing from the
reading set during the PR #2111 ctags-outage window or the ledger's first
gather).

3 new confirmed engine defects filed as issues:
- #2240: c/cpp KNOWN-MACRO SHIELD excludes a real function whenever its
  name is later redefined as a no-op stub macro (CPython's #ifdef-debug-fn/
  #else-stub idiom trips it on ASSERT_DICT_LOCKED, validate_list, and 8
  others).
- #2241: ruby args regex's do|...|/{|...|} block-parameter fallback isn't
  scoped to define_method, misattributing an unrelated iterator block deep
  in a paren-less method's body as that method's own argument list (6
  confirmed false positives in rails/*.rb).
- #2242: tcl's unbounded single-quote pairing in _build_brace_safe_stream
  mispairs SQL-literal apostrophes (no tcl-specific gate, unlike the
  existing rust/zig/scala/perl precedents in the same function), silently
  dropping drop_all_tables/drop_all_indexes from sqlite/tester.tcl.

Also corrects an already-validated ledger entry
(tcl/function/existence/agree[ctags,tree_sitter]_vs[gitgalaxy]) whose
recorded root cause was a surface-level guess ("nested braces in args")
rather than the real mechanism -- the direction (GitGalaxy defect) was
already right, the cause wasn't; root-caused by driving the pipeline
directly instead of guessing from symptoms.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Final regen after the full ledger sweep (0 unvalidated shapes remaining).
Refreshes last_reconciled_at/last_seen_count/still_reproduces on every
shape against the current corpus with real Universal Ctags + tree-sitter;
no status/verdict/credit/debit changes beyond what the two preceding
commits already recorded.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…eep-final-issues

# Conflicts:
#	docs/self_scan/tri_comparison_ledger.json
#	docs/self_scan/tri_comparison_points_of_interest.md
No status/verdict/credit/debit changes -- confirmed via diff before
committing. Just last_reconciled_at refresh from re-running the regen
after merging origin/main.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
squid-protocol and others added 3 commits August 26, 2026 06:54
…gnatures

func_start's arrow-body-start alternation had no allowance for a bare unary
`!` (`const predicate = (e: T) => !e.newDocument;`), and its two zero-generic
lookaheads had no allowance for TypeScript's optional-member `?` between a
name and its parameter list (`copy?(source: Uri): void;`, `flush?()`,
`handleDrag?()`), both silently dropping otherwise-real functions/methods.

Fixes #2231, #2232.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…pt too

tree_sitter_accuracy_audit.py's filter for GitGalaxy's intentional, correct
exclusion of reserved-word method names (catch, etc.) was scoped to
lang == "javascript" only, even though typescript's method_definition nodes
are the same tree-sitter-inherited shape and GitGalaxy's typescript
func_start carries the identical keyword blacklist. This made real
catch/return-named methods in vscode/async.ts show up as phantom
false-negative gaps. Widened the filter to cover typescript, and added
"return" to the shared reserved-keyword set (it was missing alongside
catch, the second name this issue names as a phantom gap). The
javascript-only Flow-hallucination half of the filter is left untouched.

Fixes #2233.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

Re-blesses the pinned ground-truth baseline after #2231/#2232/#2233's
regex and audit-filter fixes: found_functions 2736 -> 2773 (recall gain
from the `!`-body-arrow and `?`-optional-signature fixes across the full
23-file corpus, not just the two cited examples), real_functions 2789 ->
2788 (one phantom ground-truth entry correctly dropped by the widened
reserved-keyword filter). Accuracy summary table regenerated to match
(Typescript func_start: 98.1% -> 99.5%).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squid-protocol
squid-protocol merged commit d45eedd into main Aug 26, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the fix/tri-comparison-sweep-final-issues branch August 26, 2026 11:06
squid-protocol added a commit that referenced this pull request Aug 26, 2026


Structural drift in the golden masters is fully attributable to the
fix: vscode.d.ts now correctly extracts ~113 previously-missed real
constructor signatures, with the expected downstream ripple into
topological coordinates and structural-magnitude aggregates for the
same file/directory group.

tree_sitter_accuracy_audit.py itself needed a real code fix, not just
a baseline regeneration: it had a deliberate, pre-existing exclusion
(`pass  # Intentional drop of bodyless constructors`, from #2245)
dropping every bodyless TypeScript `constructor` node from its own
ground truth -- written back when GitGalaxy structurally could never
find one, so counting it as "real" would have permanently and
unfairly penalized recall. #2279 closes that exact gap, so the
exclusion is now stale: keeping it would have silently dropped all
123 real constructors in vscode.d.ts from ground truth and counted
every one of GitGalaxy's new, correct finds as a false
"extra_functions" regression (12 -> 127) instead of the real recall
win it is. Removed the exclusion; constructors now flow through the
same real_funcs bookkeeping as any other method_signature/
function_signature node. Confirmed via a raw tree-sitter walk of
vscode.d.ts independent of this tool's own machinery (123 method_
signature nodes named "constructor", matching exactly) before making
the change.

Net effect after the fix: found_functions 2773 -> 2898, extra_functions
12 -> 2 (both of the 2 remaining are the already-known-good abstract-
method case, unrelated to this PR). tree_sitter_accuracy_audit --all
--ci: all 31 baselined languages OK, no regressions anywhere else.
tests/tools/audit_check.py --ci: all clear.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
squid-protocol added a commit that referenced this pull request Aug 26, 2026
* fix(typescript): recognize bodyless constructor declarations

func_start's bodyless-declaration branch required a `:ReturnType`
annotation before the terminating `;`, but a TypeScript constructor
can never carry a return-type annotation at all -- making every
bodyless constructor signature (ambient .d.ts class members,
interface-like declarations) structurally unmatchable.

Split the zero-prefix branch: `constructor` gets its own alternative
with the return-type made fully optional (safe, since it's a reserved
identifier that can never collide with a real function call); every
other identifier keeps the original branch, still requiring an
explicit return type before `;` to avoid false-positiving on bare
function calls like `next();`.

Verified via the full 23-file typescript corpus diff against
tree-sitter: vscode.d.ts alone recovers all ~113 previously-missed
constructor signatures (struct_func_start/function_count now match at
671, up from 558/10 constructors found). Corpus-wide missing-function
count drops from 131 to 16, zero new regressions, zero new
over-detection.

Fixes #2279.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* chore: bless golden masters + fix stale ground-truth exclusion for #2279

Structural drift in the golden masters is fully attributable to the
fix: vscode.d.ts now correctly extracts ~113 previously-missed real
constructor signatures, with the expected downstream ripple into
topological coordinates and structural-magnitude aggregates for the
same file/directory group.

tree_sitter_accuracy_audit.py itself needed a real code fix, not just
a baseline regeneration: it had a deliberate, pre-existing exclusion
(`pass  # Intentional drop of bodyless constructors`, from #2245)
dropping every bodyless TypeScript `constructor` node from its own
ground truth -- written back when GitGalaxy structurally could never
find one, so counting it as "real" would have permanently and
unfairly penalized recall. #2279 closes that exact gap, so the
exclusion is now stale: keeping it would have silently dropped all
123 real constructors in vscode.d.ts from ground truth and counted
every one of GitGalaxy's new, correct finds as a false
"extra_functions" regression (12 -> 127) instead of the real recall
win it is. Removed the exclusion; constructors now flow through the
same real_funcs bookkeeping as any other method_signature/
function_signature node. Confirmed via a raw tree-sitter walk of
vscode.d.ts independent of this tool's own machinery (123 method_
signature nodes named "constructor", matching exactly) before making
the change.

Net effect after the fix: found_functions 2773 -> 2898, extra_functions
12 -> 2 (both of the 2 remaining are the already-known-good abstract-
method case, unrelated to this PR). tree_sitter_accuracy_audit --all
--ci: all 31 baselined languages OK, no regressions anywhere else.
tests/tools/audit_check.py --ci: all clear.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* chore: re-bless golden masters + baseline against merged main (#2276+#2277+#2279)

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* chore: re-bless golden masters against merged main (all 4 TS fixes combined)

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Joe Esquibel <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
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] Arrow-function regex rejects bodies starting with exclamation mark (!)

1 participant