-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Description
Example:
current = 0
next = -> ++current
foo = ({ a = next() }, b = next()) -> [ a, b ]
console.log foo {}
Expected output: [ 1, 2 ]
Output on master
: [ 1, 2 ]
Output on 2
: [ 2, 1 ]
This is caused by the 2
branch compiling defaults for simple parameters into the argument list, but handling complex parameters' defaults in the function body.
Output on master
(simplified)
function (arg, b) {
var a
a = arg.a != null ? arg.a : next();
if (b == null) {
b = next();
}
return [a, b];
}
Output on 2
(simplified)
function (arg, b = next()) {
var a;
a = arg.a != null ? arg.a : next();
return [a, b];
}
I encountered this whilst improving super
handling in #4354 (coming soon).
I guess the way we want to fix this is to compile destructured parameters and their defaults to ES also, but I wanted to create an issue to make sure we don't forget about it!