Skip to content

Commit

Permalink
fix(es/transforms): Fix bugs (#1691)
Browse files Browse the repository at this point in the history
swc_ecma_transforms_optimization:
 - Don't optimize optional chaining expressions. (#1688)

swc_ecma_transforms_react:
 - Don't panic. (#1683)
  • Loading branch information
kdy1 authored May 13, 2021
1 parent 24bd5ea commit f0d7a3d
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 19 deletions.
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,7 @@ Please see [comparison with babel](https://swc.rs/docs/comparison-babel).

# Performance

The lower bound of the speedup compared to babel is **18**. The benchmarks were run on Macbook pro, dual core, 2.3GHz Intel Core i5, 16 GB ram

| | performance |
| ------------------ | :------------------------------------: |
| swc (es3) | 761 ops/sec ±0.23% (89 runs sampled) |
| swc (es2015) | 800 ops/sec ±1.02% (87 runs sampled) |
| swc (es2016) | 2123 ops/sec ±0.84% (88 runs sampled) |
| swc (es2017) | 2131 ops/sec ±1.13% (90 runs sampled) |
| swc (es2018) | 2981 ops/sec ±0.25% (90 runs sampled) |
| swc-optimize (es3) | 712 ops/sec ±0.21% (86 runs sampled) |
| babel | 41.75 ops/sec ±8.07% (56 runs sampled) |
Please see [benchmark results](https://swc.rs/docs/benchmark-transform) on the website.

<h2 align="center">Supporting swc</h2>

Expand Down
2 changes: 1 addition & 1 deletion 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.16.2"
version = "0.16.3"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion 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.19.1"
version = "0.19.2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
6 changes: 6 additions & 0 deletions ecmascript/transforms/optimization/src/simplify/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,12 @@ impl SimplifyExpr {
impl Fold for SimplifyExpr {
noop_fold_type!();

/// Currently noop
#[inline]
fn fold_opt_chain_expr(&mut self, n: OptChainExpr) -> OptChainExpr {
n
}

fn fold_expr(&mut self, expr: Expr) -> Expr {
// fold children before doing something more.
let expr = expr.fold_children_with(self);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ notafunction: null })?.notafunction?.();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
({
notafunction: null
})?.notafunction?.();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ notafunction: null })?.notafunction();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
({
notafunction: null
})?.notafunction();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ notafunction: null }).notafunction?.();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
({
notafunction: null
}).notafunction?.();
16 changes: 16 additions & 0 deletions ecmascript/transforms/optimization/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use swc_common::pass::Repeat;
use swc_ecma_parser::EsConfig;
use swc_ecma_parser::Syntax;
use swc_ecma_transforms_optimization::simplify::dce::dce;
use swc_ecma_transforms_optimization::simplify::expr_simplifier;
use swc_ecma_transforms_testing::test_fixture;

#[testing::fixture("dce/**/input.js")]
Expand Down Expand Up @@ -34,3 +35,18 @@ fn dce_repeated(input: PathBuf) {
&output,
);
}

#[testing::fixture("expr-simplifier/**/input.js")]
fn expr(input: PathBuf) {
let output = input.with_file_name("output.js");

test_fixture(
Syntax::Es(EsConfig {
dynamic_import: true,
..Default::default()
}),
&|_| expr_simplifier(),
&input,
&output,
);
}
2 changes: 1 addition & 1 deletion ecmascript/transforms/react/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc_ecma_transforms_react"
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 Down
5 changes: 1 addition & 4 deletions ecmascript/transforms/react/src/jsx_src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ impl Fold for JsxSrc {
key: PropName::Ident(quote_ident!("fileName")),
value: Box::new(Expr::Lit(Lit::Str(Str {
span: DUMMY_SP,
value: match file_lines.file.name {
FileName::Real(ref p) => p.display().to_string().into(),
_ => unimplemented!("file name for other than real files"),
},
value: file_lines.file.name.to_string().into(),
has_escape: false,
kind: Default::default(),
}))),
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/transforms/typescript/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_typescript"
repository = "https://github.com/swc-project/swc.git"
version = "0.18.1"
version = "0.18.2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down

0 comments on commit f0d7a3d

Please sign in to comment.