Skip to content

fix(typescript): rule out ternary true-branch in object-method branch - #1657

Merged
squid-protocol merged 3 commits into
squid-protocol:mainfrom
uuzzrm:fix/ts-ternary-misattribution
Aug 15, 2026
Merged

fix(typescript): rule out ternary true-branch in object-method branch#1657
squid-protocol merged 3 commits into
squid-protocol:mainfrom
uuzzrm:fix/ts-ternary-misattribution

Conversation

@uuzzrm

@uuzzrm uuzzrm commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

What & why

Closes #1632. func_start's object-literal-method branch matches IDENT : followed by a function/arrow - but a ternary's true branch (cond ? name : function() { ... }, jquery/deferred.js:182-184) has the identical name :\nfunction() { surface while name is a plain identifier reference, not an object key. GitGalaxy reported a phantom mightThrow at the anonymous function.

A real object/namespace key is never preceded (skipping whitespace/newlines) by ? - that position is exclusively the ternary true-branch - so a bounded backward scan for the preceding non-whitespace char rules the shape out, the same way #1221's Invocation Shield rules out bare call statements. JavaScript and TypeScript share the branch, so the gate covers both.

Test plan

Measured against language-crucible:

typescript: found 1876, extra 299, args 1796 - unchanged (no regression)
javascript: extra_functions 11 -> 10 (the jquery/deferred.js phantom is gone)
           found_functions 599 - unchanged

The issue's repro now yields zero satellites; added a regression test covering both languages. Detector + TS/JS extraction suites: 255 passed. Both crucible modes pass after re-blessing the golden masters via update_golden_master.py.

Pairs with #1654 (#1631) and #1655 (#1629) - the three fixes touch the same _slice_by_braces region independently and merge in any order.

… (issue squid-protocol#1632)

func_start's object-literal-method branch matches `IDENT :` followed by a
function/arrow -- but a ternary's true branch (`cond ? name : function() {
... }`, jquery/deferred.js:182-184) has the identical `name :\nfunction() {`
surface while `name` is a plain identifier reference, not an object key.
GitGalaxy reported a phantom `mightThrow` at the anonymous function.

A real object/namespace key is never preceded (skipping whitespace/
newlines) by `?` -- that position is exclusively the ternary true-branch --
so a bounded backward scan for the preceding non-whitespace char rules the
shape out, the same way squid-protocol#1221's Invocation Shield rules out bare call
statements. JavaScript and TypeScript share the branch, so the gate covers
both.

Measured against language-crucible:
- typescript: found 1876, extra 299, args 1796 -- unchanged (no regression)
- javascript: extra_functions 11 -> 10 (the jquery/deferred.js phantom is
  gone), found 599 unchanged
- repro from the issue now yields zero satellites

Golden masters re-blessed via update_golden_master.py; both crucible modes
pass. Closes squid-protocol#1632.

Signed-off-by: Ruiming Zhao <uuzzrm@gmail.com>
# Conflicts:
#	gitgalaxy/core/detector.py
#	tests/golden_master_audit.json
#	tests/golden_master_zero_dep_audit.json
#	tests/ruff_audit_baseline.json
Merged origin/main (which had just picked up squid-protocol#1654's and squid-protocol#1655's typescript
fixes) into this PR's branch -- both squid-protocol#1654 and this PR's squid-protocol#1632 fix insert a
guard at the identical anchor point in _slice_by_braces's per-match loop, so
detector.py needed a manual merge combining both guard blocks in sequence
(order between them doesn't matter, each is an independent early-continue).
Re-blessed golden masters + ruff baseline on the merged code.
@squid-protocol
squid-protocol merged commit 7c317e5 into squid-protocol:main Aug 15, 2026
27 checks passed
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.

javascript/typescript func_start: ternary's cond ? name : function(){} branch misattributes the other-branch identifier as the function's name

2 participants