fix(es/transforms): Fix bugs (#1691)

swc_ecma_transforms_optimization:
 - Don't optimize optional chaining expressions. (#1688)

swc_ecma_transforms_react:
 - Don't panic. (#1683)
This commit is contained in:
강동윤 2021-05-14 00:11:27 +09:00 committed by GitHub
parent 24bd5ea4a4
commit f0d7a3d064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 40 additions and 19 deletions

View File

@ -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>

View File

@ -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]

View File

@ -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]

View File

@ -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);

View File

@ -0,0 +1 @@
({ notafunction: null })?.notafunction?.();

View File

@ -0,0 +1,3 @@
({
notafunction: null
})?.notafunction?.();

View File

@ -0,0 +1 @@
({ notafunction: null })?.notafunction();

View File

@ -0,0 +1,3 @@
({
notafunction: null
})?.notafunction();

View File

@ -0,0 +1 @@
({ notafunction: null }).notafunction?.();

View File

@ -0,0 +1,3 @@
({
notafunction: null
}).notafunction?.();

View File

@ -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")]
@ -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,
);
}

View File

@ -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]

View File

@ -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(),
}))),

View File

@ -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]