Skip to content

Commit 1cd4744

Browse files
Copilottsnobip
andauthored
Remove support of children spread inside JSX (#7869)
* Initial plan * Drop support of JSX children spread Co-authored-by: tsnobip <[email protected]> * remove JSXChildrenItems variant * add error message when parsing children spread --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: tsnobip <[email protected]>
1 parent 674cc9e commit 1cd4744

File tree

28 files changed

+76
-465
lines changed

28 files changed

+76
-465
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#### :boom: Breaking Change
1616

1717
- Fix return type of `String.charCodeAt`. https://github.com/rescript-lang/rescript/pull/7864
18+
- Remove support of JSX children spread. https://github.com/rescript-lang/rescript/pull/7869
1819

1920
#### :eyeglasses: Spec Compliance
2021

analysis/src/CompletionFrontEnd.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
13531353
(Jsx_container_element
13541354
{jsx_container_element_children = children}) ->
13551355
children
1356-
| _ -> JSXChildrenItems []
1356+
| _ -> []
13571357
in
13581358
let compName_loc = compName.loc in
13591359
let compName_lid =
@@ -1412,8 +1412,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
14121412
(Jsx_container_element
14131413
{
14141414
jsx_container_element_closing_tag = None;
1415-
jsx_container_element_children =
1416-
JSXChildrenSpreading _ | JSXChildrenItems (_ :: _);
1415+
jsx_container_element_children = _ :: _;
14171416
}) ) ->
14181417
None
14191418
| Some jsxProps, _ ->

analysis/src/CompletionJsx.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ let extractJsxProps ~(compName : Longident.t Location.loc) ~props ~children =
460460
let open Parsetree in
461461
let childrenStart =
462462
match children with
463-
| JSXChildrenItems [] -> None
464-
| JSXChildrenSpreading child | JSXChildrenItems (child :: _) ->
463+
| [] -> None
464+
| child :: _ ->
465465
if child.pexp_loc.loc_ghost then None else Some (Loc.start child.pexp_loc)
466466
in
467467
let props =

analysis/src/SemanticTokens.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,7 @@ let command ~debug ~emitter ~path =
311311
~pos:(Pos.ofLexing posOfGreatherthanAfterProps);
312312

313313
(* children *)
314-
(match children with
315-
| Parsetree.JSXChildrenSpreading child -> iterator.expr iterator child
316-
| Parsetree.JSXChildrenItems children ->
317-
List.iter (iterator.expr iterator) children);
314+
List.iter (iterator.expr iterator) children;
318315

319316
(* closing tag *)
320317
closing_tag_opt

compiler/frontend/bs_ast_mapper.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ module M = struct
292292
end
293293

294294
module E = struct
295-
let map_jsx_children sub = function
296-
| JSXChildrenSpreading e -> JSXChildrenSpreading (sub.expr sub e)
297-
| JSXChildrenItems xs -> JSXChildrenItems (List.map (sub.expr sub) xs)
295+
let map_jsx_children sub xs = List.map (sub.expr sub) xs
298296

299297
let map_jsx_prop sub = function
300298
| JSXPropPunning (optional, name) ->

compiler/ml/ast_iterator.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,7 @@ module M = struct
267267
end
268268

269269
module E = struct
270-
let iter_jsx_children sub = function
271-
| JSXChildrenSpreading e -> sub.expr sub e
272-
| JSXChildrenItems xs -> List.iter (sub.expr sub) xs
270+
let iter_jsx_children sub xs = List.iter (sub.expr sub) xs
273271

274272
let iter_jsx_prop sub = function
275273
| JSXPropPunning (_, name) -> iter_loc sub name

compiler/ml/ast_mapper.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ module M = struct
263263
end
264264

265265
module E = struct
266-
let map_jsx_children sub = function
267-
| JSXChildrenSpreading e -> JSXChildrenSpreading (sub.expr sub e)
268-
| JSXChildrenItems xs -> JSXChildrenItems (List.map (sub.expr sub) xs)
266+
let map_jsx_children sub xs = List.map (sub.expr sub) xs
269267

270268
let map_jsx_prop sub = function
271269
| JSXPropPunning (optional, name) ->

compiler/ml/ast_mapper_from0.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ module E = struct
326326
match e.pexp_desc with
327327
| Pexp_construct ({txt = Longident.Lident "[]" | Longident.Lident "::"}, _)
328328
->
329-
JSXChildrenItems (visit e)
330-
| _ -> JSXChildrenSpreading (sub.expr sub e)
329+
visit e
330+
| _ -> [sub.expr sub e]
331331

332332
let try_map_jsx_prop (sub : mapper) (lbl : Asttypes.Noloc.arg_label)
333333
(e : expression) : Parsetree.jsx_prop option =

compiler/ml/ast_mapper_to0.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,7 @@ module E = struct
340340

341341
let map_jsx_children sub loc children =
342342
match children with
343-
| JSXChildrenSpreading e -> sub.expr sub e
344-
| JSXChildrenItems xs ->
343+
| xs ->
345344
let list_expr = Ast_helper.Exp.make_list_expression loc xs None in
346345
sub.expr sub list_expr
347346

compiler/ml/depend.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@ let rec add_expr bv exp =
312312
and_jsx_props bv props;
313313
add_jsx_children bv children
314314

315-
and add_jsx_children bv = function
316-
| JSXChildrenSpreading e -> add_expr bv e
317-
| JSXChildrenItems xs -> List.iter (add_expr bv) xs
315+
and add_jsx_children bv xs = List.iter (add_expr bv) xs
318316

319317
and add_jsx_prop bv = function
320318
| JSXPropPunning (_, _) -> ()

0 commit comments

Comments
 (0)