Skip to content

Commit

Permalink
fix(es/compat): Change pass ordering of es2015 (#4029)
Browse files Browse the repository at this point in the history
**Description:**

We should apply `regenerator` after `block_scoping` because `regenerator` does not know how to handle `const`s.

**Related issue:**

 - Closes #3006
  • Loading branch information
kdy1 authored Mar 15, 2022
1 parent 5e89d18 commit e19a60a
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 24 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ jobs:
with:
profile: minimal

- name: Install required tools
run: |
cargo install cargo-deny
- name: Install cargo-deny
uses: baptiste0928/cargo-install@v1.1.0
with:
crate: cargo-deny
version: "0.11.3"

- name: Check licenses
run: |
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/crev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ jobs:
rm -rf tests
ls -al
- name: Install cargo-crev
uses: baptiste0928/cargo-install@v1.1.0
with:
crate: cargo-crev
version: "0.23.1"

- name: Configure cargo-crev
run: |
cargo install cargo-crev
git config --global user.name 'SWC bot'
git config --global user.email 'bot@swc.rs'
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
blacklisted-names = ["bool", "char", "str", "f32", "f64", "i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64", "isize", "usize"]
cognitive-complexity-threshold = 50
msrv = "1.58"
type-complexity-threshold = 25000
24 changes: 10 additions & 14 deletions crates/swc/tests/vercel/full/next-31419/1/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ import * as a from "@swc/helpers";
import b from "regenerator-runtime";
Promise.all(assignAll).then(function() {
var c = a.asyncToGenerator(b.mark(function a(c) {
var d, e, f, g;
var d, e, f;
return b.wrap(function(a) {
for(;;)switch(a.prev = a.next){
case 0:
d = "DELETE FROM \"TABLE\" WHERE \"UUID\" IN ( ", a.t0 = regeneratorRuntime.keys(obj);
case 2:
if ((a.t1 = a.t0()).done) {
a.next = 12;
break;
}
return f = obj[e = a.t1.value], d += "'".concat(f.id, "', "), a.next = 8, listOfUser(f.id);
case 8:
(g = a.sent).forEach(function(a) {
insertQuery += "INSERT INTO \"TABLE\"(\"UUID\", id, other_ids_here) VALUES ('".concat(uuidv4(), "', '").concat(f.id, "', now());");
}), a.next = 2;
break;
case 12:
for(f in d = function(f) {
var a = obj[f];
e += "'".concat(a.id, "', ");
var c = yield listOfUser(a.id);
c.forEach(function(b) {
insertQuery += "INSERT INTO \"TABLE\"(\"UUID\", id, other_ids_here) VALUES ('".concat(uuidv4(), "', '").concat(a.id, "', now());");
});
}, e = "DELETE FROM \"TABLE\" WHERE \"UUID\" IN ( ", obj)d(f);
case 3:
case "end":
return a.stop();
}
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_common/src/syntax_pos/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ struct MarkData {
)]
pub struct MutableMarkContext(pub u32, pub u32, pub u32);

/// List of proxy calls injected by the host in the plugin's runtime context.
/// When related calls being executed inside of the plugin, it'll call these
/// proxies instead which'll call actual host fn.
// List of proxy calls injected by the host in the plugin's runtime context.
// When related calls being executed inside of the plugin, it'll call these
// proxies instead which'll call actual host fn.
extern "C" {
// Instead of trying to copy-serialize `Mark`, this fn directly consume
// inner raw value as well as fn and let each context constrcuts struct
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_parser/tests/test262.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn add_test<F: FnOnce() + Send + 'static>(
should_panic: No,
compile_fail: false,
no_run: false,
ignore_message: Default::default(),
},
testfn: DynTestFn(Box::new(f)),
});
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_transforms_base/tests/fixer_test262.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ fn add_test<F: FnOnce() + Send + 'static>(
should_panic: No,
compile_fail: false,
no_run: false,
ignore_message: Default::default(),
},
testfn: DynTestFn(Box::new(f)),
});
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_transforms_compat/src/es2015/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ where
parameters(c.parameters),
computed_properties(c.computed_props),
destructuring(c.destructuring),
regenerator(c.regenerator, global_mark),
block_scoping(),
regenerator(c.regenerator, global_mark),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
async function a() {
for (const number_in_a_sequence of Array.from(new Array(7), (_, i) => i)) {
setTimeout(() => console.log(number_in_a_sequence), 10)
}
}
a()
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use swc_ecma_parser::Syntax;
use swc_ecma_transforms_base::{fixer::fixer, resolver::resolver};
use swc_ecma_transforms_compat::{
es2015,
es2015::{arrow, destructuring, function_name, parameters},
es2015::{arrow, block_scoping, destructuring, function_name, parameters},
es2017::async_to_generator,
es2022::class_properties,
};
Expand Down Expand Up @@ -3586,6 +3586,7 @@ fn exec_regenerator(input: PathBuf) {
class_properties(Some(t.comments.clone()), Default::default()),
async_to_generator(Default::default()),
es2015::for_of(Default::default()),
block_scoping(),
regenerator(Default::default(), top_level_mark)
)
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (const number_in_a_sequence of Array.from(new Array(7), (_, i) => i)) {
setTimeout(() => console.log(number_in_a_sequence), 10)
}
1 change: 1 addition & 0 deletions crates/swc_estree_compat/tests/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fn fixtures() -> Result<(), Error> {
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
ignore_message: Default::default(),
},
testfn: DynTestFn(Box::alloc().init(move || {
let syntax = if is_typescript {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2022-02-23
nightly-2022-03-12

2 comments on commit e19a60a

@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: e19a60a Previous: 0c76696 Ratio
base_tr_fixer 27052 ns/iter (± 447) 22210 ns/iter (± 751) 1.22
base_tr_resolver_and_hygiene 109512 ns/iter (± 20977) 91901 ns/iter (± 9013) 1.19
codegen_es2015 35737 ns/iter (± 197) 27767 ns/iter (± 199) 1.29
codegen_es2016 35581 ns/iter (± 208) 27713 ns/iter (± 243) 1.28
codegen_es2017 35735 ns/iter (± 200) 27739 ns/iter (± 177) 1.29
codegen_es2018 35746 ns/iter (± 194) 27641 ns/iter (± 176) 1.29
codegen_es2019 36988 ns/iter (± 1698) 27643 ns/iter (± 154) 1.34
codegen_es2020 35935 ns/iter (± 740) 27659 ns/iter (± 227) 1.30
codegen_es3 35856 ns/iter (± 728) 27393 ns/iter (± 241) 1.31
codegen_es5 35766 ns/iter (± 533) 27462 ns/iter (± 310) 1.30
full_es2015 157494905 ns/iter (± 9495374) 136313683 ns/iter (± 14557834) 1.16
full_es2016 159340989 ns/iter (± 13717754) 135077479 ns/iter (± 5884726) 1.18
full_es2017 158594116 ns/iter (± 9152330) 136134649 ns/iter (± 6824306) 1.16
full_es2018 156516865 ns/iter (± 5724229) 129790430 ns/iter (± 7739716) 1.21
full_es2019 155505484 ns/iter (± 7604364) 126033588 ns/iter (± 6144735) 1.23
full_es2020 148719957 ns/iter (± 12445748) 116215039 ns/iter (± 3101287) 1.28
full_es3 213887906 ns/iter (± 8960061) 180050115 ns/iter (± 4644360) 1.19
full_es5 201278553 ns/iter (± 8295478) 170149473 ns/iter (± 5103280) 1.18
parser 663622 ns/iter (± 19719) 540854 ns/iter (± 17435) 1.23
ser_ast_node 177 ns/iter (± 2) 151 ns/iter (± 2) 1.17
ser_serde 176 ns/iter (± 1) 145 ns/iter (± 1) 1.21
emit_colors 13407410 ns/iter (± 9475344) 4969549 ns/iter (± 3487441) 2.70
emit_large 120860895 ns/iter (± 180720308) 121924818 ns/iter (± 183229827) 0.99
base_clone 3518846 ns/iter (± 592081) 2507259 ns/iter (± 23714) 1.40
fold_span 5399863 ns/iter (± 575284) 4080971 ns/iter (± 81634) 1.32
fold_span_panic 5542598 ns/iter (± 395353) 3935121 ns/iter (± 54964) 1.41
visit_mut_span 3737451 ns/iter (± 445610) 2687845 ns/iter (± 13352) 1.39
visit_mut_span_panic 4048501 ns/iter (± 627388) 2740659 ns/iter (± 35531) 1.48
usage_builtin_type 19076263 ns/iter (± 11953119) 14733129 ns/iter (± 9183134) 1.29
usage_property 456536 ns/iter (± 7948) 352364 ns/iter (± 1057) 1.30
boxing_boxed 160 ns/iter (± 0) 135 ns/iter (± 15) 1.19
boxing_boxed_clone 84 ns/iter (± 0) 77 ns/iter (± 0) 1.09
boxing_unboxed 145 ns/iter (± 1) 116 ns/iter (± 1) 1.25
boxing_unboxed_clone 76 ns/iter (± 0) 72 ns/iter (± 0) 1.06
time_10 367 ns/iter (± 4) 294 ns/iter (± 2) 1.25
time_15 882 ns/iter (± 60) 634 ns/iter (± 2) 1.39
time_20 1418 ns/iter (± 18) 1239 ns/iter (± 3) 1.14
time_40 4909 ns/iter (± 50) 7015 ns/iter (± 17) 0.70
time_5 120 ns/iter (± 2) 94 ns/iter (± 0) 1.28
time_60 10338 ns/iter (± 75) 15915 ns/iter (± 50) 0.65
es2015 10940108 ns/iter (± 69489)
total 0 ns/iter (± 0) 0 ns/iter (± 0) NaN

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

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: e19a60a Previous: 0c76696 Ratio
emit_colors 13407410 ns/iter (± 9475344) 4969549 ns/iter (± 3487441) 2.70

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

CC: @kdy1

Please sign in to comment.