rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Omit trailing undefineds from function invocations in JS output

Open cknitt opened this issue 1 year ago • 2 comments

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.

cknitt avatar Jan 01 '24 13:01 cknitt

This is quite important because unnecessarily passing undefined like this can actually break js APIs that check args length etc.

zth avatar Jan 01 '24 13:01 zth

cc @cristianoc

zth avatar Jan 12 '24 09:01 zth

Implemented in #6653.

cknitt avatar Apr 06 '24 16:04 cknitt