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

Commitd5cc8ea

Browse files
Copilottsnobip
authored andcommitted
Wrap non-component JSX children in curly braces
1 parent1cd4744 commitd5cc8ea

File tree

11 files changed

+36
-60
lines changed

11 files changed

+36
-60
lines changed

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
####:eyeglasses: Spec Compliance
2121

22+
- Wrap variables in curly braces inside JSX children.https://github.com/rescript-lang/rescript/pull/7863
23+
2224
####:rocket: New Feature
2325

2426
- Add`Array.filterMapWithIndex` to Stdlib.https://github.com/rescript-lang/rescript/pull/7876

‎compiler/syntax/src/res_parens.ml‎

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -354,39 +354,13 @@ let jsx_prop_expr expr =
354354

355355
letjsx_child_exprexpr=
356356
match expr.Parsetree.pexp_descwith
357-
|Parsetree.Pexp_let _|Pexp_sequence _|Pexp_letexception _
358-
|Pexp_letmodule_|Pexp_open_ ->
359-
Nothing
357+
|Parsetree.Pexp_let_|Pexp_sequence_ ->Nothing
360358
|_ -> (
361359
let opt_braces, _=ParsetreeViewer.process_braces_attr exprin
362360
match opt_braceswith
363361
|Some ({Location.loc =braces_loc},_) ->Braced braces_loc
364362
|_ -> (
365363
match exprwith
366-
| {
367-
Parsetree.pexp_desc=
368-
Pexp_constant (Pconst_integer (x, _)|Pconst_float (x, _));
369-
pexp_attributes=[];
370-
}
371-
when starts_with_minus x ->
372-
Parenthesized
373-
|_whenParsetreeViewer.expr_is_await expr ->Parenthesized
374-
| {
375-
Parsetree.pexp_desc=
376-
(Pexp_ident _|Pexp_constant _|Pexp_field _|Pexp_construct _
377-
|Pexp_variant _|Pexp_array _|Pexp_pack _|Pexp_record _
378-
|Pexp_extension _|Pexp_letmodule _|Pexp_letexception _
379-
|Pexp_open _|Pexp_sequence _|Pexp_let _|Pexp_jsx_element _ );
380-
pexp_attributes=[];
381-
} ->
382-
Nothing
383-
| {
384-
Parsetree.pexp_desc=
385-
Pexp_constraint
386-
({pexp_desc=Pexp_pack _}, {ptyp_desc=Ptyp_package _});
387-
pexp_attributes=[];
388-
} ->
389-
Nothing
390364
|{pexp_desc =Pexp_jsx_element_} ->Nothing
391365
|_ ->Parenthesized))
392366

‎tests/build_tests/super_errors/expected/react_component_with_props.res.expected‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
3 │ let make = React.forwardRef((
88
4 │  ~className=?,
99
. │ ...
10-
12 │  children
10+
12 │ {children}
1111
13 │  </div>
1212
14 │ )
1313
15 │ }

‎tests/build_tests/super_errors/fixtures/react_component_with_props.res‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module V4C7 = {
99
<input
1010
type_="text" ?classNameref=?{Js.Nullable.toOption(ref)->Belt.Option.map(React.Ref.domRef)}
1111
/>
12-
children
12+
{children}
1313
</div>
1414
)
1515
}

