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

Missing parentheses when argument of UnaryExpression is LogicalExpression !(a && b) #922

Open
coderaiser opened this issue May 14, 2021 · 1 comment

Comments

@coderaiser
Copy link
Contributor

coderaiser commented May 14, 2021

When using such code:

const recast = require("recast");
const {unaryExpression} = require('@babel/types');
const babel = require('@babel/parser');

const source = '(options || !options.bidirectional) ? false : true;';

const ast = recast.parse(source, {
    parser: babel,
});

ast.program.body[0].expression = unaryExpression('!', ast.program.body[0].expression.test);

console.log(recast.print(ast).code);
// outputs
!options || !options.bidirectional

Should output:

!(options || !options.bidirectional)

Reproduced in latest version of @babel/parser when used with @babel/core@7.14.2

Fix landed in @putout/recast v1.3.1.

@gnprice
Copy link
Contributor

gnprice commented Jun 12, 2022

This issue no longer reproduces 🎉

It reproduces as of recast@0.21.0:

$ cd $(mktemp -d)
$ npm i recast@0.21.0 @babel/types @babel/parser
$ xclip -o >test.js  # (to copy the code in the description to test.js)
$ node test.js
!options || !options.bidirectional;

It no longer reproduces as of 0.21.1:

$ npm i recast@0.21.1
$ node test.js
!(options || !options.bidirectional);

From looking through what changed between those versions, I think #1068 is probably the change that fixed it.

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