Update fixer.

Fixes #231.
This commit is contained in:
강동윤 2019-02-18 22:31:50 +09:00
parent 59f6a6ffb6
commit 3252988e6a
2 changed files with 18 additions and 0 deletions

View File

@ -1,5 +1,14 @@
use super::*;
test_exec!(
::swc_ecma_parser::Syntax::default(),
|_| TemplateLiteral,
issue_231,
"const truthy = 'a=b';
const foo = `http://example.com/foo/bar${truthy && '?'}${truthy}`;
console.log(foo);"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| TemplateLiteral,

View File

@ -312,6 +312,13 @@ impl Fold<Expr> for Fixer {
e @ Expr::Assign(..) | e @ Expr::Seq(..) | e @ Expr::Yield(..) => {
box e.wrap_with_paren()
}
Expr::Bin(BinExpr { op: op_of_rhs, .. }) => {
if op_of_rhs.precedence() < expr.op.precedence() {
box expr.right.wrap_with_paren()
} else {
expr.right
}
}
_ => expr.right,
};
@ -604,4 +611,6 @@ function a() {
test_fixer!(fixer_12, "(((a, b), c), d) + e;", "d + e;");
test_fixer!(fixer_13, "delete (((1), a), (2));", "delete 2");
identical!(issue_231, "'' + (truthy && '?') + truthy;");
}