Repository navigation
[12.x] Parenthesise the in operator in a for loop's header - #9462
Open
illusionalsagacity wants to merge 2 commits into
Open
illusionalsagacity wants to merge 2 commits into
illusionalsagacity wants to merge 2 commits into
Conversation
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 was printed at level 0 as well. JavaScript reads a comma in the start as the next declaration, so a sequence was a syntax error, or, in a start ending in a variable, a second loop variable. It is now printed at level 1. 12.x has no `for...of` or `for await...of`, so the master change to their iterables and the tests of them don't apply here. Signed-off-by: Rob <illusionalsagacity@users.noreply.github.com> (cherry picked from commit ecb21d0)
JavaScript doesn't allow a bare `in` operator in the initializer of a `for` header, where the printer puts the start of a ReScript `for` loop and an end that is neither a number nor a variable. A start or end using `Dict.has` was therefore printed as a syntax error. While `Js_dump` prints the initializer, `Ext_pp` now records that `in` is forbidden until the next brackets, and `In` is printed in parentheses there. On 12.x, `Ext_pp` lives in compiler/ext and has no source map position tracking, so only the new field is added to its record. (cherry picked from commit 3172330) Signed-off-by: Rob <illusionalsagacity@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #9423 to 12.x. Builds on #9455 (the backport of #9428), which changes the same
Incase inJs_dump; on master #9423 was likewise rebased on top of #9428.Problem
JavaScript doesn't allow a bare
inoperator in the initializer of aforheader, where the printer puts the start of a ReScriptforloop and an end that is neither a number nor a variable. A start or end usingDict.haswas therefore printed as a syntax error.Before (syntax errors):
After:
Fix
As on master:
Js_dumpprints the initializer of aforheader,Ext_pprecords thatinis forbidden until the next brackets, andInis printed in parentheses there.Ext_ppallowsinagain, so anininside a call's arguments or an array gets no extra parentheses.Differences from master:
Ext_ppis incompiler/exton 12.x and has no source map position tracking, so only the newno_infield is added to its record.Tests
tests/tests/src/for_loop_in_operator_test.resis master's: aninin the end, in the start, in both, in nested conditionals, inside brackets and in the loop's body. Its.mjsis the same as on master. Built with 12.x before this change (with #9455), the module is a syntax error. No other module intests/testschanges output.Investigated by Claude.