Skip to content

Commit 753bcf7

Browse files
committed
Allow multiple dotdotdot
1 parent 410f3c2 commit 753bcf7

9 files changed

+92
-47
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/main/builtin_cmi_datasets.ml

Lines changed: 3 additions & 1 deletion
Large diffs are not rendered by default.

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* aa85187c9b598b8b3d1ab300676f1c9e *)
1+
(* f00667b6f0841924d198799669f30e1f *)
22
let module_names : string array = Obj.magic (
33
"Js" (* 23 *),
44
"Arg" (* 217 *),
@@ -89,6 +89,7 @@ let module_names : string array = Obj.magic (
8989
"BytesLabels" (* 878 *),
9090
"Dom_storage" (* 386 *),
9191
"Js_mapperRt" (* 87 *),
92+
"Js_promise2" (* 50 *),
9293
"JsxDOMStyle" (* 23 *),
9394
"Node_buffer" (* 23 *),
9495
"Node_module" (* 23 *),
@@ -224,6 +225,7 @@ let module_data : string array = Obj.magic (
224225
(* BytesLabels *)"\132\149\166\190\000\000\003Z\000\000\000\231\000\000\003\012\000\000\002\216\160\b\000\000\152\000\176#cat\144\160\160B@@@\176#map\144\160\160B@@@\176#sub\144\160\160C@@@\176$blit\144\160\160E@@@\176$copy\144\160\160A@@@\176$fill\144\160\160D@@@\176$init\144\160\160B@@@\176$iter\144\160\160B@@@\176$make\144\160\160B@@@\176$mapi\144\160\160B@@@\176$trim\144\160\160A@@@\176%equal\144\160\160B@@\144\148\192B\160\176\001\005z!x@\160\176\001\005{!y@@\151\176\1470caml_bytes_equal\160\144\004\011\160\144\004\n@\176\1929stdlib-406/bytesLabels.ml\001\001\171\0011\127\0011\155\192\004\002\001\001\171\0011\127\0011\160@\208B@@@@\176%index\144\160\160B@@@\176%iteri\144\160\160B@@@\176&concat\144\160\160B@@@\176&extend\144\160\160C@@@\176&rindex\144\160\160B@@@\176'compare\144\160\160B@@\144\148\192B\160\176\001\005w!x@\160\176\001\005x!y@@\151\176\1472caml_bytes_compare\160\144\004\011\160\144\004\n@\176\192\0044\001\001\170\0011L\0011h\192\0045\001\001\170\0011L\0011~@\208B@@@@\176'escaped\144\160\160A@@@\176(contains\144\160\160B@@@\176)index_opt\144\160\160B@@@\176)of_string\144\160\160A@@@\176)to_string\144\160\160A@@@\176*index_from\144\160\160C@@@\176*rindex_opt\144\160\160B@@@\176*sub_string\144\160\160C@@@\176+blit_string\144\160\160E@@@\176+rindex_from\144\160\160C@@@\176-contains_from\144\160\160C@@@\176.index_from_opt\144\160\160C@@@\176.rcontains_from\144\160\160C@@@\176/lowercase_ascii\144\160\160A@@@\176/rindex_from_opt\144\160\160C@@@\176/uppercase_ascii\144\160\160A@@@\1760capitalize_ascii\144\160\160A@@@\1760unsafe_of_string\144\004F@\1760unsafe_to_string\144\004D@\1762uncapitalize_ascii\144\160\160A@@@A",
225226
(* Dom_storage *)"\132\149\166\190\000\000\001n\000\000\000k\000\000\001^\000\000\001T\160\192\176#key\144\160\160B@@\144\148\192B\160\176\001\004\004!i@\160\176\001\004\005#obj@@\151\176\000B\160\151\176\180#key\160\160AA\160\004\002@\181#key@@\160\144\004\016\160\144\004\021@\176\1925others/dom_storage.mlR\001\003\022\001\0036\192\004\002R\001\003\022\001\003B@@\004\004\208B@@@@\176'getItem\144\160\160B@@\144\148\192B\160\176\001\003\246!s@\160\176\001\003\247#obj@@\151\176\000B\160\151\176\180'getItem\160\004#\160\004$@\181'getItem@@\160\144\004\015\160\144\004\020@\176\192\004\"D\000x\001\000\140\192\004#D\000x\001\000\156@@\004\003\208B@@@@\176'setItem\144\160\160C@@@\176*removeItem\144\160\160B@@\144\148\192B\160\176\001\003\255!s@\160\176\001\004\000#obj@@\174\151\176\180*removeItem\160\004G\160\004H@\181*removeItem@@\160\144\004\r\160\144\004\018@\176\192\004FL\001\001\208\001\001\238\192\004GL\001\001\208\001\002\001@\146A\208B@@A@A",
226227
(* Js_mapperRt *)"\132\149\166\190\000\000\000C\000\000\000\017\000\000\0009\000\000\0004\160\176\176'fromInt\144\160\160C@@@\176-fromIntAssert\144\160\160C@@@\1761raiseWhenNotFound\144\160\160A@@@A",
228+
(* Js_promise2 *)"\132\149\166\190\000\000\000\030\000\000\000\012\000\000\000$\000\000\000\"\160\160\176$then\144\160\160B@@@\176%catch\144\160\160B@@@A",
227229
(* JsxDOMStyle *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
228230
(* Node_buffer *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
229231
(* Node_module *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",

jscomp/ml/typedecl.ml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ let transl_declaration env sdecl id =
417417
else Record_regular
418418
in
419419
let lbls, lbls' = match lbls, lbls' with
420-
| {ld_name = {txt = "dotdotdot"}; ld_type} :: rest, _ :: rest' ->
420+
| {ld_name = {txt = "dotdotdot"}; ld_type} :: _, _ :: _ ->
421421
let rec extract t = match t.desc with
422422
| Tpoly(t, []) -> extract t
423423
| _ -> Ctype.repr t in
@@ -428,14 +428,17 @@ let transl_declaration env sdecl id =
428428
ld_type = {ld_type with ctyp_type = l.ld_type};
429429
ld_loc = l.ld_loc;
430430
ld_attributes = l.ld_attributes; } in
431-
let lbls, lbls' =
432-
match Ctype.extract_concrete_typedecl env (extract ld_type.ctyp_type) with
433-
(_p0, _p, {type_kind=Type_record (fields, _repr)}) ->
434-
(fields |> List.map mkLbl) @ rest, fields @ rest'
435-
| _ -> assert false
436-
| exception _ -> assert false
431+
let rec process_lbls acc lbls lbls' = match lbls, lbls' with
432+
| {ld_name = {txt = "dotdotdot"}; ld_type} :: rest, _ :: rest' ->
433+
(match Ctype.extract_concrete_typedecl env (extract ld_type.ctyp_type) with
434+
(_p0, _p, {type_kind=Type_record (fields, _repr)}) ->
435+
process_lbls (fst acc @ (fields |> List.map mkLbl), snd acc @ fields) rest rest'
436+
| _ -> assert false
437+
| exception _ -> assert false)
438+
| lbl::rest, lbl'::rest' -> process_lbls (fst acc @ [lbl], snd acc @ [lbl']) rest rest'
439+
| _ -> acc
437440
in
438-
lbls, lbls'
441+
process_lbls ([], []) lbls lbls'
439442
| _ -> lbls, lbls' in
440443
Ttype_record lbls, Type_record(lbls', rep)
441444
| 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,

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 19 additions & 11 deletions
Large diffs are not rendered by default.

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 19 additions & 11 deletions
Large diffs are not rendered by default.

lib/4.06.1/whole_compiler.ml

Lines changed: 19 additions & 11 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)