Skip to content

format JSX expression children with explicit braces - #8666

Open
tsnobip wants to merge 4 commits into
masterfrom
wrap-children-in-jsx
Open

tsnobip wants to merge 4 commits into
masterfrom
wrap-children-in-jsx

Conversation

@tsnobip

@tsnobip tsnobip commented Sep 22, 2026

Copy link
Copy Markdown
Member

Prepare JSX for future literal text by formatting expression children with explicit braces:

// Before
let x = <span> hello </span>

// After
let x = <span>{hello}</span>

Existing unbraced expressions remain valid syntax. Nested JSX elements stay unwrapped, and existing expression braces do not accumulate.

Child comments move inside the braces. For a single expression child, line wrapping also stays inside the braces, avoiding whitespace between the expression container and its tags:

let x =
  <span>{
    hello // some comment
  }</span>

Standalone comments in empty elements or between nested elements are wrapped in comment-only containers:

let x =
  <div>
    {/* before */}
    <Icon />
    {
      // after
    }
  </div>

The parser retains these comments without adding a child, preserving the distinction between zero, one, and multiple children. Bare {} still denotes an empty record expression; {{/* comment */}} keeps an empty record as a child. Line comments retain their style, including when their text contains */.

Literal text parsing and whitespace rules between sibling children remain future work. The next migration step is to reject unbraced expressions before enabling literal text, so existing variable references cannot silently become strings.

Validation:

  • Formatting tests check expression and comment preservation and repeatability at five widths, including leading/trailing comments, fragments, nested elements, and attributes. Malformed containers remain parse errors.
  • Parser and JSX transform tests verify unchanged child counts for React and custom JSX modules. AST bridge fixtures and generated JavaScript cover the transformation and JSX-preserve paths.

Supersedes #7863.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-22T15:13:17.962035Z 6d6005b Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tsnobip
tsnobip force-pushed the wrap-children-in-jsx branch 2 times, most recently from 4495a55 to 78476d8 Compare September 22, 2026 11:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a479f8349e

ℹ️ 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".

Comment thread CHANGELOG.md Outdated
@tsnobip
tsnobip force-pushed the wrap-children-in-jsx branch from 78476d8 to 701313d Compare September 22, 2026 12:36
@tsnobip

tsnobip commented Sep 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 701313d0e0

ℹ️ 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".

Comment thread compiler/syntax/src/res_printer.ml Outdated
@codecov

codecov Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.63014% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.58%. Comparing base (fb35986) to head (6d6005b).

Files with missing lines Patch % Lines
compiler/syntax/src/res_printer.ml 97.87% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8666   +/-   ##
=======================================
  Coverage   78.57%   78.58%           
=======================================
  Files         476      476           
  Lines       64157    64172   +15     
=======================================
+ Hits        50413    50431   +18     
+ Misses      13744    13741    -3     
Files with missing lines Coverage Δ
compiler/syntax/src/res_comments_table.ml 88.61% <100.00%> (-0.46%) ⬇️
compiler/syntax/src/res_core.ml 91.90% <100.00%> (+0.01%) ⬆️
compiler/syntax/src/res_parens.ml 87.85% <100.00%> (+2.91%) ⬆️
compiler/syntax/src/res_printer.ml 93.41% <97.87%> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Sep 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8666

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@8666

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8666

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8666

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8666

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8666

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8666

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8666

commit: 6d6005b

@github-actions

Copy link
Copy Markdown

@tsnobip

tsnobip commented Sep 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 6d6005ba9f

ℹ️ 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".

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant