Skip to content

Commit a1d40fb

Browse files
authored
Merge branch '11.0_release' into add-warn-error-ninja-rule
2 parents 96707b3 + 41ec1b0 commit a1d40fb

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#### :bug: Bug Fix
2121

2222
- Improve error when using '@deriving(accessors)' on a variant with record arguments. https://github.com/rescript-lang/rescript-compiler/pull/6712
23-
2423
- Stop escaping JSX prop names with hyphens. https://github.com/rescript-lang/rescript-compiler/pull/6705
24+
- Fix trailing undefined for optional parameters not omitted with `@send` and `@new`. https://github.com/rescript-lang/rescript-compiler/pull/6716
2525

2626
# 11.1.0-rc.7
2727

jscomp/core/lam_compile_external_call.ml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@ type specs = External_arg_spec.params
151151

152152
type exprs = E.t list
153153

154+
let keep_non_undefined_args (arg_types : specs) (args : exprs) =
155+
let rec has_undefined_trailing_args arg_types args =
156+
match (arg_types, args) with
157+
| ( [{External_arg_spec.arg_label = Arg_optional; _}],
158+
[{J.expression_desc = Undefined {isUnit = false}; _}] ) ->
159+
true
160+
| ( _ :: arg_types_rest, _ :: args_rest ) ->
161+
has_undefined_trailing_args arg_types_rest args_rest
162+
| _ -> false
163+
in
164+
let rec aux arg_types args =
165+
match (arg_types, args) with
166+
| ( {External_arg_spec.arg_label = Arg_optional; _} :: arg_types_rest,
167+
{J.expression_desc = Undefined {isUnit = false}; _} :: args_rest ) ->
168+
aux arg_types_rest args_rest
169+
| _ -> args
170+
in
171+
if (has_undefined_trailing_args arg_types args) then
172+
aux (List.rev arg_types) (List.rev args) |> List.rev
173+
else args
174+
154175
(* TODO: fix splice,
155176
we need a static guarantee that it is static array construct
156177
otherwise, we should provide a good error message here,
@@ -176,7 +197,7 @@ let assemble_args_no_splice (arg_types : specs) (args : exprs) :
176197
| _ :: _, [] -> assert false
177198
in
178199
let args, eff = aux arg_types args in
179-
( args,
200+
( keep_non_undefined_args arg_types args,
180201
match eff with
181202
| [] -> None
182203
| x :: xs ->
@@ -271,16 +292,6 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
271292
else E.call ~info:{ arity = Full; call_info = Call_na } fn args)
272293
else
273294
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
284295
add_eff eff
285296
@@ E.call ~info:{ arity = Full; call_info = Call_na } fn args
286297
| Js_module_as_fn { external_module_name; splice } ->

jscomp/test/omit_trailing_undefined_in_external_calls.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/omit_trailing_undefined_in_external_calls.res

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ external formatDate: (Js.Date.t, ~options: dateFormatOptions=?, ~done: bool=?) =
99
let x = formatDate(Js.Date.make())
1010
let x = formatDate(Js.Date.make(), ~options={someOption: true})
1111
let x = formatDate(Js.Date.make(), ~done=true)
12+
13+
@send external floatToString: (float, ~radix: int=?) => string = "toString"
14+
15+
let x = floatToString(42.)
16+
17+
@new external regExpFromString: (string, ~flags: string=?) => Js.Re.t = "RegExp"
18+
19+
let x = regExpFromString("ab+c")

0 commit comments

Comments
 (0)