ast-types icon indicating copy to clipboard operation
ast-types copied to clipboard

Apply same paren rules to NewExpression as CallExpression

Open thomasboyt opened this issue 11 years ago • 2 comments

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)

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

  

thomasboyt avatar Mar 31 '14 19:03 thomasboyt

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

benjamn avatar Mar 31 '14 21:03 benjamn

(bump)

benjamn avatar Apr 17 '14 01:04 benjamn