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

Fix parenthesization of sequence expressions in callee and function params #1566

Merged
merged 5 commits into from
Apr 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion ecmascript/transforms/base/src/fixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ impl VisitMut for Fixer<'_> {
self.ctx = old;
}

fn visit_mut_param(&mut self, node: &mut Param) {
let old = self.ctx;
self.ctx = Context::ForcedExpr { is_var_decl: false };
node.visit_mut_children_with(self);
self.ctx = old;
}

fn visit_mut_assign_expr(&mut self, expr: &mut AssignExpr) {
expr.visit_mut_children_with(self);

Expand Down Expand Up @@ -389,6 +396,13 @@ impl VisitMut for Fixer<'_> {
}
}

fn visit_mut_stmt(&mut self, s: &mut Stmt) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a broken test once I added Context::Callee to the list of contexts to wrap with parens around a sequence expression. I think a previous statement was setting the context and it wasn't being reset when moving on to the next statement.

Copy link
Member

@kdy1 kdy1 Apr 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable fix to me.

let old = self.ctx;
self.ctx = Context::Default;
s.visit_mut_children_with(self);
self.ctx = old;
}

fn visit_mut_expr_stmt(&mut self, s: &mut ExprStmt) {
let old = self.ctx;
self.ctx = Context::Default;
Expand Down Expand Up @@ -515,7 +529,7 @@ impl Fixer<'_> {
};

match self.ctx {
Context::ForcedExpr { .. } => {
Context::ForcedExpr { .. } | Context::Callee { .. } => {
kdy1 marked this conversation as resolved.
Show resolved Hide resolved
*e = Expr::Paren(ParenExpr {
span: *span,
expr: Box::new(expr),
Expand Down Expand Up @@ -1072,4 +1086,12 @@ var store = global[SHARED] || (global[SHARED] = {});
identical!(deno_9810, "await (bar = Promise.resolve(2));");

identical!(issue_1493, "('a' ?? 'b') || ''");
identical!(call_seq, "let x = ({}, () => 2)();");

identical!(
param_seq,
"function t(x = ({}, 2)) {
return x;
}"
);
}