fix(es/transforms/compat): Move the optional catch binding pass to ES2019 (#2247)

swc_ecma_transforms_compat:
 - Move optional chaining pass to `es2019`.

Co-authored-by: Donny <kdy1997.dev@gmail.com>
This commit is contained in:
Pig Fang 2021-09-21 20:54:51 +08:00 committed by GitHub
parent 180dc31550
commit 4d500baaaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 78 additions and 71 deletions

24
Cargo.lock generated
View File

@ -2287,7 +2287,7 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]]
name = "swc"
version = "0.55.0"
version = "0.56.0"
dependencies = [
"ahash",
"anyhow",
@ -2392,7 +2392,7 @@ dependencies = [
[[package]]
name = "swc_bundler"
version = "0.58.1"
version = "0.59.0"
dependencies = [
"ahash",
"anyhow",
@ -2629,7 +2629,7 @@ dependencies = [
[[package]]
name = "swc_ecma_minifier"
version = "0.27.4"
version = "0.28.0"
dependencies = [
"ansi_term 0.12.1",
"anyhow",
@ -2685,7 +2685,7 @@ dependencies = [
[[package]]
name = "swc_ecma_preset_env"
version = "0.42.1"
version = "0.43.0"
dependencies = [
"dashmap",
"fxhash",
@ -2711,7 +2711,7 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms"
version = "0.71.1"
version = "0.72.0"
dependencies = [
"pretty_assertions 0.6.1",
"sourcemap",
@ -2769,7 +2769,7 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_compat"
version = "0.34.3"
version = "0.35.0"
dependencies = [
"arrayvec",
"fxhash",
@ -2805,7 +2805,7 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_module"
version = "0.38.1"
version = "0.39.0"
dependencies = [
"Inflector",
"anyhow",
@ -2828,7 +2828,7 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_optimization"
version = "0.41.1"
version = "0.42.0"
dependencies = [
"dashmap",
"fxhash",
@ -2855,7 +2855,7 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_proposal"
version = "0.38.1"
version = "0.39.0"
dependencies = [
"either",
"fxhash",
@ -2877,7 +2877,7 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_react"
version = "0.39.1"
version = "0.40.0"
dependencies = [
"base64 0.13.0",
"dashmap",
@ -2922,7 +2922,7 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_typescript"
version = "0.40.4"
version = "0.41.0"
dependencies = [
"fxhash",
"serde",
@ -2969,7 +2969,7 @@ dependencies = [
[[package]]
name = "swc_ecmascript"
version = "0.63.1"
version = "0.64.0"
dependencies = [
"swc_ecma_ast",
"swc_ecma_codegen",

View File

@ -20,7 +20,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.55.0"
version = "0.56.0"
[lib]
name = "swc"
@ -53,16 +53,16 @@ serde = {version = "1", features = ["derive"]}
serde_json = "1"
sourcemap = "6"
swc_atoms = {version = "0.2", path = "./atoms"}
swc_bundler = {version = "0.58.1", path = "./bundler"}
swc_bundler = {version = "0.59.0", path = "./bundler"}
swc_common = {version = "0.12.1", path = "./common", features = ["sourcemap", "concurrent"]}
swc_ecma_ast = {version = "0.52.0", path = "./ecmascript/ast"}
swc_ecma_codegen = {version = "0.70.2", path = "./ecmascript/codegen"}
swc_ecma_ext_transforms = {version = "0.28.1", path = "./ecmascript/ext-transforms"}
swc_ecma_loader = {version = "0.18.1", path = "./ecmascript/loader", features = ["lru", "node", "tsc"]}
swc_ecma_minifier = {version = "0.27.2", path = "./ecmascript/minifier"}
swc_ecma_minifier = {version = "0.28.0", path = "./ecmascript/minifier"}
swc_ecma_parser = {version = "0.70.2", path = "./ecmascript/parser"}
swc_ecma_preset_env = {version = "0.42.1", path = "./ecmascript/preset-env"}
swc_ecma_transforms = {version = "0.71.1", path = "./ecmascript/transforms", features = [
swc_ecma_preset_env = {version = "0.43.0", path = "./ecmascript/preset-env"}
swc_ecma_transforms = {version = "0.72.0", path = "./ecmascript/transforms", features = [
"compat",
"module",
"optimization",
@ -73,7 +73,7 @@ swc_ecma_transforms = {version = "0.71.1", path = "./ecmascript/transforms", fea
swc_ecma_transforms_base = {version = "0.31.1", path = "./ecmascript/transforms/base"}
swc_ecma_utils = {version = "0.44.2", path = "./ecmascript/utils"}
swc_ecma_visit = {version = "0.38.1", path = "./ecmascript/visit"}
swc_ecmascript = {version = "0.63.1", path = "./ecmascript"}
swc_ecmascript = {version = "0.64.0", path = "./ecmascript"}
swc_visit = {version = "0.2.3", path = "./visit"}
[dev-dependencies]

View File

@ -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.58.1"
version = "0.59.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
@ -37,7 +37,7 @@ swc_ecma_ast = {version = "0.52.0", path = "../ecmascript/ast"}
swc_ecma_codegen = {version = "0.70.2", path = "../ecmascript/codegen"}
swc_ecma_loader = {version = "0.18.1", path = "../ecmascript/loader"}
swc_ecma_parser = {version = "0.70.2", path = "../ecmascript/parser"}
swc_ecma_transforms = {version = "0.71.1", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_transforms = {version = "0.72.0", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_utils = {version = "0.44.2", path = "../ecmascript/utils"}
swc_ecma_visit = {version = "0.38.1", path = "../ecmascript/visit"}
@ -46,7 +46,7 @@ hex = "0.4"
ntest = "0.7.2"
reqwest = {version = "0.11.4", features = ["blocking"]}
sha-1 = "0.9"
swc_ecma_transforms = {version = "0.71.1", path = "../ecmascript/transforms", features = ["react", "typescript"]}
swc_ecma_transforms = {version = "0.72.0", path = "../ecmascript/transforms", features = ["react", "typescript"]}
tempfile = "3.1.0"
testing = {version = "0.13.0", path = "../testing"}
url = "2.1.1"

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.63.1"
version = "0.64.0"
[package.metadata.docs.rs]
all-features = true
@ -35,10 +35,10 @@ typescript = ["typescript-parser", "swc_ecma_transforms/typescript"]
swc_ecma_ast = {version = "0.52.0", path = "./ast"}
swc_ecma_codegen = {version = "0.70.2", path = "./codegen", optional = true}
swc_ecma_dep_graph = {version = "0.39.1", path = "./dep-graph", optional = true}
swc_ecma_minifier = {version = "0.27.2", path = "./minifier", optional = true}
swc_ecma_minifier = {version = "0.28.0", path = "./minifier", optional = true}
swc_ecma_parser = {version = "0.70.2", path = "./parser", optional = true, default-features = false}
swc_ecma_preset_env = {version = "0.42.1", path = "./preset-env", optional = true}
swc_ecma_transforms = {version = "0.71.1", path = "./transforms", optional = true}
swc_ecma_preset_env = {version = "0.43.0", path = "./preset-env", optional = true}
swc_ecma_transforms = {version = "0.72.0", path = "./transforms", optional = true}
swc_ecma_utils = {version = "0.44.2", path = "./utils", optional = true}
swc_ecma_visit = {version = "0.38.1", path = "./visit", optional = true}

View File

@ -7,11 +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.27.4"
[[bin]]
name = "cli"
path = "./src/cli/bin.rs"
version = "0.28.0"
[features]
debug = []
@ -33,7 +29,7 @@ swc_common = {version = "0.12.0", path = "../../common"}
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
swc_ecma_codegen = {version = "0.70.2", path = "../codegen"}
swc_ecma_parser = {version = "0.70.2", path = "../parser"}
swc_ecma_transforms = {version = "0.71.1", path = "../transforms/", features = ["optimization"]}
swc_ecma_transforms = {version = "0.72.0", path = "../transforms/", features = ["optimization"]}
swc_ecma_transforms_base = {version = "0.31.1", path = "../transforms/base"}
swc_ecma_utils = {version = "0.44.2", path = "../utils"}
swc_ecma_visit = {version = "0.38.1", path = "../visit"}

View File

@ -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.42.1"
version = "0.43.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -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.12.0", path = "../../common"}
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
swc_ecma_transforms = {version = "0.71.1", path = "../transforms", features = ["compat", "proposal"]}
swc_ecma_transforms = {version = "0.72.0", path = "../transforms", features = ["compat", "proposal"]}
swc_ecma_utils = {version = "0.44.2", path = "../utils"}
swc_ecma_visit = {version = "0.38.1", path = "../visit"}
walkdir = "2"

View File

@ -14,7 +14,7 @@ use swc_atoms::{js_word, JsWord};
use swc_common::{chain, comments::Comments, FromVariant, Mark, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_transforms::{
compat::{bugfixes, es2015, es2016, es2017, es2018, es2020, es2021, es3},
compat::{bugfixes, es2015, es2016, es2017, es2018, es2019, es2020, es2021, es3},
pass::{noop, Optional},
};
use swc_ecma_utils::prepend_stmts;
@ -98,9 +98,11 @@ where
let pass = add!(pass, OptionalChaining, es2020::optional_chaining());
let pass = add!(pass, ClassProperties, es2020::class_properties());
// ES2019
let pass = add!(pass, OptionalCatchBinding, es2019::optional_catch_binding());
// ES2018
let pass = add!(pass, ObjectRestSpread, es2018::object_rest_spread());
let pass = add!(pass, OptionalCatchBinding, es2018::optional_catch_binding());
// ES2017
let pass = add!(pass, AsyncToGenerator, es2017::async_to_generator());

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.71.1"
version = "0.72.0"
[package.metadata.docs.rs]
all-features = true
@ -26,12 +26,12 @@ swc_common = {version = "0.12.0", path = "../../common"}
swc_ecma_ast = {version = "0.52.0", path = "../ast"}
swc_ecma_parser = {version = "0.70.2", path = "../parser"}
swc_ecma_transforms_base = {version = "0.31.1", path = "./base"}
swc_ecma_transforms_compat = {version = "0.34.1", path = "./compat", optional = true}
swc_ecma_transforms_module = {version = "0.38.1", path = "./module", optional = true}
swc_ecma_transforms_optimization = {version = "0.41.1", path = "./optimization", optional = true}
swc_ecma_transforms_proposal = {version = "0.38.1", path = "./proposal", optional = true}
swc_ecma_transforms_react = {version = "0.39.1", path = "./react", optional = true}
swc_ecma_transforms_typescript = {version = "0.40.2", path = "./typescript", optional = true}
swc_ecma_transforms_compat = {version = "0.35.0", path = "./compat", optional = true}
swc_ecma_transforms_module = {version = "0.39.0", path = "./module", optional = true}
swc_ecma_transforms_optimization = {version = "0.42.0", path = "./optimization", optional = true}
swc_ecma_transforms_proposal = {version = "0.39.0", path = "./proposal", optional = true}
swc_ecma_transforms_react = {version = "0.40.0", path = "./react", optional = true}
swc_ecma_transforms_typescript = {version = "0.41.0", path = "./typescript", optional = true}
swc_ecma_utils = {version = "0.44.2", path = "../utils"}
swc_ecma_visit = {version = "0.38.1", path = "../visit"}
unicode-xid = "0.2"

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.34.3"
version = "0.35.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -1,12 +1,8 @@
pub use self::{
object_rest_spread::object_rest_spread, optional_catch_binding::optional_catch_binding,
};
use swc_common::chain;
pub use self::object_rest_spread::object_rest_spread;
use swc_ecma_visit::Fold;
mod object_rest_spread;
mod optional_catch_binding;
pub fn es2018() -> impl Fold {
chain!(object_rest_spread(), optional_catch_binding())
object_rest_spread()
}

View File

@ -0,0 +1,8 @@
pub use self::optional_catch_binding::optional_catch_binding;
use swc_ecma_visit::Fold;
mod optional_catch_binding;
pub fn es2019() -> impl Fold {
optional_catch_binding()
}

View File

@ -2,7 +2,7 @@
pub use self::{
bugfixes::bugfixes, es2015::es2015, es2016::es2016, es2017::es2017, es2018::es2018,
es2020::es2020, es2021::es2021, es3::es3,
es2019::es2019, es2020::es2020, es2021::es2021, es3::es3,
};
#[macro_use]
@ -12,6 +12,7 @@ pub mod es2015;
pub mod es2016;
pub mod es2017;
pub mod es2018;
pub mod es2019;
pub mod es2020;
pub mod es2021;
pub mod es3;

View File

@ -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.38.1"
version = "0.39.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@ -26,6 +26,6 @@ swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
[dev-dependencies]
swc_ecma_transforms_compat = {version = "0.34.1", path = "../compat"}
swc_ecma_transforms_compat = {version = "0.35.0", path = "../compat"}
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing/"}
testing = {version = "0.13.0", path = "../../../testing/"}

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.41.1"
version = "0.42.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@ -26,10 +26,10 @@ swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
[dev-dependencies]
swc_ecma_transforms_compat = {version = "0.34.1", path = "../compat"}
swc_ecma_transforms_module = {version = "0.38.1", path = "../module"}
swc_ecma_transforms_proposal = {version = "0.38.1", path = "../proposal"}
swc_ecma_transforms_react = {version = "0.39.1", path = "../react"}
swc_ecma_transforms_compat = {version = "0.35.0", path = "../compat"}
swc_ecma_transforms_module = {version = "0.39.0", path = "../module"}
swc_ecma_transforms_proposal = {version = "0.39.0", path = "../proposal"}
swc_ecma_transforms_react = {version = "0.40.0", path = "../react"}
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing"}
swc_ecma_transforms_typescript = {version = "0.40.2", path = "../typescript"}
swc_ecma_transforms_typescript = {version = "0.41.0", path = "../typescript"}
testing = {version = "0.13.0", path = "../../../testing"}

View File

@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_transforms_proposal"
repository = "https://github.com/swc-project/swc.git"
version = "0.38.1"
version = "0.39.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -30,6 +30,6 @@ swc_ecma_utils = {version = "0.44.2", path = "../../utils"}
swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
[dev-dependencies]
swc_ecma_transforms_compat = {version = "0.34.1", path = "../compat"}
swc_ecma_transforms_module = {version = "0.38.1", path = "../module"}
swc_ecma_transforms_compat = {version = "0.35.0", path = "../compat"}
swc_ecma_transforms_module = {version = "0.39.0", path = "../module"}
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing"}

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.39.1"
version = "0.40.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@ -29,7 +29,7 @@ swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
[dev-dependencies]
swc_ecma_codegen = {version = "0.70.2", path = "../../codegen/"}
swc_ecma_transforms_compat = {version = "0.34.1", path = "../compat/"}
swc_ecma_transforms_module = {version = "0.38.1", path = "../module"}
swc_ecma_transforms_compat = {version = "0.35.0", path = "../compat/"}
swc_ecma_transforms_module = {version = "0.39.0", path = "../module"}
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing/"}
testing = {version = "0.13.0", path = "../../../testing"}

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.40.4"
version = "0.41.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@ -22,9 +22,9 @@ swc_ecma_visit = {version = "0.38.1", path = "../../visit"}
[dev-dependencies]
swc_ecma_codegen = {version = "0.70.2", path = "../../codegen"}
swc_ecma_transforms_compat = {version = "0.34.1", path = "../compat"}
swc_ecma_transforms_module = {version = "0.38.1", path = "../module"}
swc_ecma_transforms_proposal = {version = "0.38.1", path = "../proposal/"}
swc_ecma_transforms_compat = {version = "0.35.0", path = "../compat"}
swc_ecma_transforms_module = {version = "0.39.0", path = "../module"}
swc_ecma_transforms_proposal = {version = "0.39.0", path = "../proposal/"}
swc_ecma_transforms_testing = {version = "0.32.1", path = "../testing"}
testing = {version = "0.13.0", path = "../../../testing"}
walkdir = "2.3.1"

View File

@ -125,9 +125,9 @@ fn es2018_object_rest_spread(b: &mut Bencher) {
}
#[bench]
fn es2018_optional_catch_binding(b: &mut Bencher) {
fn es2019_optional_catch_binding(b: &mut Bencher) {
run(b, || {
swc_ecma_transforms_compat::es2018::optional_catch_binding()
swc_ecma_transforms_compat::es2019::optional_catch_binding()
});
}

View File

@ -169,6 +169,7 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> {
} else {
Either::Right(chain!(
import_assertions(),
Optional::new(typescript::strip(), syntax.typescript()),
Optional::new(
compat::es2021::es2021(),
should_enable(self.target, JscTarget::Es2021)
@ -177,7 +178,10 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> {
compat::es2020::es2020(),
should_enable(self.target, JscTarget::Es2020)
),
Optional::new(typescript::strip(), syntax.typescript()),
Optional::new(
compat::es2019::es2019(),
should_enable(self.target, JscTarget::Es2019)
),
Optional::new(
compat::es2018(),
should_enable(self.target, JscTarget::Es2018)