Skip to content
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

[js] It would be nice to have a more elegant output of default arguments in es6 #11637

Open
R32 opened this issue Apr 14, 2024 · 4 comments
Open

Comments

@R32
Copy link
Contributor

R32 commented Apr 14, 2024

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;
}
@RblSb
Copy link
Member

RblSb commented Apr 14, 2024

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

@R32
Copy link
Contributor Author

R32 commented Apr 14, 2024

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.

@RblSb
Copy link
Member

RblSb commented Apr 14, 2024

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

@RblSb
Copy link
Member

RblSb commented Apr 14, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants