diff --git a/ecmascript/transforms/Cargo.toml b/ecmascript/transforms/Cargo.toml index fdf2ed64d63..31a6f794075 100644 --- a/ecmascript/transforms/Cargo.toml +++ b/ecmascript/transforms/Cargo.toml @@ -21,6 +21,7 @@ serde = { version = "1", features = ["derive"] } indexmap = "1" ordered-float = "1.0.1" Inflector = { version = "0.11.4", default-features = false } +scoped-tls = { version = "0.1", features = ["nightly"] } [dev-dependencies] testing = { path ="../../testing" } diff --git a/ecmascript/transforms/benches/bench.rs b/ecmascript/transforms/benches/bench.rs index b08501462e9..346cad37084 100644 --- a/ecmascript/transforms/benches/bench.rs +++ b/ecmascript/transforms/benches/bench.rs @@ -12,7 +12,6 @@ extern crate swc_ecma_transforms; extern crate test; extern crate testing; -use std::sync::Arc; use swc_common::{FileName, FoldWith}; use swc_ecma_parser::{Parser, Session, SourceFileInput, Syntax}; use swc_ecma_transforms::{compat, helpers}; @@ -109,81 +108,82 @@ macro_rules! tr { () }) .unwrap(); - let helpers = Arc::new(helpers::Helpers::default()); - let mut tr = $tr(helpers); + helpers::HELPERS.set(&Default::default(), || { + let mut tr = $tr(); - $b.iter(|| { - let module = module.clone(); - test::black_box(module.fold_with(&mut tr)) - }); - Ok(()) + $b.iter(|| { + let module = module.clone(); + test::black_box(module.fold_with(&mut tr)) + }); + Ok(()) + }) }); }; } #[bench] fn all(b: &mut Bencher) { - tr!(b, |helpers| chain!( - compat::es2017(&helpers), + tr!(b, || chain!( + compat::es2017(), compat::es2016(), - compat::es2015(&helpers), + compat::es2015(), compat::es3(), )); } #[bench] fn es2018(b: &mut Bencher) { - tr!(b, |helpers| compat::es2018(&helpers)); + tr!(b, || compat::es2018()); } #[bench] fn es2018_object_rest_spread(b: &mut Bencher) { - tr!(b, |helpers| compat::es2018::object_rest_spread(helpers)); + tr!(b, || compat::es2018::object_rest_spread()); } #[bench] fn es2017(b: &mut Bencher) { - tr!(b, |helpers| compat::es2017(&helpers)); + tr!(b, || compat::es2017()); } #[bench] fn es2017_async_to_generator(b: &mut Bencher) { - tr!(b, |helpers| compat::es2017::async_to_generator(helpers)); + tr!(b, || compat::es2017::async_to_generator()); } #[bench] fn es2016(b: &mut Bencher) { - tr!(b, |_| compat::es2016()); + tr!(b, || compat::es2016()); } #[bench] fn es2016_exponentation(b: &mut Bencher) { - tr!(b, |_| compat::es2016::exponentation()); + tr!(b, || compat::es2016::exponentation()); } #[bench] fn es2015(b: &mut Bencher) { - tr!(b, |helpers| compat::es2015(&helpers)); + tr!(b, || compat::es2015()); } #[bench] fn es2015_arrow(b: &mut Bencher) { - tr!(b, |_| compat::es2015::arrow()); + tr!(b, || compat::es2015::arrow()); } #[bench] fn es2015_block_scoped_fn(b: &mut Bencher) { - tr!(b, |_| compat::es2015::BlockScopedFns); + tr!(b, || compat::es2015::BlockScopedFns); } #[bench] fn es2015_block_scoping(b: &mut Bencher) { - tr!(b, |_| compat::es2015::block_scoping()); + tr!(b, || compat::es2015::block_scoping()); } #[bench] fn es2015_classes(b: &mut Bencher) { - tr!(b, |helpers| compat::es2015::Classes { helpers }); + tr!(b, || compat::es2015::Classes); } #[bench] @@ -198,50 +198,50 @@ fn es2015_destructuring(b: &mut Bencher) { #[bench] fn es2015_duplicate_keys(b: &mut Bencher) { - tr!(b, |_| compat::es2015::duplicate_keys()); + tr!(b, || compat::es2015::duplicate_keys()); } #[bench] fn es2015_parameters(b: &mut Bencher) { - tr!(b, |_| compat::es2015::parameters()); + tr!(b, || compat::es2015::parameters()); } #[bench] fn es2015_fn_name(b: &mut Bencher) { - tr!(b, |_| compat::es2015::function_name()); + tr!(b, || compat::es2015::function_name()); } #[bench] fn es2015_for_of(b: &mut Bencher) { - tr!(b, |_| compat::es2015::for_of()); + tr!(b, || compat::es2015::for_of()); } #[bench] fn es2015_instanceof(b: &mut Bencher) { - tr!(b, |helpers| compat::es2015::InstanceOf { helpers }); + tr!(b, || compat::es2015::InstanceOf); } #[bench] fn es2015_shorthand_property(b: &mut Bencher) { - tr!(b, |_| compat::es2015::Shorthand); + tr!(b, || compat::es2015::Shorthand); } #[bench] fn es2015_spread(b: &mut Bencher) { - tr!(b, |helpers| compat::es2015::Spread { helpers }); + tr!(b, || compat::es2015::Spread); } #[bench] fn es2015_sticky_regex(b: &mut Bencher) { - tr!(b, |_| compat::es2015::StickyRegex); + tr!(b, || compat::es2015::StickyRegex); } #[bench] fn es2015_typeof_symbol(b: &mut Bencher) { - tr!(b, |helpers| compat::es2015::TypeOfSymbol { helpers }); + tr!(b, || compat::es2015::TypeOfSymbol); } #[bench] fn es3(b: &mut Bencher) { - tr!(b, |_| compat::es3()); + tr!(b, || compat::es3()); } diff --git a/ecmascript/transforms/src/compat/es2015/arrow/tests.rs b/ecmascript/transforms/src/compat/es2015/arrow/tests.rs index 8491a07d639..347bc1eea8a 100644 --- a/ecmascript/transforms/src/compat/es2015/arrow/tests.rs +++ b/ecmascript/transforms/src/compat/es2015/arrow/tests.rs @@ -2,7 +2,7 @@ use super::*; test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Arrow, + |_| Arrow, destructuring, r#"let foo = ({bar}) => undefined;"#, r#"let foo = function ({bar}) { @@ -12,7 +12,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Arrow, + |_| Arrow, basic, r#"let echo = (bar) => bar"#, r#"let echo = function(bar) { @@ -22,7 +22,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Arrow, + |_| Arrow, empty_arguments, r#"var t = () => 5 + 5;"#, r#"var t = function () { @@ -32,7 +32,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Arrow, + |_| Arrow, expression, r#"arr.map(x => x * x);"#, r#"arr.map(function (x) { @@ -42,7 +42,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Arrow, + |_| Arrow, inside_call, r#"arr.map(i => i + 1);"#, r#"arr.map(function (i) { @@ -52,7 +52,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Arrow, + |_| Arrow, multiple_arguments, r#"var t = (i, x) => i * x;"#, r#"var t = function (i, x) { @@ -61,7 +61,7 @@ test!( ); // test!(::swc_ecma_parser::Syntax::default(), -// |_, _| Arrow, +// |_| Arrow, // nested, // r#"module.exports = { // init: function () { @@ -96,7 +96,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Arrow, + |_| Arrow, paren_insertion, r#"var t = i => i * 5;"#, r#"var t = function (i) { @@ -106,7 +106,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Arrow, + |_| Arrow, single_argument, r#"var t = (i) => i * 5;"#, r#"var t = function (i) { @@ -116,7 +116,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Arrow, + |_| Arrow, statement, r#"nums.forEach(v => { if (v % 5 === 0) { diff --git a/ecmascript/transforms/src/compat/es2015/block_scoped_fn.rs b/ecmascript/transforms/src/compat/es2015/block_scoped_fn.rs index 4c228da02c7..3c21856d2e0 100644 --- a/ecmascript/transforms/src/compat/es2015/block_scoped_fn.rs +++ b/ecmascript/transforms/src/compat/es2015/block_scoped_fn.rs @@ -34,7 +34,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| BlockScopedFns, + |_| BlockScopedFns, basic, r#"{ function name (n) { diff --git a/ecmascript/transforms/src/compat/es2015/classes/constructor.rs b/ecmascript/transforms/src/compat/es2015/classes/constructor.rs index f32e73424b1..743f25b82de 100644 --- a/ecmascript/transforms/src/compat/es2015/classes/constructor.rs +++ b/ecmascript/transforms/src/compat/es2015/classes/constructor.rs @@ -1,5 +1,5 @@ use super::get_prototype_of; -use crate::{helpers::Helpers, util::ExprFactory}; +use crate::util::ExprFactory; use ast::*; use std::iter; use swc_atoms::JsWord; @@ -129,7 +129,6 @@ pub(super) fn constructor_fn(c: Constructor) -> Function { /// _this = ...; /// ``` pub(super) struct ConstructorFolder<'a> { - pub helpers: &'a Helpers, pub class_name: &'a Ident, pub mode: Option, /// Mark for `_this` @@ -158,14 +157,11 @@ impl<'a> Fold for ConstructorFolder<'a> { args, .. })) => { - let expr = make_possible_return_value( - self.helpers, - ReturningMode::Prototype { - is_constructor_default: self.is_constructor_default, - class_name: self.class_name.clone(), - args: Some(args), - }, - ); + let expr = make_possible_return_value(ReturningMode::Prototype { + is_constructor_default: self.is_constructor_default, + class_name: self.class_name.clone(), + args: Some(args), + }); match self.mode { Some(SuperFoldingMode::Assign) => Stmt::Expr(box Expr::Assign(AssignExpr { @@ -207,13 +203,10 @@ impl<'a> Fold for ConstructorFolder<'a> { let arg = stmt.arg.fold_with(self); - let arg = Some(box make_possible_return_value( - self.helpers, - ReturningMode::Returning { - mark: self.mark, - arg, - }, - )); + let arg = Some(box make_possible_return_value(ReturningMode::Returning { + mark: self.mark, + arg, + })); ReturnStmt { arg, ..stmt } } @@ -256,14 +249,11 @@ impl<'a> Fold for ConstructorFolder<'a> { args, .. }) => { - let right = box make_possible_return_value( - self.helpers, - ReturningMode::Prototype { - class_name: self.class_name.clone(), - args: Some(args), - is_constructor_default: self.is_constructor_default, - }, - ); + let right = box make_possible_return_value(ReturningMode::Prototype { + class_name: self.class_name.clone(), + args: Some(args), + is_constructor_default: self.is_constructor_default, + }); Expr::Assign(AssignExpr { span: DUMMY_SP, @@ -300,8 +290,8 @@ pub(super) enum ReturningMode { }, } -pub(super) fn make_possible_return_value(helpers: &Helpers, mode: ReturningMode) -> Expr { - helpers.possible_constructor_return(); +pub(super) fn make_possible_return_value(mode: ReturningMode) -> Expr { + helper!(possible_constructor_return); let callee = quote_ident!("_possibleConstructorReturn").as_callee(); Expr::Call(CallExpr { @@ -365,7 +355,7 @@ pub(super) fn make_possible_return_value(helpers: &Helpers, mode: ReturningMode) vec![ThisExpr { span: DUMMY_SP }.as_arg(), { let apply = box Expr::Call(CallExpr { span: DUMMY_SP, - callee: get_prototype_of(helpers, &Expr::Ident(class_name)) + callee: get_prototype_of(&Expr::Ident(class_name)) .member(fn_name) .as_callee(), @@ -404,10 +394,9 @@ pub(super) fn replace_this_in_constructor(mark: Mark, c: Constructor) -> (Constr self.found = true; let this = quote_ident!(DUMMY_SP.apply_mark(self.mark), "_this"); - // TODO: - // self.helpers.assert_this_initialized(); - if self.wrap_with_assertiion { + helper!(assert_this_initialized); + Expr::Call(CallExpr { span: DUMMY_SP, callee: quote_ident!("_assertThisInitialized").as_callee(), diff --git a/ecmascript/transforms/src/compat/es2015/classes/mod.rs b/ecmascript/transforms/src/compat/es2015/classes/mod.rs index c507bb047d6..0c9b6e348f1 100644 --- a/ecmascript/transforms/src/compat/es2015/classes/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/classes/mod.rs @@ -7,16 +7,13 @@ use self::{ prop_name::HashKey, super_field::SuperFieldAccessFolder, }; -use crate::{ - helpers::Helpers, - util::{ - alias_ident_for, default_constructor, prepend, prop_name_to_expr, ExprFactory, - ModuleItemLike, StmtLike, - }, +use crate::util::{ + alias_ident_for, default_constructor, prepend, prop_name_to_expr, ExprFactory, ModuleItemLike, + StmtLike, }; use ast::*; use indexmap::IndexMap; -use std::{iter, sync::Arc}; +use std::iter; use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP}; #[macro_use] @@ -59,10 +56,8 @@ mod tests; /// return Test; /// }(); /// ``` -#[derive(Default, Clone)] -pub struct Classes { - pub helpers: Arc, -} +#[derive(Default, Clone, Copy)] +pub struct Classes; struct Data { key_prop: Box, @@ -231,7 +226,7 @@ impl Classes { _ => false, }; if is_super_native { - self.helpers.wrap_native_super(); + helper!(wrap_native_super); ( params, vec![CallExpr { @@ -348,8 +343,8 @@ impl Classes { if let Some(ref super_class_ident) = super_class_ident { // inject helper methods - self.helpers.inherits(); - self.helpers.possible_constructor_return(); + helper!(inherits); + helper!(possible_constructor_return); stmts.push(Stmt::Expr(box Expr::Call(CallExpr { span: DUMMY_SP, @@ -392,7 +387,7 @@ impl Classes { } // inject _classCallCheck(this, Bar); - self.helpers.class_call_check(); + helper!(class_call_check); inject_class_call_check(&mut constructor, class_name.clone()); let mut body = constructor.body.unwrap().stmts; // should we insert `var _this`? @@ -418,7 +413,6 @@ impl Classes { // Handle `super()` body = body.fold_with(&mut ConstructorFolder { is_constructor_default, - helpers: &self.helpers, class_name: &class_name, mode, mark, @@ -456,10 +450,11 @@ impl Classes { arg: Some(box Expr::Ident(this)), })); } else { - let possible_return_value = box make_possible_return_value( - &self.helpers, - ReturningMode::Returning { mark, arg: None }, - ); + let possible_return_value = + box make_possible_return_value(ReturningMode::Returning { + mark, + arg: None, + }); body.push(Stmt::Return(ReturnStmt { span: DUMMY_SP, arg: Some(possible_return_value), @@ -520,7 +515,6 @@ impl Classes { let mut vars = vec![]; let mut folder = SuperFieldAccessFolder { class_name, - helpers: &self.helpers, vars: &mut vars, constructor_this_mark: this_mark, // constructor cannot be static @@ -665,7 +659,6 @@ impl Classes { let mut vars = vec![]; let mut folder = SuperFieldAccessFolder { class_name: &class_name, - helpers: &self.helpers, vars: &mut vars, constructor_this_mark: None, is_static: m.is_static, @@ -736,7 +729,7 @@ impl Classes { if props.is_empty() && static_props.is_empty() { return vec![]; } - self.helpers.create_class(); + helper!(create_class); vec![mk_create_class_call( class_name, mk_arg_obj_for_create_class(props), @@ -754,8 +747,8 @@ impl Classes { /// ```js /// Child.__proto__ || Object.getPrototypeOf(Child) /// ``` -fn get_prototype_of(helpers: &Helpers, obj: &Expr) -> Expr { - helpers.get_prototype_of(); +fn get_prototype_of(obj: &Expr) -> Expr { + helper!(get_prototype_of); Expr::Call(CallExpr { span: DUMMY_SP, diff --git a/ecmascript/transforms/src/compat/es2015/classes/super_field.rs b/ecmascript/transforms/src/compat/es2015/classes/super_field.rs index 373c0e6b9ac..da49ce85708 100644 --- a/ecmascript/transforms/src/compat/es2015/classes/super_field.rs +++ b/ecmascript/transforms/src/compat/es2015/classes/super_field.rs @@ -1,8 +1,5 @@ use super::get_prototype_of; -use crate::{ - helpers::Helpers, - util::{alias_ident_for, is_rest_arguments, ExprFactory}, -}; +use crate::util::{alias_ident_for, is_rest_arguments, ExprFactory}; use ast::*; use std::iter; use swc_common::{Fold, FoldWith, Mark, Span, Spanned, DUMMY_SP}; @@ -22,7 +19,7 @@ use swc_common::{Fold, FoldWith, Mark, Span, Spanned, DUMMY_SP}; /// 'foo', this).call(this, a); pub(super) struct SuperFieldAccessFolder<'a> { pub class_name: &'a Ident, - pub helpers: &'a Helpers, + pub vars: &'a mut Vec, /// Mark for the `_this`. Used only when folding constructor. pub constructor_this_mark: Option, @@ -41,7 +38,6 @@ pub(super) struct SuperFieldAccessFolder<'a> { } struct SuperCalleeFolder<'a> { - helpers: &'a Helpers, vars: &'a mut Vec, class_name: &'a Ident, /// True if we should inject get and @@ -179,16 +175,13 @@ impl<'a> SuperCalleeFolder<'a> { fn super_to_get_call(&mut self, super_token: Span, prop: Box, computed: bool) -> Expr { self.inject_get = true; - let proto_arg = get_prototype_of( - self.helpers, - &if self.is_static { - // Foo - Expr::Ident(self.class_name.clone()) - } else { - // Foo.prototype - self.class_name.clone().member(quote_ident!("prototype")) - }, - ) + let proto_arg = get_prototype_of(&if self.is_static { + // Foo + Expr::Ident(self.class_name.clone()) + } else { + // Foo.prototype + self.class_name.clone().member(quote_ident!("prototype")) + }) .as_arg(); let prop_arg = match *prop { @@ -209,7 +202,7 @@ impl<'a> SuperCalleeFolder<'a> { Some(mark) => { let this = quote_ident!(super_token.apply_mark(mark), "_this"); - self.helpers.assert_this_initialized(); + helper!(assert_this_initialized); CallExpr { span: DUMMY_SP, callee: quote_ident!("_assertThisInitialized").as_callee(), @@ -264,11 +257,8 @@ impl<'a> SuperCalleeFolder<'a> { } } - let proto_arg = get_prototype_of( - self.helpers, - &self.class_name.clone().member(quote_ident!("prototype")), - ) - .as_arg(); + let proto_arg = + get_prototype_of(&self.class_name.clone().member(quote_ident!("prototype"))).as_arg(); let prop_arg = match *prop { Expr::Ident(Ident { @@ -401,7 +391,6 @@ impl<'a> Fold for SuperFieldAccessFolder<'a> { class_name: self.class_name, inject_get: false, inject_set: false, - helpers: self.helpers, vars: self.vars, constructor_this_mark: self.constructor_this_mark, is_static: self.is_static, @@ -427,7 +416,7 @@ impl<'a> Fold for SuperFieldAccessFolder<'a> { } if callee_folder.inject_get { - self.helpers.get(); + helper!(get); if should_invoke_call { match n { @@ -482,7 +471,7 @@ impl<'a> Fold for SuperFieldAccessFolder<'a> { } if callee_folder.inject_set { - self.helpers.set(); + helper!(set); } n.fold_children(self) diff --git a/ecmascript/transforms/src/compat/es2015/classes/tests.rs b/ecmascript/transforms/src/compat/es2015/classes/tests.rs index de20e4bff04..3d41d8f6d0a 100644 --- a/ecmascript/transforms/src/compat/es2015/classes/tests.rs +++ b/ecmascript/transforms/src/compat/es2015/classes/tests.rs @@ -9,26 +9,17 @@ fn syntax() -> Syntax { Syntax::default() } -fn tr(helpers: Arc) -> impl Fold { - Classes { helpers } +fn tr() -> impl Fold { + Classes } -fn spec_tr(helpers: Arc) -> impl Fold { - chain!( - resolver(), - Classes { - helpers: helpers.clone() - }, - Spread { - helpers: helpers.clone() - }, - block_scoping(), - ) +fn spec_tr() -> impl Fold { + chain!(resolver(), Classes, Spread, block_scoping(),) } test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), custom_singleton, r#" let singleton; @@ -61,7 +52,7 @@ let Sub = function(_Foo) { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), custom_native, r#" class List extends Array {} @@ -80,7 +71,7 @@ let List = function(_Array) { test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), custom_nested, r#" class Hello{ @@ -110,7 +101,7 @@ expect(new Outer().hello).toBe('hello'); // spec_constructor_only test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_constructor_only, r#" class Foo { @@ -138,7 +129,7 @@ var Foo = function Foo() { // regression_5769_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_5769_exec, r#" class Point { @@ -170,7 +161,7 @@ cp.m(); // spec_this_not_allowed_before_super_in_derived_classes_5_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_this_not_allowed_before_super_in_derived_classes_5_exec, r#" class Bar {} @@ -191,7 +182,7 @@ test!( // We don't use function-name pass ignore, syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_statement, r#" var BaseView = class BaseView { @@ -252,7 +243,7 @@ function () { // get_set_set_semantics_getter_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_getter_defined_on_parent, r#" @@ -348,7 +339,7 @@ expect(obj.test).toBe(2); // spec_derived_constructor_must_call_super test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_derived_constructor_must_call_super, r#" class Foo extends Bar { @@ -382,7 +373,7 @@ function (_Bar) { // get_set_get_semantics_data_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_get_semantics_data_defined_on_parent, r#" @@ -443,7 +434,7 @@ expect(obj.get()).toBe(1); // get_set_call_semantics_setter_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_call_semantics_setter_defined_on_parent_exec, r#" @@ -477,7 +468,7 @@ expect(() => { // get_set_set_semantics_data_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_data_defined_on_parent_exec, r#" @@ -516,7 +507,7 @@ expect(obj.test).toBe(3); // regression_8499 test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_8499, r#" // Pretend that `Reflect.construct` isn't supported. @@ -575,7 +566,7 @@ expect(constructor).toBe(CustomElement); // regression_5817 test!( syntax(), - |_, helpers| chain!(tr(helpers), arrow()), + |_| chain!(tr(), arrow()), regression_5817, r#" class A extends B { @@ -624,7 +615,7 @@ function (_B) { // get_set_set_semantics_not_defined_on_parent_setter_on_obj test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_not_defined_on_parent_setter_on_obj, r#" @@ -700,7 +691,7 @@ expect(obj.test).toBe(3); // get_set_get_semantics_setter_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_get_semantics_setter_defined_on_parent, r#" @@ -782,7 +773,7 @@ expect(obj.get()).toBeUndefined(); // spec_this_not_allowed_before_super_in_derived_classes_4 test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_this_not_allowed_before_super_in_derived_classes_4, r#" class Foo extends Bar { @@ -823,7 +814,7 @@ function (_Bar) { // spec_calling_super_properties test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_calling_super_properties, r#" class Test extends Foo { @@ -874,7 +865,7 @@ function (_Foo) { // spec_instance_getter_and_setter test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_instance_getter_and_setter, r#" class Test { @@ -917,7 +908,7 @@ test!( // Module ignore, syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_2941, r#" export default class {} @@ -943,7 +934,7 @@ exports.default = _default; // regression_T2494 test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_t2494, r#" var x = { @@ -975,7 +966,7 @@ var x = { // spec_inferred_expression_name test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_inferred_expression_name, r#" var o = { foo: class foo {} }; @@ -998,7 +989,7 @@ test_exec!( // Wrong test (babel + jest fails) ignore, syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_8499_exec, r#" // Pretend that `Reflect.construct` isn't supported. @@ -1025,7 +1016,7 @@ expect(constructor).toBe(CustomElement); // spec_default_super test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_default_super, r#" class Test { @@ -1080,7 +1071,7 @@ expect(Test.test()).toBe(Function); // spec_default_super test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_default_super_constructor, r#" class Test { @@ -1100,7 +1091,7 @@ var Test = function Test() { // get_set_get_semantics_getter_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_get_semantics_getter_defined_on_parent, r#" @@ -1186,7 +1177,7 @@ expect(obj.get()).toBe(1); // spec_this_not_allowed_before_super_in_derived_classes test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_this_not_allowed_before_super_in_derived_classes, r#" class Foo extends Bar { @@ -1223,7 +1214,7 @@ function (_Bar) { // get_set_call_semantics_getter_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_call_semantics_getter_defined_on_parent, r#" @@ -1321,7 +1312,7 @@ expect(obj.call(1, 2, 3)).toBe(1); // spec_derived_constructor_must_call_super_4_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_derived_constructor_must_call_super_4_exec, r#" class Bar {} @@ -1342,7 +1333,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised"); // spec_export_default test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_export_default, r#" export default class Foo {} @@ -1361,7 +1352,7 @@ export { Foo as default }; // get_set_call_semantics_data_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_call_semantics_data_defined_on_parent_exec, r#" @@ -1395,7 +1386,7 @@ expect(obj.call(1, 2, 3)).toBe(1); // extend_builtins_spec_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), extend_builtins_spec_exec, r#" class List extends Array {} @@ -1409,7 +1400,7 @@ expect(new List).toBeInstanceOf(Array); // get_set_call_semantics_data_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_call_semantics_data_defined_on_parent, r#" @@ -1501,7 +1492,7 @@ expect(obj.call(1, 2, 3)).toBe(1); // spec_static test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_static, r#" class A { @@ -1546,7 +1537,7 @@ function () { // regression_T6755 // get_set_memoized_update -test!(syntax(),|_,helpers| tr(helpers), get_set_memoized_update, r#" +test!(syntax(),|_| tr(), get_set_memoized_update, r#" class Base {} Object.defineProperty(Base.prototype, 0, { @@ -1657,7 +1648,7 @@ expect(obj[1]).toBe(2); "#); // spec_nested_class_super_property_in_key -test!(syntax(),|_,helpers| spec_tr(helpers), +test!(syntax(),|_| spec_tr(), spec_nested_class_super_property_in_key, r#" class Hello { @@ -1736,7 +1727,7 @@ expect(new Outer().hello()).toBe('hello'); "#); // spec_super_reference_in_prop_exression -test!(syntax(),|_,helpers| spec_tr(helpers), spec_super_reference_in_prop_exression, r#" +test!(syntax(),|_| spec_tr(), spec_super_reference_in_prop_exression, r#" class Foo extends Bar { constructor() { super[super().method](); @@ -1767,7 +1758,7 @@ function (_Bar) { // spec_super_reference_before_in_lambda_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_super_reference_before_in_lambda_exec, r#" class Bar { @@ -1788,7 +1779,7 @@ new Foo(); // spec_nested_class_super_call_in_key_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_nested_class_super_call_in_key_exec, r#" @@ -1822,7 +1813,7 @@ expect(new Outer().hello()).toBe('hello'); // spec_this_not_allowed_before_super_in_derived_classes_4_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_this_not_allowed_before_super_in_derived_classes_4_exec, r#" class Bar {} @@ -1843,7 +1834,7 @@ new Foo(); // spec_this_not_allowed_before_super_in_derived_classes_2 test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_this_not_allowed_before_super_in_derived_classes_2, r#" class Foo extends Bar { @@ -1878,7 +1869,7 @@ function (_Bar) { // spec_accessing_super_properties test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_accessing_super_properties, r#" class Test extends Foo { @@ -1917,7 +1908,7 @@ function (_Foo) { // spec_computed_methods test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_computed_methods, r#" class Foo { @@ -1962,7 +1953,7 @@ function () { // get_set_set_semantics_not_defined_on_parent_data_on_obj_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_not_defined_on_parent_data_on_obj_exec, r#" @@ -1992,7 +1983,7 @@ expect(obj.test).toBe(3); // get_set_set_semantics_data_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_data_defined_on_parent, r#" @@ -2073,7 +2064,7 @@ expect(obj.test).toBe(3); // get_set_set_semantics_not_defined_on_parent_getter_on_obj test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_not_defined_on_parent_getter_on_obj, r#" @@ -2140,7 +2131,7 @@ expect(obj.test).toBe(3); // spec_returning_from_derived_constructor_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_returning_from_derived_constructor_exec, r#" @@ -2208,7 +2199,7 @@ expect(() => { // regression_2694 // regression_5769 -test!(syntax(),|_,helpers| tr(helpers), regression_5769, r#" +test!(syntax(),|_| tr(), regression_5769, r#" class Point { getX() { expect(this.x).toBe(3); // C @@ -2289,7 +2280,7 @@ cp.m(); // spec_super_function_fallback test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_super_function_fallback, r#" class Test { @@ -2318,10 +2309,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| chain!( - tr(helpers.clone()), - jsx(tester.cm.clone(), Default::default(), helpers) - ), + |tester| chain!(tr(), jsx(tester.cm.clone(), Default::default())), regression_2775, r#" import React, {Component} from 'react'; @@ -2382,7 +2370,7 @@ exports.default = RandomComponent; // extend_builtins_imported_babel_plugin_transform_builtin_classes_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), extend_builtins_imported_babel_plugin_transform_builtin_classes_exec, r#" @@ -2432,7 +2420,7 @@ test!( // Module ignore, syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_3028, r#" class b { @@ -2517,7 +2505,7 @@ exports.default = a2; // spec_instance_setter test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_instance_setter, r#" class Test { @@ -2552,7 +2540,7 @@ function () { // spec_nested_object_super_call_in_key test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_nested_object_super_call_in_key, r#" @@ -2623,7 +2611,7 @@ expect(new Outer().hello()).toBe('hello'); // get_set_set_semantics_not_defined_on_parent_not_on_obj test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_not_defined_on_parent_not_on_obj, r#" @@ -2683,7 +2671,7 @@ expect(obj.test).toBe(3); // spec_derived_constructor_no_super_return_falsey test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_derived_constructor_no_super_return_falsey, r#" class Child extends Base { @@ -2717,7 +2705,7 @@ function (_Base) { // spec_this_not_allowed_before_super_in_derived_classes_5 test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_this_not_allowed_before_super_in_derived_classes_5, r#" class Foo extends Bar { @@ -2754,7 +2742,7 @@ function (_Bar) { // spec_constructor test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_constructor, r#" class Test { @@ -2822,7 +2810,7 @@ var ConstructorScoping = function ConstructorScoping() { // spec_preserves_directives test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_preserves_directives, r#" class MyCtrl { @@ -2884,7 +2872,7 @@ var MyCtrl3 = function MyCtrl3(a) { // spec_derived_constructor_no_super_return_object test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_derived_constructor_no_super_return_object, r#" class Child extends Base { @@ -2918,7 +2906,7 @@ function (_Base) { // get_set_get_semantics_getter_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_get_semantics_getter_defined_on_parent_exec, r#" @@ -2952,7 +2940,7 @@ test!( // Module ignore, syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_t6750, r#" export default function() { @@ -2994,7 +2982,7 @@ function _default() { // spec_instance_method test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_instance_method, r#" class Test { @@ -3027,7 +3015,7 @@ function () { ); // regression_T2997 -test!(syntax(),|_,helpers| tr(helpers), regression_t2997, r#" +test!(syntax(),|_| tr(), regression_t2997, r#" class A {} class B extends A { @@ -3065,7 +3053,7 @@ function (_A) { // spec_constructor_binding_collision test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_constructor_binding_collision, r#" class Example { @@ -3092,7 +3080,7 @@ var t = new Example(); ); // spec_super_class_anonymous -test!(syntax(),|_,helpers| spec_tr(helpers), spec_super_class_anonymous, r#" +test!(syntax(),|_| spec_tr(), spec_super_class_anonymous, r#" class TestEmpty extends (class {}) { } @@ -3260,7 +3248,7 @@ function () { // spec_nested_class_super_call_in_key test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_nested_class_super_call_in_key, r#" @@ -3344,7 +3332,7 @@ expect(new Outer().hello()).toBe('hello'); // get_set_get_semantics_data_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_get_semantics_data_defined_on_parent_exec, r#" @@ -3381,7 +3369,7 @@ test!( // Module ignore, syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_2663, r#" import net from 'net'; @@ -3462,7 +3450,7 @@ exports.default = Connection; // get_set_set_semantics_setter_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_setter_defined_on_parent_exec, r#" @@ -3497,7 +3485,7 @@ expect(obj.test).toBe(2); // regression_5817_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_5817_exec, r#" // https://github.com/babel/babel/issues/5817 @@ -3525,7 +3513,7 @@ expect(table.returnParam(false)).toBe(false); // spec_instance_getter test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_instance_getter, r#" class Test { @@ -3560,7 +3548,7 @@ function () { // spec_this_not_allowed_before_super_in_derived_classes_3 test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_this_not_allowed_before_super_in_derived_classes_3, r#" class Foo extends Bar { @@ -3602,7 +3590,7 @@ function (_Bar) { test!( // TODO(kdy1): Unignore this. ignore, - syntax(),|_,helpers| spec_tr(helpers), spec_accessing_super_class, r#" + syntax(),|_| spec_tr(), spec_accessing_super_class, r#" class Test extends Foo { constructor() { woops.super.test(); @@ -3684,7 +3672,7 @@ function (_Foo) { // get_set_call_semantics_getter_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_call_semantics_getter_defined_on_parent_exec, r#" @@ -3721,7 +3709,7 @@ expect(obj.call(1, 2, 3)).toBe(1); // spec_this_not_allowed_before_super_in_derived_classes_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_this_not_allowed_before_super_in_derived_classes_exec, r#" class Bar {} @@ -3741,7 +3729,7 @@ expect(() => new Foo()).toThrow(); // spec_nested_object_super_property_in_key_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_nested_object_super_property_in_key_exec, r#" @@ -3772,7 +3760,7 @@ expect(new Outer().hello()).toBe('hello'); // regression_T6712 test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_t6712, r#" class A { @@ -3807,7 +3795,7 @@ function () { // get_set_set_semantics_setter_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_setter_defined_on_parent, r#" @@ -3898,7 +3886,7 @@ expect(obj.test).toBe(2); // get_set_call_semantics_not_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_call_semantics_not_defined_on_parent, r#" @@ -3969,7 +3957,7 @@ expect(() => { // spec_derived_constructor_must_call_super_2_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_derived_constructor_must_call_super_2_exec, r#" class Bar {} @@ -3990,7 +3978,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised"); // spec_nested_object_super_property_in_key test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_nested_object_super_property_in_key, r#" @@ -4063,7 +4051,7 @@ expect(new Outer().hello()).toBe('hello'); // get_set_set_semantics_not_defined_on_parent_setter_on_obj_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_not_defined_on_parent_setter_on_obj_exec, r#" @@ -4098,7 +4086,7 @@ expect(obj.test).toBe(3); // spec_this_not_allowed_before_super_in_derived_classes_2_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_this_not_allowed_before_super_in_derived_classes_2_exec, r#" class Bar {} @@ -4117,7 +4105,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised"); // extend_builtins_overwritten_null_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), extend_builtins_overwritten_null_exec, r#" let Array = null; @@ -4130,7 +4118,7 @@ expect(List.prototype.__proto__).toBeUndefined(); // spec_super_reference_before_bare_super_inline_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_super_reference_before_bare_super_inline_exec, r#" class Bar {} @@ -4149,7 +4137,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised"); // get_set_call_semantics_setter_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_call_semantics_setter_defined_on_parent, r#" @@ -4236,7 +4224,7 @@ expect(() => { // spec_super_class test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_super_class, r#" class Test extends Foo { } @@ -4266,7 +4254,7 @@ function (_Foo) { // spec_nested_object_super_call_in_key_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_nested_object_super_call_in_key_exec, r#" @@ -4300,7 +4288,7 @@ expect(new Outer().hello()).toBe('hello'); // spec_derived_constructor_must_call_super_2 test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_derived_constructor_must_call_super_2, r#" class Foo extends Bar { @@ -4335,7 +4323,7 @@ function (_Bar) { // spec_derived_constructor_must_call_super_3 test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_derived_constructor_must_call_super_3, r#" class Foo extends Bar { @@ -4374,7 +4362,7 @@ function (_Bar) { // spec_this_not_allowed_before_super_in_derived_classes_3_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_this_not_allowed_before_super_in_derived_classes_3_exec, r#" class Bar {} @@ -4395,7 +4383,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised"); // get_set_get_semantics_not_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_get_semantics_not_defined_on_parent_exec, r#" @@ -4423,7 +4411,7 @@ expect(obj.get()).toBeUndefined(); // get_set_set_semantics_not_defined_on_parent_data_on_obj test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_not_defined_on_parent_data_on_obj, r#" @@ -4493,7 +4481,7 @@ expect(obj.test).toBe(3); // get_set_set_semantics_not_defined_on_parent_getter_on_obj_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_not_defined_on_parent_getter_on_obj_exec, r#" @@ -4524,7 +4512,7 @@ expect(obj.test).toBe(3); // exec // get_set_memoized_assign -test!(syntax(),|_,helpers| tr(helpers), get_set_memoized_assign, r#" +test!(syntax(),|_| tr(), get_set_memoized_assign, r#" class Base {} Object.defineProperty(Base.prototype, 0, { @@ -4637,7 +4625,7 @@ expect(obj[1]).toBe(2); // extend_builtins_builtin_objects_throw_when_wrapped_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), extend_builtins_builtin_objects_throw_when_wrapped_exec, r#" // JSON is wrapped because it starts with an uppercase letter, but it @@ -4651,7 +4639,7 @@ expect(() => class BetterJSON extends JSON {}).toThrow(); // get_set_call_semantics_not_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_call_semantics_not_defined_on_parent_exec, r#" @@ -4682,7 +4670,7 @@ expect(() => { // spec_nested_class_super_property_in_key_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_nested_class_super_property_in_key_exec, r#" @@ -4713,7 +4701,7 @@ expect(new Outer().hello()).toBe('hello'); // spec_relaxed_method_coercion test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_relaxed_method_coercion, r#" // #1649 @@ -4751,7 +4739,7 @@ function () { // spec_derived_constructor_must_call_super_3_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_derived_constructor_must_call_super_3_exec, r#" class Bar {} @@ -4771,7 +4759,7 @@ new Foo(); // get_set_memoized_update_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_memoized_update_exec, r#" @@ -4822,7 +4810,7 @@ expect(obj[1]).toBe(2); // spec_computed_methods_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_computed_methods_exec, r#" const sym = Symbol(); @@ -4849,7 +4837,7 @@ expect(i[sym]()).toBe(3); // get_set_memoized_assign_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_memoized_assign_exec, r#" @@ -4900,7 +4888,7 @@ expect(obj[1]).toBe(2); // spec_derived_constructor_must_call_super_4 test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_derived_constructor_must_call_super_4, r#" class Foo extends Bar { @@ -4937,7 +4925,7 @@ function (_Bar) { // spec_super_class_id_member_expression test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_super_class_id_member_expression, r#" class BaseController extends Chaplin.Controller { @@ -4986,7 +4974,7 @@ function (_Another) { // spec_delay_arrow_function_for_bare_super_derived test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_delay_arrow_function_for_bare_super_derived, r#" class Foo extends Bar { @@ -5027,7 +5015,7 @@ function (_Bar) { // spec_default_super_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_default_super_exec, r#" class Test { @@ -5054,7 +5042,7 @@ expect(Test.test()).toBe(Function); // spec_super_reference_before_in_lambda_3_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_super_reference_before_in_lambda_3_exec, r#" class Bar { @@ -5079,7 +5067,7 @@ new Foo(); // get_set_get_semantics_not_defined_on_parent test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_get_semantics_not_defined_on_parent, r#" @@ -5147,7 +5135,7 @@ expect(obj.get()).toBeUndefined(); // spec_plain_class test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_plain_class, r#" class Test { } @@ -5166,7 +5154,7 @@ var Test = function Test() { // spec_super_reference_before_bare_super_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_super_reference_before_bare_super_exec, r#" class Bar {} @@ -5186,7 +5174,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised"); // spec_super_reference_before_in_lambda_2_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_super_reference_before_in_lambda_2_exec, r#" class Bar { @@ -5209,7 +5197,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised"); // get_set_set_semantics_not_defined_on_parent_not_on_obj_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_not_defined_on_parent_not_on_obj_exec, r#" @@ -5234,7 +5222,7 @@ expect(obj.test).toBe(3); // get_set_get_semantics_setter_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_get_semantics_setter_defined_on_parent_exec, r#" @@ -5265,7 +5253,7 @@ expect(obj.get()).toBeUndefined(); // extend_builtins_super_called_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), extend_builtins_super_called_exec, r#" var called = false; @@ -5286,7 +5274,7 @@ expect(called).toBe(true); // spec_derived_constructor_must_call_super_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_derived_constructor_must_call_super_exec, r#" class Bar {} @@ -5307,7 +5295,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised"); // spec_export_super_class test!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_export_super_class, r#" export default class extends A {} @@ -5335,7 +5323,7 @@ export { _default as default }; // extend_builtins_wrap_native_super_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), extend_builtins_wrap_native_super_exec, r#" // basic sanity check to confirm the external wrapNativeSuper helper works @@ -5370,7 +5358,7 @@ expect(t2).toBeInstanceOf(Array); // spec_super_reference_in_prop_exression_exec test_exec!( syntax(), - |_, helpers| spec_tr(helpers), + |_| spec_tr(), spec_super_reference_in_prop_exression_exec, r#" let called = false; @@ -5402,7 +5390,7 @@ expect(called).toBe(true); // get_set_set_semantics_getter_defined_on_parent_exec test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), get_set_set_semantics_getter_defined_on_parent_exec, r#" diff --git a/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs b/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs index 695247aad21..04db9fa5db5 100644 --- a/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs @@ -1,10 +1,8 @@ use crate::{ - helpers::Helpers, pass::Pass, util::{ExprFactory, StmtLike}, }; use ast::*; -use std::sync::Arc; use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP}; #[cfg(test)] @@ -41,14 +39,12 @@ mod tests; /// /// TODO(kdy1): cache reference like (_f = f, mutatorMap[_f].get = function(){}) /// instead of (mutatorMap[f].get = function(){} -pub fn computed_properties(helpers: Arc) -> impl Pass + Clone { - ComputedProps { helpers } +pub fn computed_properties() -> impl Pass + Clone + Copy { + ComputedProps } -#[derive(Default, Clone)] -struct ComputedProps { - helpers: Arc, -} +#[derive(Default, Clone, Copy)] +struct ComputedProps; #[derive(Default)] struct ObjectLitFolder { @@ -300,7 +296,7 @@ where // Add variable declaration // e.g. var ref if !folder.vars.is_empty() { - self.helpers.define_property(); + helper!(define_property); buf.push(T::from_stmt(Stmt::Decl(Decl::Var(VarDecl { span: DUMMY_SP, kind: VarDeclKind::Var, @@ -309,7 +305,7 @@ where })))); } if folder.used_define_enum_props { - self.helpers.define_enumerable_properties(); + helper!(define_enumerable_properties); } buf.push(T::from_stmt(stmt)); diff --git a/ecmascript/transforms/src/compat/es2015/computed_props/tests.rs b/ecmascript/transforms/src/compat/es2015/computed_props/tests.rs index b88eff164d3..6a37a07db1b 100644 --- a/ecmascript/transforms/src/compat/es2015/computed_props/tests.rs +++ b/ecmascript/transforms/src/compat/es2015/computed_props/tests.rs @@ -2,7 +2,7 @@ use super::*; test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, accessors, r#"var obj = { get [foobar]() { @@ -39,7 +39,7 @@ var obj = ( _obj = { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, argument, r#"foo({ [bar]: "foobar" @@ -50,7 +50,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, assignment, r#"foo = { [bar]: "foobar" @@ -60,7 +60,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, method, r#"var obj = { [foobar]() { @@ -80,7 +80,7 @@ var obj = (_obj = {}, _defineProperty(_obj, foobar, function () { ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps{helpers}, + |_| ComputedProps, mixed, r#"var obj = { ["x" + foo]: "heh", @@ -96,7 +96,7 @@ var obj = (_obj = {}, _defineProperty(_obj, "x" + foo, "heh"), _defineProperty(_ test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, multiple, r#"var obj = { ["x" + foo]: "heh", @@ -110,7 +110,7 @@ _defineProperty(_obj, "y" + bar, "noo"), _obj);"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, single, r#"var obj = { ["x" + foo]: "heh" @@ -120,7 +120,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, symbol, r#"var k = Symbol(); var foo = { @@ -142,7 +142,7 @@ var foo = ( _obj = { test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, symbol_exec, r#" var k = Symbol(); @@ -159,7 +159,7 @@ expect(foo[k]).toBe(k)"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, this, r#"var obj = { ["x" + foo.bar]: "heh" @@ -169,7 +169,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, two, r#"var obj = { first: "first", @@ -182,7 +182,7 @@ var obj = ( _obj = { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| ComputedProps { helpers }, + |_| ComputedProps, variable, r#"var foo = { [bar]: "foobar" diff --git a/ecmascript/transforms/src/compat/es2015/destructuring/mod.rs b/ecmascript/transforms/src/compat/es2015/destructuring/mod.rs index f4ad1943dd0..8348fd0e10a 100644 --- a/ecmascript/transforms/src/compat/es2015/destructuring/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/destructuring/mod.rs @@ -1,10 +1,9 @@ use crate::{ - helpers::Helpers, pass::Pass, util::{prop_name_to_expr, ExprFactory, StmtLike}, }; use ast::*; -use std::{iter, sync::Arc}; +use std::iter; use swc_atoms::JsWord; use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP}; @@ -32,14 +31,12 @@ mod tests; /// b = _arr2[1], /// rest = _arr2.slice(2); /// ``` -pub fn destructuring(helpers: Arc) -> impl Pass + Clone { - Destructuring { helpers } +pub fn destructuring() -> impl Pass + Clone + Copy { + Destructuring } -#[derive(Clone)] -struct Destructuring { - helpers: Arc, -} +#[derive(Clone, Copy)] +struct Destructuring; macro_rules! impl_for_for_stmt { ($T:tt) => { @@ -195,7 +192,7 @@ impl Fold> for Destructuring { let ref_ident = make_ref_ident(&mut decls, decl.init); let ref_ident = if can_be_null { - self.helpers.throw(); + helper!(throw); make_ref_ident( &mut decls, Some(box Expr::Cond(CondExpr { @@ -377,7 +374,6 @@ impl Fold for Destructuring { #[derive(Default)] struct AssignFolder { - helpers: Arc, vars: Vec, } @@ -385,10 +381,7 @@ impl Fold for AssignFolder { fn fold(&mut self, expr: Expr) -> Expr { let expr = match expr { // Handle iife - Expr::Fn(..) | Expr::Object(..) => Destructuring { - helpers: self.helpers.clone(), - } - .fold(expr), + Expr::Fn(..) | Expr::Object(..) => Destructuring.fold(expr), _ => expr.fold_children(self), }; diff --git a/ecmascript/transforms/src/compat/es2015/destructuring/tests.rs b/ecmascript/transforms/src/compat/es2015/destructuring/tests.rs index 6d3452124b2..e60c41cd736 100644 --- a/ecmascript/transforms/src/compat/es2015/destructuring/tests.rs +++ b/ecmascript/transforms/src/compat/es2015/destructuring/tests.rs @@ -1,12 +1,12 @@ use super::*; -fn tr(helpers: Arc) -> impl Fold { - Destructuring { helpers } +fn tr() -> impl Fold { + Destructuring } test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), obj_assign_pat, r#"let { a = 1 } = foo"#, r#"let ref = foo ? foo : _throw(new TypeError("Cannot destructure 'undefined' or 'null'")), @@ -15,7 +15,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), obj_assign_expr, r#"let a; [{ a = 1 }] = foo"#, @@ -26,7 +26,7 @@ ref = foo, ref1 = ref[0], ref2 = ref1.a, a = ref2 === void 0 ? 1 : ref2, ref;"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), array1, r#"var [a, [b], [c]] = ["hello", [", ", "junk"], ["world"]];"#, r#"var ref = ['hello', [', ', 'junk'], ['world']], a = ref[0], ref1 = ref[1], @@ -35,7 +35,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), array2, r#"[a, [b], [c]] = ["hello", [", ", "junk"], ["world"]];"#, r#"var ref, ref1, ref2; @@ -46,7 +46,7 @@ ref = ['hello', [', ', 'junk'], ['world']], a = ref[0], ref1 = ref[1], test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), assign_expr_completion_record, r#"var x, y; [x, y] = [1, 2];"#, @@ -56,7 +56,7 @@ ref = [1, 2], x = ref[0], y = ref[1], ref;"# ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), assign_expr_pat, r#"var z = {}; var { x: { y } = {} } = z;"#, @@ -69,7 +69,7 @@ var ref = z ? z : _throw(new TypeError("Cannot destructure 'undefined' or 'null' test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), assign_expr, r#"console.log([x] = [123]);"#, r#"var ref; @@ -78,7 +78,7 @@ console.log((ref = [123], x = ref[0], ref));"# test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| Destructuring { helpers }, + |_| Destructuring, chained, r#"var a, b, c, d; ({ a, b } = ({ c, d } = { a: 1, b: 2, c: 3, d: 4})); @@ -90,7 +90,7 @@ expect(d).toBe(4);"# test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| Destructuring { helpers }, + |_| Destructuring, empty_obj_pat_1, r#"expect(function () { var {} = null; @@ -98,7 +98,7 @@ test_exec!( ); // test!(::swc_ecma_parser::Syntax::default(), -// |_, helpers| tr(helpers), +// |_| tr(), // empty_obj_pat_2, // r#"var {} = null;"#, // r#"var _ref = null; @@ -107,7 +107,7 @@ test_exec!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), empty, r#"var [, a, [b], [c], d] = ["foo", "hello", [", ", "junk"], ["world"]];"#, r#"var ref = ['foo', 'hello', [', ', 'junk'], ['world']], a = ref[1], ref1 = ref[2], @@ -118,7 +118,7 @@ test!( test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), es7_object_rest_builtins, r#"var z = {}; var { ...x } = z; @@ -152,7 +152,7 @@ _o;"# test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), es7_object_rest, r#"var z = {}; var { ...x } = z; @@ -186,7 +186,7 @@ _o;"# test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), export_variable, r#"export let {a, b, c: {d, e: {f = 4}}} = {};"#, r#" @@ -202,7 +202,7 @@ export { a, b, d, f };"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), for_in, r#"for (var [name, value] in obj) { print("Name: " + name + ", Value: " + value); @@ -216,7 +216,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), for_let, r#"for (let [ i, n ] = range; ; ) {}"#, r#"for(let i = range[0], n = range[1];;){}"# @@ -224,7 +224,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), for_of, r#"for (var [ name, before, after ] of test.expectation.registers) { @@ -237,7 +237,7 @@ test!( test_exec!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| Destructuring { helpers }, + |_| Destructuring, fn_key_with_obj_rest_spread, r#"const { [(() => 1)()]: a, ...rest } = { 1: "a" }; @@ -246,7 +246,7 @@ expect(rest).toEqual({});"# ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), babel_issue_3081, r#"let list = [1, 2, 3, 4]; for (let i = 0, { length } = list; i < length; i++) { @@ -262,7 +262,7 @@ for(let i = 0, ref = list ? list : _throw(new TypeError("Cannot destructure 'und test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| Destructuring { helpers }, + |_| Destructuring, babel_issue_5090, r#"const assign = function([...arr], index, value) { arr[index] = value; @@ -277,7 +277,7 @@ expect(arr).toEqual([1, 2, 3]);"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), babel_issue_5628, r#" (function () { @@ -297,7 +297,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), babel_issue_5744, r#"if (true) [a, b] = [b, a];"#, r#"var ref; @@ -307,7 +307,7 @@ if (true) ref = [b, a], a = ref[0], b = ref[1], ref;"# test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), babel_issue_6373, r#"import { NestedObjects } from "./some-module" @@ -322,7 +322,7 @@ const Foo = _someModule.NestedObjects.Foo, test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), known_array, r#"var z = []; var [x, ...y] = z;"#, @@ -333,7 +333,7 @@ var x = z[0], test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), member_expr, r#"[foo.foo, foo.bar] = [1, 2];"#, r#"var ref; @@ -342,7 +342,7 @@ ref = [1, 2], foo.foo = ref[0], foo.bar = ref[1], ref;"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), mixed, r#"var rect = {}; var {topLeft: [x1, y1], bottomRight: [x2, y2] } = rect;"#, @@ -354,7 +354,7 @@ var ref = rect ? rect : _throw(new TypeError("Cannot destructure 'undefined' or test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), multiple, r#"var coords = [1, 2]; var { x, y } = coords, @@ -367,7 +367,7 @@ var ref = coords ? coords : _throw(new TypeError("Cannot destructure 'undefined' test_exec!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| Destructuring { helpers }, + |_| Destructuring, number_key_with_object_spread, r#"const foo = { 1: "a", @@ -383,7 +383,7 @@ expect(rest).toEqual({ 2: "b", 3: "c" });"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), object_advanced, r#"var rect = {}; var {topLeft: {x: x1, y: y1}, bottomRight: {x: x2, y: y2}} = rect; @@ -399,7 +399,7 @@ var ref3 = [0, 1, 2, 3, 4, 5, 6], foo = ref3[3], bar = ref3[5];"# ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), object_basic, r#"var coords = [1, 2]; var { x, y } = coords;"#, @@ -410,7 +410,7 @@ var ref = coords ? coords : _throw(new TypeError("Cannot destructure 'undefined' test_exec!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| Destructuring { helpers }, + |_| Destructuring, spread_generator, r#"function* f() { for (var i = 0; i < 3; i++) { @@ -423,7 +423,7 @@ expect(xs).toEqual([0, 1, 2]);"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), spread, r#"function isSorted([x, y, ...wow]) { if (!zs.length) return true diff --git a/ecmascript/transforms/src/compat/es2015/duplicate_keys/tests.rs b/ecmascript/transforms/src/compat/es2015/duplicate_keys/tests.rs index dbaecef46f0..2cadbf2fb4d 100644 --- a/ecmascript/transforms/src/compat/es2015/duplicate_keys/tests.rs +++ b/ecmascript/transforms/src/compat/es2015/duplicate_keys/tests.rs @@ -3,7 +3,7 @@ use super::*; test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, _| DuplicateKeys, + |_| DuplicateKeys, combination_dupes, r#"var x = { a: 5, a: 6 };"#, r#"var x = _defineProperty({ @@ -13,7 +13,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| DuplicateKeys, + |_| DuplicateKeys, combination_no_dupes, r#"var x = { a: 5, b: 6 };"#, r#"var x = { a: 5, b: 6 };"# @@ -21,7 +21,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| DuplicateKeys, + |_| DuplicateKeys, dup_keys_both_quoted, r#"var x = { "a\n b": 5, "a\n b": 6 };"#, r#"var x = { @@ -32,7 +32,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| DuplicateKeys, + |_| DuplicateKeys, dup_keys_dupes, r#"var x = { a: 5, a: 6 };"#, r#"var x = { @@ -43,7 +43,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| DuplicateKeys, + |_| DuplicateKeys, dup_keys_getter, r#"var x = { a: 5, get a() {return 6;} };"#, r#"var x = { @@ -58,7 +58,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| DuplicateKeys, + |_| DuplicateKeys, dup_keys_getter_and_setter, r#"var x = { get a() {}, @@ -109,7 +109,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| DuplicateKeys, + |_| DuplicateKeys, dup_keys_one_quoted, r#"var x = { a: 5, "a": 6 };"#, r#"var x = { diff --git a/ecmascript/transforms/src/compat/es2015/for_of/tests.rs b/ecmascript/transforms/src/compat/es2015/for_of/tests.rs index 21af2910444..02f0eeed787 100644 --- a/ecmascript/transforms/src/compat/es2015/for_of/tests.rs +++ b/ecmascript/transforms/src/compat/es2015/for_of/tests.rs @@ -2,7 +2,7 @@ use super::*; test!( ::swc_ecma_parser::Syntax::default(), - |_, _| ForOf, + |_| ForOf, spec_identifier, r#"for (i of arr) { }"#, @@ -32,7 +32,7 @@ try { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| ForOf, + |_| ForOf, spec_ignore_cases, r#"for (var i of foo) { switch (i) { @@ -71,7 +71,7 @@ try { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| ForOf, + |_| ForOf, spec_let, r#"for (let i of arr) { @@ -103,7 +103,7 @@ try { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| ForOf, + |_| ForOf, spec_member_expr, r#"for (obj.prop of arr) { @@ -134,7 +134,7 @@ try { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| ForOf, + |_| ForOf, spec_multiple, r#"for (var i of arr) { @@ -192,7 +192,7 @@ try { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| ForOf, + |_| ForOf, spec_nested_label_for_of, r#"b: for (let c of d()) { for (let e of f()) { @@ -247,7 +247,7 @@ try { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| ForOf, + |_| ForOf, spec_var, r#"for (var i of arr) { diff --git a/ecmascript/transforms/src/compat/es2015/function_name/tests.rs b/ecmascript/transforms/src/compat/es2015/function_name/tests.rs index 0e3d75532c5..ec2c5d5bfb1 100644 --- a/ecmascript/transforms/src/compat/es2015/function_name/tests.rs +++ b/ecmascript/transforms/src/compat/es2015/function_name/tests.rs @@ -1,17 +1,13 @@ use super::*; -use crate::{ - compat::es2015::{block_scoping, resolver}, - helpers::Helpers, -}; -use std::sync::Arc; +use crate::compat::es2015::{block_scoping, resolver}; -fn tr(_helpers: Arc) -> impl Fold { +fn tr() -> impl Fold { chain!(resolver(), function_name(), block_scoping()) } test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), basic, r#"var number = function (x) { return x; @@ -23,7 +19,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), assign, r#"number = function (x) { return x; @@ -35,7 +31,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), let_complex, r#" let TestClass = { @@ -65,7 +61,7 @@ var TestClass = { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), class_simple, r#" var Foo = function() { diff --git a/ecmascript/transforms/src/compat/es2015/instanceof.rs b/ecmascript/transforms/src/compat/es2015/instanceof.rs index 2517370454a..2bca2d79530 100644 --- a/ecmascript/transforms/src/compat/es2015/instanceof.rs +++ b/ecmascript/transforms/src/compat/es2015/instanceof.rs @@ -1,6 +1,5 @@ -use crate::{helpers::Helpers, util::ExprFactory}; +use crate::util::ExprFactory; use ast::*; -use std::sync::Arc; use swc_common::{Fold, FoldWith, Visit, VisitWith}; /// `@babel/plugin-transform-instanceof` @@ -29,9 +28,7 @@ use swc_common::{Fold, FoldWith, Visit, VisitWith}; /// _instanceof(foo, Bar); /// ``` #[derive(Clone)] -pub struct InstanceOf { - pub helpers: Arc, -} +pub struct InstanceOf; impl Fold for InstanceOf { fn fold(&mut self, expr: Expr) -> Expr { @@ -64,7 +61,7 @@ impl Fold for InstanceOf { op: op!("instanceof"), right, }) => { - self.helpers.instanceof(); + helper!(instanceof); Expr::Call(CallExpr { span, diff --git a/ecmascript/transforms/src/compat/es2015/mod.rs b/ecmascript/transforms/src/compat/es2015/mod.rs index 9f91ed0083b..012a6b43c23 100644 --- a/ecmascript/transforms/src/compat/es2015/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/mod.rs @@ -6,9 +6,8 @@ pub use self::{ shorthand_property::Shorthand, spread::Spread, sticky_regex::StickyRegex, template_literal::TemplateLiteral, typeof_symbol::TypeOfSymbol, }; -use crate::{helpers::Helpers, pass::Pass}; +use crate::pass::Pass; use ast::{Expr, Module, Stmt}; -use std::sync::Arc; mod arrow; mod block_scoped_fn; @@ -29,49 +28,33 @@ mod template_literal; mod typeof_symbol; /// Compiles es2015 to es5. -pub fn es2015(helpers: &Arc) -> impl Pass + Clone { - fn exprs(helpers: &Arc) -> impl Pass + Clone { +pub fn es2015() -> impl Pass + Clone { + fn exprs() -> impl Pass + Clone { chain_at!( Expr, arrow(), duplicate_keys(), - Spread { - helpers: helpers.clone(), - }, + Spread, StickyRegex, - InstanceOf { - helpers: helpers.clone(), - }, - TypeOfSymbol { - helpers: helpers.clone(), - }, - TemplateLiteral { - helpers: helpers.clone(), - }, + InstanceOf, + TypeOfSymbol, + TemplateLiteral, Shorthand, ) } - fn stmts(helpers: &Arc) -> impl Pass + Clone { - chain_at!( - Stmt, - function_name(), - exprs(helpers), - BlockScopedFns, - parameters(), - ) + fn stmts() -> impl Pass + Clone { + chain_at!(Stmt, function_name(), exprs(), BlockScopedFns, parameters(),) } chain_at!( Module, resolver(), - Classes { - helpers: helpers.clone(), - }, - stmts(helpers), + Classes, + stmts(), for_of(), - computed_properties(helpers.clone()), - destructuring(helpers.clone()), + computed_properties(), + destructuring(), block_scoping(), ) } diff --git a/ecmascript/transforms/src/compat/es2015/parameters/tests.rs b/ecmascript/transforms/src/compat/es2015/parameters/tests.rs index 76f71020fe0..19ead5fbb32 100644 --- a/ecmascript/transforms/src/compat/es2015/parameters/tests.rs +++ b/ecmascript/transforms/src/compat/es2015/parameters/tests.rs @@ -1,19 +1,18 @@ use super::*; -use crate::{compat::es2015::Classes, helpers::Helpers}; -use std::sync::Arc; +use crate::compat::es2015::Classes; -fn tr(helpers: Arc) -> impl Fold { +fn tr() -> impl Fold { chain!( crate::compat::es2015::resolver(), Params, - crate::compat::es2015::destructuring(helpers.clone()), + crate::compat::es2015::destructuring(), crate::compat::es2015::block_scoping(), ) } test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), babel_6057_simple, r#"const a = 'bar'; function foo(...a) { @@ -30,7 +29,7 @@ function foo() { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_before_last, r#"function foo(a = "foo", b) {}"#, r#"function foo(param, b) { @@ -40,7 +39,7 @@ test!( test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_destructuring, r#"function required(msg) { throw new Error(msg); @@ -65,7 +64,7 @@ expect(sum({arr:[1,2]})).toBe(3);"# test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_earlier_params, r#"function f(a, b = a, c = b) { return c; } @@ -75,7 +74,7 @@ expect(3).toBe(f(3));"# test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_eval, r#"let x = "outside"; function outer(a = () => eval("x")) { @@ -100,7 +99,7 @@ outer();"# test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_iife_1128, r#"const bar = true; @@ -115,12 +114,7 @@ foo(1, 2, 3);"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| chain!( - Classes { - helpers: helpers.clone() - }, - tr(helpers) - ), + |_| chain!(Classes, tr()), default_iife_4253, r#"class Ref { constructor(id = ++Ref.nextID) { @@ -140,7 +134,7 @@ test_exec!( ignore, ::swc_ecma_parser::Syntax::default(), // Stage0 - |_, helpers| tr(helpers), + |_| tr(), default_iife_4253_exec, r#"class Ref { static nextId = 0 @@ -155,12 +149,7 @@ expect(new Ref().id).toBe(2);"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| chain!( - Classes { - helpers: helpers.clone() - }, - tr(helpers) - ), + |_| chain!(Classes, tr()), default_iife_self, r#"class Ref { constructor(ref = Ref) { @@ -188,7 +177,7 @@ var X = function X(param) { test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_iife_self_exec, r#"class Ref { constructor(ref = Ref) { @@ -200,7 +189,7 @@ expect(new Ref().ref).toBe(Ref);"# ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_multiple, r#"var t = function (e = "foo", f = 5) { return e + " bar " + f; @@ -221,7 +210,7 @@ var a = function(e, param) { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_rest_mix, r#"function fn( a1, @@ -239,7 +228,7 @@ test!( ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_rest_1, r#"const a = 1; function rest(b = a, ...a) { @@ -258,7 +247,7 @@ rest(undefined, 2);"# ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_rest_2, r#"const a = 1; function rest2(b = a, ...a) { @@ -277,7 +266,7 @@ rest2(undefined, 2);"# ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_rest_3, r#"const a = 1; function rest3(b = a, ...a) { @@ -297,7 +286,7 @@ rest3(undefined, 2);"# test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_rest_exec, r#"const a = 1; function rest(b = a, ...a) { @@ -318,7 +307,7 @@ rest3(undefined, 2)"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_setter_noexec, r#"const obj = { set field(num = 1) { @@ -336,7 +325,7 @@ test!( test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_setter_exec, r#"const defaultValue = 1; const obj = { @@ -351,7 +340,7 @@ expect(obj.num).toBe(defaultValue);"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), default_single, r#"var t = function (f = "foo") { return f + " bar"; @@ -364,7 +353,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), destructuring_rest, r#"// #3861 function t(x = "default", { a, b }, ...args) { @@ -384,7 +373,7 @@ function t(param, param1) { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), regression_4333, r#"const args = 'bar'; function foo(...args) { @@ -402,7 +391,7 @@ function foo() { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), regression_4348, r#"function first(...values) { var index = 0; @@ -421,7 +410,7 @@ test!( ignore, ::swc_ecma_parser::Syntax::default(), // type - |_, helpers| tr(helpers), + |_| tr(), regression_4634, r#"let oneOf = (...nodes) => { if (nodes.length === 1) { @@ -444,7 +433,7 @@ let oneOf = function () { ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), regression_5787, r#"function f(a, ...rest) { let b = rest[rest.length - 3]; @@ -475,7 +464,7 @@ function f(a) { test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), regression_5787_exec, r#"function f1(a, ...rest) { let b = rest[rest.length - 3]; @@ -493,7 +482,7 @@ expect(f2(1, 2)).toBeUndefined();"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_args_deoptimiazation, r#"function x (...rest) { arguments; @@ -512,7 +501,7 @@ test!( // Stage 0 ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_arrow_fn, r#"var concat = (...arrs) => { var x = arrs[0]; @@ -614,7 +603,7 @@ var innerclassproperties = function () { test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_async_arrow_fn, r#"var concat = async (...arrs) => { var x = arrs[0]; @@ -659,7 +648,7 @@ function () { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| chain!(crate::compat::es2015::arrow(), tr(helpers)), + |_| chain!(crate::compat::es2015::arrow(), tr()), rest_binding_deoptimisation, r#"const deepAssign = (...args) => args = []; "#, @@ -676,7 +665,7 @@ test!( // optimiation is not implemented ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_deepest_common_ancestor_earliest_child, r#"// single reference function r(...rest){ @@ -871,7 +860,7 @@ function r() { ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_length, r#"var t = function (f, ...items) { items[0]; @@ -902,7 +891,7 @@ function t(f) { test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_length_exec, r#"var length = function (a, b, ...items) { return items.length; @@ -918,7 +907,7 @@ test!( // optimisation is not implemented ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_member_expression_deoptimisation, r#"var t = function (...items) { var x = items[0]; @@ -976,7 +965,7 @@ test!( // optimisation is not implemented ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_member_expression_optimisation, r#"var t = function (...items) { var x = items[0]; @@ -1031,7 +1020,7 @@ function t() { ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_multiple, r#"var t = function (f, ...items) { var x = f; @@ -1084,7 +1073,7 @@ test!( // optimisation is not implemented ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_nested_5656, r#"function a(...args) { const foo = (...list) => bar(...list); @@ -1145,7 +1134,7 @@ function d(thing) { ); test!(::swc_ecma_parser::Syntax::default(), - |_, helpers|chain!(Classes{helpers:helpers.clone()}, tr(helpers), + |_|chain!(Classes, tr(), crate::compat::es2015::Spread::default()), rest_nested_iife, r#"function broken(x, ...foo) { @@ -1175,7 +1164,7 @@ test!(::swc_ecma_parser::Syntax::default(), test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_patterns, r#"function foo(...[a]) {}"#, r#"function foo() { @@ -1188,7 +1177,7 @@ test!( test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_patterns_exec, r#" function foo(...{ length }) { @@ -1202,7 +1191,7 @@ test!( // optimisation is not implemented ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_spread_optimisation, r#"// optimisation diff --git a/ecmascript/transforms/src/compat/es2015/resolver/tests.rs b/ecmascript/transforms/src/compat/es2015/resolver/tests.rs index 83fe53c2411..02c678bfe05 100644 --- a/ecmascript/transforms/src/compat/es2015/resolver/tests.rs +++ b/ecmascript/transforms/src/compat/es2015/resolver/tests.rs @@ -9,7 +9,7 @@ macro_rules! identical { ($name:ident, $src:literal) => { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), $name, $src, $src @@ -57,7 +57,7 @@ fn test_mark_for() { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), basic_no_usage, " let foo; @@ -75,7 +75,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), class_nested_var, " var ConstructorScoping = function ConstructorScoping() { @@ -99,7 +99,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), basic, r#" { @@ -125,7 +125,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), general_assignment_patterns, r#"const foo = "foo"; @@ -147,7 +147,7 @@ function foobar() { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), general_function, r#"function test() { let foo = "bar"; @@ -160,7 +160,7 @@ test!( test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), babel_issue_1051, r#"foo.func1 = function() { if (cond1) { @@ -202,7 +202,7 @@ test!( ignore, ::swc_ecma_parser::Syntax::default(), // TODO(kdy1): WTF is this (again)? - |_, _| tr(), + |_| tr(), babel_issue_2174, r#"if (true) { function foo() {} @@ -226,7 +226,7 @@ if (true) { test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), babel_issue_4363, r#"function WithoutCurlyBraces() { if (true) @@ -295,7 +295,7 @@ test!( // Cannot represent function expression without parens (in result code) ignore, ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), babel_issue_4946, r#"(function foo() { let foo = true; @@ -309,7 +309,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), babel_issue_973, r#"let arr = []; for(let i = 0; i < 10; i++) { @@ -328,7 +328,7 @@ for(var i = 0; i < 10; i++){ test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), pass_assignment, r#"let a = 1; a = 2; @@ -337,7 +337,7 @@ expect(a).toBe(2);"# test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), pass_call, r#"let a = 1; @@ -350,7 +350,7 @@ expect(b()).toBe(2);"# test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), pass_update, r#"let a = 1; a++; @@ -359,7 +359,7 @@ expect(a).toBe(2);"# test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), fn_param, r#"let a = 'foo'; function foo(a) { @@ -373,7 +373,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), fn_body, r#"let a = 'foo'; function foo() { @@ -389,7 +389,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), shorthand, r#"let a = 'foo'; function foo() { @@ -405,7 +405,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), same_level, r#" var a = 'foo'; @@ -419,7 +419,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), class_block, r#" var Foo = function(_Bar) { @@ -441,7 +441,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), class_block_2, r#" var Foo = (function(_Bar) { @@ -463,7 +463,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), class_nested, r#" var Outer = function(_Hello) { diff --git a/ecmascript/transforms/src/compat/es2015/shorthand_property.rs b/ecmascript/transforms/src/compat/es2015/shorthand_property.rs index f3bbf493159..5b9b9c07c44 100644 --- a/ecmascript/transforms/src/compat/es2015/shorthand_property.rs +++ b/ecmascript/transforms/src/compat/es2015/shorthand_property.rs @@ -65,7 +65,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Shorthand, + |_| Shorthand, babel_method_plain, "var obj = { method() { @@ -81,7 +81,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Shorthand, + |_| Shorthand, babel_comments, "var A = 'a'; var o = { @@ -96,7 +96,7 @@ var o = { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Shorthand, + |_| Shorthand, babel_mixed, "var coords = { x, y, foo: 'bar' };", "var coords = { @@ -108,7 +108,7 @@ var o = { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Shorthand, + |_| Shorthand, babel_multiple, "var coords = { x, y };", "var coords = { @@ -119,7 +119,7 @@ var o = { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Shorthand, + |_| Shorthand, babel_single, "var coords = { x };", "var coords = { diff --git a/ecmascript/transforms/src/compat/es2015/spread.rs b/ecmascript/transforms/src/compat/es2015/spread.rs index 4f212148062..8d434e81d87 100644 --- a/ecmascript/transforms/src/compat/es2015/spread.rs +++ b/ecmascript/transforms/src/compat/es2015/spread.rs @@ -1,13 +1,11 @@ -use crate::{helpers::Helpers, util::ExprFactory}; +use crate::util::ExprFactory; use ast::*; -use std::{iter, mem, sync::Arc}; +use std::{iter, mem}; use swc_common::{Fold, FoldWith, Span, DUMMY_SP}; /// es2015 - `SpreadElement` #[derive(Default, Clone)] -pub struct Spread { - pub helpers: Arc, -} +pub struct Spread; impl Fold for Spread { fn fold(&mut self, e: Expr) -> Expr { @@ -24,7 +22,7 @@ impl Fold for Spread { return Expr::Array(ArrayLit { span, elems }); } - let args_array = concat_args(&self.helpers, span, elems.into_iter()); + let args_array = concat_args(span, elems.into_iter()); return args_array; } @@ -45,7 +43,7 @@ impl Fold for Spread { type_args, }); } - let args_array = concat_args(&self.helpers, span, args.into_iter().map(Some)); + let args_array = concat_args(span, args.into_iter().map(Some)); // // f.apply(undefined, args) // @@ -74,7 +72,6 @@ impl Fold for Spread { } let args = concat_args( - &self.helpers, span, iter::once(quote_expr!(span, null).as_arg()) .chain(args) @@ -101,11 +98,7 @@ impl Fold for Spread { } } -fn concat_args( - helpers: &Helpers, - span: Span, - args: impl Iterator>, -) -> Expr { +fn concat_args(span: Span, args: impl Iterator>) -> Expr { // // [] // @@ -140,7 +133,7 @@ fn concat_args( // make_arr!(); - helpers.to_consumable_array(); + helper!(to_consumable_array); buf.push( Expr::Call(CallExpr { @@ -190,7 +183,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| Spread { helpers }, + |_| Spread, call, "ca(a, b, c, ...d, e)", "ca.apply(undefined, [a, b, c].concat(_toConsumableArray(d), [e]));" @@ -198,7 +191,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| Spread { helpers }, + |_| Spread, call_multi_spread, "ca(a, b, ...d, e, f, ...h)", "ca.apply(undefined, [a, b].concat(_toConsumableArray(d), [e, f], _toConsumableArray(h)));" @@ -206,7 +199,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| Spread { helpers }, + |_| Spread, call_noop, "ca(a, b, c, d, e)", "ca(a, b, c, d, e);" @@ -214,7 +207,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| Spread { helpers }, + |_| Spread, array, "[a, b, c, ...d, e]", "[a, b, c].concat(_toConsumableArray(d), [e])" @@ -222,7 +215,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| Spread { helpers }, + |_| Spread, array_empty, "[a,, b, c, ...d,,, e]", "[a,, b, c].concat(_toConsumableArray(d), [,, e])" @@ -230,7 +223,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| Spread { helpers }, + |_| Spread, new, "new C(a, b, c, ...d, e)", "new Function.prototype.bind.apply(C, [null, a, b, c].concat(_toConsumableArray(d), \ @@ -240,7 +233,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| Spread { helpers }, + |_| Spread, new_noop, "new C(a, b, c, c, d, e)", "new C(a, b, c, c, d, e);" diff --git a/ecmascript/transforms/src/compat/es2015/sticky_regex.rs b/ecmascript/transforms/src/compat/es2015/sticky_regex.rs index affd02d1a0e..f397d368f84 100644 --- a/ecmascript/transforms/src/compat/es2015/sticky_regex.rs +++ b/ecmascript/transforms/src/compat/es2015/sticky_regex.rs @@ -59,7 +59,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| StickyRegex, + |_| StickyRegex, babel_basic, "var re = /o+/y;", "var re = new RegExp('o+', 'y');" @@ -67,7 +67,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| StickyRegex, + |_| StickyRegex, babel_ignore_non_sticky, "var re = /o+/;", "var re = /o+/;" diff --git a/ecmascript/transforms/src/compat/es2015/template_literal/mod.rs b/ecmascript/transforms/src/compat/es2015/template_literal/mod.rs index c4e6ec96d67..b26dbc35813 100644 --- a/ecmascript/transforms/src/compat/es2015/template_literal/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/template_literal/mod.rs @@ -1,14 +1,12 @@ -use crate::{helpers::Helpers, util::ExprFactory}; +use crate::util::ExprFactory; use ast::*; -use std::{iter, sync::Arc}; +use std::iter; use swc_common::{Fold, FoldWith, Spanned, DUMMY_SP}; #[cfg(test)] mod tests; #[derive(Default, Clone)] -pub struct TemplateLiteral { - pub helpers: Arc, -} +pub struct TemplateLiteral; impl Fold for TemplateLiteral { fn fold(&mut self, e: Expr) -> Expr { @@ -68,7 +66,7 @@ impl Fold for TemplateLiteral { tag, exprs, quasis, .. }) => { assert!(quasis.len() == exprs.len() + 1); - self.helpers.tagged_template_literal(); + helper!(tagged_template_literal); let fn_ident = private_ident!("_templateObject"); diff --git a/ecmascript/transforms/src/compat/es2015/template_literal/tests.rs b/ecmascript/transforms/src/compat/es2015/template_literal/tests.rs index dfb4c074626..1902cdd23d7 100644 --- a/ecmascript/transforms/src/compat/es2015/template_literal/tests.rs +++ b/ecmascript/transforms/src/compat/es2015/template_literal/tests.rs @@ -2,7 +2,7 @@ use super::*; test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, escape_quotes, r#"var t = `'${foo}' "${bar}"`;"#, r#"var t = "'" + foo + '\' "' + bar + '"';"#, @@ -11,7 +11,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, expr_first, r#"var foo = 5; var bar = 10; @@ -35,7 +35,7 @@ var example5 = '' + '';"#, test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, functions, r#"var foo = `test ${_.test(foo)} ${bar}`;"#, r#"var foo = 'test ' + _.test(foo) + ' ' + bar;"# @@ -43,7 +43,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, literals, r#"var foo = `${1}${f}oo${true}${b}ar${0}${baz}`;"#, r#"var foo = '' + 1 + f + 'oo' + true + b + 'ar' + 0 + baz;"# @@ -51,7 +51,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, multiline, r#"var o = `wow this is @@ -62,7 +62,7 @@ actually multiline!`;"#, test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, multiple, r#"var foo = `test ${foo} ${bar}`;"#, r#"var foo = 'test ' + foo + ' ' + bar;"# @@ -70,7 +70,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, none, r#"var foo = `test`;"#, r#"var foo = "test";"# @@ -78,7 +78,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, only, r#"var foo = `${test}`;"#, r#"var foo = '' + test"# @@ -86,7 +86,7 @@ test!( test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, order, r#" const calls = []; @@ -115,7 +115,7 @@ expect(calls).toEqual([1, 2, 3, 4]);"# test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, order2, r#"const calls = []; @@ -140,7 +140,7 @@ expect(calls).toEqual([1, 2]);"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, simple_tag, r#"var foo = tag`wow`; var bar = tag`first${1}second`;"#, @@ -163,7 +163,7 @@ var bar = tag(function _templateObject1() { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, single, r#"var foo = `test ${foo}`;"#, r#"var foo = 'test ' + foo;"# @@ -171,7 +171,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, statement, r#"var foo = `test ${foo + bar}`;"#, r#"var foo = 'test ' + foo + bar;"#, @@ -180,7 +180,7 @@ test!( test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, symbol, r#"const fn = () => `${Symbol()}`; @@ -189,7 +189,7 @@ expect(fn).toThrow(TypeError);"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, tag, r#" var foo = bar`wow\na${ 42 }b ${_.foobar()}`; @@ -224,7 +224,7 @@ var bar = bar(function _templateObject2() { test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| TemplateLiteral { helpers }, + |_| TemplateLiteral, template_revision, r#"tag`\unicode and \u{55}`; tag`\01`; diff --git a/ecmascript/transforms/src/compat/es2015/typeof_symbol.rs b/ecmascript/transforms/src/compat/es2015/typeof_symbol.rs index 3aaef390c0b..6a5e7efc75f 100644 --- a/ecmascript/transforms/src/compat/es2015/typeof_symbol.rs +++ b/ecmascript/transforms/src/compat/es2015/typeof_symbol.rs @@ -1,6 +1,5 @@ -use crate::{helpers::Helpers, util::ExprFactory}; +use crate::util::ExprFactory; use ast::*; -use std::sync::Arc; use swc_common::{Fold, FoldWith, Visit, VisitWith}; /// `@babel/plugin-transform-typeof-symbol` @@ -21,9 +20,7 @@ use swc_common::{Fold, FoldWith, Visit, VisitWith}; /// _typeof(Symbol()) === "symbol"; /// ``` #[derive(Clone)] -pub struct TypeOfSymbol { - pub helpers: Arc, -} +pub struct TypeOfSymbol; impl Fold for TypeOfSymbol { fn fold(&mut self, expr: Expr) -> Expr { @@ -55,7 +52,7 @@ impl Fold for TypeOfSymbol { op: op!("typeof"), arg, }) => { - self.helpers.type_of(); + helper!(type_of); return Expr::Call(CallExpr { span, callee: quote_ident!(span, "_typeof").as_callee(), diff --git a/ecmascript/transforms/src/compat/es2016/exponentation.rs b/ecmascript/transforms/src/compat/es2016/exponentation.rs index 6fea6e2d3c0..ee5182825d4 100644 --- a/ecmascript/transforms/src/compat/es2016/exponentation.rs +++ b/ecmascript/transforms/src/compat/es2016/exponentation.rs @@ -172,7 +172,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Exponentation, + |_| Exponentation, babel_binary, "2 ** 2", "Math.pow(2, 2)" @@ -181,7 +181,7 @@ mod tests { test_exec!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, _| Exponentation, + |_| Exponentation, babel_comprehensive, r#"expect(2 ** 3).toBe(8); expect(3 * 2 ** 3).toBe(24); @@ -210,7 +210,7 @@ expect(2 ** 3 ** 2).toBe(512);"# // FIXME ignore, ::swc_ecma_parser::Syntax::default(), - |_, _| Exponentation, + |_| Exponentation, babel_memoize_object, r#"var counters = 0; Object.defineProperty(global, "reader", { @@ -226,7 +226,7 @@ expect(counters).toBe(1);"# test!( ::swc_ecma_parser::Syntax::default(), - |_, _| Exponentation, + |_| Exponentation, assign, r#"x **= 3"#, r#"x = Math.pow(x, 3)"#, @@ -234,7 +234,7 @@ expect(counters).toBe(1);"# ); // test!(::swc_ecma_parser::Syntax::default(), - // |_, _| Exponentation, + // |_| Exponentation, // babel_4403, // "var a, b; // a[`${b++}`] **= 1;", diff --git a/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs b/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs index 076fc2975bc..77da678e47e 100644 --- a/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs +++ b/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs @@ -1,10 +1,9 @@ use crate::{ - helpers::Helpers, pass::Pass, util::{contains_this_expr, ExprFactory, StmtLike}, }; use ast::*; -use std::{iter, sync::Arc}; +use std::iter; use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP}; #[cfg(test)] @@ -30,16 +29,13 @@ mod tests; /// yield bar(); /// }); /// ``` -pub fn async_to_generator(helpers: Arc) -> impl Pass + Clone { - AsyncToGenerator { helpers } +pub fn async_to_generator() -> impl Pass + Clone { + AsyncToGenerator } #[derive(Default, Clone)] -struct AsyncToGenerator { - helpers: Arc, -} +struct AsyncToGenerator; struct Actual { - helpers: Arc, extra_stmts: Vec, } @@ -61,7 +57,6 @@ where Err(module_item) => buf.push(module_item), Ok(stmt) => { let mut actual = Actual { - helpers: self.helpers.clone(), extra_stmts: vec![], }; let stmt = stmt.fold_with(&mut actual); @@ -84,16 +79,13 @@ impl Fold for Actual { } let params = prop.function.params; - let fn_ref = make_fn_ref( - &self.helpers, - FnExpr { - ident: None, - function: Function { - params: vec![], - ..prop.function - }, + let fn_ref = make_fn_ref(FnExpr { + ident: None, + function: Function { + params: vec![], + ..prop.function }, - ); + }); let fn_ref = Expr::Call(CallExpr { span: DUMMY_SP, callee: fn_ref.as_callee(), @@ -348,13 +340,10 @@ impl Fold for Actual { let mut folder = MethodFolder { vars: vec![] }; let function = m.function.fold_children(&mut folder); - let expr = make_fn_ref( - &self.helpers, - FnExpr { - ident: None, - function, - }, - ); + let expr = make_fn_ref(FnExpr { + ident: None, + function, + }); let hoisted_super = if folder.vars.is_empty() { None @@ -416,7 +405,7 @@ impl Fold for Actual { }); } - return make_fn_ref(&self.helpers, fn_expr); + return make_fn_ref(fn_expr); } _ => {} } @@ -488,13 +477,10 @@ impl Actual { let ident = raw_ident.clone().unwrap_or_else(|| quote_ident!("ref")); let real_fn_ident = private_ident!(ident.span, format!("_{}", ident.sym)); - let right = make_fn_ref( - &self.helpers, - FnExpr { - ident: None, - function: f, - }, - ); + let right = make_fn_ref(FnExpr { + ident: None, + function: f, + }); if is_decl { let real_fn = FnDecl { @@ -593,7 +579,7 @@ impl Actual { /// Creates /// /// `_asyncToGenerator(function*() {})` from `async function() {}`; -fn make_fn_ref(helpers: &Helpers, mut expr: FnExpr) -> Expr { +fn make_fn_ref(mut expr: FnExpr) -> Expr { struct AwaitToYield; impl Fold for AwaitToYield { @@ -625,7 +611,7 @@ fn make_fn_ref(helpers: &Helpers, mut expr: FnExpr) -> Expr { expr.function.is_generator = true; let span = expr.span(); - helpers.async_to_generator(); + helper!(async_to_generator); let contains_this = contains_this_expr(&expr.function.body); let expr = if contains_this { diff --git a/ecmascript/transforms/src/compat/es2017/async_to_generator/tests.rs b/ecmascript/transforms/src/compat/es2017/async_to_generator/tests.rs index b7f5592f87c..52d32129769 100644 --- a/ecmascript/transforms/src/compat/es2017/async_to_generator/tests.rs +++ b/ecmascript/transforms/src/compat/es2017/async_to_generator/tests.rs @@ -15,23 +15,21 @@ impl Fold for ParenRemover { } } -fn tr(helpers: Arc) -> impl Fold { +fn tr() -> impl Fold { chain!( ParenRemover, arrow(), parameters(), - destructuring(helpers.clone()), + destructuring(), function_name(), - AsyncToGenerator { - helpers: helpers.clone() - }, + AsyncToGenerator {}, fixer() ) } test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), async_arrow_in_method, r#" let TestClass = { @@ -64,7 +62,7 @@ let TestClass = { ); test!(::swc_ecma_parser::Syntax::default(), - |_,helpers|tr(helpers), + |_|tr(), async_default_arguments, r#" function mandatory(paramName) { @@ -94,7 +92,7 @@ function foo(param) { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), async_iife, r#" (async function() { await 'ok' })(); @@ -133,7 +131,7 @@ _asyncToGenerator(function*() { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), async, r#" class Foo { @@ -155,7 +153,7 @@ class Foo { ); test!(::swc_ecma_parser::Syntax::default(), - |_,helpers|tr(helpers), + |_|tr(), deeply_nested_asyncs, r#" async function s(x, ...args) { @@ -217,7 +215,7 @@ function s(x) { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), expression, r#" var foo = async function () { @@ -263,7 +261,7 @@ var foo2 = function () { ); test!(::swc_ecma_parser::Syntax::default(), - |_,helpers|tr(helpers), + |_|tr(), function_arity, r#" async function one(a, b = 1) {} @@ -339,7 +337,7 @@ function six(a, param) { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), named_expression, r#" var foo = async function bar() { @@ -360,7 +358,7 @@ var foo = function() { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), no_parameters_and_no_id, r#" foo(async function () { @@ -378,7 +376,7 @@ foo(function() { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), object_method_with_arrows, r#" class Class { @@ -453,7 +451,7 @@ class Class{ ); test!(::swc_ecma_parser::Syntax::default(), - |_,helpers|tr(helpers), + |_|tr(), object_method_with_super, r#"class Foo extends class {} { async method() { @@ -480,7 +478,7 @@ class Foo extends class{ test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), class_method_this, r#" class Foo { @@ -499,7 +497,7 @@ return foo.foo().then(cur => { test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), class_method_super, r#" class Foo { @@ -523,7 +521,7 @@ return bar.bar().then(cur => { test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), class_getter_super, r#" let called = false; @@ -549,7 +547,7 @@ return bar.bar().then(foo => { test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), class_setter_super, r#" let called = false; @@ -576,7 +574,7 @@ return bar.bar().then(bar => { test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), class_method_this_complex, r#" class Class { @@ -609,7 +607,7 @@ return c.method(); test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), object_method, r#" let obj = { @@ -633,7 +631,7 @@ let obj = { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), babel_parameters, r#" async function foo(bar) { @@ -653,7 +651,7 @@ function foo(bar) { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), statement, r#" async function foo() { diff --git a/ecmascript/transforms/src/compat/es2017/mod.rs b/ecmascript/transforms/src/compat/es2017/mod.rs index cc2cd06b8e6..a3832abd748 100644 --- a/ecmascript/transforms/src/compat/es2017/mod.rs +++ b/ecmascript/transforms/src/compat/es2017/mod.rs @@ -1,9 +1,8 @@ pub use self::async_to_generator::async_to_generator; -use crate::{helpers::Helpers, pass::Pass}; -use std::sync::Arc; +use crate::pass::Pass; mod async_to_generator; -pub fn es2017(helpers: &Arc) -> impl Pass + Clone { - async_to_generator(helpers.clone()) +pub fn es2017() -> impl Pass + Clone { + async_to_generator() } diff --git a/ecmascript/transforms/src/compat/es2018/mod.rs b/ecmascript/transforms/src/compat/es2018/mod.rs index 8f1b7010fa7..209ea8c0e11 100644 --- a/ecmascript/transforms/src/compat/es2018/mod.rs +++ b/ecmascript/transforms/src/compat/es2018/mod.rs @@ -1,10 +1,9 @@ pub use self::object_rest_spread::object_rest_spread; -use crate::{helpers::Helpers, pass::Pass}; -use std::sync::Arc; +use crate::pass::Pass; mod object_rest_spread; -pub fn es2018(helpers: &Arc) -> impl Pass + Clone { - object_rest_spread(helpers.clone()) +pub fn es2018() -> impl Pass + Clone { + object_rest_spread() } diff --git a/ecmascript/transforms/src/compat/es2018/object_rest_spread/mod.rs b/ecmascript/transforms/src/compat/es2018/object_rest_spread/mod.rs index fb780e6ac5c..6d40dda6817 100644 --- a/ecmascript/transforms/src/compat/es2018/object_rest_spread/mod.rs +++ b/ecmascript/transforms/src/compat/es2018/object_rest_spread/mod.rs @@ -1,10 +1,9 @@ use crate::{ - helpers::Helpers, pass::Pass, util::{alias_ident_for, ExprFactory, StmtLike}, }; use ast::*; -use std::{iter, mem, sync::Arc}; +use std::{iter, mem}; use swc_common::{ util::move_map::MoveMap, Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP, }; @@ -13,22 +12,14 @@ use swc_common::{ mod tests; /// `@babel/plugin-proposal-object-rest-spread` -pub fn object_rest_spread(helpers: Arc) -> impl Pass + Clone { - chain!( - ObjectRest { - helpers: helpers.clone(), - }, - ObjectSpread { helpers } - ) +pub fn object_rest_spread() -> impl Pass + Clone { + chain!(ObjectRest, ObjectSpread) } #[derive(Clone)] -struct ObjectRest { - helpers: Arc, -} +struct ObjectRest; struct RestFolder { - helpers: Arc, /// Injected before the original statement. vars: Vec, /// Variables which should ceclaraed using `var` @@ -376,7 +367,6 @@ where for stmt in stmts { let mut folder = RestFolder { - helpers: self.helpers.clone(), vars: vec![], mutable_vars: vec![], exprs: vec![], @@ -761,18 +751,14 @@ impl RestFolder { span: DUMMY_SP, left: PatOrExpr::Pat(last.arg), op: op!("="), - right: box object_without_properties(&self.helpers, obj.clone(), excluded_props), + right: box object_without_properties(obj.clone(), excluded_props), })); } else { // println!("Var: rest = objectWithoutProperties()",); self.push_var_if_not_empty(VarDeclarator { span: DUMMY_SP, name: *last.arg, - init: Some(box object_without_properties( - &self.helpers, - obj.clone(), - excluded_props, - )), + init: Some(box object_without_properties(obj.clone(), excluded_props)), definite: false, }); } @@ -785,13 +771,9 @@ impl RestFolder { } } -fn object_without_properties( - helpers: &Helpers, - obj: Box, - excluded_props: Vec>, -) -> Expr { +fn object_without_properties(obj: Box, excluded_props: Vec>) -> Expr { if excluded_props.is_empty() { - helpers.extends(); + helper!(extends); return Expr::Call(CallExpr { span: DUMMY_SP, @@ -808,7 +790,7 @@ fn object_without_properties( }); } - helpers.object_without_properties(); + helper!(object_without_properties); Expr::Call(CallExpr { span: DUMMY_SP, @@ -888,9 +870,7 @@ fn simplify_pat(pat: Pat) -> Pat { } #[derive(Clone)] -struct ObjectSpread { - helpers: Arc, -} +struct ObjectSpread; impl Fold for ObjectSpread { fn fold(&mut self, expr: Expr) -> Expr { @@ -952,8 +932,8 @@ impl Fold for ObjectSpread { buf }; - self.helpers.define_property(); - self.helpers.object_spread(); + helper!(define_property); + helper!(object_spread); Expr::Call(CallExpr { span, callee: quote_ident!("_objectSpread").as_callee(), diff --git a/ecmascript/transforms/src/compat/es2018/object_rest_spread/tests.rs b/ecmascript/transforms/src/compat/es2018/object_rest_spread/tests.rs index b857f5a3bb2..e9ac529f6b0 100644 --- a/ecmascript/transforms/src/compat/es2018/object_rest_spread/tests.rs +++ b/ecmascript/transforms/src/compat/es2018/object_rest_spread/tests.rs @@ -1,16 +1,15 @@ use super::object_rest_spread; -use crate::{compat::es2015::Spread, helpers::Helpers}; +use crate::compat::es2015::Spread; use ast::Module; -use std::sync::Arc; use swc_common::Fold; -fn tr(helpers: Arc) -> impl Fold { - object_rest_spread(helpers.clone()) +fn tr() -> impl Fold { + object_rest_spread() } test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_function_array, r#" function foo([{...bar}]) { @@ -26,7 +25,7 @@ function foo([_param]) { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_var_basic, r#" var { a , ...b } = _ref; @@ -38,7 +37,7 @@ var { a } = _ref, b = _objectWithoutProperties(_ref, ['a']); test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_assignment_exec, r#" let foo = { @@ -54,7 +53,7 @@ expect(c).toEqual({b: 2}); test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_catch_exec, r#" try { @@ -76,7 +75,7 @@ try { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_assignment_expression, r#"({ a1 } = c1); ({ a2, ...b2 } = c2); @@ -93,7 +92,7 @@ console.log(( _c3 = c3, b3 = _objectWithoutProperties(_c3, ['a3']), { a3 } = _c test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_catch_clause, r#" try {} catch({ ...a34 }) {} @@ -135,7 +134,7 @@ try{ test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_export, r#" // ExportNamedDeclaration @@ -162,12 +161,7 @@ export var [dd, ee] = ads; test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| chain!( - tr(helpers.clone()), - Spread { - helpers: helpers.clone() - } - ), + |_| chain!(tr(), Spread {}), rest_for_x, r#" // ForXStatement @@ -243,7 +237,7 @@ async function a() { test_exec!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_impure_computed_exec, r#" var key, x, y, z; @@ -273,7 +267,7 @@ expect(z).toBe("zee"); test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_impure_computed, r#" var key, x, y, z; @@ -354,7 +348,7 @@ expect(z).toBe("zee");"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_nested_2, r#" const test = { @@ -403,7 +397,7 @@ const { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_nested_computed_key, r#" const { @@ -430,7 +424,7 @@ const _ref = { test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_nested_default_value_exec, r#" const { @@ -448,7 +442,7 @@ expect(d).toEqual({}) test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_nested_default_value, r#" const { @@ -475,7 +469,7 @@ const _ref = { test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_nested_order_exec, r#" var result = ""; @@ -502,20 +496,22 @@ expect(result).toBe("barbazfoo"); "# ); -test!(::swc_ecma_parser::Syntax::default(), - |_,helpers|tr(helpers), - rest_nested_order, - r#" +test!( + ::swc_ecma_parser::Syntax::default(), + |_| tr(), + rest_nested_order, + r#" const { a: { ...bar }, b: { ...baz }, ...foo } = obj; "#, - r#" -const bar = _extends({}, obj.a), baz = _extends({}, obj.b), foo = _objectWithoutProperties(obj, ['a', 'b']); + r#" +const bar = _extends({}, obj.a), baz = _extends({}, obj.b), foo = + _objectWithoutProperties(obj, ['a', 'b']); "# ); test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_nested_1, r#" const defunct = { @@ -552,7 +548,7 @@ const { test_exec!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_non_string_computed_exec, r#" const a = { @@ -615,7 +611,7 @@ expect(dy).toBe("sy"); test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_non_string_computed, r#" const a = { @@ -729,7 +725,7 @@ expect(dy).toBe("sy");"# test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_parameters, r#" function a({ ...a34 }) {} @@ -824,7 +820,7 @@ function b3({ test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_symbol_exec, r#" const sym = Symbol("test"); @@ -852,7 +848,7 @@ expect(Object.getOwnPropertySymbols(noSym)).toEqual([]);"# test!( ignore, ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_symbol, r#" let { @@ -893,7 +889,7 @@ if (_ref3 = {}, _Symbol$for3 = Symbol.for("foo"), ({ test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_variable_destructuring_1, r#" var z = {}; @@ -948,7 +944,7 @@ const { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_variable_destructuring_2, r#" let { @@ -972,7 +968,7 @@ let { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_variable_destructuring_3, r#" let { x4: { ...y4 } } = z; @@ -984,7 +980,7 @@ let y4 = _extends({}, z.x4); test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_with_array_rest_exec, r#" let [{ a, ...foo}, ...bar] = [{ a: 1, b:2 }, 2, 3, 4]; @@ -996,7 +992,7 @@ expect(bar).toEqual([2, 3, 4]); test_exec!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_with_array_rest_exec_2, r#" let { @@ -1016,7 +1012,7 @@ expect(objectRest).toEqual({d: 'oyez'}) test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), rest_with_array_rest, r#" let { @@ -1038,7 +1034,7 @@ let _ref = { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), spread_assignment, r#" z = { x, ...y }; @@ -1058,7 +1054,7 @@ z = { test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), spread_expression, r#" ({ x, ...y, a, ...b, c }); @@ -1093,8 +1089,9 @@ _objectSpread({}, { "# ); -test_exec!(::swc_ecma_parser::Syntax::default(), - |_,helpers|tr(helpers), +test_exec!( + ::swc_ecma_parser::Syntax::default(), + |_| tr(), spread_no_object_assign_exec, r#" Object.defineProperty(Object.prototype, 'NOSET', { @@ -1115,7 +1112,8 @@ const objSpread = { ...obj }; const obj2 = { NOSET: 123, NOWRITE: 456 }; // this line would throw `TypeError: Cannot assign to read only property 'NOWRITE'` -// if transformed as Object.assign (or equivalent) because those use *assignment* for creating properties +// if transformed as Object.assign (or equivalent) because +// those use *assignment* for creating properties // (spread defines them) const obj2Spread = { ...obj2 }; @@ -1142,7 +1140,7 @@ expect(Array.isArray(Object.getPrototypeOf(o2))).toBe(false); test!( ::swc_ecma_parser::Syntax::default(), - |_, helpers| tr(helpers), + |_| tr(), spread_variable_declaration, r#"var z = { ...x };"#, r#"var z = _objectSpread({}, x);"# diff --git a/ecmascript/transforms/src/compat/es3/member_expr_lits.rs b/ecmascript/transforms/src/compat/es3/member_expr_lits.rs index 4351f8caf44..6582310e6e6 100644 --- a/ecmascript/transforms/src/compat/es3/member_expr_lits.rs +++ b/ecmascript/transforms/src/compat/es3/member_expr_lits.rs @@ -61,7 +61,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| MemberExprLit, + |_| MemberExprLit, basic, r#"obj["foo"] = "isValid"; diff --git a/ecmascript/transforms/src/compat/es3/prop_lits.rs b/ecmascript/transforms/src/compat/es3/prop_lits.rs index b0b005f0391..71b571d14ed 100644 --- a/ecmascript/transforms/src/compat/es3/prop_lits.rs +++ b/ecmascript/transforms/src/compat/es3/prop_lits.rs @@ -72,7 +72,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| PropertyLiteral, + |_| PropertyLiteral, babel_basic, r#"var foo = { // changed diff --git a/ecmascript/transforms/src/compat/es3/reserved_word.rs b/ecmascript/transforms/src/compat/es3/reserved_word.rs index 1084b1cc4a6..42bb9fbb69d 100644 --- a/ecmascript/transforms/src/compat/es3/reserved_word.rs +++ b/ecmascript/transforms/src/compat/es3/reserved_word.rs @@ -91,7 +91,7 @@ mod tests { ($name:ident, $src:literal) => { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| ReservedWord, + |_| ReservedWord, $name, $src, $src @@ -101,7 +101,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| ReservedWord, + |_| ReservedWord, babel_issue_6477, r#" function utf8CheckByte(byte) { diff --git a/ecmascript/transforms/src/fixer.rs b/ecmascript/transforms/src/fixer.rs index ef4a776e1a0..06915944058 100644 --- a/ecmascript/transforms/src/fixer.rs +++ b/ecmascript/transforms/src/fixer.rs @@ -371,7 +371,7 @@ mod tests { macro_rules! test_fixer { ($name:ident, $from:literal, $to:literal) => { // We use noop because fixer is invoked by tests::apply_transform. - test!(Default::default(), |_, _| Noop, $name, $from, $to); + test!(Default::default(), |_| Noop, $name, $from, $to); }; } diff --git a/ecmascript/transforms/src/helpers/mod.rs b/ecmascript/transforms/src/helpers/mod.rs index 6a095beb23a..d11755829fe 100644 --- a/ecmascript/transforms/src/helpers/mod.rs +++ b/ecmascript/transforms/src/helpers/mod.rs @@ -1,8 +1,6 @@ use ast::*; -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, -}; +use scoped_tls::scoped_thread_local; +use std::sync::atomic::{AtomicBool, Ordering}; use swc_common::{ errors::{ColorConfig, Handler}, sync::Lrc, @@ -17,8 +15,15 @@ lazy_static! { static ref SESSION: Session<'static> = { Session { handler: &*HANDLER } }; } +#[macro_export] +macro_rules! helper { + ($i:ident) => {{ + $crate::helpers::HELPERS.with(|helpers| helpers.$i()); + }}; +} + macro_rules! add_to { - ($buf:expr, $name:tt, $b:expr) => {{ + ($buf:expr, $name:ident, $b:expr) => {{ lazy_static! { static ref STMTS: Vec = { let code = include_str!(concat!("_", stringify!($name), ".js")); @@ -44,22 +49,30 @@ macro_rules! add_to { }}; } +scoped_thread_local!(pub static HELPERS: Helpers); + +/// Tracks used helper methods. (e.g. __extends) +#[derive(Default)] +pub struct Helpers { + inner: Inner, +} + macro_rules! define_helpers { ( Helpers { $( $name:ident : ( $( $dep:ident ),* ), )* } ) => { - /// Tracks used helper methods. (e.g. __extends) #[derive(Default)] - pub struct Helpers { + struct Inner { $( $name: AtomicBool, )* } impl Helpers { $( pub fn $name(&self) { - self.$name.store(true, Ordering::Relaxed); + self.inner.$name.store(true, Ordering::Relaxed); + $( self.$dep(); )* @@ -71,34 +84,18 @@ macro_rules! define_helpers { fn mk_helpers(&self) -> Vec{ let mut buf = vec![]; - $( - add_to!(buf, $name, self.helpers.$name); - )* - + HELPERS.with(|helpers|{ + $( + add_to!(buf, $name, helpers.inner.$name); + )* + }); buf } } - - impl Fold for HelperResetter { - fn fold(&mut self, module:Module)->Module{ - $( - self.helpers.$name.store(false, Ordering::Relaxed); - )* - - module - } - } }; } -/// Disables all helpers. -/// Used to reset list of injected helpers. -#[derive(Clone)] -pub struct HelperResetter { - pub helpers: Arc, -} - define_helpers!(Helpers { apply_decorated_descriptor: (), array_with_holes: (), @@ -181,7 +178,6 @@ define_helpers!(Helpers { #[derive(Clone)] pub struct InjectHelpers { pub cm: Lrc, - pub helpers: Arc, } impl Fold for InjectHelpers { diff --git a/ecmascript/transforms/src/inline_globals.rs b/ecmascript/transforms/src/inline_globals.rs index e9607e39fa6..66b99809e0e 100644 --- a/ecmascript/transforms/src/inline_globals.rs +++ b/ecmascript/transforms/src/inline_globals.rs @@ -114,7 +114,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |tester, _| InlineGlobals { + |tester| InlineGlobals { envs: envs(tester, &[("NODE_ENV", "development")]), globals: globals(tester, &[]), }, @@ -125,7 +125,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |tester, _| InlineGlobals { + |tester| InlineGlobals { envs: envs(tester, &[]), globals: globals(tester, &[("__DEBUG__", "true")]), }, @@ -136,7 +136,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |tester, _| InlineGlobals { + |tester| InlineGlobals { envs: envs(tester, &[]), globals: globals(tester, &[("debug", "true")]), }, diff --git a/ecmascript/transforms/src/lib.rs b/ecmascript/transforms/src/lib.rs index f2246ee50af..604336bc505 100644 --- a/ecmascript/transforms/src/lib.rs +++ b/ecmascript/transforms/src/lib.rs @@ -18,6 +18,7 @@ extern crate fxhash; extern crate indexmap; extern crate inflector; extern crate ordered_float; +extern crate scoped_tls; extern crate swc_ecma_ast as ast; #[cfg(test)] extern crate swc_ecma_codegen; @@ -46,6 +47,8 @@ pub use self::{ #[macro_use] mod tests; #[macro_use] +pub mod helpers; +#[macro_use] mod quote; #[macro_use] mod macros; @@ -53,7 +56,6 @@ mod macros; mod hygiene; pub mod compat; mod fixer; -pub mod helpers; mod inline_globals; pub mod modules; pub mod pass; diff --git a/ecmascript/transforms/src/modules/common_js/mod.rs b/ecmascript/transforms/src/modules/common_js/mod.rs index be829cbc8c9..76d0a7947f2 100644 --- a/ecmascript/transforms/src/modules/common_js/mod.rs +++ b/ecmascript/transforms/src/modules/common_js/mod.rs @@ -3,14 +3,13 @@ use super::util::{ use_strict, Scope, VarCollector, }; use crate::{ - helpers::Helpers, pass::Pass, util::{undefined, DestructuringFinder, ExprFactory, State}, }; use ast::*; use fxhash::FxHashSet; use serde::{Deserialize, Serialize}; -use std::{collections::hash_map::Entry, iter, sync::Arc}; +use std::{collections::hash_map::Entry, iter}; use swc_atoms::JsWord; use swc_common::{Fold, FoldWith, VisitWith, DUMMY_SP}; @@ -67,9 +66,8 @@ impl Default for Lazy { } } -pub fn common_js(helpers: Arc, config: Config) -> impl Pass + Clone { +pub fn common_js(config: Config) -> impl Pass + Clone { CommonJs { - helpers, config, scope: Default::default(), in_top_level: Default::default(), @@ -78,7 +76,6 @@ pub fn common_js(helpers: Arc, config: Config) -> impl Pass + Clone { #[derive(Clone)] struct CommonJs { - helpers: Arc, config: Config, scope: State, in_top_level: State, @@ -522,7 +519,7 @@ impl Fold> for CommonJs { let rhs = match ty { Some(true) if !self.config.no_interop => { - self.helpers.interop_require_wildcard(); + helper!(interop_require_wildcard); box Expr::Call(CallExpr { span: DUMMY_SP, callee: quote_ident!("_interopRequireWildcard").as_callee(), @@ -531,7 +528,7 @@ impl Fold> for CommonJs { }) } Some(false) if !self.config.no_interop => { - self.helpers.interop_require_default(); + helper!(interop_require_default); box Expr::Call(CallExpr { span: DUMMY_SP, callee: quote_ident!("_interopRequireDefault").as_callee(), diff --git a/ecmascript/transforms/src/modules/common_js/tests.rs b/ecmascript/transforms/src/modules/common_js/tests.rs index e6e3a8caddb..a01de2b52bc 100644 --- a/ecmascript/transforms/src/modules/common_js/tests.rs +++ b/ecmascript/transforms/src/modules/common_js/tests.rs @@ -1,25 +1,21 @@ use super::{common_js, Config, Lazy}; -use crate::{compat::es2015::resolver, helpers::Helpers}; +use crate::compat::es2015::resolver; use ast::*; -use std::sync::Arc; use swc_common::Fold; fn syntax() -> ::swc_ecma_parser::Syntax { Default::default() } -fn tr(helpers: Arc, config: Config) -> impl Fold { - chain!(resolver(), common_js(helpers, config)) +fn tr(config: Config) -> impl Fold { + chain!(resolver(), common_js(config)) } test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), custom_01, r#" var foo = 1; @@ -44,13 +40,10 @@ exports.foo = foo = 3; // strict_export_2 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export_2, r#" var foo; @@ -70,12 +63,9 @@ exports.default = foo; // interop_hoist_function_exports test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_hoist_function_exports, r#" import { isEven } from "./evens"; @@ -122,12 +112,9 @@ exports.isOdd = isOdd; // misc_undefined_this_root_declaration test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), misc_undefined_this_root_declaration, r#" var self = this; @@ -144,12 +131,9 @@ var self = void 0; // interop_export_default_3 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default_3, r#" export default []; @@ -171,12 +155,9 @@ exports.default = _default; // misc_copy_getters_setters test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), misc_copy_getters_setters, r#" import Foo, { baz } from "./moduleWithGetter"; @@ -219,12 +200,9 @@ var _moduleWithGetter = _interopRequireWildcard(require("./moduleWithGetter")); // update_expression_positive_suffix test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), update_expression_positive_suffix, r#" export let diffLevel = 0; @@ -259,12 +237,9 @@ function diff() { // interop_export_default_11 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default_11, r#" export default new Cachier() @@ -293,12 +268,9 @@ function Cachier(databaseName) {} // interop_export_named_5 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_named_5, r#" var foo, bar; @@ -322,12 +294,9 @@ exports.bar = bar; // interop_exports_variable test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_exports_variable, r#" export var foo = 1; @@ -380,12 +349,9 @@ exports.foo9 = foo9; // interop_export_from_2 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_from_2, r#" export {foo} from "foo"; @@ -414,13 +380,10 @@ test!( // Same option as lazy_deps_*, but different result ignore, syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_local_reexport_default, r#" import foo from "./foo"; @@ -450,13 +413,10 @@ test!( // Same option as lazy_deps_*, but different result ignore, syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_local_reexport_namespace, r#" import * as namespace from "./foo"; @@ -483,12 +443,9 @@ exports.namespace = namespace; // interop_export_default_6 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default_6, r#" export default class {} @@ -512,13 +469,10 @@ exports.default = _default; // no_interop_import_default_only test!( syntax(), - |_, helpers| tr( - helpers, - Config { - no_interop: true, - ..Default::default() - } - ), + |_| tr(Config { + no_interop: true, + ..Default::default() + }), no_interop_import_default_only, r#" import foo from "foo"; @@ -541,12 +495,9 @@ _foo.default(); // interop_export_from_7 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_from_7, r#" export {default as foo} from "foo"; @@ -573,12 +524,9 @@ var _foo = _interopRequireDefault(require("foo")); // interop_remap test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_remap, r#" export var test = 2; @@ -641,13 +589,10 @@ exports.f = exports.e = d = 4; // lazy_dep_reexport_all test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_dep_reexport_all, r#" export * from "foo"; @@ -682,13 +627,10 @@ Object.keys(_foo).forEach(function (key) { // lazy_local_sideeffect test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_local_sideeffect, r#" import "./a"; @@ -705,13 +647,10 @@ require("./a"); // strict_export_const_destructuring_deep test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export_const_destructuring_deep, r#" export const { foo: { bar: [baz, qux] } } = {}; @@ -735,13 +674,10 @@ exports.qux = qux; // lazy_local_reexport_all test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_local_reexport_all, r#" export * from "./foo"; @@ -774,12 +710,9 @@ Object.keys(_foo).forEach(function (key) { // interop_export_from_4 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_from_4, r#" export {foo as bar} from "foo"; @@ -806,12 +739,9 @@ var _foo = require("foo"); // interop_export_destructured test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_destructured, r#" export let x = 0; @@ -882,13 +812,10 @@ function f4() { // strict_export_const_destructuring_array test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export_const_destructuring_array, r#" export const [foo, bar] = []; @@ -908,12 +835,9 @@ exports.bar = bar; // interop_export_named_3 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_named_3, r#" var foo; @@ -938,12 +862,9 @@ exports.bar = foo; // interop_imports_glob test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_imports_glob, r#" import * as foo from "foo"; @@ -964,13 +885,10 @@ var foo = _interopRequireWildcard(require("foo")); // strict_export test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export, r#" export function foo() {} @@ -989,13 +907,10 @@ function foo() {} // no_interop_import_wildcard test!( syntax(), - |_, helpers| tr( - helpers, - Config { - no_interop: true, - ..Default::default() - } - ), + |_| tr(Config { + no_interop: true, + ..Default::default() + }), no_interop_import_wildcard, r#" import * as foo from 'foo'; @@ -1018,12 +933,9 @@ foo.baz(); // interop_export_default_5 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default_5, r#" export default function () {} @@ -1045,13 +957,10 @@ exports.default = _default; // strict_export_const_destructuring_object_default_params test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export_const_destructuring_object_default_params, r#" export const { foo, bar = 1 } = {}; @@ -1074,13 +983,10 @@ exports.bar = bar; // lazy_whitelist_reexport_all test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::List(vec!["white".into()]), + ..Default::default() + }), lazy_whitelist_reexport_all, r#" export * from "white"; @@ -1128,13 +1034,10 @@ test!( // Same option as lazy_local_*, but different result ignore, syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_dep_import_namespace, r#" import * as foo from "foo"; @@ -1163,13 +1066,10 @@ console.log(foo()); // lazy_whitelist_reexport_default test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::List(vec!["white".into()]), + ..Default::default() + }), lazy_whitelist_reexport_default, r#" import foo from "white"; @@ -1206,12 +1106,9 @@ function _white() { // interop_export_default_8 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default_8, r#" export default class Foo {} @@ -1235,13 +1132,10 @@ exports.default = Foo; // strict_export_1 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export_1, r#" export default foo; @@ -1260,13 +1154,10 @@ exports.default = _default; // lazy_local_import_named test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_local_import_named, r#" import { foo } from "./foo"; @@ -1287,12 +1178,9 @@ console.log(_foo.foo); // interop_export_default_2 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default_2, r#" export default {}; @@ -1314,12 +1202,9 @@ exports.default = _default; // interop_export_named test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_named_1, r#" var foo; @@ -1342,12 +1227,9 @@ exports.foo = foo; // interop_imports_ordering test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_imports_ordering, r#" import './foo'; @@ -1373,13 +1255,10 @@ var _qux = require("./qux"); // strict_export_3 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export_3, r#" export {}; @@ -1398,12 +1277,9 @@ require("foo"); // interop_export_named_4 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_named_4, r#" var foo; @@ -1426,12 +1302,9 @@ exports.default = foo; // misc_import_const_throw test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), misc_import_const_throw, r#" import Foo from "foo"; @@ -1503,13 +1376,10 @@ Baz = ( 44, (function() { // lazy_local_import_default test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_local_import_default, r#" import foo from "./foo"; @@ -1530,13 +1400,10 @@ console.log(_foo.default); // lazy_whitelist_reexport_namespace test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::List(vec!["white".into()]), + ..Default::default() + }), lazy_whitelist_reexport_namespace, r#" import * as namespace1 from "white"; @@ -1580,12 +1447,9 @@ exports.namespace2 = namespace2; // interop_export_from_3 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_from_3, r#" export {foo, bar} from "foo"; @@ -1618,13 +1482,10 @@ var _foo = require("foo"); // lazy_dep_reexport_named test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_dep_reexport_named, r#" import { named } from "foo"; @@ -1662,12 +1523,9 @@ test!( // Comment is not supported yet ignore, syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), auxiliary_comment_overview, r#" import "foo"; @@ -1808,12 +1666,9 @@ default // interop_imports_default test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_imports_default, r#" import foo from "foo"; @@ -1837,12 +1692,9 @@ _foo.default; // misc_undefined_this_root_reference test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), misc_undefined_this_root_reference, r#" this; @@ -1861,12 +1713,9 @@ void 0; // interop_export_default_10 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default_10, r#" export default (function(){return "foo"})(); @@ -1892,13 +1741,10 @@ exports.default = _default; // lazy_whitelist_import_named test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::List(vec!["white".into()]), + ..Default::default() + }), lazy_whitelist_import_named, r#" import { foo1 } from "white"; @@ -1942,12 +1788,9 @@ function use2() { // interop_export_default test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default, r#" export default 42; @@ -1971,13 +1814,10 @@ exports.default = _default; // lazy_local_import_namespace test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_local_import_namespace, r#" import * as foo from "./foo"; @@ -1999,12 +1839,9 @@ console.log(foo); // interop_export_default_7 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default_7, r#" export default function foo () {} @@ -2027,13 +1864,10 @@ exports.default = foo; // lazy_whitelist_reexport_named test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::List(vec!["white".into()]), + ..Default::default() + }), lazy_whitelist_reexport_named, r#" import { named1 } from "white"; @@ -2083,12 +1917,9 @@ var _black = require("black"); // interop_export_from test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_from_1, r#" export * from "foo"; @@ -2119,13 +1950,10 @@ Object.keys(_foo).forEach(function (key) { // disable_strict_mode_strict_mode_false test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict_mode: false, - ..Default::default() - } - ), + |_| tr(Config { + strict_mode: false, + ..Default::default() + }), disable_strict_mode_strict_mode_false, r#" import "foo"; @@ -2146,12 +1974,9 @@ require("./directory/foo-bar"); // interop_export_from_6 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_from_6, r#" export {foo as default, bar} from "foo"; @@ -2184,12 +2009,9 @@ var _foo = require("foo"); // interop_export_from_5 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_from_5, r#" export {foo as default} from "foo"; @@ -2216,13 +2038,10 @@ var _foo = require("foo"); // strict_import test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_import, r#" import foo from "foo"; @@ -2251,12 +2070,9 @@ foo4.foo3(); // interop_export_named_2 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_named_2, r#" var foo, bar; @@ -2280,13 +2096,10 @@ exports.bar = bar; // lazy_whitelist_import_default test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::List(vec!["white".into()]), + ..Default::default() + }), lazy_whitelist_import_default, r#" import foo1 from "white"; @@ -2313,12 +2126,9 @@ console.log(_black.default); // interop_imports test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_imports, r#" import "foo"; @@ -2343,13 +2153,10 @@ require("./directory/foo-bar"); // strict_export_const_destructuring_object test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export_const_destructuring_object, r#" export const { foo: bar, baz } = {}; @@ -2374,12 +2181,9 @@ exports.baz = baz; // update_expression_negative_suffix test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), update_expression_negative_suffix, r#" export let diffLevel = 0; @@ -2416,12 +2220,9 @@ test!( // TODO(kdy1): Uningnore this ignore, syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_module_shadow, r#" export function module() { @@ -2445,13 +2246,10 @@ function _module() {} // strict_export_const_destructuring_object_rest test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export_const_destructuring_object_rest, r#" export const { foo, ...bar } = {}; @@ -2474,13 +2272,10 @@ exports.bar = bar; // lazy_whitelist_sideeffect test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::List(vec!["white".into()]), + ..Default::default() + }), lazy_whitelist_sideeffect, r#" import "white"; @@ -2500,13 +2295,10 @@ require("black"); // lazy_dep_reexport_namespace test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_dep_reexport_namespace, r#" import * as namespace from "foo"; @@ -2544,12 +2336,9 @@ function namespace() { // interop_export_default_4 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default_4, r#" export default foo; @@ -2571,13 +2360,10 @@ exports.default = _default; // no_interop_export_from test!( syntax(), - |_, helpers| tr( - helpers, - Config { - no_interop: true, - ..Default::default() - } - ), + |_| tr(Config { + no_interop: true, + ..Default::default() + }), no_interop_export_from, r#" export { default } from 'foo'; @@ -2606,13 +2392,10 @@ var _foo = require("foo"); // lazy_dep_sideeffect test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_dep_sideeffect, r#" import "foo"; @@ -2629,12 +2412,9 @@ require("foo"); // interop_export_from_8 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_from_8, r#" import { foo, foo1, foo2, foo3, foo4, foo5, foo6, foo7, foo8, foo9, foo10, foo11, foo12, @@ -3275,13 +3055,10 @@ var _foo = require("foo"); // strict_export_const_destructuring_array_default_params test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export_const_destructuring_array_default_params, r#" export const [foo, bar = 2] = []; @@ -3301,12 +3078,9 @@ exports.bar = bar; // interop_imports_named test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_imports_named, r#" import {bar} from "foo"; @@ -3344,13 +3118,10 @@ _foo.xyz; // lazy_whitelist_import_namespace test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::List(vec!["white".into()]), + ..Default::default() + }), lazy_whitelist_import_namespace, r#" import * as foo1 from "white"; @@ -3395,13 +3166,10 @@ test!( // Same option as lazy_local_*, but different result ignore, syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_dep_import_named, r#" import { foo } from "foo"; @@ -3430,13 +3198,10 @@ console.log(_foo().foo); // lazy_dep_reexport_default test!( syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_dep_reexport_default, r#" import foo from "foo"; @@ -3472,12 +3237,9 @@ function _foo() { // interop_export_default_9 test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_default_9, r#" var foo; @@ -3501,12 +3263,9 @@ exports.default = foo; // misc_undefined_this_arrow_function test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), misc_undefined_this_arrow_function, r#" var foo = () => this; @@ -3523,12 +3282,9 @@ var foo = () => void 0; // misc_undefined_this_root_call test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), misc_undefined_this_root_call, r#" this.foo(); @@ -3545,13 +3301,10 @@ this.foo(); // strict_import_wildcard test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_import_wildcard, r#" import * as foo from 'foo'; @@ -3575,13 +3328,10 @@ test!( // Same option as lazy_local_*, but different result ignore, syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_dep_import_default, r#" import foo from "foo"; @@ -3612,13 +3362,10 @@ test!( // Same option as lazy_deps_*, but different result ignore, syntax(), - |_, helpers| tr( - helpers, - Config { - lazy: Lazy::Bool(true), - ..Default::default() - } - ), + |_| tr(Config { + lazy: Lazy::Bool(true), + ..Default::default() + }), lazy_local_reexport_named, r#" import { named } from "./foo"; @@ -3646,13 +3393,10 @@ var _foo = require("./foo"); // strict_export_const_destructuring_array_rest test!( syntax(), - |_, helpers| tr( - helpers, - Config { - strict: true, - ..Default::default() - } - ), + |_| tr(Config { + strict: true, + ..Default::default() + }), strict_export_const_destructuring_array_rest, r#" export const [foo, bar, ...baz] = []; @@ -3679,12 +3423,9 @@ exports.baz = baz; // interop_imports_mixing test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_imports_mixing, r#" import foo, {baz as xyz} from "foo"; @@ -3707,12 +3448,9 @@ _foo.baz; // interop_overview test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_overview, r#" import "foo"; @@ -3770,12 +3508,9 @@ _foo2.default; // interop_export_all test!( syntax(), - |_, helpers| tr( - helpers, - Config { - ..Default::default() - } - ), + |_| tr(Config { + ..Default::default() + }), interop_export_all, r#" // The fact that this exports both a normal default, and all of the names via @@ -3827,7 +3562,7 @@ test_exec!( // We cannot inject transform at this time. ignore, syntax(), - |_, helpers| tr(helpers, Default::default()), + |_| tr(Default::default()), source_map_exec, r#" var tests = [ diff --git a/ecmascript/transforms/src/modules/umd/mod.rs b/ecmascript/transforms/src/modules/umd/mod.rs index 3be9ee74e97..46ce587b013 100644 --- a/ecmascript/transforms/src/modules/umd/mod.rs +++ b/ecmascript/transforms/src/modules/umd/mod.rs @@ -5,24 +5,23 @@ use super::util::{ make_descriptor, make_require_call, use_strict, Scope, VarCollector, }; use crate::{ - helpers::Helpers, pass::Pass, util::{prepend_stmts, DestructuringFinder, ExprFactory, State}, }; use ast::*; use fxhash::FxHashSet; -use std::{collections::hash_map::Entry, iter, sync::Arc}; +use std::{collections::hash_map::Entry, iter}; use swc_common::{sync::Lrc, Fold, FoldWith, Mark, SourceMap, VisitWith, DUMMY_SP}; mod config; #[cfg(test)] mod tests; -pub fn umd(cm: Lrc, helpers: Arc, config: Config) -> impl Pass + Clone { +pub fn umd(cm: Lrc, config: Config) -> impl Pass + Clone { Umd { config: config.build(cm.clone()), cm, - helpers, + scope: Default::default(), exports: Default::default(), } @@ -32,7 +31,6 @@ pub fn umd(cm: Lrc, helpers: Arc, config: Config) -> impl Pa struct Umd { cm: Lrc, config: BuiltConfig, - helpers: Arc, scope: State, exports: State, } @@ -443,9 +441,9 @@ impl Fold for Umd { match ty { Some(&wildcard) => { if wildcard { - self.helpers.interop_require_wildcard(); + helper!(interop_require_wildcard); } else { - self.helpers.interop_require_default(); + helper!(interop_require_default); } let right = box Expr::Call(CallExpr { span: DUMMY_SP, diff --git a/ecmascript/transforms/src/modules/umd/tests.rs b/ecmascript/transforms/src/modules/umd/tests.rs index 21fe350d6db..e12366919cd 100644 --- a/ecmascript/transforms/src/modules/umd/tests.rs +++ b/ecmascript/transforms/src/modules/umd/tests.rs @@ -5,20 +5,15 @@ fn syntax() -> ::swc_ecma_parser::Syntax { Default::default() } -fn tr( - tester: &mut crate::tests::Tester, - helpers: Arc, - config: Config, -) -> impl Fold { - chain!(resolver(), umd(tester.cm.clone(), helpers, config)) +fn tr(tester: &mut crate::tests::Tester, config: Config) -> impl Fold { + chain!(resolver(), umd(tester.cm.clone(), config)) } // exports_variable test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -90,9 +85,8 @@ export class foo9 {} // export_named test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -133,9 +127,8 @@ export {foo}; // export_default_11 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -184,9 +177,8 @@ export function Cachier(databaseName) {} // export_from_4 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -231,9 +223,8 @@ export {foo as bar} from "foo"; // export_default_3 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -277,9 +268,8 @@ export default []; // imports_default test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -320,9 +310,8 @@ foo2; // export_named_3 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -364,9 +353,8 @@ export {foo as default, bar}; // imports_glob test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -404,9 +392,8 @@ foo; // export_default_6 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -448,9 +435,8 @@ export default class {} // export_default_5 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -489,9 +475,8 @@ export default function () {} // hoist_function_exports test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -552,9 +537,8 @@ export var isOdd = (function (isEven) { // export_from_2 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -599,9 +583,8 @@ export {foo as default} from "foo"; // export_default_8 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -647,9 +630,8 @@ export default class Foo {} // export_named_5 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -691,9 +673,8 @@ export {foo, bar}; // imports_exact_globals_false test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -736,9 +717,8 @@ import fizzBuzz from "fizzbuzz"; // export_default_10 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -782,9 +762,8 @@ export default (function(){return "foo"})(); // export_from test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -827,9 +806,8 @@ export {foo} from "foo"; // export_from_5 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -880,9 +858,8 @@ export {foo, bar} from "foo"; // export_default_2 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -922,9 +899,8 @@ export default {}; // imports_named test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -974,9 +950,8 @@ xyz; // imports_mixing test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1013,9 +988,8 @@ xyz; // remap test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1096,9 +1070,8 @@ d = 4; // export_named_2 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1139,9 +1112,8 @@ export {foo as default}; // export_default_7 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1183,9 +1155,8 @@ export default function foo () {} // non_default_imports test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1218,9 +1189,8 @@ import { render } from "./lib/render"; // imports test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1255,9 +1225,8 @@ import "./directory/foo-bar"; // export_default test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1297,9 +1266,8 @@ export default 42; // export_default_4 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1339,9 +1307,8 @@ export default foo; // export_from_3 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1390,9 +1357,8 @@ export {foo as default, bar} from "foo"; // export_default_9 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1434,9 +1400,8 @@ export { foo as default }; // overview test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1499,9 +1464,8 @@ bar2; // export_named_4 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } @@ -1542,9 +1506,8 @@ export {foo as bar}; // export_from_6 test!( syntax(), - |tester, helpers| tr( + |tester| tr( tester, - helpers, Config { ..Default::default() } diff --git a/ecmascript/transforms/src/proposals/class_properties/class_name_tdz.rs b/ecmascript/transforms/src/proposals/class_properties/class_name_tdz.rs index 84c1b2495ec..cdb2435c3e4 100644 --- a/ecmascript/transforms/src/proposals/class_properties/class_name_tdz.rs +++ b/ecmascript/transforms/src/proposals/class_properties/class_name_tdz.rs @@ -1,9 +1,8 @@ -use crate::{helpers::Helpers, util::ExprFactory}; +use crate::util::ExprFactory; use ast::*; use swc_common::{Fold, FoldWith, DUMMY_SP}; pub(super) struct ClassNameTdzFolder<'a> { - pub helpers: &'a Helpers, pub class_name: &'a Ident, } @@ -14,7 +13,7 @@ impl<'a> Fold for ClassNameTdzFolder<'a> { // if i.sym == self.class_name.sym { - self.helpers.class_name_tdz_error(); + helper!(class_name_tdz_error); return Expr::Seq(SeqExpr { span: DUMMY_SP, diff --git a/ecmascript/transforms/src/proposals/class_properties/mod.rs b/ecmascript/transforms/src/proposals/class_properties/mod.rs index 98b448cea64..24495442a91 100644 --- a/ecmascript/transforms/src/proposals/class_properties/mod.rs +++ b/ecmascript/transforms/src/proposals/class_properties/mod.rs @@ -4,7 +4,6 @@ use self::{ used_name::{UsedNameCollector, UsedNameRenamer}, }; use crate::{ - helpers::Helpers, pass::Pass, util::{ alias_ident_for, constructor::inject_after_super, default_constructor, undefined, @@ -13,7 +12,6 @@ use crate::{ }; use ast::*; use fxhash::FxHashSet; -use std::sync::Arc; use swc_atoms::JsWord; use swc_common::{Fold, FoldWith, Mark, Spanned, VisitWith, DUMMY_SP}; @@ -30,16 +28,12 @@ mod used_name; /// # Impl note /// /// We use custom helper to handle export defaul class -pub fn class_properties(helpers: Arc) -> impl Pass + Clone { - ClassProperties { - helpers, - mark: Mark::root(), - } +pub fn class_properties() -> impl Pass + Clone { + ClassProperties { mark: Mark::root() } } #[derive(Clone)] struct ClassProperties { - helpers: Arc, mark: Mark, } @@ -270,10 +264,8 @@ impl ClassProperties { // we handle computed key here to preserve the execution order let key = match method.key { PropName::Computed(expr) => { - let expr = expr.fold_with(&mut ClassNameTdzFolder { - helpers: &self.helpers, - class_name: &ident, - }); + let expr = + expr.fold_with(&mut ClassNameTdzFolder { class_name: &ident }); let ident = private_ident!("tmp"); // Handle computed property vars.push(VarDeclarator { @@ -293,10 +285,9 @@ impl ClassProperties { ClassMember::ClassProp(mut prop) => { let prop_span = prop.span(); - prop.key = prop.key.fold_with(&mut ClassNameTdzFolder { - helpers: &self.helpers, - class_name: &ident, - }); + prop.key = prop + .key + .fold_with(&mut ClassNameTdzFolder { class_name: &ident }); let key = match *prop.key { Expr::Ident(ref i) if !prop.computed => Lit::Str(Str { @@ -325,7 +316,7 @@ impl ClassProperties { }); let value = prop.value.unwrap_or_else(|| undefined(prop_span)).as_arg(); - self.helpers.define_property(); + helper!(define_property); let callee = quote_ident!(DUMMY_SP, "_defineProperty").as_callee(); if prop.is_static { @@ -440,7 +431,6 @@ impl ClassProperties { statics: &statics, vars: vec![], class_name: &ident, - helpers: &self.helpers, }); ( diff --git a/ecmascript/transforms/src/proposals/class_properties/private_field.rs b/ecmascript/transforms/src/proposals/class_properties/private_field.rs index 8a678447f07..35fd6721412 100644 --- a/ecmascript/transforms/src/proposals/class_properties/private_field.rs +++ b/ecmascript/transforms/src/proposals/class_properties/private_field.rs @@ -1,7 +1,4 @@ -use crate::{ - helpers::Helpers, - util::{alias_ident_for, prepend, ExprFactory}, -}; +use crate::util::{alias_ident_for, prepend, ExprFactory}; use ast::*; use fxhash::FxHashSet; use std::{iter, mem}; @@ -13,7 +10,6 @@ pub(super) struct FieldAccessFolder<'a> { pub class_name: &'a Ident, pub vars: Vec, pub statics: &'a FxHashSet, - pub helpers: &'a Helpers, } impl<'a> Fold for FieldAccessFolder<'a> { @@ -123,7 +119,7 @@ impl<'a> Fold for FieldAccessFolder<'a> { .as_arg() }; - self.helpers.class_private_field_set(); + helper!(class_private_field_set); let set = quote_ident!("_classPrivateFieldSet").as_callee(); let expr = Expr::Call(CallExpr { @@ -248,7 +244,7 @@ impl<'a> Fold for FieldAccessFolder<'a> { }; if is_static { - self.helpers.class_static_private_field_spec_set(); + helper!(class_static_private_field_spec_set); let set = quote_ident!("_classStaticPrivateFieldSpecSet").as_callee(); Expr::Call(CallExpr { @@ -264,7 +260,7 @@ impl<'a> Fold for FieldAccessFolder<'a> { type_args: Default::default(), }) } else { - self.helpers.class_private_field_set(); + helper!(class_private_field_set); let set = quote_ident!("_classPrivateFieldSet").as_callee(); Expr::Call(CallExpr { @@ -345,7 +341,7 @@ impl<'a> FieldAccessFolder<'a> { ); if is_static { - self.helpers.class_static_private_field_spec_get(); + helper!(class_static_private_field_spec_get); let get = quote_ident!("_classStaticPrivateFieldSpecGet").as_callee(); ( @@ -362,7 +358,7 @@ impl<'a> FieldAccessFolder<'a> { Some(Expr::Ident(self.class_name.clone())), ) } else { - self.helpers.class_private_field_get(); + helper!(class_private_field_get); let get = quote_ident!("_classPrivateFieldGet").as_callee(); match *obj { diff --git a/ecmascript/transforms/src/proposals/class_properties/tests.rs b/ecmascript/transforms/src/proposals/class_properties/tests.rs index 7d73f0034b9..920cb316914 100644 --- a/ecmascript/transforms/src/proposals/class_properties/tests.rs +++ b/ecmascript/transforms/src/proposals/class_properties/tests.rs @@ -1,12 +1,8 @@ use super::*; -use crate::{ - compat::{ - es2015::{block_scoping, function_name, resolver, Classes}, - es3::ReservedWord, - }, - helpers::Helpers, +use crate::compat::{ + es2015::{block_scoping, function_name, resolver, Classes}, + es3::ReservedWord, }; -use std::sync::Arc; use swc_ecma_parser::{EsConfig, Syntax}; fn syntax() -> Syntax { @@ -17,12 +13,12 @@ fn syntax() -> Syntax { }) } -fn tr(helpers: Arc) -> impl Fold { +fn tr() -> impl Fold { chain!( resolver(), function_name(), - class_properties(helpers.clone()), - Classes { helpers }, + class_properties(), + Classes, block_scoping(), ReservedWord, ) @@ -30,7 +26,7 @@ fn tr(helpers: Arc) -> impl Fold { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_static_infer_name, r#" var Foo = class { @@ -51,7 +47,7 @@ var Foo = function() { test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_call_exec, r#" class Foo { @@ -75,7 +71,7 @@ expect(test[1]).toBe(o); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_instance_computed, r#" function test(x) { @@ -117,7 +113,7 @@ test('foo'); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_super_statement, r#" class Foo extends Bar { @@ -154,7 +150,7 @@ function (_Bar) { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_foobar, r#" class Child extends Parent { @@ -202,7 +198,7 @@ var _scopedFunctionWithThis = new WeakMap(); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_call_exec, r#" class Foo { @@ -226,7 +222,7 @@ expect(test[1]).toBe(o); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_derived_multiple_supers, r#" class Foo extends Bar { @@ -274,7 +270,7 @@ function (_Bar) { test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_static_call_exec, r#" class Foo { @@ -296,7 +292,7 @@ expect(f.test("bar")).toBe("bar"); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_instance_undefined_exec, r#" class Foo { @@ -314,7 +310,7 @@ expect(new Foo().test()).toBe(undefined); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_instance_exec, r#" class Foo { @@ -358,7 +354,7 @@ expect(f.test()).toBe(4); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_regression_t6719, r#" function withContext(ComposedComponent) { @@ -404,7 +400,7 @@ function withContext(ComposedComponent) { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_super_with_collision, r#" class A { @@ -429,7 +425,7 @@ var A = function A(force1) { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_call, r#" class Foo { @@ -472,7 +468,7 @@ function () { test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_instance_computed_exec, r#" function test(x) { @@ -494,7 +490,7 @@ test('foo'); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_declaration_order, r#" class C { @@ -531,7 +527,7 @@ expect(() => { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), nested_class_super_call_in_key, r#" @@ -599,7 +595,7 @@ expect(new Outer().hello).toBe('hello'); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_instance_undefined, r#" class Foo { @@ -620,7 +616,7 @@ var Foo = function Foo() { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_derived_multiple_supers, r#" class Foo extends Bar { @@ -678,7 +674,7 @@ var _bar = new WeakMap(); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_native_classes_exec, r#" class Foo { @@ -705,7 +701,7 @@ expect(f.test()).toBe("bar") test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_regression_t2983, r#" call(class { @@ -735,7 +731,7 @@ export { _class as default } test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_static, r#" class Foo { @@ -757,7 +753,7 @@ _defineProperty(Foo, "bar", "foo"); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_instance_undefined, r#" class Foo { @@ -784,7 +780,7 @@ var _bar = new WeakMap(); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_declaration_order_exec, r#" class C { @@ -801,7 +797,7 @@ expect(() => { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_update, r#" class Foo { @@ -842,7 +838,7 @@ function () { "# ); -test!(syntax(), |_, helpers| tr(helpers), public_super_call, r#" +test!(syntax(), |_| tr(), public_super_call, r#" class A { foo() { return "bar"; @@ -895,7 +891,7 @@ function (_A) { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_constructor_collision, r#" var foo = "bar"; @@ -932,7 +928,7 @@ var _bar = new WeakMap(); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_constructor_collision, r#" var foo = "bar"; @@ -967,7 +963,7 @@ _defineProperty(Foo, "bar", baz); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_computed, r#" const foo = "foo"; @@ -1051,7 +1047,7 @@ _defineProperty(MyClass, _ref3, '247'); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_assignment, r#" class Foo { @@ -1098,7 +1094,7 @@ function () { test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_static_exec, r#" class Foo { @@ -1119,7 +1115,7 @@ test_exec!( // TODO(kdy1): unignore ignore, syntax(), - |_, helpers| tr(helpers), + |_| tr(), regression_7371_exec, r#" @@ -1227,7 +1223,7 @@ new ComputedField(); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_static_inherited_exec, r#" class Base { @@ -1305,7 +1301,7 @@ expect(Sub2.getClass()).toBe(7); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), nested_class_super_property_in_key_exec, r#" @@ -1333,7 +1329,7 @@ expect(new Outer().hello).toBe('hello'); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_super_statement, r#" class Foo extends Bar { @@ -1377,7 +1373,7 @@ var _bar = new WeakMap(); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_private_in_derived, r#" class Outer { @@ -1421,7 +1417,7 @@ var _outer = new WeakMap(); "# ); -test!(syntax(), |_, helpers| tr(helpers), private_update, r#" +test!(syntax(), |_| tr(), private_update, r#" class Foo { #foo = 0; @@ -1466,7 +1462,7 @@ var _foo = new WeakMap(); "#); -test!(syntax(), |_, helpers| tr(helpers), public_super_expression, r#" +test!(syntax(), |_| tr(), public_super_expression, r#" class Foo extends Bar { bar = "foo"; @@ -1497,7 +1493,7 @@ var Foo = function (_Bar) { test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_computed_initialization_order_exec, r#" const actualOrder = []; @@ -1544,7 +1540,7 @@ expect(inst[9]).toBe(15); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), nested_class_super_call_in_key_exec, r#" @@ -1575,7 +1571,7 @@ expect(new Outer().hello).toBe('hello'); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_update_exec, r#" class Foo { @@ -1611,7 +1607,7 @@ expect(results[7]).toBe(4); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_extracted_this, r#" var foo = "bar"; @@ -1641,7 +1637,7 @@ var Foo = function Foo(foo1) { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_derived, r#" class Foo { @@ -1698,7 +1694,7 @@ var _prop2 = new WeakMap(); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_super_call, r#" class A { @@ -1760,7 +1756,7 @@ var _foo = new WeakMap(); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_reference_in_other_property, r#" class Foo { @@ -1806,7 +1802,7 @@ var _four = new WeakMap(); "# ); -test!(syntax(), |_, helpers| tr(helpers), nested_class_super_property_in_key, r#" +test!(syntax(), |_| tr(), nested_class_super_property_in_key, r#" class Hello { toString() { @@ -1870,7 +1866,7 @@ expect(new Outer().hello).toBe('hello'); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_reevaluated_exec, r#" function classFactory() { @@ -1930,7 +1926,7 @@ expect(() => { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_numeric, r#" class Foo { @@ -1953,7 +1949,7 @@ var Foo = function Foo() { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_assignment, r#" class Foo { @@ -2004,7 +2000,7 @@ var _foo = new WeakMap(); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_constructor_collision_exec, r#" var foo = "bar"; @@ -2030,7 +2026,7 @@ expect("bar" in f).toBe(false); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_static_export, r#" export class MyClass { @@ -2060,7 +2056,7 @@ export { MyClass2 as default }; test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_multiple, r#" class Foo { @@ -2095,7 +2091,7 @@ var _y = new WeakMap(); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_derived, r#" class Foo extends Bar { @@ -2128,7 +2124,7 @@ function (_Bar) { test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_static_undefined_exec, r#" class Foo { @@ -2143,7 +2139,7 @@ expect(Foo.num).toBeUndefined(); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_instance, r#" class Foo { @@ -2164,7 +2160,7 @@ var Foo = function Foo() { test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), static_property_tdz_edgest_case_exec, r#" expect(() => { @@ -2178,7 +2174,7 @@ expect(() => { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_non_block_arrow_func, r#" export default param => @@ -2218,7 +2214,7 @@ export default (param)=>{ test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_static_undefined, r#" class Foo { @@ -2240,7 +2236,7 @@ _defineProperty(Foo, "bar", void 0); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_static_infer_name_exec, r#" var Foo = class { @@ -2256,7 +2252,7 @@ expect(Foo.name).toBe("Foo"); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), static_property_tdz_general_exec, r#" expect(() => { @@ -2270,7 +2266,7 @@ expect(() => { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_call, r#" class Foo { @@ -2320,7 +2316,7 @@ var _foo = new WeakMap(); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_derived_exec, r#" class Foo { @@ -2351,7 +2347,7 @@ expect(b.bar()).toBe("bar"); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_extracted_this, r#" var foo = "bar"; @@ -2393,7 +2389,7 @@ var _baz = new WeakMap(); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_canonical_exec, r#" class Point { @@ -2475,7 +2471,7 @@ expect(p3.toString()).toBe("Point<0,0>") test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_static_undefined_exec, r#" class Foo { @@ -2499,7 +2495,7 @@ expect(Foo.test()).toBe(undefined); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), public_update_exec, r#" class Foo { @@ -2535,7 +2531,7 @@ expect(results[7]).toBe(4); test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_static_call, r#" class Foo { @@ -2581,7 +2577,7 @@ var _foo = { test!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_super_expression, r#" class Foo extends Bar { @@ -2624,7 +2620,7 @@ var _bar = new WeakMap(); test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_native_classes_exec, r#" class Foo { @@ -2651,7 +2647,7 @@ expect(f.test()).toBe("bar") test_exec!( syntax(), - |_, helpers| tr(helpers), + |_| tr(), private_multiple_exec, r#" class Foo { diff --git a/ecmascript/transforms/src/proposals/decorators/mod.rs b/ecmascript/transforms/src/proposals/decorators/mod.rs index f17eb5d19e3..557746f4a6a 100644 --- a/ecmascript/transforms/src/proposals/decorators/mod.rs +++ b/ecmascript/transforms/src/proposals/decorators/mod.rs @@ -1,5 +1,4 @@ use crate::{ - helpers::Helpers, pass::Pass, util::{ alias_ident_for, constructor::inject_after_super, prop_name_to_expr_value, undefined, @@ -7,7 +6,7 @@ use crate::{ }, }; use ast::*; -use std::{iter, sync::Arc}; +use std::iter; use swc_common::{util::move_map::MoveMap, Fold, FoldWith, Spanned, Visit, VisitWith, DUMMY_SP}; #[cfg(test)] @@ -53,16 +52,14 @@ mod tests; /// } /// } /// ``` -pub fn decorators(helpers: Arc) -> impl Pass + Clone { +pub fn decorators() -> impl Pass + Clone { Decorators { - helpers, is_in_strict: false, } } #[derive(Clone)] struct Decorators { - helpers: Arc, is_in_strict: bool, } @@ -465,7 +462,7 @@ impl Decorators { .map(Some) .collect(); - self.helpers.decorate(); + helper!(decorate); let decorate_call = Expr::Call(make_decorate_call( class.decorators, iter::once({ diff --git a/ecmascript/transforms/src/proposals/decorators/tests.rs b/ecmascript/transforms/src/proposals/decorators/tests.rs index 0b33f40f744..61d18dd757a 100644 --- a/ecmascript/transforms/src/proposals/decorators/tests.rs +++ b/ecmascript/transforms/src/proposals/decorators/tests.rs @@ -1,6 +1,5 @@ use super::*; -use crate::{helpers::Helpers, proposals::class_properties}; -use std::sync::Arc; +use crate::proposals::class_properties; use swc_ecma_parser::{EsConfig, Syntax}; fn syntax(decorators_before_export: bool) -> Syntax { @@ -12,25 +11,19 @@ fn syntax(decorators_before_export: bool) -> Syntax { }) } -fn tr(helpers: Arc) -> impl Fold { - chain!( - decorators(helpers.clone()), - class_properties(helpers.clone()), - ) +fn tr() -> impl Fold { + chain!(decorators(), class_properties(),) } /// Folder for `transformation_*` tests -fn transformation(helpers: Arc) -> impl Fold { - chain!( - decorators(helpers.clone()), - class_properties(helpers.clone()), - ) +fn transformation() -> impl Fold { + chain!(decorators(), class_properties(),) } // transformation_declaration test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_declaration, r#" @dec() @@ -58,7 +51,7 @@ let A = _decorate([dec()], function (_initialize) { // transformation_initialize_after_super_multiple test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_initialize_after_super_multiple, r#" @dec @@ -121,7 +114,7 @@ let B = _decorate([dec], function (_initialize, _A) { // transformation_export_default_anonymous test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_export_default_anonymous, r#" export default @dec() class {} @@ -147,7 +140,7 @@ export default _decorate([dec()], function (_initialize) { // transformation_initialize_after_super_statement test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_initialize_after_super_statement, r#" @dec @@ -182,7 +175,7 @@ let B = _decorate([dec], function (_initialize, _A) { // element_descriptors_created_own_method_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_created_own_method_exec, r#" function pushElement(e) { @@ -219,7 +212,7 @@ expect(Object.getOwnPropertyDescriptor(new A(), "foo")).toEqual({ // finishers_return_class_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), finishers_return_class_exec, r#" class C {} @@ -244,7 +237,7 @@ expect(A).toBe(C); // misc_method_name_not_shadow test!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), misc_method_name_not_shadow, r#" var method = 1; @@ -286,7 +279,7 @@ let Foo = _decorate([decorator], function (_initialize) { // element_descriptors_original_class_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_original_class_exec, r#" var el = null; @@ -314,7 +307,7 @@ expect(el.elements).toHaveLength(3); // duplicated_keys_create_existing_element_with_extras_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_create_existing_element_with_extras_exec, r#" function decorate(el) { @@ -348,7 +341,7 @@ expect(() => { // finishers_no_in_extras_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), finishers_no_in_extras_exec, r#" class C {} @@ -378,7 +371,7 @@ expect(() => { // duplicated_keys_computed_keys_same_value test!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_computed_keys_same_value, r#" @(_ => desc = _) @@ -427,7 +420,7 @@ let Foo = _decorate([_ => desc = _], function (_initialize) { // transformation_only_decorated test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_only_decorated, r#" class B { @@ -450,7 +443,7 @@ class B { // ordering_finishers_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), ordering_finishers_exec, r#" var log = []; @@ -493,7 +486,7 @@ expect(log).toEqual(numsFrom0to9); // transformation_initiailzer_after_super_bug_8808 test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_initiailzer_after_super_bug_8808, r#" @decorator(parameter) @@ -527,7 +520,7 @@ let Sub = _decorate([decorator(parameter)], function (_initialize, _Super) { // duplicated_keys_original_method_overwritten_no_decorators_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_original_method_overwritten_no_decorators_exec, r#" var el; @@ -552,7 +545,7 @@ expect(A.prototype.method()).toBe(2); // transformation_arguments test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_arguments, r#" @dec(a, b, ...c) @@ -587,7 +580,7 @@ let A = _decorate([dec(a, b, ...c)], function (_initialize) { // duplicated_keys_original_method_overwritten_both_decorated_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_original_method_overwritten_both_decorated_exec, r#" expect(() => { @@ -611,7 +604,7 @@ test_exec!( // Babel 7.3.0 fails ignore, syntax(false), - |_, helpers| tr(helpers), + |_| tr(), ordering_field_initializers_after_methods_exec, r#" var counter = 0; @@ -647,7 +640,7 @@ expect(counter).toBe(2); // misc_to_primitive_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), misc_to_primitive_exec, r#" let calls = 0; @@ -673,7 +666,7 @@ expect(calls).toBe(1); // transformation_initialize_after_super_expression test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_initialize_after_super_expression, r#" @dec @@ -708,7 +701,7 @@ let B = _decorate([dec], function (_initialize, _A) { // element_descriptors_not_reused_field_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_not_reused_field_exec, r#" var dec1, dec2; @@ -730,7 +723,7 @@ expect(dec1.initializer).toBe(dec2.initializer); // transformation_export_default_named test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_export_default_named, r#" export default @dec() class Foo {} @@ -757,7 +750,7 @@ export { Foo as default }; // element_descriptors_original_own_field_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_original_own_field_exec, r#" var el = null; @@ -788,7 +781,7 @@ expect(el.initializer()).toBe(val); // ordering_decorators_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), ordering_decorators_exec, r#" var log = []; @@ -829,7 +822,7 @@ expect(log).toEqual(numsFrom0to23); // element_descriptors_default_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_default_exec, r#" function decorate(el) { @@ -852,7 +845,7 @@ expect(Foo.prototype.bar).toBe(2); // element_descriptors_original_prototype_method_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_original_prototype_method_exec, r#" var el = null; @@ -879,7 +872,7 @@ expect(el).toEqual(Object.defineProperty({ // misc_method_name_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), misc_method_name_exec, r#" function decorator() {} @@ -897,7 +890,7 @@ expect(Foo.prototype.method.name).toBe("method"); test!( ignore, syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_strict_directive, r#" (() => { @@ -967,7 +960,7 @@ test!( // element_descriptors_created_static_method_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_created_static_method_exec, r#" function pushElement(e) { @@ -1004,7 +997,7 @@ expect(Object.getOwnPropertyDescriptor(A, "foo")).toEqual({ // misc_method_name_not_shadow_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), misc_method_name_not_shadow_exec, r#" function decorator() {} @@ -1027,7 +1020,7 @@ expect(Foo.prototype.method.name).toBe("method"); // duplicated_keys_original_method_overwritten_second_decorated_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_original_method_overwritten_second_decorated_exec, r#" expect(() => { @@ -1048,7 +1041,7 @@ expect(() => { // duplicated_keys_get_set_both_decorated_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_get_set_both_decorated_exec, r#" function dec(el) { return el } @@ -1068,7 +1061,7 @@ expect(() => { // duplicated_keys_original_method_overwritten_first_decorated_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_original_method_overwritten_first_decorated_exec, r#" expect(() => { @@ -1089,7 +1082,7 @@ expect(() => { // element_descriptors_created_prototype_field_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_created_prototype_field_exec, r#" function pushElement(e) { @@ -1127,7 +1120,7 @@ expect(Object.getOwnPropertyDescriptor(A.prototype, "foo")).toEqual({ // transformation_extends test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_extends, r#" @dec class A extends B {} @@ -1158,7 +1151,7 @@ let A = _decorate([dec], function (_initialize, _B) { // transformation_extends_await test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_extends_await, r#" async function g() { @@ -1192,7 +1185,7 @@ async function g() { // transformation_extends_yield test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_extends_yield, r#" function* g() { @@ -1226,7 +1219,7 @@ function* g() { // element_descriptors_created_static_field_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_created_static_field_exec, r#" function pushElement(e) { @@ -1265,7 +1258,7 @@ expect(Object.getOwnPropertyDescriptor(A, "foo")).toEqual({ // element_descriptors_created_own_field_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_created_own_field_exec, r#" function pushElement(e) { @@ -1304,7 +1297,7 @@ expect(Object.getOwnPropertyDescriptor(new A(), "foo")).toEqual({ // element_descriptors_not_reused_method_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_not_reused_method_exec, r#" var dec1, dec2; @@ -1326,7 +1319,7 @@ expect(dec1.descriptor.value).toBe(dec2.descriptor.value); // element_descriptors_not_reused_class_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_not_reused_class_exec, r#" var dec1, dec2; @@ -1343,7 +1336,7 @@ expect(dec1).not.toBe(dec2); // duplicated_keys_computed_keys_same_ast_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_computed_keys_same_ast_exec, r#" var i = 0; @@ -1380,7 +1373,7 @@ expect(i).toBe(2); // transformation_initialize_after_super_bug_8931 test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_initialize_after_super_bug_8931, r#" @dec @@ -1421,7 +1414,7 @@ test_exec!( // Babel 7.3.0 fails ignore, syntax(false), - |_, helpers| tr(helpers), + |_| tr(), ordering_static_field_initializers_after_methods_exec, r#" var counter = 0; @@ -1453,7 +1446,7 @@ expect(counter).toBe(2); // element_descriptors_original_static_method_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_original_static_method_exec, r#" var el = null; @@ -1480,7 +1473,7 @@ expect(el).toEqual(Object.defineProperty({ // duplicated_keys_extras_duplicated_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_extras_duplicated_exec, r#" function decorate(el) { @@ -1521,7 +1514,7 @@ expect(() => { // duplicated_keys_extras_same_as_return_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_extras_same_as_return_exec, r#" function decorate(el) { @@ -1561,7 +1554,7 @@ expect(() => { // finishers_class_as_parameter_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), finishers_class_as_parameter_exec, r#" var C; @@ -1586,7 +1579,7 @@ expect(C).toBe(A); // duplicated_keys_moved_and_created_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_moved_and_created_exec, r#" var value1, value2 = {}; @@ -1628,7 +1621,7 @@ expect(Foo.prototype.bar).toBe(value2); // transformation_expression test!( syntax(false), - |_, helpers| transformation(helpers), + |_| transformation(), transformation_expression, r#" (@dec() class {}); @@ -1655,7 +1648,7 @@ _decorate([dec()], function (_initialize) { // duplicated_keys_original_method_prototype_and_static_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_original_method_prototype_and_static_exec, r#" var el; @@ -1682,7 +1675,7 @@ expect(A.method()).toBe(2); // duplicated_keys_computed_keys_same_ast test!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_computed_keys_same_ast, r#" @(_ => desc = _) @@ -1731,7 +1724,7 @@ let Foo = _decorate([_ => desc = _], function (_initialize) { // element_descriptors_created_prototype_method_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_created_prototype_method_exec, r#" function pushElement(e) { @@ -1767,7 +1760,7 @@ expect(Object.getOwnPropertyDescriptor(A.prototype, "foo")).toEqual({ // duplicated_keys_create_existing_element_from_method_decorator_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_create_existing_element_from_method_decorator_exec, r#" function decorate() { @@ -1799,7 +1792,7 @@ expect(() => { // element_descriptors_original_static_field_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_original_static_field_exec, r#" var el = null; @@ -1829,7 +1822,7 @@ expect(el.initializer()).toBe(val); // duplicated_keys_coalesce_get_set_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_coalesce_get_set_exec, r#" var el, el1; @@ -1861,7 +1854,7 @@ expect(desc.set()).toBe(2); // transformation_extends_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), transformation_extends_exec, r#" class B {} @@ -1877,7 +1870,7 @@ expect(new A).toBeInstanceOf(B); // duplicated_keys_create_existing_element_from_class_decorator_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_create_existing_element_from_class_decorator_exec, r#" function pushElement(e) { @@ -1907,7 +1900,7 @@ expect(() => { // duplicated_keys_computed_keys_same_value_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), duplicated_keys_computed_keys_same_value_exec, r#" var i = 0; @@ -1946,7 +1939,7 @@ expect(j).toBe(1); // element_descriptors_original_own_field_without_initiailzer_exec test_exec!( syntax(false), - |_, helpers| tr(helpers), + |_| tr(), element_descriptors_original_own_field_without_initiailzer_exec, r#" var el = null; diff --git a/ecmascript/transforms/src/react/display_name/tests.rs b/ecmascript/transforms/src/react/display_name/tests.rs index f7f27c71eed..08b9b13726a 100644 --- a/ecmascript/transforms/src/react/display_name/tests.rs +++ b/ecmascript/transforms/src/react/display_name/tests.rs @@ -6,7 +6,7 @@ fn tr() -> impl Fold { test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), assignment_expression, r#" foo = createReactClass({}); @@ -24,7 +24,7 @@ bar = React.createClass({ test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), nested, r#" var foo = qux(createReactClass({})); @@ -42,7 +42,7 @@ var bar = qux(React.createClass({ test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), object_property, r#" ({ @@ -67,7 +67,7 @@ test!( test!( ::swc_ecma_parser::Syntax::default(), - |_, _| tr(), + |_| tr(), variable_declarator, r#" var foo = createReactClass({}); diff --git a/ecmascript/transforms/src/react/jsx/mod.rs b/ecmascript/transforms/src/react/jsx/mod.rs index c585574cd08..915ac8c3024 100644 --- a/ecmascript/transforms/src/react/jsx/mod.rs +++ b/ecmascript/transforms/src/react/jsx/mod.rs @@ -1,7 +1,7 @@ -use crate::{helpers::Helpers, pass::Pass, util::ExprFactory}; +use crate::{pass::Pass, util::ExprFactory}; use ast::*; use serde::{Deserialize, Serialize}; -use std::{iter, mem, sync::Arc}; +use std::{iter, mem}; use swc_atoms::JsWord; use swc_common::{ errors::{ColorConfig, Handler}, @@ -58,7 +58,7 @@ fn default_throw_if_namespace() -> bool { /// `@babel/plugin-transform-react-jsx` /// /// Turn JSX into React function calls -pub fn jsx(cm: Lrc, options: Options, helpers: Arc) -> impl Pass + Clone { +pub fn jsx(cm: Lrc, options: Options) -> impl Pass + Clone { let handler = Handler::with_tty_emitter(ColorConfig::Always, false, true, Some(cm.clone())); let session = Session { handler: &handler }; @@ -81,7 +81,6 @@ pub fn jsx(cm: Lrc, options: Options, helpers: Arc) -> impl expr: parse("pragma_frag", options.pragma_frag), }, use_builtins: options.use_builtins, - helpers, } } @@ -90,7 +89,6 @@ struct Jsx { pragma: ExprOrSuper, pragma_frag: ExprOrSpread, use_builtins: bool, - helpers: Arc, } impl Jsx { @@ -212,7 +210,7 @@ impl Jsx { if self.use_builtins { member_expr!(DUMMY_SP, Object.assign).as_callee() } else { - self.helpers.extends(); + helper!(extends); quote_ident!("_extends").as_callee() } }, diff --git a/ecmascript/transforms/src/react/jsx/tests.rs b/ecmascript/transforms/src/react/jsx/tests.rs index 1842607863c..137e57e656c 100644 --- a/ecmascript/transforms/src/react/jsx/tests.rs +++ b/ecmascript/transforms/src/react/jsx/tests.rs @@ -4,20 +4,11 @@ use crate::{ es2015::{arrow, Classes}, es3::PropertyLiteral, }, - helpers::Helpers, react::display_name, }; -use std::sync::Arc; -fn tr(cm: Lrc, options: Options, helpers: Arc) -> impl Fold { - chain!( - jsx(cm.clone(), options, helpers.clone()), - display_name(), - Classes { - helpers: helpers.clone() - }, - arrow(), - ) +fn tr(cm: Lrc, options: Options) -> impl Fold { + chain!(jsx(cm.clone(), options), display_name(), Classes, arrow(),) } test!( @@ -25,7 +16,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_add_appropriate_newlines, r#" @@ -275,7 +266,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_honor_custom_jsx_comment_if_jsx_pragma_option_set, r#"/** @jsx dom */ @@ -300,7 +291,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_honor_custom_jsx_comment, r#" /** @jsx dom */ @@ -327,13 +318,12 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr( + |tester| tr( tester.cm.clone(), Options { pragma: "dom".into(), ..Default::default() - }, - helpers + } ), react_honor_custom_jsx_pragma_option, r#" @@ -357,7 +347,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_jsx_with_retainlines_option, r#"var div =
test
;"#, r#"var div = React.createElement("div", null, "test");"# @@ -368,7 +358,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_jsx_without_retainlines_option, r#"var div =
test
;"#, r#"var div = React.createElement("div", null, "test");"# @@ -381,7 +371,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_optimisation_react_constant_elements, r#" class App extends React.Component { @@ -445,10 +435,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| chain!( - tr(tester.cm.clone(), Default::default(), helpers), - PropertyLiteral - ), + |tester| chain!(tr(tester.cm.clone(), Default::default()), PropertyLiteral), react_should_add_quotes_es3, r#"var es3 = ;"#, r#" @@ -468,7 +455,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_allow_constructor_as_prop, r#";"#, r#" @@ -483,7 +470,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_allow_deeper_js_namespacing, r#";"#, r#"React.createElement(Namespace.DeepNamespace.Component, null);"# @@ -494,7 +481,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_allow_elements_as_attributes, r#"
/>"#, r#" @@ -508,7 +495,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_allow_js_namespacing, r#";"#, r#"React.createElement(Namespace.Component, null);"# @@ -519,7 +506,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_allow_nested_fragments, r#"
@@ -555,7 +542,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_allow_no_pragmafrag_if_frag_unused, r#" /** @jsx dom */ @@ -574,7 +561,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_allow_pragmafrag_and_frag, r#" /** @jsx dom */ @@ -595,7 +582,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_avoid_wrapping_in_extra_parens_if_not_needed, r#" var x =
@@ -627,7 +614,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_convert_simple_tags, r#"var x =
;"#, r#"var x = React.createElement("div", null);"# @@ -638,7 +625,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_convert_simple_text, r#"var x =
text
;"#, r#"var x = React.createElement("div", null, "text");"# @@ -649,7 +636,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_escape_xhtml_jsxattribute, r#"
; @@ -675,7 +662,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_escape_xhtml_jsxtext_1, r#"
wow
; @@ -706,7 +693,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_escape_xhtml_jsxtext_2, r#"
this should not parse as unicode: \u00a0
; @@ -724,7 +711,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_escape_xhtml_jsxtext_3, r#"
this should parse as nbsp:
; @@ -739,7 +726,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_handle_attributed_elements, r#" var HelloMessage = React.createClass({ @@ -772,7 +759,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_handle_has_own_property_correctly, r#"testing;"#, r#"React.createElement("hasOwnProperty", null, "testing");"# @@ -783,7 +770,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_have_correct_comma_in_nested_children, r#" var x =
@@ -807,7 +794,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_insert_commas_after_expressions_before_whitespace, r#" var x = @@ -842,7 +829,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_not_add_quotes_to_identifier_names, r#"var e = ;"#, r#" @@ -862,7 +849,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_not_mangle_expressioncontainer_attribute_values, r#";"#, r#" @@ -877,7 +864,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_not_strip_nbsp_even_coupled_with_other_whitespace, r#"
 
;"#, r#"React.createElement("div", null, "\xA0 ");"#, @@ -889,7 +876,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_not_strip_tags_with_a_single_child_of_nbsp, r#"
 
;"#, r#"React.createElement("div", null, "\xA0");"#, @@ -903,7 +890,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_properly_handle_comments_between_props, r#" var x = ( @@ -934,7 +921,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_quote_jsx_attributes, r#";"#, r#" @@ -949,14 +936,13 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr( + |tester| tr( tester.cm.clone(), Options { pragma: "h".into(), throw_if_namespace: false, ..Default::default() }, - helpers ), react_should_support_xml_namespaces_if_flag, r#";"#, @@ -970,7 +956,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_should_transform_known_hyphenated_tags, r#";"#, r#"React.createElement("font-face", null);"# @@ -981,7 +967,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_wraps_props_in_react_spread_for_first_spread_attributes, r#" "#, r#" @@ -1016,7 +1002,7 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr(tester.cm.clone(), Default::default(), helpers), + |tester| tr(tester.cm.clone(), Default::default()), react_wraps_props_in_react_spread_for_middle_spread_attributes, r#""#, r#" @@ -1032,13 +1018,12 @@ test!( jsx: true, ..Default::default() }), - |tester, helpers| tr( + |tester| tr( tester.cm.clone(), Options { use_builtins: true, ..Default::default() }, - helpers ), use_builtins_assignment, r#"var div = "#, diff --git a/ecmascript/transforms/src/react/jsx_self/tests.rs b/ecmascript/transforms/src/react/jsx_self/tests.rs index 592c779d197..d41d8f5bdbf 100644 --- a/ecmascript/transforms/src/react/jsx_self/tests.rs +++ b/ecmascript/transforms/src/react/jsx_self/tests.rs @@ -9,7 +9,7 @@ test!( jsx: true, ..Default::default() }), - |_, _| tr(), + |_| tr(), basic_sample, r#"var x = "#, r#"var x = ;"# diff --git a/ecmascript/transforms/src/react/jsx_src/tests.rs b/ecmascript/transforms/src/react/jsx_src/tests.rs index 5746b881fdd..071993dbb8a 100644 --- a/ecmascript/transforms/src/react/jsx_src/tests.rs +++ b/ecmascript/transforms/src/react/jsx_src/tests.rs @@ -12,7 +12,7 @@ test_exec!( jsx: true, ..Default::default() }), - |_, _| tr(), + |_| tr(), basic_sample, r#" var actual = transform( @@ -37,7 +37,7 @@ test!( jsx: true, ..Default::default() }), - |_, _| tr(), + |_| tr(), no_jsx, r#"var x = 42;"#, r#"var x = 42;"# @@ -49,7 +49,7 @@ test_exec!( jsx: true, ..Default::default() }), - |_, _| tr(), + |_| tr(), with_source, r#" var actual = transform( diff --git a/ecmascript/transforms/src/react/mod.rs b/ecmascript/transforms/src/react/mod.rs index cae15e74c7a..27818386367 100644 --- a/ecmascript/transforms/src/react/mod.rs +++ b/ecmascript/transforms/src/react/mod.rs @@ -4,8 +4,7 @@ pub use self::{ jsx_self::jsx_self, jsx_src::jsx_src, }; -use crate::{helpers::Helpers, pass::Pass}; -use std::sync::Arc; +use crate::pass::Pass; use swc_common::{sync::Lrc, SourceMap}; mod display_name; @@ -16,11 +15,11 @@ mod jsx_src; /// `@babel/preset-react` /// /// Preset for all React plugins. -pub fn react(cm: Lrc, options: Options, helpers: Arc) -> impl Pass + Clone { +pub fn react(cm: Lrc, options: Options) -> impl Pass + Clone { let Options { development, .. } = options; chain!( - jsx(cm.clone(), options, helpers), + jsx(cm.clone(), options), display_name(), jsx_src(development, cm), jsx_self(development) diff --git a/ecmascript/transforms/src/simplify/expr/tests.rs b/ecmascript/transforms/src/simplify/expr/tests.rs index be74aac3f39..97f11b34071 100644 --- a/ecmascript/transforms/src/simplify/expr/tests.rs +++ b/ecmascript/transforms/src/simplify/expr/tests.rs @@ -3,7 +3,7 @@ use super::SimplifyExpr; fn test_expr(src: &str, expected: &str) { test_transform!( ::swc_ecma_parser::Syntax::default(), - |_, _| SimplifyExpr, + |_| SimplifyExpr, src, expected, true diff --git a/ecmascript/transforms/src/simplify/tests.rs b/ecmascript/transforms/src/simplify/tests.rs index df99667ba55..18c5a07450a 100644 --- a/ecmascript/transforms/src/simplify/tests.rs +++ b/ecmascript/transforms/src/simplify/tests.rs @@ -5,7 +5,7 @@ macro_rules! test_stmt { ($l:expr, $r:expr) => { test_transform!( ::swc_ecma_parser::Syntax::default(), - |_, _| Simplifier { enable: true }, + |_| Simplifier { enable: true }, $l, $r ) diff --git a/ecmascript/transforms/src/tests.rs b/ecmascript/transforms/src/tests.rs index 74eee10d3ee..64efa356b86 100644 --- a/ecmascript/transforms/src/tests.rs +++ b/ecmascript/transforms/src/tests.rs @@ -1,4 +1,4 @@ -use crate::helpers::{Helpers, InjectHelpers}; +use crate::helpers::{InjectHelpers, HELPERS}; use ast::*; use sourcemap::SourceMapBuilder; use std::{ @@ -28,7 +28,9 @@ impl<'a> Tester<'a> { where F: FnOnce(&mut Tester) -> Result<(), ()>, { - let out = ::testing::run_test(false, |cm, handler| op(&mut Tester { cm, handler })); + let out = ::testing::run_test(false, |cm, handler| { + HELPERS.set(&Default::default(), || op(&mut Tester { cm, handler })) + }); match out { Ok(()) => {} @@ -150,12 +152,12 @@ impl<'a> Tester<'a> { } } -fn make_tr(op: F, tester: &mut Tester, helpers: Arc) -> P +fn make_tr(op: F, tester: &mut Tester) -> P where - F: FnOnce(&mut Tester, Arc) -> P, + F: FnOnce(&mut Tester) -> P, P: Fold, { - op(tester, helpers) + op(tester) } #[cfg(test)] @@ -176,15 +178,15 @@ pub(crate) fn test_transform( expected: &str, ok_if_code_eq: bool, ) where - F: FnOnce(&mut Tester, Arc) -> P, + F: FnOnce(&mut Tester) -> P, { crate::tests::Tester::run(|tester| { let expected = tester.apply_transform(::testing::DropSpan, "output.js", syntax, expected)?; eprintln!("----- Actual -----"); - let helpers = Arc::new(Helpers::default()); - let tr = crate::tests::make_tr(tr, tester, helpers.clone()); + + let tr = crate::tests::make_tr(tr, tester); let actual = tester .apply_transform(tr, "input.js", syntax, input)? .fold_with(&mut crate::hygiene::hygiene()) @@ -258,11 +260,10 @@ macro_rules! exec_tr { pub(crate) fn exec_tr(test_name: &str, syntax: Syntax, tr: F, input: &str) where - F: FnOnce(&mut Tester, Arc) -> P, + F: FnOnce(&mut Tester) -> P, { Tester::run(|tester| { - let helpers = Arc::new(Helpers::default()); - let tr = make_tr(tr, tester, helpers.clone()); + let tr = make_tr(tr, tester); let module = tester.apply_transform( tr, @@ -282,7 +283,6 @@ where let src_without_helpers = tester.print(&module); let module = module.fold_with(&mut InjectHelpers { cm: tester.cm.clone(), - helpers: helpers.clone(), }); let src = tester.print(&module);