Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

# 11.1.0-rc.4 (Unreleased)

#### :nail-care: Polish
- Omit `undefined` in external function calls for optional arguments when not supplied. https://github.com/rescript-lang/rescript-compiler/pull/6653
Comment thread
zth marked this conversation as resolved.
Outdated

# 11.1.0-rc.3

#### :nail_care: Polish
Expand Down
10 changes: 10 additions & 0 deletions jscomp/core/lam_compile_external_call.ml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
else E.call ~info:{ arity = Full; call_info = Call_na } fn args)
else
let args, eff = assemble_args_no_splice arg_types args in
let rec keepNonUndefinedArgs argsList (argTypes : specs) =
match (argsList, argTypes) with
| ( {J.expression_desc = Undefined {isUnit = false}; _} :: rest,
{External_arg_spec.arg_label = Arg_optional; _} :: argTypes ) ->
keepNonUndefinedArgs rest argTypes
| _ -> argsList
in
let args =
keepNonUndefinedArgs (List.rev args) (List.rev arg_types) |> List.rev
in
add_eff eff
@@ E.call ~info:{ arity = Full; call_info = Call_na } fn args
| Js_module_as_fn { external_module_name; splice } ->
Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/build.ninja

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions jscomp/test/omit_trailing_undefined_in_external_calls.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions jscomp/test/omit_trailing_undefined_in_external_calls.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@@uncurried

type dateFormatOptions = {someOption?: bool}

@module("SomeModule")
external formatDate: (Js.Date.t, ~options: dateFormatOptions=?, ~done: bool=?) => string =
"formatDate"

let x = formatDate(Js.Date.make())
let x = formatDate(Js.Date.make(), ~options={someOption: true})
let x = formatDate(Js.Date.make(), ~done=true)