question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exponential operator in if condition is not transpiled

See original GitHub issue

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));

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
brad4dcommented, Feb 27, 2018

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

0reactions
teppeiscommented, Mar 1, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Use the Exponentiation Operator in JavaScript - Egghead.io
ES2016 introduced the exponentiation operator ** to JavaScript. This lesson shows how it works and how you can use it as a replacement...
Read more >
Exponentiation (**) - JavaScript - MDN Web Docs - Mozilla
The exponentiation (**) operator returns the result of raising the first operand to the power of the second operand.
Read more >
The Exponentiation Operator in JavaScript - Marius Schulz
#The Exponentiation Operator in Babel​​ Similarly, the exponentiation operator can be transpiled by Babel as well. By default, however, Babel ...
Read more >
CoffeeScript
CoffeeScript can compile if statements into JavaScript expressions, using the ternary operator when possible, and closure wrapping otherwise. There is no ...
Read more >
Webpack and Babel not transpiling a dependency inside ...
Ok, it turns out to process files inside node_modules you need to use babel.config.js rather than .babelrc as explained here and here:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found