Skip to content

Commit d93fec0

Browse files
committed
Merge branch '11.0_release' into 11-to-master
# Conflicts: # CHANGELOG.md # jscomp/common/bs_version.ml # jscomp/test/build.ninja # package-lock.json # package.json # packages/std/package.json
2 parents b5d901a + e6309c7 commit d93fec0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+540
-178
lines changed

CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@
2727

2828
- Make the `--help` arg be prioritized in the CLI, so correctly prints help message and skip other commands. https://github.com/rescript-lang/rescript-compiler/pull/6667
2929

30+
# 11.1.0-rc.5
31+
32+
#### :bug: Bug Fix
33+
34+
- Fix misparsing in/after JSX. https://github.com/rescript-lang/rescript-compiler/pull/6686
35+
- Fix `@deriving(accessors)` outputting curried functions in uncurried mode. https://github.com/rescript-lang/rescript-compiler/pull/6687
36+
37+
# 11.1.0-rc.4
38+
39+
#### :bug: Bug Fix
40+
41+
- Fix emitting static import instead of dynamic import. https://github.com/rescript-lang/rescript-compiler/pull/6664
42+
- Fix local type variables breaking react components. https://github.com/rescript-lang/rescript-compiler/pull/6665
43+
- Fix remove redundant branches in generated switch body. https://github.com/rescript-lang/rescript-compiler/pull/6672
44+
- Fix issue in partial application when the last named arg is provided. https://github.com/rescript-lang/rescript-compiler/pull/6681
45+
46+
#### :nail-care: Polish
47+
48+
- Omit `undefined` in external function calls for trailing optional arguments when not supplied. https://github.com/rescript-lang/rescript-compiler/pull/6653
49+
- Make pattern match suggestions to be easier to copy-paste. https://github.com/rescript-lang/rescript-compiler/pull/6656
50+
3051
# 11.1.0-rc.3
3152

3253
#### :nail_care: Polish

