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

EcmaVersion 7: Unary minus and exponentiation not working #462

Open
crguezl opened this issue Feb 8, 2024 · 1 comment
Open

EcmaVersion 7: Unary minus and exponentiation not working #462

crguezl opened this issue Feb 8, 2024 · 1 comment

Comments

@crguezl
Copy link

crguezl commented Feb 8, 2024

escodegen does not support the combination of unary minus and exponentiation:

  arith2js-parallel-computing-group-parallel git:(essay-2023-02-15-miercoles)  node
Welcome to Node.js v18.8.0.
Type ".help" for more information.
> let  espree = require('espree')
> let ast = espree.parse('(-2)**2') // gives an error since the default compiler is ecma 5
Uncaught [SyntaxError: Unexpected token *
> let ast3 = espree.parse('(-2)**2', { ecmaVersion: 7}) // no errors. Right AST
> let escodegen = require('escodegen')
> let gc = escodegen.generate(ast3) // escodegen does not support this feature. The code generated is wrong
> gc
'-2 ** 2;'
> eval(gc) // the evaluation of the code produces errors
Uncaught:
SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence
> -2 ** 2 # JS does not accept this expression
-2 ** 2
^^^^^
Uncaught:
SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence
> (-2) ** 2  # ... But this code works 
4
@j4k0xb
Copy link

j4k0xb commented Feb 27, 2024

can't reproduce, this was fixed years ago (#407) and generates (-2) ** 2

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