Skip to content

Commit 681e466

Browse files
committed
Allow multiple dotdotdot
1 parent 5dd8959 commit 681e466

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

jscomp/core/record_attributes_check.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ let rec check_duplicated_labels_aux (lbls : Parsetree.label_declaration list)
8181
match lbls with
8282
| [] -> None
8383
| { pld_name = { txt } as pld_name; pld_attributes } :: rest -> (
84-
if Set_string.mem coll txt then Some pld_name
84+
(* TODO: this operates on the parse tree and does not know about expansion *)
85+
if Set_string.mem coll txt && txt <> "dotdotdot" then Some pld_name
8586
else
8687
let coll_with_lbl = Set_string.add coll txt in
8788
match Ext_list.find_opt pld_attributes find_name_with_loc with

jscomp/ml/typedecl.ml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ let transl_declaration env sdecl id =
447447
else Record_regular
448448
in
449449
let lbls, lbls' = match lbls, lbls' with
450-
| {ld_name = {txt = "dotdotdot"}; ld_type} :: rest, _ :: rest' ->
450+
| {ld_name = {txt = "dotdotdot"}; ld_type} :: _, _ :: _ ->
451451
let rec extract t = match t.desc with
452452
| Tpoly(t, []) -> extract t
453453
| _ -> Ctype.repr t in
@@ -458,14 +458,17 @@ let transl_declaration env sdecl id =
458458
ld_type = {ld_type with ctyp_type = l.ld_type};
459459
ld_loc = l.ld_loc;
460460
ld_attributes = l.ld_attributes; } in
461-
let lbls, lbls' =
462-
match Ctype.extract_concrete_typedecl env (extract ld_type.ctyp_type) with
463-
(_p0, _p, {type_kind=Type_record (fields, _repr)}) ->
464-
(fields |> List.map mkLbl) @ rest, fields @ rest'
465-
| _ -> assert false
466-
| exception _ -> assert false
461+
let rec process_lbls acc lbls lbls' = match lbls, lbls' with
462+
| {ld_name = {txt = "dotdotdot"}; ld_type} :: rest, _ :: rest' ->
463+
(match Ctype.extract_concrete_typedecl env (extract ld_type.ctyp_type) with
464+
(_p0, _p, {type_kind=Type_record (fields, _repr)}) ->
465+
process_lbls (fst acc @ (fields |> List.map mkLbl), snd acc @ fields) rest rest'
466+
| _ -> assert false
467+
| exception _ -> assert false)
468+
| lbl::rest, lbl'::rest' -> process_lbls (fst acc @ [lbl], snd acc @ [lbl']) rest rest'
469+
| _ -> acc
467470
in
468-
lbls, lbls'
471+
process_lbls ([], []) lbls lbls'
469472
| _ -> lbls, lbls' in
470473
Ttype_record lbls, Type_record(lbls', rep)
471474
| Ptype_open -> Ttype_open, Type_open

jscomp/test/DotDotDot.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,14 @@ var v = {
77
z: ""
88
};
99

10+
var v2 = {
11+
x: 10,
12+
y: "",
13+
z: "",
14+
v: 1.0,
15+
w: 2.0
16+
};
17+
1018
exports.v = v;
19+
exports.v2 = v2;
1120
/* No side effect */

jscomp/test/DotDotDot.res

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ type c = {dotdotdot: b, z: string}
66

77
let v: c = {x: 10, y: "", z: ""}
88

9+
type vw = {v: float, w: float}
10+
11+
type cvw = {dotdotdot: c, dotdotdot: vw}
12+
13+
let v2: cvw = {x: 10, y: "", z: "", v: 1.0, w: 2.0}
14+
915
type globalProps = {
1016
id?: string,
1117
name?: string,
@@ -21,9 +27,7 @@ type anchorProps = {
2127
}
2228

2329
// globalProps only case?
24-
type divProps = {
25-
dotdotdot: globalProps,
26-
}
30+
type divProps = {dotdotdot: globalProps}
2731

2832
type svgProps = {
2933
dotdotdot: globalProps,

0 commit comments

Comments
 (0)