Repository navigation
Keep regexp statements parseable after formatting - #8720
fhammerschmidt merged 14 commits into
Conversation
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8720 +/- ##
==========================================
+ Coverage 80.54% 80.57% +0.02%
==========================================
Files 447 447
Lines 61166 61210 +44
==========================================
+ Hits 49264 49317 +53
+ Misses 11902 11893 -9
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ad914954a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7ef23231f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Thanks for picking this up! I ran a review with Claude, and it found a few things. Some of them may not hold up, so please push back where they're wrong. 1. Fix this in the parser instead? ( let t = s
/a/->RegExp.test(t)still parses as 2. Unneeded parentheses at the top level ( 3. 4. Double parentheses (
5. 6. Same logic in three places ( 7. Extra allocation for Suggested tests, whichever approach you go with: a regexp statement as the first top-level item, one after |
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
|
@cknitt Points 2–7 are now implemented:
The suggested tests are included: first top-level regexp, regexp after For 1, I kept the formatter approach because adding let b = a
/2That currently means This PR therefore preserves the existing division rules and prevents formatting from removing necessary statement separation. Handwritten regexp statements following another expression still need parentheses or a semicolon. The parser alternative would need a broader parsing decision. Validation passes: compiler build, syntax and roundtrip suites, 267 OUnit tests, 591 runtime tests, all 42 build fixtures, 744 documentation examples, and formatting/changelog checks. Comment preservation and formatting stability are checked at widths 20, 40, 80, 100, and 120. |
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
|
Re-reviewed in Claude:
|
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
|
|
Preserve both the regexp statement regression checks and the new JSX child migration tests in the syntax runner. Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Formatting a parenthesized regexp statement after a binding or another expression removed the parentheses, causing its opening
/to be parsed as division continuing the previous statement. Keep parentheses around statements whose printed expression starts with a regexp, including pipes, binary expressions, ternaries, object and field reads and writes, bracket access, chained calls, and PPX-generated##accesses.Track whether the previous structure item or block row can continue as an expression, so first statements and statements following declarations such as
type,open, ormodulekeep their existing formatting. Statement attributes already separate expressions and do not need an extra regexp wrapper. Follow the printer's operand-parenthesis rules to avoid wrapping expressions whose left edge is already protected. Share the statement-printing logic across block and structure contexts, and inspect placeholder bodies without allocating a rewritten AST. Preserve attributes on placeholder calls, include attributes in statement locations when preserving blank lines, and parenthesize attributed ternary conditions to retain their scope. Middle and final ternary operands keep their existing formatting.Keep protection on the expression's first and last lines so narrow formatting widths remain stable and preserve comments. This fixes #8688 without changing existing division rules. Extending the newline heuristic for unary operators to
/would change valid multiline division such asa\n /2, while whitespace-leading regexps would remain ambiguous. Handwritten regexp statements after another expression still require parentheses or a semicolon.Intended for backporting to v12 after merging on master.
Validation:
make compileranddune build @fmt.node scripts/test.js -ounit -mocha -build -docstrings: 267 OUnit tests, 591 runtime tests, all 42 build fixtures, CommonJS and stdlib tests, and 744 documentation examples. The regexp fixture checks formatting, reparsing,-check-lam, and runtime behavior, including attributed calls and placeholders.make test-syntaxandmake test-syntax-roundtrip.type/open/module, statement attributes, PPX##accesses, attributed expressions, and a regexp ternary used as a binary operand.openand module aliases.