Skip to content

Commit

Permalink
fix(es/transforms/base): Wrap binary operands of unary expressions. (#…
Browse files Browse the repository at this point in the history
…1793)

swc_ecma_transforms_base:
 - `fixer`: Handle binary operands of unary expressions correctly. (#1789)
  • Loading branch information
kdy1 authored Jun 5, 2021
1 parent 0bd2a3a commit 03db7ad
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log(-0, 0, -1 / 0, -1 / 0);
console.log(-0, 0, -(1 / 0), -(1 / 0));
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log(-2 / 3);
console.log(-(2 / 3));
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
4 changes: 2 additions & 2 deletions ecmascript/transforms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/transforms/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions ecmascript/transforms/base/src/fixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)
Expand Down Expand Up @@ -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)");
}

0 comments on commit 03db7ad

Please sign in to comment.