Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Wrap non-components JSX children in curly braces#7863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge1 commit intomaster
base:master
Choose a base branch
Loading
fromcopilot/modify-printer-variable-wrap-jsx

Conversation

Copy link
Contributor

CopilotAI commentedSep 9, 2025
edited by tsnobip
Loading

This PR modifies the ReScript printer to wrap variables (identifiers) in curly braces when they appear as JSX children, making the output consistent with standard JSX conventions.

Problem

Previously, variables inside JSX children were printed without braces:

lethello="world"letc="test"letx= <span>hello </span>lety= <span>hello <span/></span>letz= <div>...c</div>

This is inconsistent with JSX standards where variables and spread expressions should be wrapped in braces to distinguish them from text content.

Solution

With this change, variables and constants are now wrapped in curly braces:

lethello="world"letc="test"letx= <span>{hello}</span>lety= <span>{hello}<span/></span>letz= <div>{...c}</div>

Implementation

The fix involves surgical changes to thejsx_child_expr function incompiler/syntax/src/res_parens.ml:

  1. Variables: RemovedPexp_ident _ (variables/identifiers) from the pattern that returnedNothing, causing them to fall through to the default case that returnsParenthesized, which wraps them in braces.

What Changes

Now wrapped in braces:

  • Variables:hello{hello}
  • Identifiers:someVar{someVar}
  • constants:"hello" ->{"hello"}
  • field access:obj.field ->{obj.field}
  • constructors:Some(x) ->{Some(x)}
  • extensions:%raw("eval()") ->{%raw("eval()")}
  • records and objects:{"x": 1, "y": 2} ->{{"x": 1, "y": 2}}

Already had braces (no change):

  • Function calls:{func()} stays{func()}
  • Binary expressions:{a + b} stays{a + b}

** Remaining to support **

  • comments

Testing

All existing syntax tests have been updated to reflect the new behavior. The changes are minimal and targeted, affecting only variables in JSX children while preserving existing behavior for all other expression types.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.

