fix(es/transforms/base): Wrap binary operands of unary expressions. (#1793)

swc_ecma_transforms_base:
 - `fixer`: Handle binary operands of unary expressions correctly. (#1789)
This commit is contained in:
강동윤 2021-06-05 21:58:50 +09:00 committed by GitHub
parent 0bd2a3a07e
commit 03db7adc9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 12 deletions

View File

@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecmascript"
repository = "https://github.com/swc-project/swc.git"
version = "0.36.1"
version = "0.36.2"
[package.metadata.docs.rs]
all-features = true
@ -33,7 +33,7 @@ swc_ecma_codegen = {version = "0.55.0", path = "./codegen", optional = true}
swc_ecma_dep_graph = {version = "0.25.0", path = "./dep-graph", optional = true}
swc_ecma_minifier = {version = "0.2.3", path = "./minifier", optional = true}
swc_ecma_parser = {version = "0.57.0", path = "./parser", optional = true}
swc_ecma_transforms = {version = "0.50.1", path = "./transforms", optional = true}
swc_ecma_transforms = {version = "0.50.2", path = "./transforms", optional = true}
swc_ecma_utils = {version = "0.36.0", path = "./utils", optional = true}
swc_ecma_visit = {version = "0.31.0", path = "./visit", optional = true}

View File

@ -1 +1 @@
console.log(-0, 0, -1 / 0, -1 / 0);
console.log(-0, 0, -(1 / 0), -(1 / 0));

View File

@ -1 +1 @@
console.log(-2 / 3);
console.log(-(2 / 3));

View File

@ -13,6 +13,6 @@ var v = [
];
v.forEach(function(x) {
v.forEach(function(y) {
console.log(+(x * y), +x / y, +x % y, -(x * y), -x / y, -x % y);
console.log(+(x * y), +(x / y), +(x % y), -(x * y), -(x / y), -(x % y));
});
});

View File

@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_transforms"
repository = "https://github.com/swc-project/swc.git"
version = "0.50.1"
version = "0.50.2"
[package.metadata.docs.rs]
all-features = true
@ -25,7 +25,7 @@ swc_atoms = {version = "0.2.0", path = "../../atoms"}
swc_common = {version = "0.10.16", path = "../../common"}
swc_ecma_ast = {version = "0.45.0", path = "../ast"}
swc_ecma_parser = {version = "0.57.0", path = "../parser"}
swc_ecma_transforms_base = {version = "0.15.6", path = "./base"}
swc_ecma_transforms_base = {version = "0.15.7", path = "./base"}
swc_ecma_transforms_compat = {version = "0.17.9", path = "./compat", optional = true}
swc_ecma_transforms_module = {version = "0.17.1", path = "./module", optional = true}
swc_ecma_transforms_optimization = {version = "0.20.3", path = "./optimization", optional = true}

View File

@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_transforms_base"
repository = "https://github.com/swc-project/swc.git"
version = "0.15.6"
version = "0.15.7"
[dependencies]
fxhash = "0.2.1"

View File

@ -277,10 +277,7 @@ impl VisitMut for Fixer<'_> {
n.visit_mut_children_with(self);
self.ctx = old;
match *n.arg {
// Don't wrap
Expr::Bin(BinExpr { op: op!("%"), .. }) | Expr::Bin(BinExpr { op: op!("/"), .. }) => {}
match &*n.arg {
Expr::Assign(..)
| Expr::Bin(..)
| Expr::Seq(..)
@ -1220,4 +1217,6 @@ var store = global[SHARED] || (global[SHARED] = {});
identical!(minifier_004, "(void 0)(0)");
identical!(issue_1781, "const n = ~~(Math.PI * 10)");
identical!(issue_1789, "+(+1 / 4)");
}