-
Notifications
You must be signed in to change notification settings - Fork 469
Omit trailing undefined #6652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Omit trailing undefined #6652
Conversation
SomeModule.formatDate(new Date()); | ||
|
||
SomeModule.formatDate(new Date(), { | ||
someOption: true | ||
}); | ||
|
||
var x = SomeModule.formatDate(new Date(), undefined, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the difference of these 3. The first one has 2 optional args omitted, and because of that get no undefineds. The second one has the last optional arg omitted, and because of that skips the trailing undefined too.
The third call has the last optional arg set, and therefore gets undefined in between so the args end up in the right positions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff! 🎉
This is great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that it could be done with a simple local transformation.
Superseded by #6653 (I messed up git) |
Fixes #6543
This omits trailing
undefineds
when applying external functions with optional arguments, when the optional argument itself is not provided (or isNone
). Only applies to external calls, because that's the only place where it could matter.Some more background: ReScript v11 with uncurried mode allows us to write much more ergonomic external function bindings because we can have optional arguments where we don't need a trailing unit to apply the function itself. But, this comes with a potential problem. All arguments, whether they're actually supplied or not, would be printed as
undefined
in the resulting JS. External JS calls might care about the number of args sent into it, sosomeJsFn(1)
andsomeJsFn(1, undefined)
is not always treated the same. Several JS APIs can break if provided the wrong amount of arguments unless intended.cc @cristianoc what do you think about this?