Skip to content

Commit bd64b09

Browse files
avpfacebook-github-bot
authored andcommitted
Avoid parens around spread arguments
Reviewed By: tmikov Differential Revision: D33072069 fbshipit-source-id: 2dfcd20c7f82c4f717a6c5b23a4efc6abc34159c
1 parent deabbfd commit bd64b09

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

unsupported/juno/crates/juno/src/gen_js.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,12 @@ impl<W: Write> GenJS<W> {
919919
if i > 0 {
920920
self.comma();
921921
}
922-
self.print_comma_expression(ctx, *arg, Path::new(node, NodeField::arguments));
922+
self.print_child(
923+
ctx,
924+
Some(*arg),
925+
Path::new(node, NodeField::arguments),
926+
ChildPos::Anywhere,
927+
);
923928
}
924929
out!(self, ")");
925930
}
@@ -948,7 +953,12 @@ impl<W: Write> GenJS<W> {
948953
if i > 0 {
949954
self.comma();
950955
}
951-
self.print_comma_expression(ctx, *arg, Path::new(node, NodeField::arguments));
956+
self.print_child(
957+
ctx,
958+
Some(*arg),
959+
Path::new(node, NodeField::arguments),
960+
ChildPos::Anywhere,
961+
);
952962
}
953963
out!(self, ")");
954964
}
@@ -3556,6 +3566,13 @@ impl<W: Write> GenJS<W> {
35563566
// Nullish coalescing always requires parens when mixed with any
35573567
// other logical operations.
35583568
return NeedParens::Yes;
3569+
} else if matches!(
3570+
path.parent,
3571+
Node::CallExpression(_) | Node::OptionalCallExpression(_)
3572+
) && matches!(child, Node::SpreadElement(_))
3573+
{
3574+
// It's illegal to place parens around spread arguments.
3575+
return NeedParens::No;
35593576
}
35603577

35613578
let (child_prec, _child_assoc) = self.get_precedence(child);

unsupported/juno/crates/juno/tests/gen_js/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@ fn test_calls() {
199199
test_roundtrip("f();");
200200
test_roundtrip("f(1);");
201201
test_roundtrip("f(1, 2);");
202+
test_roundtrip("f(1, (2,3), 4);");
202203
test_roundtrip("(f?.(1, 2))(3);");
203204
test_roundtrip("f?.(1, 2)?.(3)(5);");
205+
test_roundtrip("f(...x)");
204206
test_roundtrip("new f();");
205207
test_roundtrip("new f(1);");
206208
test_roundtrip("new(a.b);");

0 commit comments

Comments
 (0)