Skip to content

Commit

Permalink
feat(es/preset-env): Add ES2022 features to preset-env (#3072)
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki authored Dec 19, 2021
1 parent 46994e0 commit 7beaabd
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 83 deletions.
12 changes: 12 additions & 0 deletions crates/swc_ecma_preset_env/scripts/transform-data-gen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require("fs");
const path = require("path");
const data = require("@babel/compat-data/plugins");

const transform_data_json = path.join(
__dirname,
"..",
"src",
"transform_data.json"
);

fs.writeFileSync(transform_data_json, JSON.stringify(data, null, 4) + "\n");
4 changes: 3 additions & 1 deletion crates/swc_ecma_preset_env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ where

// Proposals

// ES2021
// ES2022
let pass = add!(
pass,
ClassProperties,
es2022::class_properties(es2022::class_properties::Config { loose })
);
let pass = add!(pass, ClassStaticBlock, es2022::static_blocks());
let pass = add!(pass, PrivatePropertyInObject, es2022::private_in_object());

// ES2021
let pass = add!(
Expand Down
32 changes: 28 additions & 4 deletions crates/swc_ecma_preset_env/src/transform_data.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
{
"proposal-class-static-block": {
"chrome": "94",
"opera": "80",
"edge": "94",
"firefox": "93",
"node": "16.11"
},
"proposal-private-property-in-object": {
"chrome": "91",
"opera": "77",
"edge": "91",
"firefox": "90",
"safari": "15",
"node": "16.9",
"ios": "15",
"electron": "13.0"
},
"proposal-class-properties": {
"chrome": "74",
"opera": "62",
"edge": "79",
"firefox": "90",
"safari": "14.1",
"node": "12",
"ios": "15",
"samsung": "11",
"electron": "6.0"
},
Expand All @@ -16,6 +34,8 @@
"firefox": "90",
"safari": "15",
"node": "14.6",
"ios": "15",
"samsung": "14",
"electron": "10.0"
},
"proposal-numeric-separator": {
Expand All @@ -37,6 +57,7 @@
"safari": "14",
"node": "15",
"ios": "14",
"samsung": "14",
"electron": "10.0"
},
"proposal-nullish-coalescing-operator": {
Expand All @@ -51,9 +72,14 @@
"electron": "8.0"
},
"proposal-optional-chaining": {
"chrome": "91",
"opera": "77",
"edge": "91",
"firefox": "74",
"safari": "13.1",
"ios": "13.4"
"node": "16.9",
"ios": "13.4",
"electron": "13.0"
},
"proposal-json-strings": {
"chrome": "66",
Expand Down Expand Up @@ -82,9 +108,7 @@
"opera": "36",
"edge": "18",
"firefox": "53",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
},
Expand Down Expand Up @@ -370,7 +394,7 @@
"chrome": "46",
"opera": "33",
"edge": "14",
"firefox": "45",
"firefox": "41",
"safari": "10",
"node": "5",
"ios": "10",
Expand Down
6 changes: 6 additions & 0 deletions crates/swc_ecma_preset_env/src/transform_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ pub enum Feature {
/// `proposal-private-methods`
PrivateMethods,

/// `proposal-class-static-block`
ClassStaticBlock,

/// `proposal-private-property-in-object`
PrivatePropertyInObject,

/// `transform-unicode-escapes`
UnicodeEscapes,

Expand Down
156 changes: 78 additions & 78 deletions crates/swc_ecma_preset_env/src/transform_data_bugfixes.json
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
{
"transform-async-to-generator": {
"chrome": "55",
"opera": "42",
"edge": "15",
"firefox": "52",
"safari": "10.1",
"node": "7.6",
"ios": "10.3",
"samsung": "6",
"electron": "1.6"
},
"bugfix/transform-async-arrows-in-class": {
"chrome": "55",
"opera": "42",
"edge": "15",
"firefox": "52",
"safari": "11",
"node": "7.6",
"ios": "11",
"samsung": "6",
"electron": "1.6"
},
"transform-parameters": {
"chrome": "49",
"opera": "36",
"edge": "15",
"firefox": "53",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
},
"bugfix/transform-edge-default-parameters": {
"chrome": "49",
"opera": "36",
"edge": "18",
"firefox": "52",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
},
"transform-block-scoping": {
"chrome": "49",
"opera": "36",
"edge": "14",
"firefox": "51",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
},
"transform-template-literals": {
"chrome": "41",
"opera": "28",
"edge": "13",
"firefox": "34",
"safari": "9",
"node": "4",
"ios": "9",
"samsung": "3.4",
"electron": "0.21"
},
"bugfix/transform-tagged-template-caching": {
"chrome": "41",
"opera": "28",
"edge": "12",
"firefox": "34",
"safari": "13",
"node": "4",
"ios": "13",
"samsung": "3.4",
"electron": "0.21"
}
}
"transform-async-to-generator": {
"chrome": "55",
"opera": "42",
"edge": "15",
"firefox": "52",
"safari": "10.1",
"node": "7.6",
"ios": "10.3",
"samsung": "6",
"electron": "1.6"
},
"bugfix/transform-async-arrows-in-class": {
"chrome": "55",
"opera": "42",
"edge": "15",
"firefox": "52",
"safari": "11",
"node": "7.6",
"ios": "11",
"samsung": "6",
"electron": "1.6"
},
"transform-parameters": {
"chrome": "49",
"opera": "36",
"edge": "15",
"firefox": "53",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
},
"bugfix/transform-edge-default-parameters": {
"chrome": "49",
"opera": "36",
"edge": "18",
"firefox": "52",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
},
"transform-block-scoping": {
"chrome": "49",
"opera": "36",
"edge": "14",
"firefox": "51",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
},
"transform-template-literals": {
"chrome": "41",
"opera": "28",
"edge": "13",
"firefox": "34",
"safari": "9",
"node": "4",
"ios": "9",
"samsung": "3.4",
"electron": "0.21"
},
"bugfix/transform-tagged-template-caching": {
"chrome": "41",
"opera": "28",
"edge": "12",
"firefox": "34",
"safari": "13",
"node": "4",
"ios": "13",
"samsung": "3.4",
"electron": "0.21"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"version": "napi version -p scripts/npm"
},
"devDependencies": {
"@babel/compat-data": "^7.16.4",
"@babel/core": "^7.13.16",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-decorators": "^7.13.15",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.14.9.tgz#ac7996ceaafcf8f410119c8af0d1db4cf914a210"
integrity sha512-p3QjZmMGHDGdpcwEYYWu7i7oJShJvtgMjJeb0W95PPhSm++3lm8YXYOh45Y6iCN9PkZLTZ7CIX5nFrp7pw7TXw==

"@babel/compat-data@^7.16.4":
version "7.16.4"
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.16.4.tgz#081d6bbc336ec5c2435c6346b2ae1fb98b5ac68e"
integrity sha512-1o/jo7D+kC9ZjHX5v+EHrdjl3PhxMrLSOTGsOdHJ+KL8HCaEK6ehrVL2RS6oHDZp+L7xLirLrPmQtEng769J/Q==

"@babel/core@^7.1.0", "@babel/core@^7.13.16", "@babel/core@^7.7.2", "@babel/core@^7.7.5":
version "7.14.8"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.14.8.tgz#20cdf7c84b5d86d83fac8710a8bc605a7ba3f010"
Expand Down

1 comment on commit 7beaabd

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 7beaabd Previous: 46994e0 Ratio
full_es2015 226546007 ns/iter (± 9684189) 187536972 ns/iter (± 24964500) 1.21
full_es2016 186975514 ns/iter (± 5197239) 129433059 ns/iter (± 21689541) 1.44
full_es2017 192614918 ns/iter (± 11680164) 157279917 ns/iter (± 29123659) 1.22
full_es2018 191842268 ns/iter (± 11863546) 157384992 ns/iter (± 27772420) 1.22
full_es2019 191084025 ns/iter (± 12221751) 130492578 ns/iter (± 9311101) 1.46
full_es2020 189798797 ns/iter (± 11303498) 129468050 ns/iter (± 7431969) 1.47
full_es3 262605993 ns/iter (± 10796475) 189342190 ns/iter (± 28932563) 1.39
full_es5 239215762 ns/iter (± 12761165) 174356016 ns/iter (± 8796922) 1.37
parser 831546 ns/iter (± 18625) 592287 ns/iter (± 35225) 1.40

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.