Skip to content

js_parser: stop the [x][0] / {f:x}.f folds from changing optional-chain / this / assignment semantics - #36730

Merged
Jarred-Sumner merged 6 commits into
mainfrom
farm/40497af5/array-index-inline-optional-chain
Aug 4, 2026
Merged

js_parser: stop the [x][0] / {f:x}.f folds from changing optional-chain / this / assignment semantics#36730
Jarred-Sumner merged 6 commits into
mainfrom
farm/40497af5/array-index-inline-optional-chain

js_parser: don't inline an optional chain out of [x][0]

21bbd33
Select commit
Loading
Failed to load commit list.
Claude / Claude Code Review completed Aug 1, 2026 in 32m 28s

Code review found 1 potential issue

Found 2 candidates, confirmed 1. See review comments for details.

Details

Severity Count
🔴 Important 0
🟡 Nit 0
🟣 Pre-existing 1
Severity File:Line Issue
🟣 Pre-existing src/js_parser/visit/visit_expr.rs:1108-1111 [x][0] fold ignores call/delete/assign parent context

Annotations

Check notice on line 1111 in src/js_parser/visit/visit_expr.rs

See this annotation in the file changed.

@claude claude / Claude Code Review

[x][0] fold ignores call/delete/assign parent context

Pre-existing (not introduced here), but same bug class at the same fold: the `[x][0] -> x` fold at lines 1091 and 1108 doesn't consult `is_call_target`, `is_delete_target`, or `in_.assign_target`, so `[obj.m][0]()` becomes `obj.m()` (wrong `this`), `delete [obj.p][0]` becomes `delete obj.p`, and `[obj.p][0] = 5` becomes `obj.p = 5` — all observable diffs vs Node. Every sibling fold (comma, `??`, `||`, `&&`, ternary) already guards `is_call_target && x.has_value_for_this_in_call()` and emits `(0,