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
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletionscompiler/syntax/src/res_core.ml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2977,6 +2977,21 @@ and parse_jsx_prop p : Parsetree.jsx_prop option =
and parse_jsx_props p : Parsetree.jsx_prop list =
parse_region ~grammar:Grammar.JsxAttribute ~f:parse_jsx_prop p

and wrap_jsx_string_literal expr =
(* Check if the expression is a string literal and wrap it with Jsx.string() *)
match expr.Parsetree.pexp_desc with
| Pexp_constant (Pconst_string (s, delimiter)) ->
let jsx_string_ident =
Ast_helper.Exp.ident
~loc:expr.pexp_loc
(Location.mkloc (Longident.Ldot (Longident.Lident "Jsx", "string")) expr.pexp_loc)
in
Ast_helper.Exp.apply
~loc:expr.pexp_loc
jsx_string_ident
[(Nolabel, expr)]
| _ -> expr

and parse_jsx_children p : Parsetree.jsx_children =
let rec loop p children =
match p.Parser.token with
Expand All@@ -2991,12 +3006,14 @@ and parse_jsx_children p : Parsetree.jsx_children =
let child =
parse_primary_expr ~operand:(parse_atomic_expr p) ~no_call:true p
in
loop p (child :: children)
let wrapped_child = wrap_jsx_string_literal child in
loop p (wrapped_child :: children)
| token when Grammar.is_jsx_child_start token ->
let child =
parse_primary_expr ~operand:(parse_atomic_expr p) ~no_call:true p
in
loop p (child :: children)
let wrapped_child = wrap_jsx_string_literal child in
loop p (wrapped_child :: children)
| _ -> children
in
let children =
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,6 +86,12 @@ let _ = <Outer inner=<Inner /> />

let _ = <div onClick=onClickHandler> <> "foobar" </> </div>

// Test automatic string wrapping in JSX children
let _ = <span>hello world</span>
let _ = <div>simple string</div>
let _ = <> fragment string </>
let _ = <div>first string<span>nested</span>last string</div>


let _ =
<Window
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp