ast-types
ast-types copied to clipboard
Apply same paren rules to NewExpression as CallExpression
Before, this AST:
b.newExpression(
b.logicalExpression(
'||',
b.identifier('One'),
b.identifier('Two')
),
[b.identifier('foo')]
);
would print as:
new One || Two(foo)
This fixes it to print as:
new (One || Two)(foo)
- [ ]
General Comment - <img border=0 src='https://avatars.githubusercontent.com/u/5750?v=3' height=16 width=16'> Can you audit the other places in this file where
n.CallExpression.checkis used and decide if those sites need an.NewExpression.checktoo? If you think it helps, you can also create a kind of union type:
var CallOrNewExpression = types.Type.or(
n.CallExpression,
n.NewExpression
);
and then do CallOrNewExpression.check(node) instead of n.CallExpression.check(node) || n.NewExpression.check(node).
Can you audit the other places in this file where n.CallExpression.check is used and decide if those sites need a n.NewExpression.check too?
If you think it helps, you can also create a kind of union type:
var CallOrNewExpression = types.Type.or(
n.CallExpression,
n.NewExpression
);
and then do CallOrNewExpression.check(node) instead of n.CallExpression.check(node) || n.NewExpression.check(node).
(bump)