Semantic Diff

#9428 Print the operands of in and loop headers with the levels JS needs

1 commit

aacaf7206841611e209512ff949c9b6cf6596228..pr-9428

86599e210 · illusionalsagacity · Nov 25, 2026, 19:41 UTC

Print the operands of in and loop headers with the levels JS needs

Why

Js_dump printed both operands of the in operator, which Dict.has compiles to, at level 0, so that a conditional, a sequence or a comparison got no parentheses and JavaScript took only part of it as the operand. It also printed an in without parentheses at levels up to 12, so that an in on the right of a comparison, or an operand of +, was split the same way. In now takes its levels from instanceof, which is in the same class of operators.

The start of a for loop whose end is a number or a variable, and what for...of and for await...of iterate, were printed at level 0 as well. JavaScript reads a comma in the start as the next declaration and doesn't allow one in an iterable, so a sequence was a syntax error, or, in a start ending in a variable, a second loop variable. They are now printed at level 1.

modifiedJS operands of in

let property = (d, b) => d->Dict.has(b ? "x" : "y")let obj = (b, d, e) => (b ? d : e)->Dict.has("a")
js
Before
After
function property(d, b) {function property(d, b) { return b ? "x" : "y" in d; return ( b ? "x" : "y" ) in d;}} function obj(b, d, e) {function obj(b, d, e) { return "a" in b ? d : e; return "a" in ( b ? d : e );}}

modifiedJS in as an operand

let lessThan = (d, e) => d->Dict.has("a") < e->Dict.has("a")
js
Before
After
function lessThan(d, e) {function lessThan(d, e) { return "a" in d < "a" in e; return "a" in d < ("a" in e);}}

modifiedJS sequence in a loop header

let start = (f, g) =>  for i in {    f()    g()  } to 5 {    f()  }let iterable = (f, items: array<int>) =>  for _ of {    f()    items  } {    f()  }
js
Before syntax errors
After
for (let i = f(), g(); i <= 5; ++i) {for (let i = (f(), g()); i <= 5; ++i) {……for (let _for_of of f(), items) {for (let _for_of of (f(), items)) {

Review

  • Do other outputs change? A dict literal tested with in is now printed as key in ({a: 1}), as an object literal is as the operand of any other operator. No other checked-in output changes.