You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Implement parser to get spread expressions * Flatten array and call concatMany just once * Remove empty array in the parser output * Implement spread array printer * Update array parsing tests * Clean up * Fix tests * Fix extra whitespace got deleted by editor and run ocamlformat * Update changelog
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,7 @@
30
30
- Experimental support of tagged template literals, e.g. ```sql`select * from ${table}```. https://github.com/rescript-lang/rescript-compiler/pull/6250
31
31
- Experimental support for generic/custom JSX transforms. https://github.com/rescript-lang/rescript-compiler/pull/6565
32
32
-`dict` is now a builtin type. https://github.com/rescript-lang/rescript-compiler/pull/6590
33
+
- Add support for array spread. https://github.com/rescript-lang/rescript-compiler/pull/6608
Copy file name to clipboardExpand all lines: jscomp/syntax/tests/parsing/errors/other/expected/spread.res.txt
+28-40Lines changed: 28 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -1,79 +1,67 @@
1
1
2
2
Syntax error!
3
-
tests/parsing/errors/other/spread.res:1:12-14
3
+
tests/parsing/errors/other/spread.res:1:6-8
4
4
5
-
1 │ let arr = [...x, ...y]
6
-
2 │ let [...arr, _] = [1, 2, 3]
7
-
3 │
8
-
9
-
Arrays can't use the `...` spread currently. Please use `concat` or other Array helpers.
10
-
11
-
12
-
Syntax error!
13
-
tests/parsing/errors/other/spread.res:2:6-8
14
-
15
-
1 │ let arr = [...x, ...y]
16
-
2 │ let [...arr, _] = [1, 2, 3]
17
-
3 │
18
-
4 │ let record = {...x, ...y}
5
+
1 │ let [...arr, _] = [1, 2, 3]
6
+
2 │
7
+
3 │ let record = {...x, ...y}
19
8
20
9
Array's `...` spread is not supported in pattern matches.
21
10
Explanation: such spread would create a subarray; out of performance concern, our pattern matching currently guarantees to never create new intermediate data.
22
11
Solution: if it's to validate the first few elements, use a `when` clause + Array size check + `get` checks on the current pattern. If it's to obtain a subarray, use `Array.sub` or `Belt.Array.slice`.
23
12
24
13
25
14
Syntax error!
26
-
tests/parsing/errors/other/spread.res:4:21-23
15
+
tests/parsing/errors/other/spread.res:3:21-23
27
16
28
-
2 │ let [...arr, _] = [1, 2, 3]
29
-
3 │
30
-
4 │ let record = {...x, ...y}
31
-
5 │ let {...x, ...y} = myRecord
32
-
6 │
17
+
1 │ let [...arr, _] = [1, 2, 3]
18
+
2 │
19
+
3 │ let record = {...x, ...y}
20
+
4 │ let {...x, ...y} = myRecord
21
+
5 │
33
22
34
23
Records can only have one `...` spread, at the beginning.
35
24
Explanation: since records have a known, fixed shape, a spread like `{a, ...b}` wouldn't make sense, as `b` would override every field of `a` anyway.
36
25
37
26
38
27
Syntax error!
39
-
tests/parsing/errors/other/spread.res:5:15-18
28
+
tests/parsing/errors/other/spread.res:4:15-18
40
29
41
-
3 │
42
-
4 │ let record = {...x, ...y}
43
-
5 │ let {...x, ...y} = myRecord
44
-
6 │
45
-
7 │ let list{...x, ...y} = myList
30
+
2 │
31
+
3 │ let record = {...x, ...y}
32
+
4 │ let {...x, ...y} = myRecord
33
+
5 │
34
+
6 │ let list{...x, ...y} = myList
46
35
47
36
Record's `...` spread is not supported in pattern matches.
48
37
Explanation: you can't collect a subset of a record's field into its own record, since a record needs an explicit declaration and that subset wouldn't have one.
49
38
Solution: you need to pull out each field you want explicitly.
50
39
51
40
52
41
Syntax error!
53
-
tests/parsing/errors/other/spread.res:7:13-22
42
+
tests/parsing/errors/other/spread.res:6:13-22
54
43
55
-
5 │ let {...x, ...y} = myRecord
56
-
6 │
57
-
7 │ let list{...x, ...y} = myList
58
-
8 │
59
-
9 │ type t = {...a}
44
+
4 │ let {...x, ...y} = myRecord
45
+
5 │
46
+
6 │ let list{...x, ...y} = myList
47
+
7 │
48
+
8 │ type t = {...a}
60
49
61
50
List pattern matches only supports one `...` spread, at the end.
62
51
Explanation: a list spread at the tail is efficient, but a spread in the middle would create new lists; out of performance concern, our pattern matching currently guarantees to never create new intermediate data.
63
52
64
53
65
54
Syntax error!
66
-
tests/parsing/errors/other/spread.res:10:20
55
+
tests/parsing/errors/other/spread.res:9:20
67
56
68
-
8 │
69
-
9 │ type t = {...a}
70
-
10 │ type t = Foo({...a})
71
-
11 │ type t = option<foo, {...x}>
72
-
12 │
57
+
7 │
58
+
8 │ type t = {...a}
59
+
9 │ type t = Foo({...a})
60
+
10 │ type t = option<foo, {...x}>
61
+
11 │
73
62
74
63
I'm not sure what to parse here when looking at ")".
0 commit comments