When compiling the code x = (if foo! then bar(that) or baz(that)) (that is, relying on if-let to locally bind result of the first subexpression), the resulting JavaScript looks like this:
x = (that = foo()) ? bar(that) || baz(that) : void 8;
Which works pretty straightforwardly, as one would expect. If, however, you pass the same exact expression to, say, while loop, the output will have different structure:
while (if foo! then bar(that) or baz(that))
console.log 42
while ((that = foo()) && bar(that) || baz(that)) {
console.log(42);
}
Which deviates from expected behaviour, because now baz will be executed even when that is falsey (due to JavaScript operator precedence).
It is possible to reproduce structure from the first example in second case, but only by providing an explicit else branch:
while (if foo! then bar(that) or baz(that) else void)
console.log 42
while ((that = foo()) ? bar(that) || baz(that) : void 8) {
console.log(42);
}
When compiling the code
x = (if foo! then bar(that) or baz(that))(that is, relying on if-let to locally bind result of the first subexpression), the resulting JavaScript looks like this:Which works pretty straightforwardly, as one would expect. If, however, you pass the same exact expression to, say,
whileloop, the output will have different structure:Which deviates from expected behaviour, because now
bazwill be executed even whenthatis falsey (due to JavaScript operator precedence).It is possible to reproduce structure from the first example in second case, but only by providing an explicit
elsebranch: