Repository navigation
[12.x] Print the operands of in and loop headers with the levels JS needs - #9455
Open
illusionalsagacity wants to merge 1 commit into
Open
illusionalsagacity wants to merge 1 commit into
illusionalsagacity wants to merge 1 commit 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)
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
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 #9428 to 12.x.
Problem
Js_dumpprinted both operands of theinoperator, whichDict.hascompiles 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 aninwithout parentheses at levels up to 12, so that aninon the right of a comparison, or an operand of+, was split the same way. The start of aforloop whose end is a number or a variable was printed at level 0 as well, so a sequence in it was a syntax error, or, in a start ending in a variable, a second loop variable.Before:
After:
Fix
As on master:
Intakes its levels frominstanceof, which is in the same class of operators.forloop whose end is a number or a variable is printed at level 1.Differences from master:
for...oforfor await...of, so the master change to their iterables, and the tests of them, don't apply.Tests
tests/tests/src/printer_operand_levels_test.resis master's without thefor...ofandfor await...ofcases. It covers conditional, sequence and operator operands ofin, a dict literal as its object,inas an operand of<,===and++, and a sequence as the start of aforloop. Its.mjsis the same as on master for those cases. Built with 12.x before this change, the module is a syntax error. No other module intests/testschanges output.Investigated by Claude.