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

Fold comma operation when left argument has no side effects. #2803

Open
leewz opened this issue Feb 2, 2018 · 2 comments
Open

Fold comma operation when left argument has no side effects. #2803

leewz opened this issue Feb 2, 2018 · 2 comments

Comments

@leewz
Copy link

leewz commented Feb 2, 2018

(Using https://closure-compiler.appspot.com/home with Advanced Optimizations.)

Currently, the compiler shows a warning:

JSC_USELESS_CODE: Suspicious code. This code lacks side-effects. Is there a bug? at line 1 character 13
console.log((1, 0) > 5)
             ^

However, it doesn't (edit:) always constant-fold the comma operator.

This is folded:

console.log((1,0));

This is not:

console.log((1, 0) > 5)

Output:

console.log(5<(1,0));
@MatrixFrog
Copy link
Contributor

If I remember correctly, after reporting that warning, it adds some temporary code to explicitly protect the 1 from being removed. The reason for this is that sometimes an expression that should have no side effects, is actually necessary to workaround a browser bug, e.g. elem.offsetWidth; // force the browser to re-layout

Obviously 1 will never have side effects no matter how buggy your browser is :) so maybe we can make this a little less aggressive.

@leewz
Copy link
Author

leewz commented Feb 3, 2018 via email

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