rescript-compiler
rescript-compiler copied to clipboard
Omit trailing undefineds from function invocations in JS output
It would be great if we could special case code generation so that trailing undefineds are omitted from function invocations.
Example: Consider the following bindings (uncurried mode):
type dateFormatOptions = {someOption?: bool}
@module("SomeModule")
external formatDate: (Date.t, ~options: dateFormatOptions=?) => string = "formatDate"
Now
let x = formatDate(Date.make())
will compile to
var x = SomeModule.formatDate(new Date(), undefined);
which works, but has an unnecessary undefined for the trailing optional parameter. It would be nice if that could be omitted.
This is quite important because unnecessarily passing undefined like this can actually break js APIs that check args length etc.
cc @cristianoc
Implemented in #6653.