‎tests/gentype_tests/typescript-react-example/src/Hooks.res‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module Inner = {
6060

6161
moduleNoProps= {
6262
@genType @react.component
63-
letmake= ()=> <div>React.null </div>
63+
letmake= ()=> <div>{React.null} </div>
6464
}
6565

6666
typecb= (~_to:vehicle)=>unit
@@ -133,7 +133,7 @@ module WithChildren = {
133133
letaComponentWithChildren= (~vehicle, ~children)=>
134134
<div>
135135
{React.string("Another Hook "++vehicle.name)}
136-
<div>children </div>
136+
<div>{children} </div>
137137
</div>
138138
}
139139

‎tests/syntax_tests/data/conversion/reason/expected/jsxProps.res.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ let handleClick = (href, event) =>
66

77
@react.component
88
let make = (~href, ~className="", ~children) =>
9-
<a href className onClick={event => handleClick(href, event)}> children </a>
9+
<a href className onClick={event => handleClick(href, event)}>{children} </a>

‎tests/syntax_tests/data/printer/comments/expected/jsx.res.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Cite = {
33
let make = (~author: option<string>, ~children) => {
44
// For semantics, check out
55
// https://css-tricks.com/quoting-in-html-quotations-citations-and-blockquotes/
6-
<div> foo </div>
6+
<div>{foo} </div>
77
}
88
}
99

‎tests/syntax_tests/data/printer/expr/expected/braced.res.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ apply({
282282
a
283283
})
284284

285-
let x = {<div> child </div>}
285+
let x = {<div>{child} </div>}
286286

287287
// not valid jsx
288288
let x = {@JSX child}

‎tests/syntax_tests/data/printer/expr/expected/exoticIdent.res.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ let x = 1
6161

6262
let x =
6363
<div \"aria-foo"=\"type">
64-
\"module"
65-
\"let"
64+
{\"module"}
65+
{\"let"}
6666
</div>
6767

6868
type dict = {

‎tests/syntax_tests/data/printer/expr/expected/jsx.res.txt‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ let x =
209209

210210
let x =
211211
<div>
212-
ident
213-
"constant"
212+
{ident}
213+
{"constant"}
214214
{
215215
let a = 1
216216
let b = 2
@@ -240,13 +240,13 @@ let x =
240240
| Error => ()
241241
}}
242242
{(a, b, c)}
243-
Rgb(red, blue, green)
244-
list{}
245-
list{a, b}
246-
list{a, b, ...x}
247-
[a, b, c]
248-
{x: 1, y: 2}
249-
foo.bar
243+
{Rgb(red, blue, green)}
244+
{list{}}
245+
{list{a, b}}
246+
{list{a, b, ...x}}
247+
{[a, b, c]}
248+
{{x: 1, y: 2}}
249+
{foo.bar}
250250
{user.name = "Steve"}
251251
{if true {
252252
()
@@ -264,29 +264,29 @@ let x =
264264
do(i)
265265
}}
266266
{(20: int)}
267-
{
267+
{{
268268
module L = Log
269269
L.log()
270-
}
271-
{
270+
}}
271+
{{
272272
exception Exit
273273
throw(Exit)
274-
}
274+
}}
275275
{assert(true)}
276276
{module(Foo)}
277-
module(Foo)
277+
{module(Foo)}
278278
{module(Foo: Bar)}
279-
module(Foo: Bar)
280-
{
279+
{module(Foo: Bar)}
280+
{{
281281
open React
282282
React.render()
283-
}
284-
%raw("eval()")
285-
{"x": 1, "y": 2}
283+
}}
284+
{%raw("eval()")}
285+
{{"x": 1, "y": 2}}
286286
{@attr ident}
287287
</div>
288288

289-
let x = <MyComponent sidebar={<div> test </div>} nav={<Navbar />} />
289+
let x = <MyComponent sidebar={<div>{test} </div>} nav={<Navbar />} />
290290

291291
<div>
292292
{possibleGradeValues
@@ -314,7 +314,7 @@ let x = <MyComponent sidebar={<div> test </div>} nav={<Navbar />} />
314314
module App = {
315315
@react.component
316316
let make = () => {
317-
<>1 </>
317+
<>{1} </>
318318
}
319319
}
320320

@@ -492,14 +492,14 @@ let fragmented_moo =
492492

493493
let arrow_with_fragment = el => <>
494494
{t(nbsp ++ "(")}
495-
el
495+
{el}
496496
{t(")")}
497497
</>
498498

499499
let arrow_with_container_tag = el =>
500500
<div>
501501
{t(nbsp ++ "(")}
502-
el
502+
{el}
503503
{t(")")}
504504
</div>
505505

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp