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

Pretty-print output for increment/decrement operator expression followed by method call causes error when evaluated #1384

Open
cgdangelo opened this issue Jan 11, 2024 · 0 comments

Comments

@cgdangelo
Copy link

Given an expression of the form (a++).toString(), pretty-printing removes the parentheses around the operator expression, transforming it to a++.toString().

When that output is evaluated, a SyntaxError or ReferenceError is thrown for postfix and prefix operators respectively.

> recast.print(recast.parse("a=0;(a++).toString()")).code
'a=0;(a++).toString()'
> eval(_)
'0'
> recast.prettyPrint(recast.parse("a=0;(a++).toString()")).code
'a = 0;\na++.toString();'
> eval(_)
Uncaught SyntaxError: Unexpected token '.'
> recast.print(recast.parse("a=0;(--a).toString()")).code
'a=0;(--a).toString()'
> eval(_)
'-1'
> recast.prettyPrint(recast.parse("a=0;(--a).toString()")).code
'a = 0;\n--a.toString();'
> eval(_)
Uncaught ReferenceError: Invalid left-hand side expression in prefix operation
    at eval (eval at <anonymous> (REPL484:1:1), <anonymous>:2:5)
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

1 participant