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

Exponential operator in if condition is not transpiled #2821

Closed
teppeis opened this issue Feb 18, 2018 · 7 comments
Closed

Exponential operator in if condition is not transpiled #2821

teppeis opened this issue Feb 18, 2018 · 7 comments
Assignees

Comments

@teppeis
Copy link
Contributor

teppeis commented Feb 18, 2018

Original source code:

if (2 ** 3 > 0) { alert('test'); }

Expected transpiled code:

0 < Math.pow(2, 3) && alert("test");

Actual result

0 < 2 ** 3 && alert("test");

Same result in ternary operator.


Also, it throws an error in Advanced Optimization.

JSC_INTERNAL_ERROR_UNEXPECTED_TOKEN: Internal Error: TypeCheck doesn't know how to handle EXPONENT at line 1 character 4
if (2 ** 3 > 0) { alert('test'); }
    ^

If another exponential operator is in body, they are transpiled.
Original:

if (2 ** 3 > 0) { alert(2 ** 3); }

Transpiled:

0 < Math.pow(2, 3) && alert(Math.pow(2, 3));
@teppeis teppeis changed the title Exponential operator in if condition Exponential operator in if condition is not transpiled Feb 18, 2018
@MatrixFrog MatrixFrog self-assigned this Feb 26, 2018
@MatrixFrog
Copy link
Contributor

I can't seem to repro this with the compiler jar so this seems to be a quirk of the webservice. Will take a look.

@teppeis
Copy link
Contributor Author

teppeis commented Feb 27, 2018

@brad4d brad4d self-assigned this Feb 27, 2018
@brad4d
Copy link
Contributor

brad4d commented Feb 27, 2018

@teppeis I've reproduced this in the unit test. I'm debugging it now.

@MatrixFrog MatrixFrog removed their assignment Feb 27, 2018
@brad4d
Copy link
Contributor

brad4d commented Feb 27, 2018

Even simpler repro

(2 ** 3) / 3;

Looks like the root cause is in IRFactory.
It fails to record that the exponent operator is used in some cases.

@brad4d
Copy link
Contributor

brad4d commented Feb 27, 2018

correction to repro
2 ** 3 > 3

@brad4d
Copy link
Contributor

brad4d commented Feb 27, 2018

fix sent for internal review

@teppeis
Copy link
Contributor Author

teppeis commented Mar 1, 2018

@MatrixFrog @brad4d thanks!

sebasjm pushed a commit to sebasjm/closure-compiler that referenced this issue Mar 11, 2018
Fixes google#2821

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=187221401
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

3 participants