docs/docson/build-schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@
439439
"properties": {
440440
"number": {
441441
"type": "string",
442-
"description": "Default: -40+6+7+27+32..39+44+45 [Here](https://caml.inria.fr/pub/docs/manual-ocaml/comp.html#sec270) for the meanings of the warning flags"
442+
"description": "Default: \"+a-4-9-20-40-41-42-50-61-102\". Go [here](https://rescript-lang.org/docs/manual/latest/warning-numbers) for the meanings of the warning flags"
443443
},
444444
"error": {
445445
"oneOf": [

jscomp/build_tests/super_errors/expected/warnings4.res.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
14 │
1111

1212
You forgot to handle a possible case here, for example:
13-
#second(_) | #fourth | #third
13+
| #second(_) | #fourth | #third

jscomp/build_tests/super_errors/expected/warnings5.res.expected

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Either bind these labels explicitly or add ', _' to the pattern.
2424
15 │ switch y {
2525

2626
You forgot to handle a possible case here, for example:
27-
{otherValue: true, _}
27+
| {otherValue: true, _}
2828

2929

3030
Warning number 9
@@ -52,7 +52,7 @@ Either bind these labels explicitly or add ', _' to the pattern.
5252
19 │ let arr = [1]
5353

5454
You forgot to handle a possible case here, for example:
55-
{typ: WithPayload(false), _}
55+
| {typ: WithPayload(false), _}
5656
| {typ: Variant | One | Two | Three | Four | Five | Six | Seven(_), _}
5757

5858

@@ -68,7 +68,7 @@ Either bind these labels explicitly or add ', _' to the pattern.
6868
25 │ switch arr {
6969

7070
You forgot to handle a possible case here, for example:
71-
[_]
71+
| [_]
7272

7373

7474
Warning number 8
@@ -83,7 +83,7 @@ Either bind these labels explicitly or add ', _' to the pattern.
8383
29 │ switch arr {
8484

8585
You forgot to handle a possible case here, for example:
86-
[]
86+
| []
8787

8888

8989
Warning number 8
@@ -98,7 +98,7 @@ Either bind these labels explicitly or add ', _' to the pattern.
9898
33 │ let lst = list{}
9999

100100
You forgot to handle a possible case here, for example:
101-
[1, 0] | [0, _] | []
101+
| [1, 0] | [0, _] | []
102102

103103

104104
Warning number 8
@@ -113,7 +113,7 @@ Either bind these labels explicitly or add ', _' to the pattern.
113113
39 │ switch lst {
114114

115115
You forgot to handle a possible case here, for example:
116-
list{_, ..._}
116+
| list{_, ..._}
117117

118118

119119
Warning number 8
@@ -128,7 +128,7 @@ Either bind these labels explicitly or add ', _' to the pattern.
128128
43 │ switch lst {
129129

130130
You forgot to handle a possible case here, for example:
131-
list{1, 2, _, ..._} | list{1, 0, ..._} | list{1} | list{0, ..._} | list{}
131+
| list{1, 2, _, ..._} | list{1, 0, ..._} | list{1} | list{0, ..._} | list{}
132132

133133

134134
Warning number 8
@@ -143,7 +143,7 @@ Either bind these labels explicitly or add ', _' to the pattern.
143143
47 │ switch "abc" {
144144

145145
You forgot to handle a possible case here, for example:
146-
list{1, _, ..._} | list{0, ..._} | list{}
146+
| list{1, _, ..._} | list{0, ..._} | list{}
147147

148148

149149
Warning number 8
@@ -158,7 +158,7 @@ Either bind these labels explicitly or add ', _' to the pattern.
158158
51 │ switch 0 {
159159

160160
You forgot to handle a possible case here, for example:
161-
"*"
161+
| "*"
162162

163163

164164
Warning number 8
@@ -173,7 +173,7 @@ Either bind these labels explicitly or add ', _' to the pattern.
173173
55 │ let tuple = (1, true)
174174

175175
You forgot to handle a possible case here, for example:
176-
0
176+
| 0
177177

178178

179179
Warning number 8
@@ -187,4 +187,4 @@ Either bind these labels explicitly or add ', _' to the pattern.
187187
60 │
188188

189189
You forgot to handle a possible case here, for example:
190-
(_, true)
190+
| (_, true)

jscomp/core/lam.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,13 @@ let rec transform_uncurried_arg_type loc (arg_types : External_arg_spec.params)
788788
| ([], [] | _ :: _, [] | [], _ :: _) as ok -> ok
789789

790790
let handle_bs_non_obj_ffi (arg_types : External_arg_spec.params)
791-
(result_type : External_ffi_types.return_wrapper) ffi args loc prim_name =
791+
(result_type : External_ffi_types.return_wrapper) ffi args loc prim_name ~dynamic_import =
792792
if no_auto_uncurried_arg_types arg_types then
793793
result_wrap loc result_type
794-
(prim ~primitive:(Pjs_call { prim_name; arg_types; ffi }) ~args loc)
794+
(prim ~primitive:(Pjs_call { prim_name; arg_types; ffi; dynamic_import }) ~args loc)
795795
else
796796
let n_arg_types, n_args = transform_uncurried_arg_type loc arg_types args in
797797
result_wrap loc result_type
798798
(prim
799-
~primitive:(Pjs_call { prim_name; arg_types = n_arg_types; ffi })
799+
~primitive:(Pjs_call { prim_name; arg_types = n_arg_types; ffi; dynamic_import })
800800
~args:n_args loc)

jscomp/core/lam.mli

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ val handle_bs_non_obj_ffi :
9191
t list ->
9292
Location.t ->
9393
string ->
94+
dynamic_import: bool ->
9495
t
9596

9697
(**************************************************************)

jscomp/core/lam_compile.ml

+5
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ and compile_general_cases :
573573
break still should not be printed (it will be continuned)
574574
TOOD: disabled temporarily since it's not perfect yet *)
575575
morph_declare_to_assign cxt (fun cxt declaration ->
576+
(* Exclude cases that are the same as the default if the default is defined *)
577+
let cases = match default with
578+
| Default lam -> List.filter (fun (_, lam1) -> not (Lam.eq_approx lam lam1)) cases
579+
| _ -> cases
580+
in
576581
let default =
577582
match default with
578583
| Complete -> None

jscomp/core/lam_compile_env.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let reset () =
6060
be escaped quite ugly
6161
*)
6262
let add_js_module ?import_attributes (hint_name : External_ffi_types.module_bind_name)
63-
(module_name : string) default : Ident.t =
63+
(module_name : string) default ~dynamic_import : Ident.t =
6464
let id =
6565
Ident.create
6666
(match hint_name with
@@ -71,7 +71,7 @@ let add_js_module ?import_attributes (hint_name : External_ffi_types.module_bind
7171
| Phint_nothing -> Ext_modulename.js_id_name_of_hint_name module_name)
7272
in
7373
let lam_module_ident : J.module_id =
74-
{ id; kind = External { name = module_name; default; import_attributes }; dynamic_import = false }
74+
{ id; kind = External { name = module_name; default; import_attributes }; dynamic_import }
7575
in
7676
match Lam_module_ident.Hash.find_key_opt cached_tbl lam_module_ident with
7777
| None ->

jscomp/core/lam_compile_env.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
val reset : unit -> unit
2828

2929
val add_js_module :
30-
?import_attributes:External_ffi_types.import_attributes -> External_ffi_types.module_bind_name -> string -> bool -> Ident.t
30+
?import_attributes:External_ffi_types.import_attributes -> External_ffi_types.module_bind_name -> string -> bool -> dynamic_import:bool -> Ident.t
3131
(**
3232
[add_js_module hint_name module_name]
3333
Given a js module name and hint name, assign an id to it

jscomp/core/lam_compile_external_call.ml

+25-14
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ let splice_obj_apply obj name args =
5050
bundle *)
5151

5252
let external_var
53-
({ bundle; module_bind_name; import_attributes } : External_ffi_types.external_module_name) =
54-
let id = Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle false in
53+
({ bundle; module_bind_name; import_attributes } : External_ffi_types.external_module_name) ~dynamic_import =
54+
let id = Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle false ~dynamic_import in
5555
E.external_var ?import_attributes ~external_name:bundle id
5656

5757
(* let handle_external_opt
@@ -216,21 +216,22 @@ let assemble_args_has_splice (arg_types : specs) (args : exprs) :
216216

217217
let translate_scoped_module_val
218218
(module_name : External_ffi_types.external_module_name option) (fn : string)
219-
(scopes : string list) =
219+
(scopes : string list)
220+
~dynamic_import =
220221
match module_name with
221222
| Some { bundle; module_bind_name; import_attributes } -> (
222223
match scopes with
223224
| [] ->
224225
let default = fn = "default" in
225226
let id =
226-
Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle default
227+
Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle default ~dynamic_import
227228
in
228229
E.external_var_field ?import_attributes ~external_name:bundle ~field:fn ~default id
229230
| x :: rest ->
230231
(* TODO: what happens when scope contains "default" ?*)
231232
let default = false in
232233
let id =
233-
Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle default
234+
Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle default ~dynamic_import
234235
in
235236
let start =
236237
E.external_var_field ?import_attributes ~external_name:bundle ~field:x ~default id
@@ -250,10 +251,10 @@ let translate_scoped_access scopes obj =
250251
| x :: xs -> Ext_list.fold_left xs (E.dot obj x) E.dot
251252

252253
let translate_ffi (cxt : Lam_compile_context.t) arg_types
253-
(ffi : External_ffi_types.external_spec) (args : J.expression list) =
254+
(ffi : External_ffi_types.external_spec) (args : J.expression list) ~dynamic_import =
254255
match ffi with
255256
| Js_call { external_module_name; name; splice: _; scopes; tagged_template = true } ->
256-
let fn = translate_scoped_module_val external_module_name name scopes in
257+
let fn = translate_scoped_module_val external_module_name name scopes ~dynamic_import in
257258
(match args with
258259
| [ {expression_desc = Array (strings, _); _}; {expression_desc = Array (values, _); _} ] ->
259260
E.tagged_template fn strings values
@@ -262,18 +263,28 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
262263
(if dynamic then splice_apply fn args
263264
else E.call ~info:{ arity = Full; call_info = Call_na } fn args))
264265
| Js_call { external_module_name = module_name; name = fn; splice; scopes; tagged_template = false } ->
265-
let fn = translate_scoped_module_val module_name fn scopes in
266+
let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in
266267
if splice then
267268
let args, eff, dynamic = assemble_args_has_splice arg_types args in
268269
add_eff eff
269270
(if dynamic then splice_apply fn args
270271
else E.call ~info:{ arity = Full; call_info = Call_na } fn args)
271272
else
272273
let args, eff = assemble_args_no_splice arg_types args in
274+
let rec keepNonUndefinedArgs argsList (argTypes : specs) =
275+
match (argsList, argTypes) with
276+
| ( {J.expression_desc = Undefined {isUnit = false}; _} :: rest,
277+
{External_arg_spec.arg_label = Arg_optional; _} :: argTypes ) ->
278+
keepNonUndefinedArgs rest argTypes
279+
| _ -> argsList
280+
in
281+
let args =
282+
keepNonUndefinedArgs (List.rev args) (List.rev arg_types) |> List.rev
283+
in
273284
add_eff eff
274285
@@ E.call ~info:{ arity = Full; call_info = Call_na } fn args
275286
| Js_module_as_fn { external_module_name; splice } ->
276-
let fn = external_var external_module_name in
287+
let fn = external_var external_module_name ~dynamic_import in
277288
if splice then
278289
let args, eff, dynamic = assemble_args_has_splice arg_types args in
279290
(* TODO: fix in rest calling convention *)
@@ -303,14 +314,14 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
303314
in
304315
if splice then
305316
let args, eff, dynamic = assemble_args_has_splice arg_types args in
306-
let fn = translate_scoped_module_val module_name fn scopes in
317+
let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in
307318
add_eff eff
308319
(mark ();
309320
if dynamic then splice_new_apply fn args
310321
else E.new_ fn args)
311322
else
312323
let args, eff = assemble_args_no_splice arg_types args in
313-
let fn = translate_scoped_module_val module_name fn scopes in
324+
let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in
314325
add_eff eff
315326
(mark (); E.new_ fn args)
316327
| Js_send { splice; name; js_send_scopes } -> (
@@ -336,16 +347,16 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
336347
~info:{ arity = Full; call_info = Call_na }
337348
(E.dot self name) args)
338349
| _ -> assert false)
339-
| Js_module_as_var module_name -> external_var module_name
350+
| Js_module_as_var module_name -> external_var module_name ~dynamic_import
340351
| Js_var { name; external_module_name; scopes } ->
341352
(* TODO #11
342353
1. check args -- error checking
343354
2. support [@@scope "window"]
344355
we need know whether we should call [add_js_module] or not
345356
*)
346-
translate_scoped_module_val external_module_name name scopes
357+
translate_scoped_module_val external_module_name name scopes ~dynamic_import
347358
| Js_module_as_class module_name ->
348-
let fn = external_var module_name in
359+
let fn = external_var module_name ~dynamic_import in
349360
let args, eff = assemble_args_no_splice arg_types args in
350361
(* TODO: fix in rest calling convention *)
351362
add_eff eff

jscomp/core/lam_compile_external_call.mli

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ val translate_ffi :
3434
External_arg_spec.params ->
3535
External_ffi_types.external_spec ->
3636
J.expression list ->
37+
dynamic_import:bool ->
3738
J.expression
3839

3940
(** TODO: document supported attributes

jscomp/core/lam_compile_primitive.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
337337
(* Lam_compile_external_call.translate loc cxt prim args *)
338338
(* Test if the argument is a block or an immediate integer *)
339339
| Pjs_object_create _ -> assert false
340-
| Pjs_call { arg_types; ffi } ->
341-
Lam_compile_external_call.translate_ffi cxt arg_types ffi args
340+
| Pjs_call { arg_types; ffi; dynamic_import } ->
341+
Lam_compile_external_call.translate_ffi cxt arg_types ffi args ~dynamic_import
342342
(* FIXME, this can be removed later *)
343343
| Pisint -> E.is_type_number (Ext_list.singleton_exn args)
344344
| Pis_poly_var_block -> E.is_type_object (Ext_list.singleton_exn args)

jscomp/core/lam_convert.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
380380
let may_depends = Lam_module_ident.Hash_set.create 0 in
381381

382382
let rec convert_ccall (a_prim : Primitive.description)
383-
(args : Lambda.lambda list) loc : Lam.t =
383+
(args : Lambda.lambda list) loc ~dynamic_import : Lam.t =
384384
let prim_name = a_prim.prim_name in
385385
let prim_name_len = String.length prim_name in
386386
match External_ffi_types.from_string a_prim.prim_native_name with
@@ -400,7 +400,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
400400
| Param_number i -> Ext_list.init i (fun _ -> External_arg_spec.dummy)
401401
in
402402
let args = Ext_list.map args convert_aux in
403-
Lam.handle_bs_non_obj_ffi arg_types result_type ffi args loc prim_name
403+
Lam.handle_bs_non_obj_ffi arg_types result_type ffi args loc prim_name ~dynamic_import
404404
| Ffi_inline_const i -> Lam.const i
405405
and convert_js_primitive (p : Primitive.description)
406406
(args : Lambda.lambda list) loc : Lam.t =
@@ -542,7 +542,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
542542
convert_pipe f x outer_loc
543543
| Lprim (Prevapply, _, _) -> assert false
544544
| Lprim (Pdirapply, _, _) -> assert false
545-
| Lprim (Pccall a, args, loc) -> convert_ccall a args loc
545+
| Lprim (Pccall a, args, loc) -> convert_ccall a args loc ~dynamic_import
546546
| Lprim (Pgetglobal id, args, _) ->
547547
let args = Ext_list.map args convert_aux in
548548
if Ident.is_predef_exn id then

jscomp/core/lam_primitive.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type t =
4848
prim_name : string;
4949
arg_types : External_arg_spec.params;
5050
ffi : External_ffi_types.external_spec;
51+
dynamic_import: bool;
5152
}
5253
| Pjs_object_create of External_arg_spec.obj_params
5354
(* Exceptions *)
@@ -249,11 +250,11 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
249250
i0 = i1 && flag0 = flag1 && eq_tag_info info0 info1
250251
| _ -> false)
251252
| Pduprecord -> rhs = Pduprecord
252-
| Pjs_call { prim_name; arg_types; ffi } -> (
253+
| Pjs_call { prim_name; arg_types; ffi; dynamic_import } -> (
253254
match rhs with
254255
| Pjs_call rhs ->
255256
prim_name = rhs.prim_name && arg_types = rhs.arg_types
256-
&& ffi = rhs.ffi
257+
&& ffi = rhs.ffi && dynamic_import = rhs.dynamic_import
257258
| _ -> false)
258259
| Pjs_object_create obj_create -> (
259260
match rhs with

jscomp/core/lam_primitive.mli

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type t =
4343
prim_name : string;
4444
arg_types : External_arg_spec.params;
4545
ffi : External_ffi_types.external_spec;
46+
dynamic_import: bool;
4647
}
4748
| Pjs_object_create of External_arg_spec.obj_params
4849
| Praise

0 commit comments

Comments
 (0)