@tsnobiptsnobip changed the title[WIP] Modify the printer so that it wraps variables inside curly braces inside JSX:res<span> hello </span>should be printed asres<span>{hello}</span>andres<span> hello <span/></span>should be printed as ```res<span>{hello}<s...[WIP] printer: wrap variables with curly braces inside JSXSep 9, 2025
CopilotAI changed the title[WIP] printer: wrap variables with curly braces inside JSXWrap variables in curly braces inside JSX childrenSep 9, 2025
CopilotAI requested a review fromtsnobipSeptember 9, 2025 13:55
Copilot finished work on behalf oftsnobipSeptember 9, 2025 13:55
@tsnobip
Copy link
Member

tsnobip commentedSep 9, 2025
edited
Loading

@copilot update the syntax tests accordingly and fix the wrapping of spread variables:

<div>...element </div>

should be wrapped like this:

<div> {...element} </div>

not like this:

<div>...{element} </div>

EDIT: Not necessary anymore, children spread inside JSX is no longer supported since#7869.

Copy link
ContributorAuthor

CopilotAI commentedSep 9, 2025

@copilot update the syntax tests accordingly and fix the wrapping of spread variables:

<div>...element </div>

...

Fixed spread variables in JSX children to be wrapped in curly braces. The change ensures...variable becomes{...variable} instead of remaining unwrapped. Updated syntax tests accordingly. Commit:db4b047

CopilotAI changed the titleWrap variables in curly braces inside JSX childrenWrap variables and spread expressions in curly braces inside JSX childrenSep 9, 2025
Copilot finished work on behalf oftsnobipSeptember 9, 2025 15:51
@tsnobiptsnobip changed the titleWrap variables and spread expressions in curly braces inside JSX childrenWrap variables in curly braces inside JSX childrenSep 12, 2025
@tsnobiptsnobipforce-pushed thecopilot/modify-printer-variable-wrap-jsx branch 2 times, most recently from312375d toe6ebbb9CompareSeptember 12, 2025 06:45
@tsnobiptsnobip marked this pull request as ready for reviewSeptember 12, 2025 06:46
@pkg-pr-new
Copy link

pkg-pr-newbot commentedSep 12, 2025
edited
Loading

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7863

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7863

@rescript/win32-x64

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

commit:d5cc8ea

@tsnobiptsnobip marked this pull request as draftSeptember 12, 2025 07:17
@tsnobiptsnobipforce-pushed thecopilot/modify-printer-variable-wrap-jsx branch frome6ebbb9 tod5cc8eaCompareSeptember 12, 2025 07:23
@tsnobiptsnobip changed the titleWrap variables in curly braces inside JSX childrenWrap non-components JSX children in curly bracesSep 12, 2025
@tsnobiptsnobip marked this pull request as ready for reviewSeptember 12, 2025 07:28
@nojaf
Copy link
Member

It is quite the turnoff that the PR description mentions code that doesn't compile:

image

The goal is to wrap Jsx.element type identifiers in braces?

tsnobip reacted with thumbs up emoji

@cknitt
Copy link
Member

According to the PR description,

letx= <span>hello </span>

should be reformatted to

letx= <span>{hello}</span>

but instead it does keep the spaces:

letx= <span> {hello} </span>

This is not ideal, because in JavaScript JSX those spaces would actually go into the output:
https://babeljs.io/repl#?config_lz=N4IgZglgNgpgdgQwLYxALhAJxgBygOgCsBnADxABoQdtiYAXY9AbWZHgDdLR6FMBzBkwwATGGAQBXKIwoACOAHt6ciDDkBGDfKUq1AfSSKARpo2UQRkdJjCJUOlWOT-kUrfT1MkmAF8AuhRs2AgAxvTcWJJw9BAo6CBS9IpICLGhIAFBIMS8ggC0AEyRYqGKmGnlxABqMJjEEIpwCYUADIUAzPlaFjgQODBQEHAwAAqYijiKxAhQCQAWYQDWmf6BOYqSmKEwACoAngMJVjaZQA&code_lz=DYUwLgBAHhC8EB4DOAHAhgOwHwQN4AsRhgB7AX0QHpVMsAoIA&lineWrap=true&version=7.28.4

@tsnobip
Copy link
Member

It is quite the turnoff that the PR description mentions code that doesn't compile:

image

The goal is to wrap Jsx.element type identifiers in braces?

Yes only for Jsx.element for now, AI made a pretty terrible description of the PR, I actually restarted it from scratch, I should have maybe create another PR instead, to avoid this noise.

@tsnobip
Copy link
Member

According to the PR description,

letx= <span>hello </span>

should be reformatted to

letx= <span>{hello}</span>

but instead it does keep the spaces:

letx= <span> {hello} </span>

This is not ideal, because in JavaScript JSX those spaces would actually go into the output:
https://babeljs.io/repl#?config_lz=N4IgZglgNgpgdgQwLYxALhAJxgBygOgCsBnADxABoQdtiYAXY9AbWZHgDdLR6FMBzBkwwATGGAQBXKIwoACOAHt6ciDDkBGDfKUq1AfSSKARpo2UQRkdJjCJUOlWOT-kUrfT1MkmAF8AuhRs2AgAxvTcWJJw9BAo6CBS9IpICLGhIAFBIMS8ggC0AEyRYqGKmGnlxABqMJjEEIpwCYUADIUAzPlaFjgQODBQEHAwAAqYijiKxAhQCQAWYQDWmf6BOYqSmKEwACoAngMJVjaZQA&code_lz=DYUwLgBAHhC8EB4DOAHAhgOwHwQN4AsRhgB7AX0QHpVMsAoIA&lineWrap=true&version=7.28.4

Yes whitespace is a big issue if we start having string templates.

@fhammerschmidt
Copy link
Member

Maybe wrap stuff in "" if there are spaces between words, but trim the outer spaces away. Could be similar to how polymorphic variants do it.

#"hello world"

@tsnobiptsnobip marked this pull request as draftSeptember 12, 2025 13:21
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@tsnobiptsnobipAwaiting requested review from tsnobip

At least 1 approving review is required to merge this pull request.

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@tsnobip@nojaf@cknitt@fhammerschmidt

[8]ページ先頭

©2009-2025 Movatter.jp