Skip to content

Commit

Permalink
fix(es/transforms): Fix bugs (#1783)
Browse files Browse the repository at this point in the history
swc_ecma_transforms_base:
- `fixer`: Wrap operand of a unary expression if it's a binary expression. (#1781, #1789)

swc_ecma_transforms_module:
 - Allow multiple `export *` even if it has the same item. (#1780)
  • Loading branch information
kdy1 authored Jun 5, 2021
1 parent 4e7723a commit 0bd2a3a
Show file tree
Hide file tree
Showing 19 changed files with 134 additions and 69 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.20.0"
version = "0.20.1"

[lib]
name = "swc"
Expand All @@ -34,8 +34,8 @@ swc_ecma_ast = {version = "0.45.0", path = "./ecmascript/ast"}
swc_ecma_codegen = {version = "0.55.0", path = "./ecmascript/codegen"}
swc_ecma_ext_transforms = {version = "0.15.0", path = "./ecmascript/ext-transforms"}
swc_ecma_parser = {version = "0.57.0", path = "./ecmascript/parser"}
swc_ecma_preset_env = {version = "0.20.0", path = "./ecmascript/preset_env"}
swc_ecma_transforms = {version = "0.50.0", path = "./ecmascript/transforms", features = [
swc_ecma_preset_env = {version = "0.20.4", path = "./ecmascript/preset_env"}
swc_ecma_transforms = {version = "0.50.1", path = "./ecmascript/transforms", features = [
"compat",
"module",
"optimization",
Expand Down
6 changes: 3 additions & 3 deletions bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "src/**/*.js"]
license = "Apache-2.0/MIT"
name = "swc_bundler"
repository = "https://github.com/swc-project/swc.git"
version = "0.37.3"
version = "0.37.4"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
Expand All @@ -36,7 +36,7 @@ swc_common = {version = "0.10.16", path = "../common"}
swc_ecma_ast = {version = "0.45.0", path = "../ecmascript/ast"}
swc_ecma_codegen = {version = "0.55.0", path = "../ecmascript/codegen"}
swc_ecma_parser = {version = "0.57.0", path = "../ecmascript/parser"}
swc_ecma_transforms = {version = "0.50.0", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_transforms = {version = "0.50.1", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_utils = {version = "0.36.0", path = "../ecmascript/utils"}
swc_ecma_visit = {version = "0.31.0", path = "../ecmascript/visit"}

Expand All @@ -45,7 +45,7 @@ hex = "0.4"
ntest = "0.7.2"
reqwest = {version = "0.10.8", features = ["blocking"]}
sha-1 = "0.9"
swc_ecma_transforms = {version = "0.50.0", path = "../ecmascript/transforms", features = ["react", "typescript"]}
swc_ecma_transforms = {version = "0.50.1", path = "../ecmascript/transforms", features = ["react", "typescript"]}
tempfile = "3.1.0"
testing = {version = "0.10.5", path = "../testing"}
url = "2.1.1"
Expand Down
6 changes: 3 additions & 3 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.0"
version = "0.36.1"

[package.metadata.docs.rs]
all-features = true
Expand All @@ -31,9 +31,9 @@ typescript = ["swc_ecma_transforms/typescript"]
swc_ecma_ast = {version = "0.45.0", path = "./ast"}
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.2-beta.0", path = "./minifier", 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.0", path = "./transforms", optional = true}
swc_ecma_transforms = {version = "0.50.1", 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
6 changes: 3 additions & 3 deletions ecmascript/minifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "src/lists/*.json"]
license = "Apache-2.0/MIT"
name = "swc_ecma_minifier"
repository = "https://github.com/swc-project/swc.git"
version = "0.2.2-beta.0"
version = "0.2.3"

[features]
debug = []
Expand All @@ -27,8 +27,8 @@ swc_common = {version = "0.10.8", path = "../../common"}
swc_ecma_ast = {version = "0.45.0", path = "../ast"}
swc_ecma_codegen = {version = "0.55.0", path = "../codegen"}
swc_ecma_parser = {version = "0.57.0", path = "../parser"}
swc_ecma_transforms = {version = "0.50.0", path = "../transforms/", features = ["optimization"]}
swc_ecma_transforms_base = {version = "0.15.0", path = "../transforms/base"}
swc_ecma_transforms = {version = "0.50.1", path = "../transforms/", features = ["optimization"]}
swc_ecma_transforms_base = {version = "0.15.6", path = "../transforms/base"}
swc_ecma_utils = {version = "0.36.0", path = "../utils"}
swc_ecma_visit = {version = "0.31.0", path = "../visit"}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
var v = [0, 1, NaN, 1 / 0, null, void 0, true, false, "", "foo", /foo/];
v.forEach(function (x) {
v.forEach(function (y) {
console.log(+x * y, +x / y, +x % y, -x * y, -x / y, -x % y);
var v = [
0,
1,
NaN,
1 / 0,
null,
void 0,
true,
false,
"",
"foo",
/foo/
];
v.forEach(function(x) {
v.forEach(function(y) {
console.log(+(x * y), +x / y, +x % y, -(x * y), -x / y, -x % y);
});
});
4 changes: 2 additions & 2 deletions ecmascript/preset_env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ documentation = "https://rustdoc.swc.rs/swc_ecma_preset_env/"
edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_preset_env"
version = "0.20.3"
version = "0.20.4"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -22,7 +22,7 @@ string_enum = {version = "0.3.1", path = "../../macros/string_enum"}
swc_atoms = {version = "0.2", path = "../../atoms"}
swc_common = {version = "0.10.16", path = "../../common"}
swc_ecma_ast = {version = "0.45.0", path = "../ast"}
swc_ecma_transforms = {version = "0.50.0", path = "../transforms", features = ["compat", "proposal"]}
swc_ecma_transforms = {version = "0.50.1", path = "../transforms", features = ["compat", "proposal"]}
swc_ecma_utils = {version = "0.36.0", path = "../utils"}
swc_ecma_visit = {version = "0.31.0", path = "../visit"}
walkdir = "2"
Expand Down
18 changes: 9 additions & 9 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.0"
version = "0.50.1"

[package.metadata.docs.rs]
all-features = true
Expand All @@ -25,13 +25,13 @@ 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.0", path = "./base"}
swc_ecma_transforms_compat = {version = "0.17.0", path = "./compat", optional = true}
swc_ecma_transforms_module = {version = "0.17.0", path = "./module", optional = true}
swc_ecma_transforms_optimization = {version = "0.20.0", path = "./optimization", optional = true}
swc_ecma_transforms_proposal = {version = "0.17.0", path = "./proposal", optional = true}
swc_ecma_transforms_react = {version = "0.18.0", path = "./react", optional = true}
swc_ecma_transforms_typescript = {version = "0.19.0", path = "./typescript", optional = true}
swc_ecma_transforms_base = {version = "0.15.6", 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}
swc_ecma_transforms_proposal = {version = "0.17.1", path = "./proposal", optional = true}
swc_ecma_transforms_react = {version = "0.18.2", path = "./react", optional = true}
swc_ecma_transforms_typescript = {version = "0.19.4", path = "./typescript", optional = true}
swc_ecma_utils = {version = "0.36.0", path = "../utils"}
swc_ecma_visit = {version = "0.31.0", path = "../visit"}
unicode-xid = "0.2"
Expand All @@ -40,7 +40,7 @@ unicode-xid = "0.2"
pretty_assertions = "0.6"
sourcemap = "6"
swc_ecma_codegen = {version = "0.55.0", path = "../codegen"}
swc_ecma_transforms_testing = {version = "0.15.0", path = "./testing"}
swc_ecma_transforms_testing = {version = "0.15.1", path = "./testing"}
tempfile = "3"
testing = {version = "0.10.5", path = "../../testing"}
walkdir = "2"
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.5"
version = "0.15.6"

[dependencies]
fxhash = "0.2.1"
Expand Down
6 changes: 3 additions & 3 deletions ecmascript/transforms/base/src/fixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ impl VisitMut for Fixer<'_> {

match *n.arg {
// Don't wrap
Expr::Bin(BinExpr { op: op!("*"), .. })
| Expr::Bin(BinExpr { op: op!("%"), .. })
| Expr::Bin(BinExpr { op: op!("/"), .. }) => {}
Expr::Bin(BinExpr { op: op!("%"), .. }) | Expr::Bin(BinExpr { op: op!("/"), .. }) => {}

Expr::Assign(..)
| Expr::Bin(..)
Expand Down Expand Up @@ -1220,4 +1218,6 @@ var store = global[SHARED] || (global[SHARED] = {});
identical!(minifier_003, "(four ** one) ** two");

identical!(minifier_004, "(void 0)(0)");

identical!(issue_1781, "const n = ~~(Math.PI * 10)");
}
4 changes: 2 additions & 2 deletions ecmascript/transforms/classes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_transforms_classes"
repository = "https://github.com/swc-project/swc.git"
version = "0.1.0"
version = "0.1.1"

[dependencies]
swc_atoms = {version = "0.2.6", path = "../../../atoms"}
swc_common = {version = "0.10.20", path = "../../../common"}
swc_ecma_ast = {version = "0.45.0", path = "../../ast"}
swc_ecma_transforms_base = {version = "0.15.5", path = "../base"}
swc_ecma_transforms_base = {version = "0.15.6", path = "../base"}
swc_ecma_utils = {version = "0.36.0", path = "../../utils"}
swc_ecma_visit = {version = "0.31.0", path = "../../visit"}
8 changes: 4 additions & 4 deletions ecmascript/transforms/compat/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_compat"
repository = "https://github.com/swc-project/swc.git"
version = "0.17.8"
version = "0.17.9"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -21,13 +21,13 @@ smallvec = "1.6.0"
swc_atoms = {version = "0.2.5", path = "../../../atoms"}
swc_common = {version = "0.10.16", path = "../../../common"}
swc_ecma_ast = {version = "0.45.0", path = "../../ast"}
swc_ecma_transforms_base = {version = "0.15.0", path = "../base"}
swc_ecma_transforms_classes = {version = "0.1.0", path = "../classes"}
swc_ecma_transforms_base = {version = "0.15.6", path = "../base"}
swc_ecma_transforms_classes = {version = "0.1.1", path = "../classes"}
swc_ecma_transforms_macros = {version = "0.2.1", path = "../macros"}
swc_ecma_utils = {version = "0.36.0", path = "../../utils"}
swc_ecma_visit = {version = "0.31.0", path = "../../visit"}

[dev-dependencies]
swc_ecma_parser = {version = "0.57.0", path = "../../parser"}
swc_ecma_transforms_testing = {version = "0.15.0", path = "../testing"}
swc_ecma_transforms_testing = {version = "0.15.1", path = "../testing"}
testing = {version = "0.10.5", path = "../../../testing"}
8 changes: 4 additions & 4 deletions ecmascript/transforms/module/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_module"
repository = "https://github.com/swc-project/swc.git"
version = "0.17.0"
version = "0.17.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -18,11 +18,11 @@ swc_atoms = {version = "0.2", 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.0", path = "../base"}
swc_ecma_transforms_base = {version = "0.15.6", path = "../base"}
swc_ecma_utils = {version = "0.36.0", path = "../../utils"}
swc_ecma_visit = {version = "0.31.0", path = "../../visit"}

[dev-dependencies]
swc_ecma_transforms_compat = {version = "0.17.0", path = "../compat"}
swc_ecma_transforms_testing = {version = "0.15.0", path = "../testing/"}
swc_ecma_transforms_compat = {version = "0.17.9", path = "../compat"}
swc_ecma_transforms_testing = {version = "0.15.1", path = "../testing/"}
testing = {version = "0.10.5", path = "../../../testing/"}
2 changes: 1 addition & 1 deletion ecmascript/transforms/module/src/common_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl Fold for CommonJs {

// Used only if export * exists
let exported_names = {
if !export_alls.is_empty() && has_export {
if (!export_alls.is_empty() && has_export) || export_alls.len() >= 2 {
let exported_names = private_ident!("_exportNames");
stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
span: DUMMY_SP,
Expand Down
53 changes: 53 additions & 0 deletions ecmascript/transforms/module/tests/common_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,12 +1244,15 @@ export * from "black";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
};
var _white = require("white");
var _black = require("black");
Object.keys(_white).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
Expand All @@ -1260,6 +1263,7 @@ Object.keys(_white).forEach(function (key) {
Object.keys(_black).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
Expand Down Expand Up @@ -4191,6 +4195,8 @@ export * from './pipes';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
};
require("reflect-metadata");
var _http = require("./http");
var _interfaces = require("./interfaces");
Expand All @@ -4203,6 +4209,7 @@ export * from './pipes';
});
Object.keys(_http).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
Expand All @@ -4212,6 +4219,7 @@ export * from './pipes';
});
Object.keys(_pipes).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
Expand Down Expand Up @@ -4712,3 +4720,48 @@ test!(
})();
"
);

test!(
syntax(),
|_| tr(Default::default()),
issue_1780_1,
"
export const BIZ = 'biz';
export * from './File1';
export * from './File2';
",
"
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _exportNames = {
BIZ: true
};
exports.BIZ = void 0;
var _file1 = require('./File1');
var _file2 = require('./File2');
const BIZ = 'biz';
exports.BIZ = BIZ;
Object.keys(_file1).forEach(function(key) {
if (key === 'default' || key === '__esModule') return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _file1[key];
}
});
});
Object.keys(_file2).forEach(function(key) {
if (key === 'default' || key === '__esModule') return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _file2[key];
}
});
});
"
);
16 changes: 8 additions & 8 deletions ecmascript/transforms/optimization/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_optimization"
repository = "https://github.com/swc-project/swc.git"
version = "0.20.2"
version = "0.20.3"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -21,15 +21,15 @@ swc_atoms = {version = "0.2", 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.0", path = "../base"}
swc_ecma_transforms_base = {version = "0.15.6", path = "../base"}
swc_ecma_utils = {version = "0.36.0", path = "../../utils"}
swc_ecma_visit = {version = "0.31.0", path = "../../visit"}

[dev-dependencies]
swc_ecma_transforms_compat = {version = "0.17.0", path = "../compat"}
swc_ecma_transforms_module = {version = "0.17.0", path = "../module"}
swc_ecma_transforms_proposal = {version = "0.17.0", path = "../proposal"}
swc_ecma_transforms_react = {version = "0.18.0", path = "../react"}
swc_ecma_transforms_testing = {version = "0.15.0", path = "../testing"}
swc_ecma_transforms_typescript = {version = "0.19.0", path = "../typescript"}
swc_ecma_transforms_compat = {version = "0.17.9", path = "../compat"}
swc_ecma_transforms_module = {version = "0.17.1", path = "../module"}
swc_ecma_transforms_proposal = {version = "0.17.1", path = "../proposal"}
swc_ecma_transforms_react = {version = "0.18.2", path = "../react"}
swc_ecma_transforms_testing = {version = "0.15.1", path = "../testing"}
swc_ecma_transforms_typescript = {version = "0.19.4", path = "../typescript"}
testing = {version = "0.10.5", path = "../../../testing"}
Loading

0 comments on commit 0bd2a3a

Please sign in to comment.