From e19a60aad44318d9752f790c913bf010423e7f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 15 Mar 2022 23:17:03 +0900 Subject: [PATCH] fix(es/compat): Change pass ordering of `es2015` (#4029) **Description:** We should apply `regenerator` after `block_scoping` because `regenerator` does not know how to handle `const`s. **Related issue:** - Closes https://github.com/swc-project/swc/issues/3006 --- .github/workflows/cargo.yml | 8 ++++--- .github/workflows/crev.yml | 7 +++++- clippy.toml | 1 + .../vercel/full/next-31419/1/output/index.js | 24 ++++++++----------- crates/swc_common/src/syntax_pos/hygiene.rs | 6 ++--- crates/swc_ecma_parser/tests/test262.rs | 1 + .../tests/fixer_test262.rs | 1 + .../src/es2015/mod.rs | 2 +- .../async-to-generator/issue-3006/exec.js | 6 +++++ .../tests/es2017_async_to_generator.rs | 3 ++- .../tests/for-of/issue-3006/1/exec.js | 3 +++ crates/swc_estree_compat/tests/convert.rs | 1 + rust-toolchain | 2 +- 13 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/async-to-generator/issue-3006/exec.js create mode 100644 crates/swc_ecma_transforms_compat/tests/for-of/issue-3006/1/exec.js diff --git a/.github/workflows/cargo.yml b/.github/workflows/cargo.yml index 53828ee2bfab..98e23cbfd717 100644 --- a/.github/workflows/cargo.yml +++ b/.github/workflows/cargo.yml @@ -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: | diff --git a/.github/workflows/crev.yml b/.github/workflows/crev.yml index d225c5e522f2..a94863777db8 100644 --- a/.github/workflows/crev.yml +++ b/.github/workflows/crev.yml @@ -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' diff --git a/clippy.toml b/clippy.toml index a721df909d0b..907c5ca04498 100644 --- a/clippy.toml +++ b/clippy.toml @@ -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 diff --git a/crates/swc/tests/vercel/full/next-31419/1/output/index.js b/crates/swc/tests/vercel/full/next-31419/1/output/index.js index 28474ef9fb03..4e83baf8c524 100644 --- a/crates/swc/tests/vercel/full/next-31419/1/output/index.js +++ b/crates/swc/tests/vercel/full/next-31419/1/output/index.js @@ -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(); } diff --git a/crates/swc_common/src/syntax_pos/hygiene.rs b/crates/swc_common/src/syntax_pos/hygiene.rs index 66e40db910b0..a4a42f81b291 100644 --- a/crates/swc_common/src/syntax_pos/hygiene.rs +++ b/crates/swc_common/src/syntax_pos/hygiene.rs @@ -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 diff --git a/crates/swc_ecma_parser/tests/test262.rs b/crates/swc_ecma_parser/tests/test262.rs index 00b4bd3ca8cb..e98bde5d55e1 100644 --- a/crates/swc_ecma_parser/tests/test262.rs +++ b/crates/swc_ecma_parser/tests/test262.rs @@ -95,6 +95,7 @@ fn add_test( should_panic: No, compile_fail: false, no_run: false, + ignore_message: Default::default(), }, testfn: DynTestFn(Box::new(f)), }); diff --git a/crates/swc_ecma_transforms_base/tests/fixer_test262.rs b/crates/swc_ecma_transforms_base/tests/fixer_test262.rs index ac99aae7d0c2..1f8ecb7f9cf2 100644 --- a/crates/swc_ecma_transforms_base/tests/fixer_test262.rs +++ b/crates/swc_ecma_transforms_base/tests/fixer_test262.rs @@ -106,6 +106,7 @@ fn add_test( should_panic: No, compile_fail: false, no_run: false, + ignore_message: Default::default(), }, testfn: DynTestFn(Box::new(f)), }); diff --git a/crates/swc_ecma_transforms_compat/src/es2015/mod.rs b/crates/swc_ecma_transforms_compat/src/es2015/mod.rs index 48ee94ebca0b..2923e12f0dbd 100644 --- a/crates/swc_ecma_transforms_compat/src/es2015/mod.rs +++ b/crates/swc_ecma_transforms_compat/src/es2015/mod.rs @@ -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), ) } diff --git a/crates/swc_ecma_transforms_compat/tests/async-to-generator/issue-3006/exec.js b/crates/swc_ecma_transforms_compat/tests/async-to-generator/issue-3006/exec.js new file mode 100644 index 000000000000..9fe1184e7e6d --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/async-to-generator/issue-3006/exec.js @@ -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() \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs index 5307c4558a76..977002a8e073 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs @@ -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, }; @@ -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) ) }, diff --git a/crates/swc_ecma_transforms_compat/tests/for-of/issue-3006/1/exec.js b/crates/swc_ecma_transforms_compat/tests/for-of/issue-3006/1/exec.js new file mode 100644 index 000000000000..8beadc7899a6 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/for-of/issue-3006/1/exec.js @@ -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) +} diff --git a/crates/swc_estree_compat/tests/convert.rs b/crates/swc_estree_compat/tests/convert.rs index 6259090e1dae..6acdbcd65c44 100644 --- a/crates/swc_estree_compat/tests/convert.rs +++ b/crates/swc_estree_compat/tests/convert.rs @@ -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 { diff --git a/rust-toolchain b/rust-toolchain index 4e7e21b01962..74e26fbed37d 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-02-23 \ No newline at end of file +nightly-2022-03-12 \ No newline at end of file