haxe
haxe copied to clipboard
[js] It would be nice to have a more elegant output of default arguments in es6
haxe source :
function multiply( a, b = 1 ) {
return a * b;
}
Current output :
function multiply(a,b) {
if(b == null) {
b = 1;
}
return a * b;
}
Expected output : es6 default parameters
function multiply( a, b = 1 ) {
return a * b;
}
Haxe often generates calls like multiply(1, null), so this will be impossible to do and will break the specification with null vars, because JS doesn't update null values in args
I did some testing and found that it seems like Haxe only generates multiply(1, null) for external functions.
And also for external functions, null doesn't seem to be necessary in multiply(1, null). I know that null isn't undefined, but there should be some way to handle it.
final x = null; foo(x); also generate let x = null, and not undefined, so there is a lot of things to change to undefined generation, and it can break other things then
In this case, we will have to change all null generation to undefined for js target. This could be more logical, but more significant reasons are needed than just this one case of pretty code, because this is still a breaking change for js.Lib.undefined checks
IMO this isn't worth the trouble. There are likely subtle differences here which would cause problems down the line, so I prefer to keep things as they are.