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

Automatically wrap JSX string literals with Jsx.string()#7860

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 merge3 commits intomaster
base:master
Choose a base branch
Loading
fromcopilot/enhance-jsx-string-support

Conversation

Copy link
Contributor

CopilotAI commentedSep 9, 2025
edited
Loading

This PR implements automatic wrapping of string literals in JSX children withJsx.string() calls, eliminating the need for manual wrapping.

Problem

Currently, string literals in JSX children must be explicitly wrapped:

// Current - requires manual wrapping<span>{Jsx.string("hello")}</span><> {Jsx.string("world")} </>// What developers want to write<span>hello</span><>world </>

Solution

Modified the JSX children parser incompiler/syntax/src/res_core.ml to automatically detect string literals and wrap them withJsx.string() calls during AST construction.

Implementation Details

  1. Addedwrap_jsx_string_literal function that:

    • Detects string literal expressions (Pexp_constant (Pconst_string ...))
    • Creates AST nodes representingJsx.string(originalString) function calls
    • Preserves original source location information
  2. Integrated intoparse_jsx_children:

    • Applied to both JSX parsing paths (element and fragment children)
    • Only affects direct string literals, not expressions in braces
    • Maintains backward compatibility with existing code

Examples

After this change, the following transformations happen automatically:

// Input<span>helloworld</span>// Parsed as equivalent to<span>{Jsx.string("hello world")}</span>// Input<>fragmenttext </>// Parsed as equivalent to<> {Jsx.string("fragment text")} </>// Input<div>first<span>nested</span>last</div>// Parsed as equivalent to<div>{Jsx.string("first")}<span>{Jsx.string("nested")}</span>{Jsx.string("last")}</div>

Backward Compatibility

  • Existing explicitly wrapped strings continue to work unchanged:<span>{Jsx.string("hello")}</span>
  • Expressions in braces remain unaffected:<span>{someVariable}</span>
  • Only bare string literals get automatically wrapped

Test Cases

Added comprehensive test cases totests/syntax_tests/data/parsing/grammar/expressions/jsx.res covering:

  • Basic string literals in JSX elements
  • String literals in JSX fragments
  • Multiple string literals with nested elements
  • Mixed content scenarios

The implementation follows established patterns in the ReScript compiler codebase and maintains full compatibility with existing JSX usage patterns.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command:/usr/lib/apt/methods/https (dns block)
  • opam.ocaml.org
    • Triggering command:/usr/bin/curl --write-out %{http_code}\n --retry 3 --retry-delay 2 --user-agent opam/2.1.5 -L -o /tmp/opam-5289-e2dcfc/index.tar.gz.part -- REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 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.

CopilotAIand others added2 commitsSeptember 9, 2025 13:26
Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com>
Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com>
@nojaf
Copy link
Member

@tsnobip I have doing some work in this area over inmaster...nojaf:rescript:jsx2

CopilotAI changed the title[WIP] Right now children of a JSX element in Rescript must be of typeJsx.element, for exampleres<span>hello</span>expects ahello variable of typeJsx.element,we want to change this so it'd be an equivalent of: ```res<span>{Jsx.string("h...Automatically wrap JSX string literals with Jsx.string()Sep 9, 2025
CopilotAI requested a review fromtsnobipSeptember 9, 2025 13:33
Copilot finished work on behalf oftsnobipSeptember 9, 2025 13:33
@tsnobip
Copy link
Member

@nojaf nice! The handling of whitespace inside HTML/JSX is such a mess though, good luck with that!
I'll then focus on wrapping variables inside curly braces for now then. This way, users of V12 will have their projects automatically formatted and we can introduce your work in v12.1 (or as soon as it's ready!)!

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.

3 participants

@nojaf@tsnobip

[8]ページ先頭

©2009-2025 Movatter.jp