mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 22:56:11 +03:00
Make Helper scoped thread local (#134)
This allows injecting helpers per file without any multi threading issue.
This commit is contained in:
parent
a1629d3997
commit
4c6c4bc595
@ -21,6 +21,7 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
indexmap = "1"
|
indexmap = "1"
|
||||||
ordered-float = "1.0.1"
|
ordered-float = "1.0.1"
|
||||||
Inflector = { version = "0.11.4", default-features = false }
|
Inflector = { version = "0.11.4", default-features = false }
|
||||||
|
scoped-tls = { version = "0.1", features = ["nightly"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
testing = { path ="../../testing" }
|
testing = { path ="../../testing" }
|
||||||
|
@ -12,7 +12,6 @@ extern crate swc_ecma_transforms;
|
|||||||
extern crate test;
|
extern crate test;
|
||||||
extern crate testing;
|
extern crate testing;
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
use swc_common::{FileName, FoldWith};
|
use swc_common::{FileName, FoldWith};
|
||||||
use swc_ecma_parser::{Parser, Session, SourceFileInput, Syntax};
|
use swc_ecma_parser::{Parser, Session, SourceFileInput, Syntax};
|
||||||
use swc_ecma_transforms::{compat, helpers};
|
use swc_ecma_transforms::{compat, helpers};
|
||||||
@ -109,81 +108,82 @@ macro_rules! tr {
|
|||||||
()
|
()
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let helpers = Arc::new(helpers::Helpers::default());
|
helpers::HELPERS.set(&Default::default(), || {
|
||||||
let mut tr = $tr(helpers);
|
let mut tr = $tr();
|
||||||
|
|
||||||
$b.iter(|| {
|
$b.iter(|| {
|
||||||
let module = module.clone();
|
let module = module.clone();
|
||||||
test::black_box(module.fold_with(&mut tr))
|
test::black_box(module.fold_with(&mut tr))
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
|
})
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn all(b: &mut Bencher) {
|
fn all(b: &mut Bencher) {
|
||||||
tr!(b, |helpers| chain!(
|
tr!(b, || chain!(
|
||||||
compat::es2017(&helpers),
|
compat::es2017(),
|
||||||
compat::es2016(),
|
compat::es2016(),
|
||||||
compat::es2015(&helpers),
|
compat::es2015(),
|
||||||
compat::es3(),
|
compat::es3(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2018(b: &mut Bencher) {
|
fn es2018(b: &mut Bencher) {
|
||||||
tr!(b, |helpers| compat::es2018(&helpers));
|
tr!(b, || compat::es2018());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2018_object_rest_spread(b: &mut Bencher) {
|
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]
|
#[bench]
|
||||||
fn es2017(b: &mut Bencher) {
|
fn es2017(b: &mut Bencher) {
|
||||||
tr!(b, |helpers| compat::es2017(&helpers));
|
tr!(b, || compat::es2017());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2017_async_to_generator(b: &mut Bencher) {
|
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]
|
#[bench]
|
||||||
fn es2016(b: &mut Bencher) {
|
fn es2016(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2016());
|
tr!(b, || compat::es2016());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2016_exponentation(b: &mut Bencher) {
|
fn es2016_exponentation(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2016::exponentation());
|
tr!(b, || compat::es2016::exponentation());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015(b: &mut Bencher) {
|
fn es2015(b: &mut Bencher) {
|
||||||
tr!(b, |helpers| compat::es2015(&helpers));
|
tr!(b, || compat::es2015());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_arrow(b: &mut Bencher) {
|
fn es2015_arrow(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2015::arrow());
|
tr!(b, || compat::es2015::arrow());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_block_scoped_fn(b: &mut Bencher) {
|
fn es2015_block_scoped_fn(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2015::BlockScopedFns);
|
tr!(b, || compat::es2015::BlockScopedFns);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_block_scoping(b: &mut Bencher) {
|
fn es2015_block_scoping(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2015::block_scoping());
|
tr!(b, || compat::es2015::block_scoping());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_classes(b: &mut Bencher) {
|
fn es2015_classes(b: &mut Bencher) {
|
||||||
tr!(b, |helpers| compat::es2015::Classes { helpers });
|
tr!(b, || compat::es2015::Classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
@ -198,50 +198,50 @@ fn es2015_destructuring(b: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_duplicate_keys(b: &mut Bencher) {
|
fn es2015_duplicate_keys(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2015::duplicate_keys());
|
tr!(b, || compat::es2015::duplicate_keys());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_parameters(b: &mut Bencher) {
|
fn es2015_parameters(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2015::parameters());
|
tr!(b, || compat::es2015::parameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_fn_name(b: &mut Bencher) {
|
fn es2015_fn_name(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2015::function_name());
|
tr!(b, || compat::es2015::function_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_for_of(b: &mut Bencher) {
|
fn es2015_for_of(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2015::for_of());
|
tr!(b, || compat::es2015::for_of());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_instanceof(b: &mut Bencher) {
|
fn es2015_instanceof(b: &mut Bencher) {
|
||||||
tr!(b, |helpers| compat::es2015::InstanceOf { helpers });
|
tr!(b, || compat::es2015::InstanceOf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_shorthand_property(b: &mut Bencher) {
|
fn es2015_shorthand_property(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2015::Shorthand);
|
tr!(b, || compat::es2015::Shorthand);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_spread(b: &mut Bencher) {
|
fn es2015_spread(b: &mut Bencher) {
|
||||||
tr!(b, |helpers| compat::es2015::Spread { helpers });
|
tr!(b, || compat::es2015::Spread);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_sticky_regex(b: &mut Bencher) {
|
fn es2015_sticky_regex(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es2015::StickyRegex);
|
tr!(b, || compat::es2015::StickyRegex);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es2015_typeof_symbol(b: &mut Bencher) {
|
fn es2015_typeof_symbol(b: &mut Bencher) {
|
||||||
tr!(b, |helpers| compat::es2015::TypeOfSymbol { helpers });
|
tr!(b, || compat::es2015::TypeOfSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn es3(b: &mut Bencher) {
|
fn es3(b: &mut Bencher) {
|
||||||
tr!(b, |_| compat::es3());
|
tr!(b, || compat::es3());
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ use super::*;
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Arrow,
|
|_| Arrow,
|
||||||
destructuring,
|
destructuring,
|
||||||
r#"let foo = ({bar}) => undefined;"#,
|
r#"let foo = ({bar}) => undefined;"#,
|
||||||
r#"let foo = function ({bar}) {
|
r#"let foo = function ({bar}) {
|
||||||
@ -12,7 +12,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Arrow,
|
|_| Arrow,
|
||||||
basic,
|
basic,
|
||||||
r#"let echo = (bar) => bar"#,
|
r#"let echo = (bar) => bar"#,
|
||||||
r#"let echo = function(bar) {
|
r#"let echo = function(bar) {
|
||||||
@ -22,7 +22,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Arrow,
|
|_| Arrow,
|
||||||
empty_arguments,
|
empty_arguments,
|
||||||
r#"var t = () => 5 + 5;"#,
|
r#"var t = () => 5 + 5;"#,
|
||||||
r#"var t = function () {
|
r#"var t = function () {
|
||||||
@ -32,7 +32,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Arrow,
|
|_| Arrow,
|
||||||
expression,
|
expression,
|
||||||
r#"arr.map(x => x * x);"#,
|
r#"arr.map(x => x * x);"#,
|
||||||
r#"arr.map(function (x) {
|
r#"arr.map(function (x) {
|
||||||
@ -42,7 +42,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Arrow,
|
|_| Arrow,
|
||||||
inside_call,
|
inside_call,
|
||||||
r#"arr.map(i => i + 1);"#,
|
r#"arr.map(i => i + 1);"#,
|
||||||
r#"arr.map(function (i) {
|
r#"arr.map(function (i) {
|
||||||
@ -52,7 +52,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Arrow,
|
|_| Arrow,
|
||||||
multiple_arguments,
|
multiple_arguments,
|
||||||
r#"var t = (i, x) => i * x;"#,
|
r#"var t = (i, x) => i * x;"#,
|
||||||
r#"var t = function (i, x) {
|
r#"var t = function (i, x) {
|
||||||
@ -61,7 +61,7 @@ test!(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// test!(::swc_ecma_parser::Syntax::default(),
|
// test!(::swc_ecma_parser::Syntax::default(),
|
||||||
// |_, _| Arrow,
|
// |_| Arrow,
|
||||||
// nested,
|
// nested,
|
||||||
// r#"module.exports = {
|
// r#"module.exports = {
|
||||||
// init: function () {
|
// init: function () {
|
||||||
@ -96,7 +96,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Arrow,
|
|_| Arrow,
|
||||||
paren_insertion,
|
paren_insertion,
|
||||||
r#"var t = i => i * 5;"#,
|
r#"var t = i => i * 5;"#,
|
||||||
r#"var t = function (i) {
|
r#"var t = function (i) {
|
||||||
@ -106,7 +106,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Arrow,
|
|_| Arrow,
|
||||||
single_argument,
|
single_argument,
|
||||||
r#"var t = (i) => i * 5;"#,
|
r#"var t = (i) => i * 5;"#,
|
||||||
r#"var t = function (i) {
|
r#"var t = function (i) {
|
||||||
@ -116,7 +116,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Arrow,
|
|_| Arrow,
|
||||||
statement,
|
statement,
|
||||||
r#"nums.forEach(v => {
|
r#"nums.forEach(v => {
|
||||||
if (v % 5 === 0) {
|
if (v % 5 === 0) {
|
||||||
|
@ -34,7 +34,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| BlockScopedFns,
|
|_| BlockScopedFns,
|
||||||
basic,
|
basic,
|
||||||
r#"{
|
r#"{
|
||||||
function name (n) {
|
function name (n) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use super::get_prototype_of;
|
use super::get_prototype_of;
|
||||||
use crate::{helpers::Helpers, util::ExprFactory};
|
use crate::util::ExprFactory;
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use swc_atoms::JsWord;
|
use swc_atoms::JsWord;
|
||||||
@ -129,7 +129,6 @@ pub(super) fn constructor_fn(c: Constructor) -> Function {
|
|||||||
/// _this = ...;
|
/// _this = ...;
|
||||||
/// ```
|
/// ```
|
||||||
pub(super) struct ConstructorFolder<'a> {
|
pub(super) struct ConstructorFolder<'a> {
|
||||||
pub helpers: &'a Helpers,
|
|
||||||
pub class_name: &'a Ident,
|
pub class_name: &'a Ident,
|
||||||
pub mode: Option<SuperFoldingMode>,
|
pub mode: Option<SuperFoldingMode>,
|
||||||
/// Mark for `_this`
|
/// Mark for `_this`
|
||||||
@ -158,14 +157,11 @@ impl<'a> Fold<Stmt> for ConstructorFolder<'a> {
|
|||||||
args,
|
args,
|
||||||
..
|
..
|
||||||
})) => {
|
})) => {
|
||||||
let expr = make_possible_return_value(
|
let expr = make_possible_return_value(ReturningMode::Prototype {
|
||||||
self.helpers,
|
|
||||||
ReturningMode::Prototype {
|
|
||||||
is_constructor_default: self.is_constructor_default,
|
is_constructor_default: self.is_constructor_default,
|
||||||
class_name: self.class_name.clone(),
|
class_name: self.class_name.clone(),
|
||||||
args: Some(args),
|
args: Some(args),
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
match self.mode {
|
match self.mode {
|
||||||
Some(SuperFoldingMode::Assign) => Stmt::Expr(box Expr::Assign(AssignExpr {
|
Some(SuperFoldingMode::Assign) => Stmt::Expr(box Expr::Assign(AssignExpr {
|
||||||
@ -207,13 +203,10 @@ impl<'a> Fold<ReturnStmt> for ConstructorFolder<'a> {
|
|||||||
|
|
||||||
let arg = stmt.arg.fold_with(self);
|
let arg = stmt.arg.fold_with(self);
|
||||||
|
|
||||||
let arg = Some(box make_possible_return_value(
|
let arg = Some(box make_possible_return_value(ReturningMode::Returning {
|
||||||
self.helpers,
|
|
||||||
ReturningMode::Returning {
|
|
||||||
mark: self.mark,
|
mark: self.mark,
|
||||||
arg,
|
arg,
|
||||||
},
|
}));
|
||||||
));
|
|
||||||
|
|
||||||
ReturnStmt { arg, ..stmt }
|
ReturnStmt { arg, ..stmt }
|
||||||
}
|
}
|
||||||
@ -256,14 +249,11 @@ impl<'a> Fold<Expr> for ConstructorFolder<'a> {
|
|||||||
args,
|
args,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
let right = box make_possible_return_value(
|
let right = box make_possible_return_value(ReturningMode::Prototype {
|
||||||
self.helpers,
|
|
||||||
ReturningMode::Prototype {
|
|
||||||
class_name: self.class_name.clone(),
|
class_name: self.class_name.clone(),
|
||||||
args: Some(args),
|
args: Some(args),
|
||||||
is_constructor_default: self.is_constructor_default,
|
is_constructor_default: self.is_constructor_default,
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
Expr::Assign(AssignExpr {
|
Expr::Assign(AssignExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
@ -300,8 +290,8 @@ pub(super) enum ReturningMode {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn make_possible_return_value(helpers: &Helpers, mode: ReturningMode) -> Expr {
|
pub(super) fn make_possible_return_value(mode: ReturningMode) -> Expr {
|
||||||
helpers.possible_constructor_return();
|
helper!(possible_constructor_return);
|
||||||
let callee = quote_ident!("_possibleConstructorReturn").as_callee();
|
let callee = quote_ident!("_possibleConstructorReturn").as_callee();
|
||||||
|
|
||||||
Expr::Call(CallExpr {
|
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(), {
|
vec![ThisExpr { span: DUMMY_SP }.as_arg(), {
|
||||||
let apply = box Expr::Call(CallExpr {
|
let apply = box Expr::Call(CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
callee: get_prototype_of(helpers, &Expr::Ident(class_name))
|
callee: get_prototype_of(&Expr::Ident(class_name))
|
||||||
.member(fn_name)
|
.member(fn_name)
|
||||||
.as_callee(),
|
.as_callee(),
|
||||||
|
|
||||||
@ -404,10 +394,9 @@ pub(super) fn replace_this_in_constructor(mark: Mark, c: Constructor) -> (Constr
|
|||||||
self.found = true;
|
self.found = true;
|
||||||
let this = quote_ident!(DUMMY_SP.apply_mark(self.mark), "_this");
|
let this = quote_ident!(DUMMY_SP.apply_mark(self.mark), "_this");
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// self.helpers.assert_this_initialized();
|
|
||||||
|
|
||||||
if self.wrap_with_assertiion {
|
if self.wrap_with_assertiion {
|
||||||
|
helper!(assert_this_initialized);
|
||||||
|
|
||||||
Expr::Call(CallExpr {
|
Expr::Call(CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
callee: quote_ident!("_assertThisInitialized").as_callee(),
|
callee: quote_ident!("_assertThisInitialized").as_callee(),
|
||||||
|
@ -7,16 +7,13 @@ use self::{
|
|||||||
prop_name::HashKey,
|
prop_name::HashKey,
|
||||||
super_field::SuperFieldAccessFolder,
|
super_field::SuperFieldAccessFolder,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::util::{
|
||||||
helpers::Helpers,
|
alias_ident_for, default_constructor, prepend, prop_name_to_expr, ExprFactory, ModuleItemLike,
|
||||||
util::{
|
StmtLike,
|
||||||
alias_ident_for, default_constructor, prepend, prop_name_to_expr, ExprFactory,
|
|
||||||
ModuleItemLike, StmtLike,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use std::{iter, sync::Arc};
|
use std::iter;
|
||||||
use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP};
|
use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -59,10 +56,8 @@ mod tests;
|
|||||||
/// return Test;
|
/// return Test;
|
||||||
/// }();
|
/// }();
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone, Copy)]
|
||||||
pub struct Classes {
|
pub struct Classes;
|
||||||
pub helpers: Arc<Helpers>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Data {
|
struct Data {
|
||||||
key_prop: Box<Prop>,
|
key_prop: Box<Prop>,
|
||||||
@ -231,7 +226,7 @@ impl Classes {
|
|||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
if is_super_native {
|
if is_super_native {
|
||||||
self.helpers.wrap_native_super();
|
helper!(wrap_native_super);
|
||||||
(
|
(
|
||||||
params,
|
params,
|
||||||
vec![CallExpr {
|
vec![CallExpr {
|
||||||
@ -348,8 +343,8 @@ impl Classes {
|
|||||||
|
|
||||||
if let Some(ref super_class_ident) = super_class_ident {
|
if let Some(ref super_class_ident) = super_class_ident {
|
||||||
// inject helper methods
|
// inject helper methods
|
||||||
self.helpers.inherits();
|
helper!(inherits);
|
||||||
self.helpers.possible_constructor_return();
|
helper!(possible_constructor_return);
|
||||||
|
|
||||||
stmts.push(Stmt::Expr(box Expr::Call(CallExpr {
|
stmts.push(Stmt::Expr(box Expr::Call(CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
@ -392,7 +387,7 @@ impl Classes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// inject _classCallCheck(this, Bar);
|
// inject _classCallCheck(this, Bar);
|
||||||
self.helpers.class_call_check();
|
helper!(class_call_check);
|
||||||
inject_class_call_check(&mut constructor, class_name.clone());
|
inject_class_call_check(&mut constructor, class_name.clone());
|
||||||
let mut body = constructor.body.unwrap().stmts;
|
let mut body = constructor.body.unwrap().stmts;
|
||||||
// should we insert `var _this`?
|
// should we insert `var _this`?
|
||||||
@ -418,7 +413,6 @@ impl Classes {
|
|||||||
// Handle `super()`
|
// Handle `super()`
|
||||||
body = body.fold_with(&mut ConstructorFolder {
|
body = body.fold_with(&mut ConstructorFolder {
|
||||||
is_constructor_default,
|
is_constructor_default,
|
||||||
helpers: &self.helpers,
|
|
||||||
class_name: &class_name,
|
class_name: &class_name,
|
||||||
mode,
|
mode,
|
||||||
mark,
|
mark,
|
||||||
@ -456,10 +450,11 @@ impl Classes {
|
|||||||
arg: Some(box Expr::Ident(this)),
|
arg: Some(box Expr::Ident(this)),
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
let possible_return_value = box make_possible_return_value(
|
let possible_return_value =
|
||||||
&self.helpers,
|
box make_possible_return_value(ReturningMode::Returning {
|
||||||
ReturningMode::Returning { mark, arg: None },
|
mark,
|
||||||
);
|
arg: None,
|
||||||
|
});
|
||||||
body.push(Stmt::Return(ReturnStmt {
|
body.push(Stmt::Return(ReturnStmt {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
arg: Some(possible_return_value),
|
arg: Some(possible_return_value),
|
||||||
@ -520,7 +515,6 @@ impl Classes {
|
|||||||
let mut vars = vec![];
|
let mut vars = vec![];
|
||||||
let mut folder = SuperFieldAccessFolder {
|
let mut folder = SuperFieldAccessFolder {
|
||||||
class_name,
|
class_name,
|
||||||
helpers: &self.helpers,
|
|
||||||
vars: &mut vars,
|
vars: &mut vars,
|
||||||
constructor_this_mark: this_mark,
|
constructor_this_mark: this_mark,
|
||||||
// constructor cannot be static
|
// constructor cannot be static
|
||||||
@ -665,7 +659,6 @@ impl Classes {
|
|||||||
let mut vars = vec![];
|
let mut vars = vec![];
|
||||||
let mut folder = SuperFieldAccessFolder {
|
let mut folder = SuperFieldAccessFolder {
|
||||||
class_name: &class_name,
|
class_name: &class_name,
|
||||||
helpers: &self.helpers,
|
|
||||||
vars: &mut vars,
|
vars: &mut vars,
|
||||||
constructor_this_mark: None,
|
constructor_this_mark: None,
|
||||||
is_static: m.is_static,
|
is_static: m.is_static,
|
||||||
@ -736,7 +729,7 @@ impl Classes {
|
|||||||
if props.is_empty() && static_props.is_empty() {
|
if props.is_empty() && static_props.is_empty() {
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
self.helpers.create_class();
|
helper!(create_class);
|
||||||
vec![mk_create_class_call(
|
vec![mk_create_class_call(
|
||||||
class_name,
|
class_name,
|
||||||
mk_arg_obj_for_create_class(props),
|
mk_arg_obj_for_create_class(props),
|
||||||
@ -754,8 +747,8 @@ impl Classes {
|
|||||||
/// ```js
|
/// ```js
|
||||||
/// Child.__proto__ || Object.getPrototypeOf(Child)
|
/// Child.__proto__ || Object.getPrototypeOf(Child)
|
||||||
/// ```
|
/// ```
|
||||||
fn get_prototype_of(helpers: &Helpers, obj: &Expr) -> Expr {
|
fn get_prototype_of(obj: &Expr) -> Expr {
|
||||||
helpers.get_prototype_of();
|
helper!(get_prototype_of);
|
||||||
|
|
||||||
Expr::Call(CallExpr {
|
Expr::Call(CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
use super::get_prototype_of;
|
use super::get_prototype_of;
|
||||||
use crate::{
|
use crate::util::{alias_ident_for, is_rest_arguments, ExprFactory};
|
||||||
helpers::Helpers,
|
|
||||||
util::{alias_ident_for, is_rest_arguments, ExprFactory},
|
|
||||||
};
|
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use swc_common::{Fold, FoldWith, Mark, Span, Spanned, DUMMY_SP};
|
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);
|
/// 'foo', this).call(this, a);
|
||||||
pub(super) struct SuperFieldAccessFolder<'a> {
|
pub(super) struct SuperFieldAccessFolder<'a> {
|
||||||
pub class_name: &'a Ident,
|
pub class_name: &'a Ident,
|
||||||
pub helpers: &'a Helpers,
|
|
||||||
pub vars: &'a mut Vec<VarDeclarator>,
|
pub vars: &'a mut Vec<VarDeclarator>,
|
||||||
/// Mark for the `_this`. Used only when folding constructor.
|
/// Mark for the `_this`. Used only when folding constructor.
|
||||||
pub constructor_this_mark: Option<Mark>,
|
pub constructor_this_mark: Option<Mark>,
|
||||||
@ -41,7 +38,6 @@ pub(super) struct SuperFieldAccessFolder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct SuperCalleeFolder<'a> {
|
struct SuperCalleeFolder<'a> {
|
||||||
helpers: &'a Helpers,
|
|
||||||
vars: &'a mut Vec<VarDeclarator>,
|
vars: &'a mut Vec<VarDeclarator>,
|
||||||
class_name: &'a Ident,
|
class_name: &'a Ident,
|
||||||
/// True if we should inject get and
|
/// 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<Expr>, computed: bool) -> Expr {
|
fn super_to_get_call(&mut self, super_token: Span, prop: Box<Expr>, computed: bool) -> Expr {
|
||||||
self.inject_get = true;
|
self.inject_get = true;
|
||||||
|
|
||||||
let proto_arg = get_prototype_of(
|
let proto_arg = get_prototype_of(&if self.is_static {
|
||||||
self.helpers,
|
|
||||||
&if self.is_static {
|
|
||||||
// Foo
|
// Foo
|
||||||
Expr::Ident(self.class_name.clone())
|
Expr::Ident(self.class_name.clone())
|
||||||
} else {
|
} else {
|
||||||
// Foo.prototype
|
// Foo.prototype
|
||||||
self.class_name.clone().member(quote_ident!("prototype"))
|
self.class_name.clone().member(quote_ident!("prototype"))
|
||||||
},
|
})
|
||||||
)
|
|
||||||
.as_arg();
|
.as_arg();
|
||||||
|
|
||||||
let prop_arg = match *prop {
|
let prop_arg = match *prop {
|
||||||
@ -209,7 +202,7 @@ impl<'a> SuperCalleeFolder<'a> {
|
|||||||
Some(mark) => {
|
Some(mark) => {
|
||||||
let this = quote_ident!(super_token.apply_mark(mark), "_this");
|
let this = quote_ident!(super_token.apply_mark(mark), "_this");
|
||||||
|
|
||||||
self.helpers.assert_this_initialized();
|
helper!(assert_this_initialized);
|
||||||
CallExpr {
|
CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
callee: quote_ident!("_assertThisInitialized").as_callee(),
|
callee: quote_ident!("_assertThisInitialized").as_callee(),
|
||||||
@ -264,11 +257,8 @@ impl<'a> SuperCalleeFolder<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let proto_arg = get_prototype_of(
|
let proto_arg =
|
||||||
self.helpers,
|
get_prototype_of(&self.class_name.clone().member(quote_ident!("prototype"))).as_arg();
|
||||||
&self.class_name.clone().member(quote_ident!("prototype")),
|
|
||||||
)
|
|
||||||
.as_arg();
|
|
||||||
|
|
||||||
let prop_arg = match *prop {
|
let prop_arg = match *prop {
|
||||||
Expr::Ident(Ident {
|
Expr::Ident(Ident {
|
||||||
@ -401,7 +391,6 @@ impl<'a> Fold<Expr> for SuperFieldAccessFolder<'a> {
|
|||||||
class_name: self.class_name,
|
class_name: self.class_name,
|
||||||
inject_get: false,
|
inject_get: false,
|
||||||
inject_set: false,
|
inject_set: false,
|
||||||
helpers: self.helpers,
|
|
||||||
vars: self.vars,
|
vars: self.vars,
|
||||||
constructor_this_mark: self.constructor_this_mark,
|
constructor_this_mark: self.constructor_this_mark,
|
||||||
is_static: self.is_static,
|
is_static: self.is_static,
|
||||||
@ -427,7 +416,7 @@ impl<'a> Fold<Expr> for SuperFieldAccessFolder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if callee_folder.inject_get {
|
if callee_folder.inject_get {
|
||||||
self.helpers.get();
|
helper!(get);
|
||||||
|
|
||||||
if should_invoke_call {
|
if should_invoke_call {
|
||||||
match n {
|
match n {
|
||||||
@ -482,7 +471,7 @@ impl<'a> Fold<Expr> for SuperFieldAccessFolder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if callee_folder.inject_set {
|
if callee_folder.inject_set {
|
||||||
self.helpers.set();
|
helper!(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
n.fold_children(self)
|
n.fold_children(self)
|
||||||
|
@ -9,26 +9,17 @@ fn syntax() -> Syntax {
|
|||||||
Syntax::default()
|
Syntax::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tr(helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn tr() -> impl Fold<Module> {
|
||||||
Classes { helpers }
|
Classes
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spec_tr(helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn spec_tr() -> impl Fold<Module> {
|
||||||
chain!(
|
chain!(resolver(), Classes, Spread, block_scoping(),)
|
||||||
resolver(),
|
|
||||||
Classes {
|
|
||||||
helpers: helpers.clone()
|
|
||||||
},
|
|
||||||
Spread {
|
|
||||||
helpers: helpers.clone()
|
|
||||||
},
|
|
||||||
block_scoping(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
custom_singleton,
|
custom_singleton,
|
||||||
r#"
|
r#"
|
||||||
let singleton;
|
let singleton;
|
||||||
@ -61,7 +52,7 @@ let Sub = function(_Foo) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
custom_native,
|
custom_native,
|
||||||
r#"
|
r#"
|
||||||
class List extends Array {}
|
class List extends Array {}
|
||||||
@ -80,7 +71,7 @@ let List = function(_Array) {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
custom_nested,
|
custom_nested,
|
||||||
r#"
|
r#"
|
||||||
class Hello{
|
class Hello{
|
||||||
@ -110,7 +101,7 @@ expect(new Outer().hello).toBe('hello');
|
|||||||
// spec_constructor_only
|
// spec_constructor_only
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_constructor_only,
|
spec_constructor_only,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -138,7 +129,7 @@ var Foo = function Foo() {
|
|||||||
// regression_5769_exec
|
// regression_5769_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_5769_exec,
|
regression_5769_exec,
|
||||||
r#"
|
r#"
|
||||||
class Point {
|
class Point {
|
||||||
@ -170,7 +161,7 @@ cp.m();
|
|||||||
// spec_this_not_allowed_before_super_in_derived_classes_5_exec
|
// spec_this_not_allowed_before_super_in_derived_classes_5_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_this_not_allowed_before_super_in_derived_classes_5_exec,
|
spec_this_not_allowed_before_super_in_derived_classes_5_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -191,7 +182,7 @@ test!(
|
|||||||
// We don't use function-name pass
|
// We don't use function-name pass
|
||||||
ignore,
|
ignore,
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_statement,
|
spec_statement,
|
||||||
r#"
|
r#"
|
||||||
var BaseView = class BaseView {
|
var BaseView = class BaseView {
|
||||||
@ -252,7 +243,7 @@ function () {
|
|||||||
// get_set_set_semantics_getter_defined_on_parent
|
// get_set_set_semantics_getter_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_getter_defined_on_parent,
|
get_set_set_semantics_getter_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -348,7 +339,7 @@ expect(obj.test).toBe(2);
|
|||||||
// spec_derived_constructor_must_call_super
|
// spec_derived_constructor_must_call_super
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_derived_constructor_must_call_super,
|
spec_derived_constructor_must_call_super,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -382,7 +373,7 @@ function (_Bar) {
|
|||||||
// get_set_get_semantics_data_defined_on_parent
|
// get_set_get_semantics_data_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_get_semantics_data_defined_on_parent,
|
get_set_get_semantics_data_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -443,7 +434,7 @@ expect(obj.get()).toBe(1);
|
|||||||
// get_set_call_semantics_setter_defined_on_parent_exec
|
// get_set_call_semantics_setter_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_call_semantics_setter_defined_on_parent_exec,
|
get_set_call_semantics_setter_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -477,7 +468,7 @@ expect(() => {
|
|||||||
// get_set_set_semantics_data_defined_on_parent_exec
|
// get_set_set_semantics_data_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_data_defined_on_parent_exec,
|
get_set_set_semantics_data_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -516,7 +507,7 @@ expect(obj.test).toBe(3);
|
|||||||
// regression_8499
|
// regression_8499
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_8499,
|
regression_8499,
|
||||||
r#"
|
r#"
|
||||||
// Pretend that `Reflect.construct` isn't supported.
|
// Pretend that `Reflect.construct` isn't supported.
|
||||||
@ -575,7 +566,7 @@ expect(constructor).toBe(CustomElement);
|
|||||||
// regression_5817
|
// regression_5817
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| chain!(tr(helpers), arrow()),
|
|_| chain!(tr(), arrow()),
|
||||||
regression_5817,
|
regression_5817,
|
||||||
r#"
|
r#"
|
||||||
class A extends B {
|
class A extends B {
|
||||||
@ -624,7 +615,7 @@ function (_B) {
|
|||||||
// get_set_set_semantics_not_defined_on_parent_setter_on_obj
|
// get_set_set_semantics_not_defined_on_parent_setter_on_obj
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_not_defined_on_parent_setter_on_obj,
|
get_set_set_semantics_not_defined_on_parent_setter_on_obj,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -700,7 +691,7 @@ expect(obj.test).toBe(3);
|
|||||||
// get_set_get_semantics_setter_defined_on_parent
|
// get_set_get_semantics_setter_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_get_semantics_setter_defined_on_parent,
|
get_set_get_semantics_setter_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -782,7 +773,7 @@ expect(obj.get()).toBeUndefined();
|
|||||||
// spec_this_not_allowed_before_super_in_derived_classes_4
|
// spec_this_not_allowed_before_super_in_derived_classes_4
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_this_not_allowed_before_super_in_derived_classes_4,
|
spec_this_not_allowed_before_super_in_derived_classes_4,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -823,7 +814,7 @@ function (_Bar) {
|
|||||||
// spec_calling_super_properties
|
// spec_calling_super_properties
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_calling_super_properties,
|
spec_calling_super_properties,
|
||||||
r#"
|
r#"
|
||||||
class Test extends Foo {
|
class Test extends Foo {
|
||||||
@ -874,7 +865,7 @@ function (_Foo) {
|
|||||||
// spec_instance_getter_and_setter
|
// spec_instance_getter_and_setter
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_instance_getter_and_setter,
|
spec_instance_getter_and_setter,
|
||||||
r#"
|
r#"
|
||||||
class Test {
|
class Test {
|
||||||
@ -917,7 +908,7 @@ test!(
|
|||||||
// Module
|
// Module
|
||||||
ignore,
|
ignore,
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_2941,
|
regression_2941,
|
||||||
r#"
|
r#"
|
||||||
export default class {}
|
export default class {}
|
||||||
@ -943,7 +934,7 @@ exports.default = _default;
|
|||||||
// regression_T2494
|
// regression_T2494
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_t2494,
|
regression_t2494,
|
||||||
r#"
|
r#"
|
||||||
var x = {
|
var x = {
|
||||||
@ -975,7 +966,7 @@ var x = {
|
|||||||
// spec_inferred_expression_name
|
// spec_inferred_expression_name
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_inferred_expression_name,
|
spec_inferred_expression_name,
|
||||||
r#"
|
r#"
|
||||||
var o = { foo: class foo {} };
|
var o = { foo: class foo {} };
|
||||||
@ -998,7 +989,7 @@ test_exec!(
|
|||||||
// Wrong test (babel + jest fails)
|
// Wrong test (babel + jest fails)
|
||||||
ignore,
|
ignore,
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_8499_exec,
|
regression_8499_exec,
|
||||||
r#"
|
r#"
|
||||||
// Pretend that `Reflect.construct` isn't supported.
|
// Pretend that `Reflect.construct` isn't supported.
|
||||||
@ -1025,7 +1016,7 @@ expect(constructor).toBe(CustomElement);
|
|||||||
// spec_default_super
|
// spec_default_super
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_default_super,
|
spec_default_super,
|
||||||
r#"
|
r#"
|
||||||
class Test {
|
class Test {
|
||||||
@ -1080,7 +1071,7 @@ expect(Test.test()).toBe(Function);
|
|||||||
// spec_default_super
|
// spec_default_super
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_default_super_constructor,
|
spec_default_super_constructor,
|
||||||
r#"
|
r#"
|
||||||
class Test {
|
class Test {
|
||||||
@ -1100,7 +1091,7 @@ var Test = function Test() {
|
|||||||
// get_set_get_semantics_getter_defined_on_parent
|
// get_set_get_semantics_getter_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_get_semantics_getter_defined_on_parent,
|
get_set_get_semantics_getter_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -1186,7 +1177,7 @@ expect(obj.get()).toBe(1);
|
|||||||
// spec_this_not_allowed_before_super_in_derived_classes
|
// spec_this_not_allowed_before_super_in_derived_classes
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_this_not_allowed_before_super_in_derived_classes,
|
spec_this_not_allowed_before_super_in_derived_classes,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -1223,7 +1214,7 @@ function (_Bar) {
|
|||||||
// get_set_call_semantics_getter_defined_on_parent
|
// get_set_call_semantics_getter_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_call_semantics_getter_defined_on_parent,
|
get_set_call_semantics_getter_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -1321,7 +1312,7 @@ expect(obj.call(1, 2, 3)).toBe(1);
|
|||||||
// spec_derived_constructor_must_call_super_4_exec
|
// spec_derived_constructor_must_call_super_4_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_derived_constructor_must_call_super_4_exec,
|
spec_derived_constructor_must_call_super_4_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -1342,7 +1333,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised");
|
|||||||
// spec_export_default
|
// spec_export_default
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_export_default,
|
spec_export_default,
|
||||||
r#"
|
r#"
|
||||||
export default class Foo {}
|
export default class Foo {}
|
||||||
@ -1361,7 +1352,7 @@ export { Foo as default };
|
|||||||
// get_set_call_semantics_data_defined_on_parent_exec
|
// get_set_call_semantics_data_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_call_semantics_data_defined_on_parent_exec,
|
get_set_call_semantics_data_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -1395,7 +1386,7 @@ expect(obj.call(1, 2, 3)).toBe(1);
|
|||||||
// extend_builtins_spec_exec
|
// extend_builtins_spec_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
extend_builtins_spec_exec,
|
extend_builtins_spec_exec,
|
||||||
r#"
|
r#"
|
||||||
class List extends Array {}
|
class List extends Array {}
|
||||||
@ -1409,7 +1400,7 @@ expect(new List).toBeInstanceOf(Array);
|
|||||||
// get_set_call_semantics_data_defined_on_parent
|
// get_set_call_semantics_data_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_call_semantics_data_defined_on_parent,
|
get_set_call_semantics_data_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -1501,7 +1492,7 @@ expect(obj.call(1, 2, 3)).toBe(1);
|
|||||||
// spec_static
|
// spec_static
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_static,
|
spec_static,
|
||||||
r#"
|
r#"
|
||||||
class A {
|
class A {
|
||||||
@ -1546,7 +1537,7 @@ function () {
|
|||||||
// regression_T6755
|
// regression_T6755
|
||||||
|
|
||||||
// get_set_memoized_update
|
// get_set_memoized_update
|
||||||
test!(syntax(),|_,helpers| tr(helpers), get_set_memoized_update, r#"
|
test!(syntax(),|_| tr(), get_set_memoized_update, r#"
|
||||||
|
|
||||||
class Base {}
|
class Base {}
|
||||||
Object.defineProperty(Base.prototype, 0, {
|
Object.defineProperty(Base.prototype, 0, {
|
||||||
@ -1657,7 +1648,7 @@ expect(obj[1]).toBe(2);
|
|||||||
"#);
|
"#);
|
||||||
|
|
||||||
// spec_nested_class_super_property_in_key
|
// 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#"
|
spec_nested_class_super_property_in_key, r#"
|
||||||
|
|
||||||
class Hello {
|
class Hello {
|
||||||
@ -1736,7 +1727,7 @@ expect(new Outer().hello()).toBe('hello');
|
|||||||
"#);
|
"#);
|
||||||
|
|
||||||
// spec_super_reference_in_prop_exression
|
// 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 {
|
class Foo extends Bar {
|
||||||
constructor() {
|
constructor() {
|
||||||
super[super().method]();
|
super[super().method]();
|
||||||
@ -1767,7 +1758,7 @@ function (_Bar) {
|
|||||||
// spec_super_reference_before_in_lambda_exec
|
// spec_super_reference_before_in_lambda_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_super_reference_before_in_lambda_exec,
|
spec_super_reference_before_in_lambda_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {
|
class Bar {
|
||||||
@ -1788,7 +1779,7 @@ new Foo();
|
|||||||
// spec_nested_class_super_call_in_key_exec
|
// spec_nested_class_super_call_in_key_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_nested_class_super_call_in_key_exec,
|
spec_nested_class_super_call_in_key_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -1822,7 +1813,7 @@ expect(new Outer().hello()).toBe('hello');
|
|||||||
// spec_this_not_allowed_before_super_in_derived_classes_4_exec
|
// spec_this_not_allowed_before_super_in_derived_classes_4_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_this_not_allowed_before_super_in_derived_classes_4_exec,
|
spec_this_not_allowed_before_super_in_derived_classes_4_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -1843,7 +1834,7 @@ new Foo();
|
|||||||
// spec_this_not_allowed_before_super_in_derived_classes_2
|
// spec_this_not_allowed_before_super_in_derived_classes_2
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_this_not_allowed_before_super_in_derived_classes_2,
|
spec_this_not_allowed_before_super_in_derived_classes_2,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -1878,7 +1869,7 @@ function (_Bar) {
|
|||||||
// spec_accessing_super_properties
|
// spec_accessing_super_properties
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_accessing_super_properties,
|
spec_accessing_super_properties,
|
||||||
r#"
|
r#"
|
||||||
class Test extends Foo {
|
class Test extends Foo {
|
||||||
@ -1917,7 +1908,7 @@ function (_Foo) {
|
|||||||
// spec_computed_methods
|
// spec_computed_methods
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_computed_methods,
|
spec_computed_methods,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -1962,7 +1953,7 @@ function () {
|
|||||||
// get_set_set_semantics_not_defined_on_parent_data_on_obj_exec
|
// get_set_set_semantics_not_defined_on_parent_data_on_obj_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_not_defined_on_parent_data_on_obj_exec,
|
get_set_set_semantics_not_defined_on_parent_data_on_obj_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -1992,7 +1983,7 @@ expect(obj.test).toBe(3);
|
|||||||
// get_set_set_semantics_data_defined_on_parent
|
// get_set_set_semantics_data_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_data_defined_on_parent,
|
get_set_set_semantics_data_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -2073,7 +2064,7 @@ expect(obj.test).toBe(3);
|
|||||||
// get_set_set_semantics_not_defined_on_parent_getter_on_obj
|
// get_set_set_semantics_not_defined_on_parent_getter_on_obj
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_not_defined_on_parent_getter_on_obj,
|
get_set_set_semantics_not_defined_on_parent_getter_on_obj,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -2140,7 +2131,7 @@ expect(obj.test).toBe(3);
|
|||||||
// spec_returning_from_derived_constructor_exec
|
// spec_returning_from_derived_constructor_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_returning_from_derived_constructor_exec,
|
spec_returning_from_derived_constructor_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -2208,7 +2199,7 @@ expect(() => {
|
|||||||
// regression_2694
|
// regression_2694
|
||||||
|
|
||||||
// regression_5769
|
// regression_5769
|
||||||
test!(syntax(),|_,helpers| tr(helpers), regression_5769, r#"
|
test!(syntax(),|_| tr(), regression_5769, r#"
|
||||||
class Point {
|
class Point {
|
||||||
getX() {
|
getX() {
|
||||||
expect(this.x).toBe(3); // C
|
expect(this.x).toBe(3); // C
|
||||||
@ -2289,7 +2280,7 @@ cp.m();
|
|||||||
// spec_super_function_fallback
|
// spec_super_function_fallback
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_super_function_fallback,
|
spec_super_function_fallback,
|
||||||
r#"
|
r#"
|
||||||
class Test {
|
class Test {
|
||||||
@ -2318,10 +2309,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| chain!(
|
|tester| chain!(tr(), jsx(tester.cm.clone(), Default::default())),
|
||||||
tr(helpers.clone()),
|
|
||||||
jsx(tester.cm.clone(), Default::default(), helpers)
|
|
||||||
),
|
|
||||||
regression_2775,
|
regression_2775,
|
||||||
r#"
|
r#"
|
||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
@ -2382,7 +2370,7 @@ exports.default = RandomComponent;
|
|||||||
// extend_builtins_imported_babel_plugin_transform_builtin_classes_exec
|
// extend_builtins_imported_babel_plugin_transform_builtin_classes_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
extend_builtins_imported_babel_plugin_transform_builtin_classes_exec,
|
extend_builtins_imported_babel_plugin_transform_builtin_classes_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -2432,7 +2420,7 @@ test!(
|
|||||||
// Module
|
// Module
|
||||||
ignore,
|
ignore,
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_3028,
|
regression_3028,
|
||||||
r#"
|
r#"
|
||||||
class b {
|
class b {
|
||||||
@ -2517,7 +2505,7 @@ exports.default = a2;
|
|||||||
// spec_instance_setter
|
// spec_instance_setter
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_instance_setter,
|
spec_instance_setter,
|
||||||
r#"
|
r#"
|
||||||
class Test {
|
class Test {
|
||||||
@ -2552,7 +2540,7 @@ function () {
|
|||||||
// spec_nested_object_super_call_in_key
|
// spec_nested_object_super_call_in_key
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_nested_object_super_call_in_key,
|
spec_nested_object_super_call_in_key,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -2623,7 +2611,7 @@ expect(new Outer().hello()).toBe('hello');
|
|||||||
// get_set_set_semantics_not_defined_on_parent_not_on_obj
|
// get_set_set_semantics_not_defined_on_parent_not_on_obj
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_not_defined_on_parent_not_on_obj,
|
get_set_set_semantics_not_defined_on_parent_not_on_obj,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -2683,7 +2671,7 @@ expect(obj.test).toBe(3);
|
|||||||
// spec_derived_constructor_no_super_return_falsey
|
// spec_derived_constructor_no_super_return_falsey
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_derived_constructor_no_super_return_falsey,
|
spec_derived_constructor_no_super_return_falsey,
|
||||||
r#"
|
r#"
|
||||||
class Child extends Base {
|
class Child extends Base {
|
||||||
@ -2717,7 +2705,7 @@ function (_Base) {
|
|||||||
// spec_this_not_allowed_before_super_in_derived_classes_5
|
// spec_this_not_allowed_before_super_in_derived_classes_5
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_this_not_allowed_before_super_in_derived_classes_5,
|
spec_this_not_allowed_before_super_in_derived_classes_5,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -2754,7 +2742,7 @@ function (_Bar) {
|
|||||||
// spec_constructor
|
// spec_constructor
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_constructor,
|
spec_constructor,
|
||||||
r#"
|
r#"
|
||||||
class Test {
|
class Test {
|
||||||
@ -2822,7 +2810,7 @@ var ConstructorScoping = function ConstructorScoping() {
|
|||||||
// spec_preserves_directives
|
// spec_preserves_directives
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_preserves_directives,
|
spec_preserves_directives,
|
||||||
r#"
|
r#"
|
||||||
class MyCtrl {
|
class MyCtrl {
|
||||||
@ -2884,7 +2872,7 @@ var MyCtrl3 = function MyCtrl3(a) {
|
|||||||
// spec_derived_constructor_no_super_return_object
|
// spec_derived_constructor_no_super_return_object
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_derived_constructor_no_super_return_object,
|
spec_derived_constructor_no_super_return_object,
|
||||||
r#"
|
r#"
|
||||||
class Child extends Base {
|
class Child extends Base {
|
||||||
@ -2918,7 +2906,7 @@ function (_Base) {
|
|||||||
// get_set_get_semantics_getter_defined_on_parent_exec
|
// get_set_get_semantics_getter_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_get_semantics_getter_defined_on_parent_exec,
|
get_set_get_semantics_getter_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -2952,7 +2940,7 @@ test!(
|
|||||||
// Module
|
// Module
|
||||||
ignore,
|
ignore,
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_t6750,
|
regression_t6750,
|
||||||
r#"
|
r#"
|
||||||
export default function() {
|
export default function() {
|
||||||
@ -2994,7 +2982,7 @@ function _default() {
|
|||||||
// spec_instance_method
|
// spec_instance_method
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_instance_method,
|
spec_instance_method,
|
||||||
r#"
|
r#"
|
||||||
class Test {
|
class Test {
|
||||||
@ -3027,7 +3015,7 @@ function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// regression_T2997
|
// regression_T2997
|
||||||
test!(syntax(),|_,helpers| tr(helpers), regression_t2997, r#"
|
test!(syntax(),|_| tr(), regression_t2997, r#"
|
||||||
class A {}
|
class A {}
|
||||||
|
|
||||||
class B extends A {
|
class B extends A {
|
||||||
@ -3065,7 +3053,7 @@ function (_A) {
|
|||||||
// spec_constructor_binding_collision
|
// spec_constructor_binding_collision
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_constructor_binding_collision,
|
spec_constructor_binding_collision,
|
||||||
r#"
|
r#"
|
||||||
class Example {
|
class Example {
|
||||||
@ -3092,7 +3080,7 @@ var t = new Example();
|
|||||||
);
|
);
|
||||||
|
|
||||||
// spec_super_class_anonymous
|
// 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 {}) {
|
class TestEmpty extends (class {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3260,7 +3248,7 @@ function () {
|
|||||||
// spec_nested_class_super_call_in_key
|
// spec_nested_class_super_call_in_key
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_nested_class_super_call_in_key,
|
spec_nested_class_super_call_in_key,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -3344,7 +3332,7 @@ expect(new Outer().hello()).toBe('hello');
|
|||||||
// get_set_get_semantics_data_defined_on_parent_exec
|
// get_set_get_semantics_data_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_get_semantics_data_defined_on_parent_exec,
|
get_set_get_semantics_data_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -3381,7 +3369,7 @@ test!(
|
|||||||
// Module
|
// Module
|
||||||
ignore,
|
ignore,
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_2663,
|
regression_2663,
|
||||||
r#"
|
r#"
|
||||||
import net from 'net';
|
import net from 'net';
|
||||||
@ -3462,7 +3450,7 @@ exports.default = Connection;
|
|||||||
// get_set_set_semantics_setter_defined_on_parent_exec
|
// get_set_set_semantics_setter_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_setter_defined_on_parent_exec,
|
get_set_set_semantics_setter_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -3497,7 +3485,7 @@ expect(obj.test).toBe(2);
|
|||||||
// regression_5817_exec
|
// regression_5817_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_5817_exec,
|
regression_5817_exec,
|
||||||
r#"
|
r#"
|
||||||
// https://github.com/babel/babel/issues/5817
|
// https://github.com/babel/babel/issues/5817
|
||||||
@ -3525,7 +3513,7 @@ expect(table.returnParam(false)).toBe(false);
|
|||||||
// spec_instance_getter
|
// spec_instance_getter
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_instance_getter,
|
spec_instance_getter,
|
||||||
r#"
|
r#"
|
||||||
class Test {
|
class Test {
|
||||||
@ -3560,7 +3548,7 @@ function () {
|
|||||||
// spec_this_not_allowed_before_super_in_derived_classes_3
|
// spec_this_not_allowed_before_super_in_derived_classes_3
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_this_not_allowed_before_super_in_derived_classes_3,
|
spec_this_not_allowed_before_super_in_derived_classes_3,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -3602,7 +3590,7 @@ function (_Bar) {
|
|||||||
test!(
|
test!(
|
||||||
// TODO(kdy1): Unignore this.
|
// TODO(kdy1): Unignore this.
|
||||||
ignore,
|
ignore,
|
||||||
syntax(),|_,helpers| spec_tr(helpers), spec_accessing_super_class, r#"
|
syntax(),|_| spec_tr(), spec_accessing_super_class, r#"
|
||||||
class Test extends Foo {
|
class Test extends Foo {
|
||||||
constructor() {
|
constructor() {
|
||||||
woops.super.test();
|
woops.super.test();
|
||||||
@ -3684,7 +3672,7 @@ function (_Foo) {
|
|||||||
// get_set_call_semantics_getter_defined_on_parent_exec
|
// get_set_call_semantics_getter_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_call_semantics_getter_defined_on_parent_exec,
|
get_set_call_semantics_getter_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -3721,7 +3709,7 @@ expect(obj.call(1, 2, 3)).toBe(1);
|
|||||||
// spec_this_not_allowed_before_super_in_derived_classes_exec
|
// spec_this_not_allowed_before_super_in_derived_classes_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_this_not_allowed_before_super_in_derived_classes_exec,
|
spec_this_not_allowed_before_super_in_derived_classes_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -3741,7 +3729,7 @@ expect(() => new Foo()).toThrow();
|
|||||||
// spec_nested_object_super_property_in_key_exec
|
// spec_nested_object_super_property_in_key_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_nested_object_super_property_in_key_exec,
|
spec_nested_object_super_property_in_key_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -3772,7 +3760,7 @@ expect(new Outer().hello()).toBe('hello');
|
|||||||
// regression_T6712
|
// regression_T6712
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_t6712,
|
regression_t6712,
|
||||||
r#"
|
r#"
|
||||||
class A {
|
class A {
|
||||||
@ -3807,7 +3795,7 @@ function () {
|
|||||||
// get_set_set_semantics_setter_defined_on_parent
|
// get_set_set_semantics_setter_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_setter_defined_on_parent,
|
get_set_set_semantics_setter_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -3898,7 +3886,7 @@ expect(obj.test).toBe(2);
|
|||||||
// get_set_call_semantics_not_defined_on_parent
|
// get_set_call_semantics_not_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_call_semantics_not_defined_on_parent,
|
get_set_call_semantics_not_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -3969,7 +3957,7 @@ expect(() => {
|
|||||||
// spec_derived_constructor_must_call_super_2_exec
|
// spec_derived_constructor_must_call_super_2_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_derived_constructor_must_call_super_2_exec,
|
spec_derived_constructor_must_call_super_2_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -3990,7 +3978,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised");
|
|||||||
// spec_nested_object_super_property_in_key
|
// spec_nested_object_super_property_in_key
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_nested_object_super_property_in_key,
|
spec_nested_object_super_property_in_key,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4063,7 +4051,7 @@ expect(new Outer().hello()).toBe('hello');
|
|||||||
// get_set_set_semantics_not_defined_on_parent_setter_on_obj_exec
|
// get_set_set_semantics_not_defined_on_parent_setter_on_obj_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_not_defined_on_parent_setter_on_obj_exec,
|
get_set_set_semantics_not_defined_on_parent_setter_on_obj_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4098,7 +4086,7 @@ expect(obj.test).toBe(3);
|
|||||||
// spec_this_not_allowed_before_super_in_derived_classes_2_exec
|
// spec_this_not_allowed_before_super_in_derived_classes_2_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_this_not_allowed_before_super_in_derived_classes_2_exec,
|
spec_this_not_allowed_before_super_in_derived_classes_2_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -4117,7 +4105,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised");
|
|||||||
// extend_builtins_overwritten_null_exec
|
// extend_builtins_overwritten_null_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
extend_builtins_overwritten_null_exec,
|
extend_builtins_overwritten_null_exec,
|
||||||
r#"
|
r#"
|
||||||
let Array = null;
|
let Array = null;
|
||||||
@ -4130,7 +4118,7 @@ expect(List.prototype.__proto__).toBeUndefined();
|
|||||||
// spec_super_reference_before_bare_super_inline_exec
|
// spec_super_reference_before_bare_super_inline_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_super_reference_before_bare_super_inline_exec,
|
spec_super_reference_before_bare_super_inline_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -4149,7 +4137,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised");
|
|||||||
// get_set_call_semantics_setter_defined_on_parent
|
// get_set_call_semantics_setter_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_call_semantics_setter_defined_on_parent,
|
get_set_call_semantics_setter_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4236,7 +4224,7 @@ expect(() => {
|
|||||||
// spec_super_class
|
// spec_super_class
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_super_class,
|
spec_super_class,
|
||||||
r#"
|
r#"
|
||||||
class Test extends Foo { }
|
class Test extends Foo { }
|
||||||
@ -4266,7 +4254,7 @@ function (_Foo) {
|
|||||||
// spec_nested_object_super_call_in_key_exec
|
// spec_nested_object_super_call_in_key_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_nested_object_super_call_in_key_exec,
|
spec_nested_object_super_call_in_key_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4300,7 +4288,7 @@ expect(new Outer().hello()).toBe('hello');
|
|||||||
// spec_derived_constructor_must_call_super_2
|
// spec_derived_constructor_must_call_super_2
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_derived_constructor_must_call_super_2,
|
spec_derived_constructor_must_call_super_2,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -4335,7 +4323,7 @@ function (_Bar) {
|
|||||||
// spec_derived_constructor_must_call_super_3
|
// spec_derived_constructor_must_call_super_3
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_derived_constructor_must_call_super_3,
|
spec_derived_constructor_must_call_super_3,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -4374,7 +4362,7 @@ function (_Bar) {
|
|||||||
// spec_this_not_allowed_before_super_in_derived_classes_3_exec
|
// spec_this_not_allowed_before_super_in_derived_classes_3_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_this_not_allowed_before_super_in_derived_classes_3_exec,
|
spec_this_not_allowed_before_super_in_derived_classes_3_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -4395,7 +4383,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised");
|
|||||||
// get_set_get_semantics_not_defined_on_parent_exec
|
// get_set_get_semantics_not_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_get_semantics_not_defined_on_parent_exec,
|
get_set_get_semantics_not_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4423,7 +4411,7 @@ expect(obj.get()).toBeUndefined();
|
|||||||
// get_set_set_semantics_not_defined_on_parent_data_on_obj
|
// get_set_set_semantics_not_defined_on_parent_data_on_obj
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_not_defined_on_parent_data_on_obj,
|
get_set_set_semantics_not_defined_on_parent_data_on_obj,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4493,7 +4481,7 @@ expect(obj.test).toBe(3);
|
|||||||
// get_set_set_semantics_not_defined_on_parent_getter_on_obj_exec
|
// get_set_set_semantics_not_defined_on_parent_getter_on_obj_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_not_defined_on_parent_getter_on_obj_exec,
|
get_set_set_semantics_not_defined_on_parent_getter_on_obj_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4524,7 +4512,7 @@ expect(obj.test).toBe(3);
|
|||||||
// exec
|
// exec
|
||||||
|
|
||||||
// get_set_memoized_assign
|
// get_set_memoized_assign
|
||||||
test!(syntax(),|_,helpers| tr(helpers), get_set_memoized_assign, r#"
|
test!(syntax(),|_| tr(), get_set_memoized_assign, r#"
|
||||||
|
|
||||||
class Base {}
|
class Base {}
|
||||||
Object.defineProperty(Base.prototype, 0, {
|
Object.defineProperty(Base.prototype, 0, {
|
||||||
@ -4637,7 +4625,7 @@ expect(obj[1]).toBe(2);
|
|||||||
// extend_builtins_builtin_objects_throw_when_wrapped_exec
|
// extend_builtins_builtin_objects_throw_when_wrapped_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
extend_builtins_builtin_objects_throw_when_wrapped_exec,
|
extend_builtins_builtin_objects_throw_when_wrapped_exec,
|
||||||
r#"
|
r#"
|
||||||
// JSON is wrapped because it starts with an uppercase letter, but it
|
// 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
|
// get_set_call_semantics_not_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_call_semantics_not_defined_on_parent_exec,
|
get_set_call_semantics_not_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4682,7 +4670,7 @@ expect(() => {
|
|||||||
// spec_nested_class_super_property_in_key_exec
|
// spec_nested_class_super_property_in_key_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_nested_class_super_property_in_key_exec,
|
spec_nested_class_super_property_in_key_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4713,7 +4701,7 @@ expect(new Outer().hello()).toBe('hello');
|
|||||||
// spec_relaxed_method_coercion
|
// spec_relaxed_method_coercion
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_relaxed_method_coercion,
|
spec_relaxed_method_coercion,
|
||||||
r#"
|
r#"
|
||||||
// #1649
|
// #1649
|
||||||
@ -4751,7 +4739,7 @@ function () {
|
|||||||
// spec_derived_constructor_must_call_super_3_exec
|
// spec_derived_constructor_must_call_super_3_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_derived_constructor_must_call_super_3_exec,
|
spec_derived_constructor_must_call_super_3_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -4771,7 +4759,7 @@ new Foo();
|
|||||||
// get_set_memoized_update_exec
|
// get_set_memoized_update_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_memoized_update_exec,
|
get_set_memoized_update_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4822,7 +4810,7 @@ expect(obj[1]).toBe(2);
|
|||||||
// spec_computed_methods_exec
|
// spec_computed_methods_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_computed_methods_exec,
|
spec_computed_methods_exec,
|
||||||
r#"
|
r#"
|
||||||
const sym = Symbol();
|
const sym = Symbol();
|
||||||
@ -4849,7 +4837,7 @@ expect(i[sym]()).toBe(3);
|
|||||||
// get_set_memoized_assign_exec
|
// get_set_memoized_assign_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_memoized_assign_exec,
|
get_set_memoized_assign_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -4900,7 +4888,7 @@ expect(obj[1]).toBe(2);
|
|||||||
// spec_derived_constructor_must_call_super_4
|
// spec_derived_constructor_must_call_super_4
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_derived_constructor_must_call_super_4,
|
spec_derived_constructor_must_call_super_4,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -4937,7 +4925,7 @@ function (_Bar) {
|
|||||||
// spec_super_class_id_member_expression
|
// spec_super_class_id_member_expression
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_super_class_id_member_expression,
|
spec_super_class_id_member_expression,
|
||||||
r#"
|
r#"
|
||||||
class BaseController extends Chaplin.Controller {
|
class BaseController extends Chaplin.Controller {
|
||||||
@ -4986,7 +4974,7 @@ function (_Another) {
|
|||||||
// spec_delay_arrow_function_for_bare_super_derived
|
// spec_delay_arrow_function_for_bare_super_derived
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_delay_arrow_function_for_bare_super_derived,
|
spec_delay_arrow_function_for_bare_super_derived,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -5027,7 +5015,7 @@ function (_Bar) {
|
|||||||
// spec_default_super_exec
|
// spec_default_super_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_default_super_exec,
|
spec_default_super_exec,
|
||||||
r#"
|
r#"
|
||||||
class Test {
|
class Test {
|
||||||
@ -5054,7 +5042,7 @@ expect(Test.test()).toBe(Function);
|
|||||||
// spec_super_reference_before_in_lambda_3_exec
|
// spec_super_reference_before_in_lambda_3_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_super_reference_before_in_lambda_3_exec,
|
spec_super_reference_before_in_lambda_3_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {
|
class Bar {
|
||||||
@ -5079,7 +5067,7 @@ new Foo();
|
|||||||
// get_set_get_semantics_not_defined_on_parent
|
// get_set_get_semantics_not_defined_on_parent
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_get_semantics_not_defined_on_parent,
|
get_set_get_semantics_not_defined_on_parent,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -5147,7 +5135,7 @@ expect(obj.get()).toBeUndefined();
|
|||||||
// spec_plain_class
|
// spec_plain_class
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_plain_class,
|
spec_plain_class,
|
||||||
r#"
|
r#"
|
||||||
class Test { }
|
class Test { }
|
||||||
@ -5166,7 +5154,7 @@ var Test = function Test() {
|
|||||||
// spec_super_reference_before_bare_super_exec
|
// spec_super_reference_before_bare_super_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_super_reference_before_bare_super_exec,
|
spec_super_reference_before_bare_super_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -5186,7 +5174,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised");
|
|||||||
// spec_super_reference_before_in_lambda_2_exec
|
// spec_super_reference_before_in_lambda_2_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_super_reference_before_in_lambda_2_exec,
|
spec_super_reference_before_in_lambda_2_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {
|
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
|
// get_set_set_semantics_not_defined_on_parent_not_on_obj_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_not_defined_on_parent_not_on_obj_exec,
|
get_set_set_semantics_not_defined_on_parent_not_on_obj_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -5234,7 +5222,7 @@ expect(obj.test).toBe(3);
|
|||||||
// get_set_get_semantics_setter_defined_on_parent_exec
|
// get_set_get_semantics_setter_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_get_semantics_setter_defined_on_parent_exec,
|
get_set_get_semantics_setter_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -5265,7 +5253,7 @@ expect(obj.get()).toBeUndefined();
|
|||||||
// extend_builtins_super_called_exec
|
// extend_builtins_super_called_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
extend_builtins_super_called_exec,
|
extend_builtins_super_called_exec,
|
||||||
r#"
|
r#"
|
||||||
var called = false;
|
var called = false;
|
||||||
@ -5286,7 +5274,7 @@ expect(called).toBe(true);
|
|||||||
// spec_derived_constructor_must_call_super_exec
|
// spec_derived_constructor_must_call_super_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_derived_constructor_must_call_super_exec,
|
spec_derived_constructor_must_call_super_exec,
|
||||||
r#"
|
r#"
|
||||||
class Bar {}
|
class Bar {}
|
||||||
@ -5307,7 +5295,7 @@ expect(() => new Foo()).toThrow("this hasn't been initialised");
|
|||||||
// spec_export_super_class
|
// spec_export_super_class
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_export_super_class,
|
spec_export_super_class,
|
||||||
r#"
|
r#"
|
||||||
export default class extends A {}
|
export default class extends A {}
|
||||||
@ -5335,7 +5323,7 @@ export { _default as default };
|
|||||||
// extend_builtins_wrap_native_super_exec
|
// extend_builtins_wrap_native_super_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
extend_builtins_wrap_native_super_exec,
|
extend_builtins_wrap_native_super_exec,
|
||||||
r#"
|
r#"
|
||||||
// basic sanity check to confirm the external wrapNativeSuper helper works
|
// 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
|
// spec_super_reference_in_prop_exression_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| spec_tr(helpers),
|
|_| spec_tr(),
|
||||||
spec_super_reference_in_prop_exression_exec,
|
spec_super_reference_in_prop_exression_exec,
|
||||||
r#"
|
r#"
|
||||||
let called = false;
|
let called = false;
|
||||||
@ -5402,7 +5390,7 @@ expect(called).toBe(true);
|
|||||||
// get_set_set_semantics_getter_defined_on_parent_exec
|
// get_set_set_semantics_getter_defined_on_parent_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
get_set_set_semantics_getter_defined_on_parent_exec,
|
get_set_set_semantics_getter_defined_on_parent_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
helpers::Helpers,
|
|
||||||
pass::Pass,
|
pass::Pass,
|
||||||
util::{ExprFactory, StmtLike},
|
util::{ExprFactory, StmtLike},
|
||||||
};
|
};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::sync::Arc;
|
|
||||||
use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP};
|
use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -41,14 +39,12 @@ mod tests;
|
|||||||
///
|
///
|
||||||
/// TODO(kdy1): cache reference like (_f = f, mutatorMap[_f].get = function(){})
|
/// TODO(kdy1): cache reference like (_f = f, mutatorMap[_f].get = function(){})
|
||||||
/// instead of (mutatorMap[f].get = function(){}
|
/// instead of (mutatorMap[f].get = function(){}
|
||||||
pub fn computed_properties(helpers: Arc<Helpers>) -> impl Pass + Clone {
|
pub fn computed_properties() -> impl Pass + Clone + Copy {
|
||||||
ComputedProps { helpers }
|
ComputedProps
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone, Copy)]
|
||||||
struct ComputedProps {
|
struct ComputedProps;
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ObjectLitFolder {
|
struct ObjectLitFolder {
|
||||||
@ -300,7 +296,7 @@ where
|
|||||||
// Add variable declaration
|
// Add variable declaration
|
||||||
// e.g. var ref
|
// e.g. var ref
|
||||||
if !folder.vars.is_empty() {
|
if !folder.vars.is_empty() {
|
||||||
self.helpers.define_property();
|
helper!(define_property);
|
||||||
buf.push(T::from_stmt(Stmt::Decl(Decl::Var(VarDecl {
|
buf.push(T::from_stmt(Stmt::Decl(Decl::Var(VarDecl {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
kind: VarDeclKind::Var,
|
kind: VarDeclKind::Var,
|
||||||
@ -309,7 +305,7 @@ where
|
|||||||
}))));
|
}))));
|
||||||
}
|
}
|
||||||
if folder.used_define_enum_props {
|
if folder.used_define_enum_props {
|
||||||
self.helpers.define_enumerable_properties();
|
helper!(define_enumerable_properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.push(T::from_stmt(stmt));
|
buf.push(T::from_stmt(stmt));
|
||||||
|
@ -2,7 +2,7 @@ use super::*;
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
accessors,
|
accessors,
|
||||||
r#"var obj = {
|
r#"var obj = {
|
||||||
get [foobar]() {
|
get [foobar]() {
|
||||||
@ -39,7 +39,7 @@ var obj = ( _obj = {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
argument,
|
argument,
|
||||||
r#"foo({
|
r#"foo({
|
||||||
[bar]: "foobar"
|
[bar]: "foobar"
|
||||||
@ -50,7 +50,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
assignment,
|
assignment,
|
||||||
r#"foo = {
|
r#"foo = {
|
||||||
[bar]: "foobar"
|
[bar]: "foobar"
|
||||||
@ -60,7 +60,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
method,
|
method,
|
||||||
r#"var obj = {
|
r#"var obj = {
|
||||||
[foobar]() {
|
[foobar]() {
|
||||||
@ -80,7 +80,7 @@ var obj = (_obj = {}, _defineProperty(_obj, foobar, function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps{helpers},
|
|_| ComputedProps,
|
||||||
mixed,
|
mixed,
|
||||||
r#"var obj = {
|
r#"var obj = {
|
||||||
["x" + foo]: "heh",
|
["x" + foo]: "heh",
|
||||||
@ -96,7 +96,7 @@ var obj = (_obj = {}, _defineProperty(_obj, "x" + foo, "heh"), _defineProperty(_
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
multiple,
|
multiple,
|
||||||
r#"var obj = {
|
r#"var obj = {
|
||||||
["x" + foo]: "heh",
|
["x" + foo]: "heh",
|
||||||
@ -110,7 +110,7 @@ _defineProperty(_obj, "y" + bar, "noo"), _obj);"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
single,
|
single,
|
||||||
r#"var obj = {
|
r#"var obj = {
|
||||||
["x" + foo]: "heh"
|
["x" + foo]: "heh"
|
||||||
@ -120,7 +120,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
symbol,
|
symbol,
|
||||||
r#"var k = Symbol();
|
r#"var k = Symbol();
|
||||||
var foo = {
|
var foo = {
|
||||||
@ -142,7 +142,7 @@ var foo = ( _obj = {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
symbol_exec,
|
symbol_exec,
|
||||||
r#"
|
r#"
|
||||||
var k = Symbol();
|
var k = Symbol();
|
||||||
@ -159,7 +159,7 @@ expect(foo[k]).toBe(k)"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
this,
|
this,
|
||||||
r#"var obj = {
|
r#"var obj = {
|
||||||
["x" + foo.bar]: "heh"
|
["x" + foo.bar]: "heh"
|
||||||
@ -169,7 +169,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
two,
|
two,
|
||||||
r#"var obj = {
|
r#"var obj = {
|
||||||
first: "first",
|
first: "first",
|
||||||
@ -182,7 +182,7 @@ var obj = ( _obj = {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| ComputedProps { helpers },
|
|_| ComputedProps,
|
||||||
variable,
|
variable,
|
||||||
r#"var foo = {
|
r#"var foo = {
|
||||||
[bar]: "foobar"
|
[bar]: "foobar"
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
helpers::Helpers,
|
|
||||||
pass::Pass,
|
pass::Pass,
|
||||||
util::{prop_name_to_expr, ExprFactory, StmtLike},
|
util::{prop_name_to_expr, ExprFactory, StmtLike},
|
||||||
};
|
};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::{iter, sync::Arc};
|
use std::iter;
|
||||||
use swc_atoms::JsWord;
|
use swc_atoms::JsWord;
|
||||||
use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP};
|
use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP};
|
||||||
|
|
||||||
@ -32,14 +31,12 @@ mod tests;
|
|||||||
/// b = _arr2[1],
|
/// b = _arr2[1],
|
||||||
/// rest = _arr2.slice(2);
|
/// rest = _arr2.slice(2);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn destructuring(helpers: Arc<Helpers>) -> impl Pass + Clone {
|
pub fn destructuring() -> impl Pass + Clone + Copy {
|
||||||
Destructuring { helpers }
|
Destructuring
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Copy)]
|
||||||
struct Destructuring {
|
struct Destructuring;
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! impl_for_for_stmt {
|
macro_rules! impl_for_for_stmt {
|
||||||
($T:tt) => {
|
($T:tt) => {
|
||||||
@ -195,7 +192,7 @@ impl Fold<Vec<VarDeclarator>> for Destructuring {
|
|||||||
let ref_ident = make_ref_ident(&mut decls, decl.init);
|
let ref_ident = make_ref_ident(&mut decls, decl.init);
|
||||||
|
|
||||||
let ref_ident = if can_be_null {
|
let ref_ident = if can_be_null {
|
||||||
self.helpers.throw();
|
helper!(throw);
|
||||||
make_ref_ident(
|
make_ref_ident(
|
||||||
&mut decls,
|
&mut decls,
|
||||||
Some(box Expr::Cond(CondExpr {
|
Some(box Expr::Cond(CondExpr {
|
||||||
@ -377,7 +374,6 @@ impl Fold<Function> for Destructuring {
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct AssignFolder {
|
struct AssignFolder {
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
vars: Vec<VarDeclarator>,
|
vars: Vec<VarDeclarator>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,10 +381,7 @@ impl Fold<Expr> for AssignFolder {
|
|||||||
fn fold(&mut self, expr: Expr) -> Expr {
|
fn fold(&mut self, expr: Expr) -> Expr {
|
||||||
let expr = match expr {
|
let expr = match expr {
|
||||||
// Handle iife
|
// Handle iife
|
||||||
Expr::Fn(..) | Expr::Object(..) => Destructuring {
|
Expr::Fn(..) | Expr::Object(..) => Destructuring.fold(expr),
|
||||||
helpers: self.helpers.clone(),
|
|
||||||
}
|
|
||||||
.fold(expr),
|
|
||||||
_ => expr.fold_children(self),
|
_ => expr.fold_children(self),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn tr(helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn tr() -> impl Fold<Module> {
|
||||||
Destructuring { helpers }
|
Destructuring
|
||||||
}
|
}
|
||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
obj_assign_pat,
|
obj_assign_pat,
|
||||||
r#"let { a = 1 } = foo"#,
|
r#"let { a = 1 } = foo"#,
|
||||||
r#"let ref = foo ? foo : _throw(new TypeError("Cannot destructure 'undefined' or 'null'")),
|
r#"let ref = foo ? foo : _throw(new TypeError("Cannot destructure 'undefined' or 'null'")),
|
||||||
@ -15,7 +15,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
obj_assign_expr,
|
obj_assign_expr,
|
||||||
r#"let a;
|
r#"let a;
|
||||||
[{ a = 1 }] = foo"#,
|
[{ a = 1 }] = foo"#,
|
||||||
@ -26,7 +26,7 @@ ref = foo, ref1 = ref[0], ref2 = ref1.a, a = ref2 === void 0 ? 1 : ref2, ref;"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
array1,
|
array1,
|
||||||
r#"var [a, [b], [c]] = ["hello", [", ", "junk"], ["world"]];"#,
|
r#"var [a, [b], [c]] = ["hello", [", ", "junk"], ["world"]];"#,
|
||||||
r#"var ref = ['hello', [', ', 'junk'], ['world']], a = ref[0], ref1 = ref[1],
|
r#"var ref = ['hello', [', ', 'junk'], ['world']], a = ref[0], ref1 = ref[1],
|
||||||
@ -35,7 +35,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
array2,
|
array2,
|
||||||
r#"[a, [b], [c]] = ["hello", [", ", "junk"], ["world"]];"#,
|
r#"[a, [b], [c]] = ["hello", [", ", "junk"], ["world"]];"#,
|
||||||
r#"var ref, ref1, ref2;
|
r#"var ref, ref1, ref2;
|
||||||
@ -46,7 +46,7 @@ ref = ['hello', [', ', 'junk'], ['world']], a = ref[0], ref1 = ref[1],
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
assign_expr_completion_record,
|
assign_expr_completion_record,
|
||||||
r#"var x, y;
|
r#"var x, y;
|
||||||
[x, y] = [1, 2];"#,
|
[x, y] = [1, 2];"#,
|
||||||
@ -56,7 +56,7 @@ ref = [1, 2], x = ref[0], y = ref[1], ref;"#
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
assign_expr_pat,
|
assign_expr_pat,
|
||||||
r#"var z = {};
|
r#"var z = {};
|
||||||
var { x: { y } = {} } = z;"#,
|
var { x: { y } = {} } = z;"#,
|
||||||
@ -69,7 +69,7 @@ var ref = z ? z : _throw(new TypeError("Cannot destructure 'undefined' or 'null'
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
assign_expr,
|
assign_expr,
|
||||||
r#"console.log([x] = [123]);"#,
|
r#"console.log([x] = [123]);"#,
|
||||||
r#"var ref;
|
r#"var ref;
|
||||||
@ -78,7 +78,7 @@ console.log((ref = [123], x = ref[0], ref));"#
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Destructuring { helpers },
|
|_| Destructuring,
|
||||||
chained,
|
chained,
|
||||||
r#"var a, b, c, d;
|
r#"var a, b, c, d;
|
||||||
({ a, b } = ({ c, d } = { a: 1, b: 2, c: 3, d: 4}));
|
({ a, b } = ({ c, d } = { a: 1, b: 2, c: 3, d: 4}));
|
||||||
@ -90,7 +90,7 @@ expect(d).toBe(4);"#
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Destructuring { helpers },
|
|_| Destructuring,
|
||||||
empty_obj_pat_1,
|
empty_obj_pat_1,
|
||||||
r#"expect(function () {
|
r#"expect(function () {
|
||||||
var {} = null;
|
var {} = null;
|
||||||
@ -98,7 +98,7 @@ test_exec!(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// test!(::swc_ecma_parser::Syntax::default(),
|
// test!(::swc_ecma_parser::Syntax::default(),
|
||||||
// |_, helpers| tr(helpers),
|
// |_| tr(),
|
||||||
// empty_obj_pat_2,
|
// empty_obj_pat_2,
|
||||||
// r#"var {} = null;"#,
|
// r#"var {} = null;"#,
|
||||||
// r#"var _ref = null;
|
// r#"var _ref = null;
|
||||||
@ -107,7 +107,7 @@ test_exec!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
empty,
|
empty,
|
||||||
r#"var [, a, [b], [c], d] = ["foo", "hello", [", ", "junk"], ["world"]];"#,
|
r#"var [, a, [b], [c], d] = ["foo", "hello", [", ", "junk"], ["world"]];"#,
|
||||||
r#"var ref = ['foo', 'hello', [', ', 'junk'], ['world']], a = ref[1], ref1 = ref[2],
|
r#"var ref = ['foo', 'hello', [', ', 'junk'], ['world']], a = ref[1], ref1 = ref[2],
|
||||||
@ -118,7 +118,7 @@ test!(
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
es7_object_rest_builtins,
|
es7_object_rest_builtins,
|
||||||
r#"var z = {};
|
r#"var z = {};
|
||||||
var { ...x } = z;
|
var { ...x } = z;
|
||||||
@ -152,7 +152,7 @@ _o;"#
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
es7_object_rest,
|
es7_object_rest,
|
||||||
r#"var z = {};
|
r#"var z = {};
|
||||||
var { ...x } = z;
|
var { ...x } = z;
|
||||||
@ -186,7 +186,7 @@ _o;"#
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
export_variable,
|
export_variable,
|
||||||
r#"export let {a, b, c: {d, e: {f = 4}}} = {};"#,
|
r#"export let {a, b, c: {d, e: {f = 4}}} = {};"#,
|
||||||
r#"
|
r#"
|
||||||
@ -202,7 +202,7 @@ export { a, b, d, f };"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
for_in,
|
for_in,
|
||||||
r#"for (var [name, value] in obj) {
|
r#"for (var [name, value] in obj) {
|
||||||
print("Name: " + name + ", Value: " + value);
|
print("Name: " + name + ", Value: " + value);
|
||||||
@ -216,7 +216,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
for_let,
|
for_let,
|
||||||
r#"for (let [ i, n ] = range; ; ) {}"#,
|
r#"for (let [ i, n ] = range; ; ) {}"#,
|
||||||
r#"for(let i = range[0], n = range[1];;){}"#
|
r#"for(let i = range[0], n = range[1];;){}"#
|
||||||
@ -224,7 +224,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
for_of,
|
for_of,
|
||||||
r#"for (var [ name, before, after ] of test.expectation.registers) {
|
r#"for (var [ name, before, after ] of test.expectation.registers) {
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ test!(
|
|||||||
test_exec!(
|
test_exec!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Destructuring { helpers },
|
|_| Destructuring,
|
||||||
fn_key_with_obj_rest_spread,
|
fn_key_with_obj_rest_spread,
|
||||||
r#"const { [(() => 1)()]: a, ...rest } = { 1: "a" };
|
r#"const { [(() => 1)()]: a, ...rest } = { 1: "a" };
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ expect(rest).toEqual({});"#
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
babel_issue_3081,
|
babel_issue_3081,
|
||||||
r#"let list = [1, 2, 3, 4];
|
r#"let list = [1, 2, 3, 4];
|
||||||
for (let i = 0, { length } = list; i < length; i++) {
|
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!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Destructuring { helpers },
|
|_| Destructuring,
|
||||||
babel_issue_5090,
|
babel_issue_5090,
|
||||||
r#"const assign = function([...arr], index, value) {
|
r#"const assign = function([...arr], index, value) {
|
||||||
arr[index] = value;
|
arr[index] = value;
|
||||||
@ -277,7 +277,7 @@ expect(arr).toEqual([1, 2, 3]);"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
babel_issue_5628,
|
babel_issue_5628,
|
||||||
r#"
|
r#"
|
||||||
(function () {
|
(function () {
|
||||||
@ -297,7 +297,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
babel_issue_5744,
|
babel_issue_5744,
|
||||||
r#"if (true) [a, b] = [b, a];"#,
|
r#"if (true) [a, b] = [b, a];"#,
|
||||||
r#"var ref;
|
r#"var ref;
|
||||||
@ -307,7 +307,7 @@ if (true) ref = [b, a], a = ref[0], b = ref[1], ref;"#
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
babel_issue_6373,
|
babel_issue_6373,
|
||||||
r#"import { NestedObjects } from "./some-module"
|
r#"import { NestedObjects } from "./some-module"
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ const Foo = _someModule.NestedObjects.Foo,
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
known_array,
|
known_array,
|
||||||
r#"var z = [];
|
r#"var z = [];
|
||||||
var [x, ...y] = z;"#,
|
var [x, ...y] = z;"#,
|
||||||
@ -333,7 +333,7 @@ var x = z[0],
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
member_expr,
|
member_expr,
|
||||||
r#"[foo.foo, foo.bar] = [1, 2];"#,
|
r#"[foo.foo, foo.bar] = [1, 2];"#,
|
||||||
r#"var ref;
|
r#"var ref;
|
||||||
@ -342,7 +342,7 @@ ref = [1, 2], foo.foo = ref[0], foo.bar = ref[1], ref;"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
mixed,
|
mixed,
|
||||||
r#"var rect = {};
|
r#"var rect = {};
|
||||||
var {topLeft: [x1, y1], bottomRight: [x2, y2] } = 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!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
multiple,
|
multiple,
|
||||||
r#"var coords = [1, 2];
|
r#"var coords = [1, 2];
|
||||||
var { x, y } = coords,
|
var { x, y } = coords,
|
||||||
@ -367,7 +367,7 @@ var ref = coords ? coords : _throw(new TypeError("Cannot destructure 'undefined'
|
|||||||
test_exec!(
|
test_exec!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Destructuring { helpers },
|
|_| Destructuring,
|
||||||
number_key_with_object_spread,
|
number_key_with_object_spread,
|
||||||
r#"const foo = {
|
r#"const foo = {
|
||||||
1: "a",
|
1: "a",
|
||||||
@ -383,7 +383,7 @@ expect(rest).toEqual({ 2: "b", 3: "c" });"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
object_advanced,
|
object_advanced,
|
||||||
r#"var rect = {};
|
r#"var rect = {};
|
||||||
var {topLeft: {x: x1, y: y1}, bottomRight: {x: x2, y: y2}} = 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(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
object_basic,
|
object_basic,
|
||||||
r#"var coords = [1, 2];
|
r#"var coords = [1, 2];
|
||||||
var { x, y } = coords;"#,
|
var { x, y } = coords;"#,
|
||||||
@ -410,7 +410,7 @@ var ref = coords ? coords : _throw(new TypeError("Cannot destructure 'undefined'
|
|||||||
test_exec!(
|
test_exec!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Destructuring { helpers },
|
|_| Destructuring,
|
||||||
spread_generator,
|
spread_generator,
|
||||||
r#"function* f() {
|
r#"function* f() {
|
||||||
for (var i = 0; i < 3; i++) {
|
for (var i = 0; i < 3; i++) {
|
||||||
@ -423,7 +423,7 @@ expect(xs).toEqual([0, 1, 2]);"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
spread,
|
spread,
|
||||||
r#"function isSorted([x, y, ...wow]) {
|
r#"function isSorted([x, y, ...wow]) {
|
||||||
if (!zs.length) return true
|
if (!zs.length) return true
|
||||||
|
@ -3,7 +3,7 @@ use super::*;
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| DuplicateKeys,
|
|_| DuplicateKeys,
|
||||||
combination_dupes,
|
combination_dupes,
|
||||||
r#"var x = { a: 5, a: 6 };"#,
|
r#"var x = { a: 5, a: 6 };"#,
|
||||||
r#"var x = _defineProperty({
|
r#"var x = _defineProperty({
|
||||||
@ -13,7 +13,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| DuplicateKeys,
|
|_| DuplicateKeys,
|
||||||
combination_no_dupes,
|
combination_no_dupes,
|
||||||
r#"var x = { a: 5, b: 6 };"#,
|
r#"var x = { a: 5, b: 6 };"#,
|
||||||
r#"var x = { a: 5, b: 6 };"#
|
r#"var x = { a: 5, b: 6 };"#
|
||||||
@ -21,7 +21,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| DuplicateKeys,
|
|_| DuplicateKeys,
|
||||||
dup_keys_both_quoted,
|
dup_keys_both_quoted,
|
||||||
r#"var x = { "a\n b": 5, "a\n b": 6 };"#,
|
r#"var x = { "a\n b": 5, "a\n b": 6 };"#,
|
||||||
r#"var x = {
|
r#"var x = {
|
||||||
@ -32,7 +32,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| DuplicateKeys,
|
|_| DuplicateKeys,
|
||||||
dup_keys_dupes,
|
dup_keys_dupes,
|
||||||
r#"var x = { a: 5, a: 6 };"#,
|
r#"var x = { a: 5, a: 6 };"#,
|
||||||
r#"var x = {
|
r#"var x = {
|
||||||
@ -43,7 +43,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| DuplicateKeys,
|
|_| DuplicateKeys,
|
||||||
dup_keys_getter,
|
dup_keys_getter,
|
||||||
r#"var x = { a: 5, get a() {return 6;} };"#,
|
r#"var x = { a: 5, get a() {return 6;} };"#,
|
||||||
r#"var x = {
|
r#"var x = {
|
||||||
@ -58,7 +58,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| DuplicateKeys,
|
|_| DuplicateKeys,
|
||||||
dup_keys_getter_and_setter,
|
dup_keys_getter_and_setter,
|
||||||
r#"var x = {
|
r#"var x = {
|
||||||
get a() {},
|
get a() {},
|
||||||
@ -109,7 +109,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| DuplicateKeys,
|
|_| DuplicateKeys,
|
||||||
dup_keys_one_quoted,
|
dup_keys_one_quoted,
|
||||||
r#"var x = { a: 5, "a": 6 };"#,
|
r#"var x = { a: 5, "a": 6 };"#,
|
||||||
r#"var x = {
|
r#"var x = {
|
||||||
|
@ -2,7 +2,7 @@ use super::*;
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| ForOf,
|
|_| ForOf,
|
||||||
spec_identifier,
|
spec_identifier,
|
||||||
r#"for (i of arr) {
|
r#"for (i of arr) {
|
||||||
}"#,
|
}"#,
|
||||||
@ -32,7 +32,7 @@ try {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| ForOf,
|
|_| ForOf,
|
||||||
spec_ignore_cases,
|
spec_ignore_cases,
|
||||||
r#"for (var i of foo) {
|
r#"for (var i of foo) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
@ -71,7 +71,7 @@ try {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| ForOf,
|
|_| ForOf,
|
||||||
spec_let,
|
spec_let,
|
||||||
r#"for (let i of arr) {
|
r#"for (let i of arr) {
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ try {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| ForOf,
|
|_| ForOf,
|
||||||
spec_member_expr,
|
spec_member_expr,
|
||||||
r#"for (obj.prop of arr) {
|
r#"for (obj.prop of arr) {
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ try {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| ForOf,
|
|_| ForOf,
|
||||||
spec_multiple,
|
spec_multiple,
|
||||||
r#"for (var i of arr) {
|
r#"for (var i of arr) {
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ try {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| ForOf,
|
|_| ForOf,
|
||||||
spec_nested_label_for_of,
|
spec_nested_label_for_of,
|
||||||
r#"b: for (let c of d()) {
|
r#"b: for (let c of d()) {
|
||||||
for (let e of f()) {
|
for (let e of f()) {
|
||||||
@ -247,7 +247,7 @@ try {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| ForOf,
|
|_| ForOf,
|
||||||
spec_var,
|
spec_var,
|
||||||
r#"for (var i of arr) {
|
r#"for (var i of arr) {
|
||||||
|
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::compat::es2015::{block_scoping, resolver};
|
||||||
compat::es2015::{block_scoping, resolver},
|
|
||||||
helpers::Helpers,
|
|
||||||
};
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
fn tr(_helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn tr() -> impl Fold<Module> {
|
||||||
chain!(resolver(), function_name(), block_scoping())
|
chain!(resolver(), function_name(), block_scoping())
|
||||||
}
|
}
|
||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
basic,
|
basic,
|
||||||
r#"var number = function (x) {
|
r#"var number = function (x) {
|
||||||
return x;
|
return x;
|
||||||
@ -23,7 +19,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
assign,
|
assign,
|
||||||
r#"number = function (x) {
|
r#"number = function (x) {
|
||||||
return x;
|
return x;
|
||||||
@ -35,7 +31,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
let_complex,
|
let_complex,
|
||||||
r#"
|
r#"
|
||||||
let TestClass = {
|
let TestClass = {
|
||||||
@ -65,7 +61,7 @@ var TestClass = {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
class_simple,
|
class_simple,
|
||||||
r#"
|
r#"
|
||||||
var Foo = function() {
|
var Foo = function() {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::{helpers::Helpers, util::ExprFactory};
|
use crate::util::ExprFactory;
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::sync::Arc;
|
|
||||||
use swc_common::{Fold, FoldWith, Visit, VisitWith};
|
use swc_common::{Fold, FoldWith, Visit, VisitWith};
|
||||||
|
|
||||||
/// `@babel/plugin-transform-instanceof`
|
/// `@babel/plugin-transform-instanceof`
|
||||||
@ -29,9 +28,7 @@ use swc_common::{Fold, FoldWith, Visit, VisitWith};
|
|||||||
/// _instanceof(foo, Bar);
|
/// _instanceof(foo, Bar);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct InstanceOf {
|
pub struct InstanceOf;
|
||||||
pub helpers: Arc<Helpers>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Fold<Expr> for InstanceOf {
|
impl Fold<Expr> for InstanceOf {
|
||||||
fn fold(&mut self, expr: Expr) -> Expr {
|
fn fold(&mut self, expr: Expr) -> Expr {
|
||||||
@ -64,7 +61,7 @@ impl Fold<Expr> for InstanceOf {
|
|||||||
op: op!("instanceof"),
|
op: op!("instanceof"),
|
||||||
right,
|
right,
|
||||||
}) => {
|
}) => {
|
||||||
self.helpers.instanceof();
|
helper!(instanceof);
|
||||||
|
|
||||||
Expr::Call(CallExpr {
|
Expr::Call(CallExpr {
|
||||||
span,
|
span,
|
||||||
|
@ -6,9 +6,8 @@ pub use self::{
|
|||||||
shorthand_property::Shorthand, spread::Spread, sticky_regex::StickyRegex,
|
shorthand_property::Shorthand, spread::Spread, sticky_regex::StickyRegex,
|
||||||
template_literal::TemplateLiteral, typeof_symbol::TypeOfSymbol,
|
template_literal::TemplateLiteral, typeof_symbol::TypeOfSymbol,
|
||||||
};
|
};
|
||||||
use crate::{helpers::Helpers, pass::Pass};
|
use crate::pass::Pass;
|
||||||
use ast::{Expr, Module, Stmt};
|
use ast::{Expr, Module, Stmt};
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
mod arrow;
|
mod arrow;
|
||||||
mod block_scoped_fn;
|
mod block_scoped_fn;
|
||||||
@ -29,49 +28,33 @@ mod template_literal;
|
|||||||
mod typeof_symbol;
|
mod typeof_symbol;
|
||||||
|
|
||||||
/// Compiles es2015 to es5.
|
/// Compiles es2015 to es5.
|
||||||
pub fn es2015(helpers: &Arc<Helpers>) -> impl Pass + Clone {
|
pub fn es2015() -> impl Pass + Clone {
|
||||||
fn exprs(helpers: &Arc<Helpers>) -> impl Pass + Clone {
|
fn exprs() -> impl Pass + Clone {
|
||||||
chain_at!(
|
chain_at!(
|
||||||
Expr,
|
Expr,
|
||||||
arrow(),
|
arrow(),
|
||||||
duplicate_keys(),
|
duplicate_keys(),
|
||||||
Spread {
|
Spread,
|
||||||
helpers: helpers.clone(),
|
|
||||||
},
|
|
||||||
StickyRegex,
|
StickyRegex,
|
||||||
InstanceOf {
|
InstanceOf,
|
||||||
helpers: helpers.clone(),
|
TypeOfSymbol,
|
||||||
},
|
TemplateLiteral,
|
||||||
TypeOfSymbol {
|
|
||||||
helpers: helpers.clone(),
|
|
||||||
},
|
|
||||||
TemplateLiteral {
|
|
||||||
helpers: helpers.clone(),
|
|
||||||
},
|
|
||||||
Shorthand,
|
Shorthand,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stmts(helpers: &Arc<Helpers>) -> impl Pass + Clone {
|
fn stmts() -> impl Pass + Clone {
|
||||||
chain_at!(
|
chain_at!(Stmt, function_name(), exprs(), BlockScopedFns, parameters(),)
|
||||||
Stmt,
|
|
||||||
function_name(),
|
|
||||||
exprs(helpers),
|
|
||||||
BlockScopedFns,
|
|
||||||
parameters(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chain_at!(
|
chain_at!(
|
||||||
Module,
|
Module,
|
||||||
resolver(),
|
resolver(),
|
||||||
Classes {
|
Classes,
|
||||||
helpers: helpers.clone(),
|
stmts(),
|
||||||
},
|
|
||||||
stmts(helpers),
|
|
||||||
for_of(),
|
for_of(),
|
||||||
computed_properties(helpers.clone()),
|
computed_properties(),
|
||||||
destructuring(helpers.clone()),
|
destructuring(),
|
||||||
block_scoping(),
|
block_scoping(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{compat::es2015::Classes, helpers::Helpers};
|
use crate::compat::es2015::Classes;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
fn tr(helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn tr() -> impl Fold<Module> {
|
||||||
chain!(
|
chain!(
|
||||||
crate::compat::es2015::resolver(),
|
crate::compat::es2015::resolver(),
|
||||||
Params,
|
Params,
|
||||||
crate::compat::es2015::destructuring(helpers.clone()),
|
crate::compat::es2015::destructuring(),
|
||||||
crate::compat::es2015::block_scoping(),
|
crate::compat::es2015::block_scoping(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
babel_6057_simple,
|
babel_6057_simple,
|
||||||
r#"const a = 'bar';
|
r#"const a = 'bar';
|
||||||
function foo(...a) {
|
function foo(...a) {
|
||||||
@ -30,7 +29,7 @@ function foo() {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_before_last,
|
default_before_last,
|
||||||
r#"function foo(a = "foo", b) {}"#,
|
r#"function foo(a = "foo", b) {}"#,
|
||||||
r#"function foo(param, b) {
|
r#"function foo(param, b) {
|
||||||
@ -40,7 +39,7 @@ test!(
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_destructuring,
|
default_destructuring,
|
||||||
r#"function required(msg) {
|
r#"function required(msg) {
|
||||||
throw new Error(msg);
|
throw new Error(msg);
|
||||||
@ -65,7 +64,7 @@ expect(sum({arr:[1,2]})).toBe(3);"#
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_earlier_params,
|
default_earlier_params,
|
||||||
r#"function f(a, b = a, c = b) { return c; }
|
r#"function f(a, b = a, c = b) { return c; }
|
||||||
|
|
||||||
@ -75,7 +74,7 @@ expect(3).toBe(f(3));"#
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_eval,
|
default_eval,
|
||||||
r#"let x = "outside";
|
r#"let x = "outside";
|
||||||
function outer(a = () => eval("x")) {
|
function outer(a = () => eval("x")) {
|
||||||
@ -100,7 +99,7 @@ outer();"#
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_iife_1128,
|
default_iife_1128,
|
||||||
r#"const bar = true;
|
r#"const bar = true;
|
||||||
|
|
||||||
@ -115,12 +114,7 @@ foo(1, 2, 3);"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| chain!(
|
|_| chain!(Classes, tr()),
|
||||||
Classes {
|
|
||||||
helpers: helpers.clone()
|
|
||||||
},
|
|
||||||
tr(helpers)
|
|
||||||
),
|
|
||||||
default_iife_4253,
|
default_iife_4253,
|
||||||
r#"class Ref {
|
r#"class Ref {
|
||||||
constructor(id = ++Ref.nextID) {
|
constructor(id = ++Ref.nextID) {
|
||||||
@ -140,7 +134,7 @@ test_exec!(
|
|||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
// Stage0
|
// Stage0
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_iife_4253_exec,
|
default_iife_4253_exec,
|
||||||
r#"class Ref {
|
r#"class Ref {
|
||||||
static nextId = 0
|
static nextId = 0
|
||||||
@ -155,12 +149,7 @@ expect(new Ref().id).toBe(2);"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| chain!(
|
|_| chain!(Classes, tr()),
|
||||||
Classes {
|
|
||||||
helpers: helpers.clone()
|
|
||||||
},
|
|
||||||
tr(helpers)
|
|
||||||
),
|
|
||||||
default_iife_self,
|
default_iife_self,
|
||||||
r#"class Ref {
|
r#"class Ref {
|
||||||
constructor(ref = Ref) {
|
constructor(ref = Ref) {
|
||||||
@ -188,7 +177,7 @@ var X = function X(param) {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_iife_self_exec,
|
default_iife_self_exec,
|
||||||
r#"class Ref {
|
r#"class Ref {
|
||||||
constructor(ref = Ref) {
|
constructor(ref = Ref) {
|
||||||
@ -200,7 +189,7 @@ expect(new Ref().ref).toBe(Ref);"#
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_multiple,
|
default_multiple,
|
||||||
r#"var t = function (e = "foo", f = 5) {
|
r#"var t = function (e = "foo", f = 5) {
|
||||||
return e + " bar " + f;
|
return e + " bar " + f;
|
||||||
@ -221,7 +210,7 @@ var a = function(e, param) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_rest_mix,
|
default_rest_mix,
|
||||||
r#"function fn(
|
r#"function fn(
|
||||||
a1,
|
a1,
|
||||||
@ -239,7 +228,7 @@ test!(
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_rest_1,
|
default_rest_1,
|
||||||
r#"const a = 1;
|
r#"const a = 1;
|
||||||
function rest(b = a, ...a) {
|
function rest(b = a, ...a) {
|
||||||
@ -258,7 +247,7 @@ rest(undefined, 2);"#
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_rest_2,
|
default_rest_2,
|
||||||
r#"const a = 1;
|
r#"const a = 1;
|
||||||
function rest2(b = a, ...a) {
|
function rest2(b = a, ...a) {
|
||||||
@ -277,7 +266,7 @@ rest2(undefined, 2);"#
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_rest_3,
|
default_rest_3,
|
||||||
r#"const a = 1;
|
r#"const a = 1;
|
||||||
function rest3(b = a, ...a) {
|
function rest3(b = a, ...a) {
|
||||||
@ -297,7 +286,7 @@ rest3(undefined, 2);"#
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_rest_exec,
|
default_rest_exec,
|
||||||
r#"const a = 1;
|
r#"const a = 1;
|
||||||
function rest(b = a, ...a) {
|
function rest(b = a, ...a) {
|
||||||
@ -318,7 +307,7 @@ rest3(undefined, 2)"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_setter_noexec,
|
default_setter_noexec,
|
||||||
r#"const obj = {
|
r#"const obj = {
|
||||||
set field(num = 1) {
|
set field(num = 1) {
|
||||||
@ -336,7 +325,7 @@ test!(
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_setter_exec,
|
default_setter_exec,
|
||||||
r#"const defaultValue = 1;
|
r#"const defaultValue = 1;
|
||||||
const obj = {
|
const obj = {
|
||||||
@ -351,7 +340,7 @@ expect(obj.num).toBe(defaultValue);"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
default_single,
|
default_single,
|
||||||
r#"var t = function (f = "foo") {
|
r#"var t = function (f = "foo") {
|
||||||
return f + " bar";
|
return f + " bar";
|
||||||
@ -364,7 +353,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
destructuring_rest,
|
destructuring_rest,
|
||||||
r#"// #3861
|
r#"// #3861
|
||||||
function t(x = "default", { a, b }, ...args) {
|
function t(x = "default", { a, b }, ...args) {
|
||||||
@ -384,7 +373,7 @@ function t(param, param1) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_4333,
|
regression_4333,
|
||||||
r#"const args = 'bar';
|
r#"const args = 'bar';
|
||||||
function foo(...args) {
|
function foo(...args) {
|
||||||
@ -402,7 +391,7 @@ function foo() {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_4348,
|
regression_4348,
|
||||||
r#"function first(...values) {
|
r#"function first(...values) {
|
||||||
var index = 0;
|
var index = 0;
|
||||||
@ -421,7 +410,7 @@ test!(
|
|||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
// type
|
// type
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_4634,
|
regression_4634,
|
||||||
r#"let oneOf = (...nodes) => {
|
r#"let oneOf = (...nodes) => {
|
||||||
if (nodes.length === 1) {
|
if (nodes.length === 1) {
|
||||||
@ -444,7 +433,7 @@ let oneOf = function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_5787,
|
regression_5787,
|
||||||
r#"function f(a, ...rest) {
|
r#"function f(a, ...rest) {
|
||||||
let b = rest[rest.length - 3];
|
let b = rest[rest.length - 3];
|
||||||
@ -475,7 +464,7 @@ function f(a) {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_5787_exec,
|
regression_5787_exec,
|
||||||
r#"function f1(a, ...rest) {
|
r#"function f1(a, ...rest) {
|
||||||
let b = rest[rest.length - 3];
|
let b = rest[rest.length - 3];
|
||||||
@ -493,7 +482,7 @@ expect(f2(1, 2)).toBeUndefined();"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_args_deoptimiazation,
|
rest_args_deoptimiazation,
|
||||||
r#"function x (...rest) {
|
r#"function x (...rest) {
|
||||||
arguments;
|
arguments;
|
||||||
@ -512,7 +501,7 @@ test!(
|
|||||||
// Stage 0
|
// Stage 0
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_arrow_fn,
|
rest_arrow_fn,
|
||||||
r#"var concat = (...arrs) => {
|
r#"var concat = (...arrs) => {
|
||||||
var x = arrs[0];
|
var x = arrs[0];
|
||||||
@ -614,7 +603,7 @@ var innerclassproperties = function () {
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_async_arrow_fn,
|
rest_async_arrow_fn,
|
||||||
r#"var concat = async (...arrs) => {
|
r#"var concat = async (...arrs) => {
|
||||||
var x = arrs[0];
|
var x = arrs[0];
|
||||||
@ -659,7 +648,7 @@ function () {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| chain!(crate::compat::es2015::arrow(), tr(helpers)),
|
|_| chain!(crate::compat::es2015::arrow(), tr()),
|
||||||
rest_binding_deoptimisation,
|
rest_binding_deoptimisation,
|
||||||
r#"const deepAssign = (...args) => args = [];
|
r#"const deepAssign = (...args) => args = [];
|
||||||
"#,
|
"#,
|
||||||
@ -676,7 +665,7 @@ test!(
|
|||||||
// optimiation is not implemented
|
// optimiation is not implemented
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_deepest_common_ancestor_earliest_child,
|
rest_deepest_common_ancestor_earliest_child,
|
||||||
r#"// single reference
|
r#"// single reference
|
||||||
function r(...rest){
|
function r(...rest){
|
||||||
@ -871,7 +860,7 @@ function r() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_length,
|
rest_length,
|
||||||
r#"var t = function (f, ...items) {
|
r#"var t = function (f, ...items) {
|
||||||
items[0];
|
items[0];
|
||||||
@ -902,7 +891,7 @@ function t(f) {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_length_exec,
|
rest_length_exec,
|
||||||
r#"var length = function (a, b, ...items) {
|
r#"var length = function (a, b, ...items) {
|
||||||
return items.length;
|
return items.length;
|
||||||
@ -918,7 +907,7 @@ test!(
|
|||||||
// optimisation is not implemented
|
// optimisation is not implemented
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_member_expression_deoptimisation,
|
rest_member_expression_deoptimisation,
|
||||||
r#"var t = function (...items) {
|
r#"var t = function (...items) {
|
||||||
var x = items[0];
|
var x = items[0];
|
||||||
@ -976,7 +965,7 @@ test!(
|
|||||||
// optimisation is not implemented
|
// optimisation is not implemented
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_member_expression_optimisation,
|
rest_member_expression_optimisation,
|
||||||
r#"var t = function (...items) {
|
r#"var t = function (...items) {
|
||||||
var x = items[0];
|
var x = items[0];
|
||||||
@ -1031,7 +1020,7 @@ function t() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_multiple,
|
rest_multiple,
|
||||||
r#"var t = function (f, ...items) {
|
r#"var t = function (f, ...items) {
|
||||||
var x = f;
|
var x = f;
|
||||||
@ -1084,7 +1073,7 @@ test!(
|
|||||||
// optimisation is not implemented
|
// optimisation is not implemented
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_nested_5656,
|
rest_nested_5656,
|
||||||
r#"function a(...args) {
|
r#"function a(...args) {
|
||||||
const foo = (...list) => bar(...list);
|
const foo = (...list) => bar(...list);
|
||||||
@ -1145,7 +1134,7 @@ function d(thing) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers|chain!(Classes{helpers:helpers.clone()}, tr(helpers),
|
|_|chain!(Classes, tr(),
|
||||||
crate::compat::es2015::Spread::default()),
|
crate::compat::es2015::Spread::default()),
|
||||||
rest_nested_iife,
|
rest_nested_iife,
|
||||||
r#"function broken(x, ...foo) {
|
r#"function broken(x, ...foo) {
|
||||||
@ -1175,7 +1164,7 @@ test!(::swc_ecma_parser::Syntax::default(),
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_patterns,
|
rest_patterns,
|
||||||
r#"function foo(...[a]) {}"#,
|
r#"function foo(...[a]) {}"#,
|
||||||
r#"function foo() {
|
r#"function foo() {
|
||||||
@ -1188,7 +1177,7 @@ test!(
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_patterns_exec,
|
rest_patterns_exec,
|
||||||
r#"
|
r#"
|
||||||
function foo(...{ length }) {
|
function foo(...{ length }) {
|
||||||
@ -1202,7 +1191,7 @@ test!(
|
|||||||
// optimisation is not implemented
|
// optimisation is not implemented
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_spread_optimisation,
|
rest_spread_optimisation,
|
||||||
r#"// optimisation
|
r#"// optimisation
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ macro_rules! identical {
|
|||||||
($name:ident, $src:literal) => {
|
($name:ident, $src:literal) => {
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
$name,
|
$name,
|
||||||
$src,
|
$src,
|
||||||
$src
|
$src
|
||||||
@ -57,7 +57,7 @@ fn test_mark_for() {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
basic_no_usage,
|
basic_no_usage,
|
||||||
"
|
"
|
||||||
let foo;
|
let foo;
|
||||||
@ -75,7 +75,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
class_nested_var,
|
class_nested_var,
|
||||||
"
|
"
|
||||||
var ConstructorScoping = function ConstructorScoping() {
|
var ConstructorScoping = function ConstructorScoping() {
|
||||||
@ -99,7 +99,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
basic,
|
basic,
|
||||||
r#"
|
r#"
|
||||||
{
|
{
|
||||||
@ -125,7 +125,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
general_assignment_patterns,
|
general_assignment_patterns,
|
||||||
r#"const foo = "foo";
|
r#"const foo = "foo";
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ function foobar() {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
general_function,
|
general_function,
|
||||||
r#"function test() {
|
r#"function test() {
|
||||||
let foo = "bar";
|
let foo = "bar";
|
||||||
@ -160,7 +160,7 @@ test!(
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
babel_issue_1051,
|
babel_issue_1051,
|
||||||
r#"foo.func1 = function() {
|
r#"foo.func1 = function() {
|
||||||
if (cond1) {
|
if (cond1) {
|
||||||
@ -202,7 +202,7 @@ test!(
|
|||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
// TODO(kdy1): WTF is this (again)?
|
// TODO(kdy1): WTF is this (again)?
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
babel_issue_2174,
|
babel_issue_2174,
|
||||||
r#"if (true) {
|
r#"if (true) {
|
||||||
function foo() {}
|
function foo() {}
|
||||||
@ -226,7 +226,7 @@ if (true) {
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
babel_issue_4363,
|
babel_issue_4363,
|
||||||
r#"function WithoutCurlyBraces() {
|
r#"function WithoutCurlyBraces() {
|
||||||
if (true)
|
if (true)
|
||||||
@ -295,7 +295,7 @@ test!(
|
|||||||
// Cannot represent function expression without parens (in result code)
|
// Cannot represent function expression without parens (in result code)
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
babel_issue_4946,
|
babel_issue_4946,
|
||||||
r#"(function foo() {
|
r#"(function foo() {
|
||||||
let foo = true;
|
let foo = true;
|
||||||
@ -309,7 +309,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
babel_issue_973,
|
babel_issue_973,
|
||||||
r#"let arr = [];
|
r#"let arr = [];
|
||||||
for(let i = 0; i < 10; i++) {
|
for(let i = 0; i < 10; i++) {
|
||||||
@ -328,7 +328,7 @@ for(var i = 0; i < 10; i++){
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
pass_assignment,
|
pass_assignment,
|
||||||
r#"let a = 1;
|
r#"let a = 1;
|
||||||
a = 2;
|
a = 2;
|
||||||
@ -337,7 +337,7 @@ expect(a).toBe(2);"#
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
pass_call,
|
pass_call,
|
||||||
r#"let a = 1;
|
r#"let a = 1;
|
||||||
|
|
||||||
@ -350,7 +350,7 @@ expect(b()).toBe(2);"#
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
pass_update,
|
pass_update,
|
||||||
r#"let a = 1;
|
r#"let a = 1;
|
||||||
a++;
|
a++;
|
||||||
@ -359,7 +359,7 @@ expect(a).toBe(2);"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
fn_param,
|
fn_param,
|
||||||
r#"let a = 'foo';
|
r#"let a = 'foo';
|
||||||
function foo(a) {
|
function foo(a) {
|
||||||
@ -373,7 +373,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
fn_body,
|
fn_body,
|
||||||
r#"let a = 'foo';
|
r#"let a = 'foo';
|
||||||
function foo() {
|
function foo() {
|
||||||
@ -389,7 +389,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
shorthand,
|
shorthand,
|
||||||
r#"let a = 'foo';
|
r#"let a = 'foo';
|
||||||
function foo() {
|
function foo() {
|
||||||
@ -405,7 +405,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
same_level,
|
same_level,
|
||||||
r#"
|
r#"
|
||||||
var a = 'foo';
|
var a = 'foo';
|
||||||
@ -419,7 +419,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
class_block,
|
class_block,
|
||||||
r#"
|
r#"
|
||||||
var Foo = function(_Bar) {
|
var Foo = function(_Bar) {
|
||||||
@ -441,7 +441,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
class_block_2,
|
class_block_2,
|
||||||
r#"
|
r#"
|
||||||
var Foo = (function(_Bar) {
|
var Foo = (function(_Bar) {
|
||||||
@ -463,7 +463,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
class_nested,
|
class_nested,
|
||||||
r#"
|
r#"
|
||||||
var Outer = function(_Hello) {
|
var Outer = function(_Hello) {
|
||||||
|
@ -65,7 +65,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Shorthand,
|
|_| Shorthand,
|
||||||
babel_method_plain,
|
babel_method_plain,
|
||||||
"var obj = {
|
"var obj = {
|
||||||
method() {
|
method() {
|
||||||
@ -81,7 +81,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Shorthand,
|
|_| Shorthand,
|
||||||
babel_comments,
|
babel_comments,
|
||||||
"var A = 'a';
|
"var A = 'a';
|
||||||
var o = {
|
var o = {
|
||||||
@ -96,7 +96,7 @@ var o = {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Shorthand,
|
|_| Shorthand,
|
||||||
babel_mixed,
|
babel_mixed,
|
||||||
"var coords = { x, y, foo: 'bar' };",
|
"var coords = { x, y, foo: 'bar' };",
|
||||||
"var coords = {
|
"var coords = {
|
||||||
@ -108,7 +108,7 @@ var o = {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Shorthand,
|
|_| Shorthand,
|
||||||
babel_multiple,
|
babel_multiple,
|
||||||
"var coords = { x, y };",
|
"var coords = { x, y };",
|
||||||
"var coords = {
|
"var coords = {
|
||||||
@ -119,7 +119,7 @@ var o = {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Shorthand,
|
|_| Shorthand,
|
||||||
babel_single,
|
babel_single,
|
||||||
"var coords = { x };",
|
"var coords = { x };",
|
||||||
"var coords = {
|
"var coords = {
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
use crate::{helpers::Helpers, util::ExprFactory};
|
use crate::util::ExprFactory;
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::{iter, mem, sync::Arc};
|
use std::{iter, mem};
|
||||||
use swc_common::{Fold, FoldWith, Span, DUMMY_SP};
|
use swc_common::{Fold, FoldWith, Span, DUMMY_SP};
|
||||||
|
|
||||||
/// es2015 - `SpreadElement`
|
/// es2015 - `SpreadElement`
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct Spread {
|
pub struct Spread;
|
||||||
pub helpers: Arc<Helpers>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Fold<Expr> for Spread {
|
impl Fold<Expr> for Spread {
|
||||||
fn fold(&mut self, e: Expr) -> Expr {
|
fn fold(&mut self, e: Expr) -> Expr {
|
||||||
@ -24,7 +22,7 @@ impl Fold<Expr> for Spread {
|
|||||||
return Expr::Array(ArrayLit { span, elems });
|
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;
|
return args_array;
|
||||||
}
|
}
|
||||||
@ -45,7 +43,7 @@ impl Fold<Expr> for Spread {
|
|||||||
type_args,
|
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)
|
// f.apply(undefined, args)
|
||||||
//
|
//
|
||||||
@ -74,7 +72,6 @@ impl Fold<Expr> for Spread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let args = concat_args(
|
let args = concat_args(
|
||||||
&self.helpers,
|
|
||||||
span,
|
span,
|
||||||
iter::once(quote_expr!(span, null).as_arg())
|
iter::once(quote_expr!(span, null).as_arg())
|
||||||
.chain(args)
|
.chain(args)
|
||||||
@ -101,11 +98,7 @@ impl Fold<Expr> for Spread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn concat_args(
|
fn concat_args(span: Span, args: impl Iterator<Item = Option<ExprOrSpread>>) -> Expr {
|
||||||
helpers: &Helpers,
|
|
||||||
span: Span,
|
|
||||||
args: impl Iterator<Item = Option<ExprOrSpread>>,
|
|
||||||
) -> Expr {
|
|
||||||
//
|
//
|
||||||
// []
|
// []
|
||||||
//
|
//
|
||||||
@ -140,7 +133,7 @@ fn concat_args(
|
|||||||
//
|
//
|
||||||
make_arr!();
|
make_arr!();
|
||||||
|
|
||||||
helpers.to_consumable_array();
|
helper!(to_consumable_array);
|
||||||
|
|
||||||
buf.push(
|
buf.push(
|
||||||
Expr::Call(CallExpr {
|
Expr::Call(CallExpr {
|
||||||
@ -190,7 +183,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Spread { helpers },
|
|_| Spread,
|
||||||
call,
|
call,
|
||||||
"ca(a, b, c, ...d, e)",
|
"ca(a, b, c, ...d, e)",
|
||||||
"ca.apply(undefined, [a, b, c].concat(_toConsumableArray(d), [e]));"
|
"ca.apply(undefined, [a, b, c].concat(_toConsumableArray(d), [e]));"
|
||||||
@ -198,7 +191,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Spread { helpers },
|
|_| Spread,
|
||||||
call_multi_spread,
|
call_multi_spread,
|
||||||
"ca(a, b, ...d, e, f, ...h)",
|
"ca(a, b, ...d, e, f, ...h)",
|
||||||
"ca.apply(undefined, [a, b].concat(_toConsumableArray(d), [e, f], _toConsumableArray(h)));"
|
"ca.apply(undefined, [a, b].concat(_toConsumableArray(d), [e, f], _toConsumableArray(h)));"
|
||||||
@ -206,7 +199,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Spread { helpers },
|
|_| Spread,
|
||||||
call_noop,
|
call_noop,
|
||||||
"ca(a, b, c, d, e)",
|
"ca(a, b, c, d, e)",
|
||||||
"ca(a, b, c, d, e);"
|
"ca(a, b, c, d, e);"
|
||||||
@ -214,7 +207,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Spread { helpers },
|
|_| Spread,
|
||||||
array,
|
array,
|
||||||
"[a, b, c, ...d, e]",
|
"[a, b, c, ...d, e]",
|
||||||
"[a, b, c].concat(_toConsumableArray(d), [e])"
|
"[a, b, c].concat(_toConsumableArray(d), [e])"
|
||||||
@ -222,7 +215,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Spread { helpers },
|
|_| Spread,
|
||||||
array_empty,
|
array_empty,
|
||||||
"[a,, b, c, ...d,,, e]",
|
"[a,, b, c, ...d,,, e]",
|
||||||
"[a,, b, c].concat(_toConsumableArray(d), [,, e])"
|
"[a,, b, c].concat(_toConsumableArray(d), [,, e])"
|
||||||
@ -230,7 +223,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Spread { helpers },
|
|_| Spread,
|
||||||
new,
|
new,
|
||||||
"new C(a, b, c, ...d, e)",
|
"new C(a, b, c, ...d, e)",
|
||||||
"new Function.prototype.bind.apply(C, [null, a, b, c].concat(_toConsumableArray(d), \
|
"new Function.prototype.bind.apply(C, [null, a, b, c].concat(_toConsumableArray(d), \
|
||||||
@ -240,7 +233,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| Spread { helpers },
|
|_| Spread,
|
||||||
new_noop,
|
new_noop,
|
||||||
"new C(a, b, c, c, d, e)",
|
"new C(a, b, c, c, d, e)",
|
||||||
"new C(a, b, c, c, d, e);"
|
"new C(a, b, c, c, d, e);"
|
||||||
|
@ -59,7 +59,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| StickyRegex,
|
|_| StickyRegex,
|
||||||
babel_basic,
|
babel_basic,
|
||||||
"var re = /o+/y;",
|
"var re = /o+/y;",
|
||||||
"var re = new RegExp('o+', 'y');"
|
"var re = new RegExp('o+', 'y');"
|
||||||
@ -67,7 +67,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| StickyRegex,
|
|_| StickyRegex,
|
||||||
babel_ignore_non_sticky,
|
babel_ignore_non_sticky,
|
||||||
"var re = /o+/;",
|
"var re = /o+/;",
|
||||||
"var re = /o+/;"
|
"var re = /o+/;"
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
use crate::{helpers::Helpers, util::ExprFactory};
|
use crate::util::ExprFactory;
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::{iter, sync::Arc};
|
use std::iter;
|
||||||
use swc_common::{Fold, FoldWith, Spanned, DUMMY_SP};
|
use swc_common::{Fold, FoldWith, Spanned, DUMMY_SP};
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct TemplateLiteral {
|
pub struct TemplateLiteral;
|
||||||
pub helpers: Arc<Helpers>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Fold<Expr> for TemplateLiteral {
|
impl Fold<Expr> for TemplateLiteral {
|
||||||
fn fold(&mut self, e: Expr) -> Expr {
|
fn fold(&mut self, e: Expr) -> Expr {
|
||||||
@ -68,7 +66,7 @@ impl Fold<Expr> for TemplateLiteral {
|
|||||||
tag, exprs, quasis, ..
|
tag, exprs, quasis, ..
|
||||||
}) => {
|
}) => {
|
||||||
assert!(quasis.len() == exprs.len() + 1);
|
assert!(quasis.len() == exprs.len() + 1);
|
||||||
self.helpers.tagged_template_literal();
|
helper!(tagged_template_literal);
|
||||||
|
|
||||||
let fn_ident = private_ident!("_templateObject");
|
let fn_ident = private_ident!("_templateObject");
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use super::*;
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
escape_quotes,
|
escape_quotes,
|
||||||
r#"var t = `'${foo}' "${bar}"`;"#,
|
r#"var t = `'${foo}' "${bar}"`;"#,
|
||||||
r#"var t = "'" + foo + '\' "' + bar + '"';"#,
|
r#"var t = "'" + foo + '\' "' + bar + '"';"#,
|
||||||
@ -11,7 +11,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
expr_first,
|
expr_first,
|
||||||
r#"var foo = 5;
|
r#"var foo = 5;
|
||||||
var bar = 10;
|
var bar = 10;
|
||||||
@ -35,7 +35,7 @@ var example5 = '' + '';"#,
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
functions,
|
functions,
|
||||||
r#"var foo = `test ${_.test(foo)} ${bar}`;"#,
|
r#"var foo = `test ${_.test(foo)} ${bar}`;"#,
|
||||||
r#"var foo = 'test ' + _.test(foo) + ' ' + bar;"#
|
r#"var foo = 'test ' + _.test(foo) + ' ' + bar;"#
|
||||||
@ -43,7 +43,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
literals,
|
literals,
|
||||||
r#"var foo = `${1}${f}oo${true}${b}ar${0}${baz}`;"#,
|
r#"var foo = `${1}${f}oo${true}${b}ar${0}${baz}`;"#,
|
||||||
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!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
multiline,
|
multiline,
|
||||||
r#"var o = `wow
|
r#"var o = `wow
|
||||||
this is
|
this is
|
||||||
@ -62,7 +62,7 @@ actually multiline!`;"#,
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
multiple,
|
multiple,
|
||||||
r#"var foo = `test ${foo} ${bar}`;"#,
|
r#"var foo = `test ${foo} ${bar}`;"#,
|
||||||
r#"var foo = 'test ' + foo + ' ' + bar;"#
|
r#"var foo = 'test ' + foo + ' ' + bar;"#
|
||||||
@ -70,7 +70,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
none,
|
none,
|
||||||
r#"var foo = `test`;"#,
|
r#"var foo = `test`;"#,
|
||||||
r#"var foo = "test";"#
|
r#"var foo = "test";"#
|
||||||
@ -78,7 +78,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
only,
|
only,
|
||||||
r#"var foo = `${test}`;"#,
|
r#"var foo = `${test}`;"#,
|
||||||
r#"var foo = '' + test"#
|
r#"var foo = '' + test"#
|
||||||
@ -86,7 +86,7 @@ test!(
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
order,
|
order,
|
||||||
r#"
|
r#"
|
||||||
const calls = [];
|
const calls = [];
|
||||||
@ -115,7 +115,7 @@ expect(calls).toEqual([1, 2, 3, 4]);"#
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
order2,
|
order2,
|
||||||
r#"const calls = [];
|
r#"const calls = [];
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ expect(calls).toEqual([1, 2]);"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
simple_tag,
|
simple_tag,
|
||||||
r#"var foo = tag`wow`;
|
r#"var foo = tag`wow`;
|
||||||
var bar = tag`first${1}second`;"#,
|
var bar = tag`first${1}second`;"#,
|
||||||
@ -163,7 +163,7 @@ var bar = tag(function _templateObject1() {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
single,
|
single,
|
||||||
r#"var foo = `test ${foo}`;"#,
|
r#"var foo = `test ${foo}`;"#,
|
||||||
r#"var foo = 'test ' + foo;"#
|
r#"var foo = 'test ' + foo;"#
|
||||||
@ -171,7 +171,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
statement,
|
statement,
|
||||||
r#"var foo = `test ${foo + bar}`;"#,
|
r#"var foo = `test ${foo + bar}`;"#,
|
||||||
r#"var foo = 'test ' + foo + bar;"#,
|
r#"var foo = 'test ' + foo + bar;"#,
|
||||||
@ -180,7 +180,7 @@ test!(
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
symbol,
|
symbol,
|
||||||
r#"const fn = () => `${Symbol()}`;
|
r#"const fn = () => `${Symbol()}`;
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ expect(fn).toThrow(TypeError);"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
tag,
|
tag,
|
||||||
r#"
|
r#"
|
||||||
var foo = bar`wow\na${ 42 }b ${_.foobar()}`;
|
var foo = bar`wow\na${ 42 }b ${_.foobar()}`;
|
||||||
@ -224,7 +224,7 @@ var bar = bar(function _templateObject2() {
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| TemplateLiteral { helpers },
|
|_| TemplateLiteral,
|
||||||
template_revision,
|
template_revision,
|
||||||
r#"tag`\unicode and \u{55}`;
|
r#"tag`\unicode and \u{55}`;
|
||||||
tag`\01`;
|
tag`\01`;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::{helpers::Helpers, util::ExprFactory};
|
use crate::util::ExprFactory;
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::sync::Arc;
|
|
||||||
use swc_common::{Fold, FoldWith, Visit, VisitWith};
|
use swc_common::{Fold, FoldWith, Visit, VisitWith};
|
||||||
|
|
||||||
/// `@babel/plugin-transform-typeof-symbol`
|
/// `@babel/plugin-transform-typeof-symbol`
|
||||||
@ -21,9 +20,7 @@ use swc_common::{Fold, FoldWith, Visit, VisitWith};
|
|||||||
/// _typeof(Symbol()) === "symbol";
|
/// _typeof(Symbol()) === "symbol";
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TypeOfSymbol {
|
pub struct TypeOfSymbol;
|
||||||
pub helpers: Arc<Helpers>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Fold<Expr> for TypeOfSymbol {
|
impl Fold<Expr> for TypeOfSymbol {
|
||||||
fn fold(&mut self, expr: Expr) -> Expr {
|
fn fold(&mut self, expr: Expr) -> Expr {
|
||||||
@ -55,7 +52,7 @@ impl Fold<Expr> for TypeOfSymbol {
|
|||||||
op: op!("typeof"),
|
op: op!("typeof"),
|
||||||
arg,
|
arg,
|
||||||
}) => {
|
}) => {
|
||||||
self.helpers.type_of();
|
helper!(type_of);
|
||||||
return Expr::Call(CallExpr {
|
return Expr::Call(CallExpr {
|
||||||
span,
|
span,
|
||||||
callee: quote_ident!(span, "_typeof").as_callee(),
|
callee: quote_ident!(span, "_typeof").as_callee(),
|
||||||
|
@ -172,7 +172,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Exponentation,
|
|_| Exponentation,
|
||||||
babel_binary,
|
babel_binary,
|
||||||
"2 ** 2",
|
"2 ** 2",
|
||||||
"Math.pow(2, 2)"
|
"Math.pow(2, 2)"
|
||||||
@ -181,7 +181,7 @@ mod tests {
|
|||||||
test_exec!(
|
test_exec!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Exponentation,
|
|_| Exponentation,
|
||||||
babel_comprehensive,
|
babel_comprehensive,
|
||||||
r#"expect(2 ** 3).toBe(8);
|
r#"expect(2 ** 3).toBe(8);
|
||||||
expect(3 * 2 ** 3).toBe(24);
|
expect(3 * 2 ** 3).toBe(24);
|
||||||
@ -210,7 +210,7 @@ expect(2 ** 3 ** 2).toBe(512);"#
|
|||||||
// FIXME
|
// FIXME
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Exponentation,
|
|_| Exponentation,
|
||||||
babel_memoize_object,
|
babel_memoize_object,
|
||||||
r#"var counters = 0;
|
r#"var counters = 0;
|
||||||
Object.defineProperty(global, "reader", {
|
Object.defineProperty(global, "reader", {
|
||||||
@ -226,7 +226,7 @@ expect(counters).toBe(1);"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Exponentation,
|
|_| Exponentation,
|
||||||
assign,
|
assign,
|
||||||
r#"x **= 3"#,
|
r#"x **= 3"#,
|
||||||
r#"x = Math.pow(x, 3)"#,
|
r#"x = Math.pow(x, 3)"#,
|
||||||
@ -234,7 +234,7 @@ expect(counters).toBe(1);"#
|
|||||||
);
|
);
|
||||||
|
|
||||||
// test!(::swc_ecma_parser::Syntax::default(),
|
// test!(::swc_ecma_parser::Syntax::default(),
|
||||||
// |_, _| Exponentation,
|
// |_| Exponentation,
|
||||||
// babel_4403,
|
// babel_4403,
|
||||||
// "var a, b;
|
// "var a, b;
|
||||||
// a[`${b++}`] **= 1;",
|
// a[`${b++}`] **= 1;",
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
helpers::Helpers,
|
|
||||||
pass::Pass,
|
pass::Pass,
|
||||||
util::{contains_this_expr, ExprFactory, StmtLike},
|
util::{contains_this_expr, ExprFactory, StmtLike},
|
||||||
};
|
};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::{iter, sync::Arc};
|
use std::iter;
|
||||||
use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP};
|
use swc_common::{Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -30,16 +29,13 @@ mod tests;
|
|||||||
/// yield bar();
|
/// yield bar();
|
||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
pub fn async_to_generator(helpers: Arc<Helpers>) -> impl Pass + Clone {
|
pub fn async_to_generator() -> impl Pass + Clone {
|
||||||
AsyncToGenerator { helpers }
|
AsyncToGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
struct AsyncToGenerator {
|
struct AsyncToGenerator;
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
}
|
|
||||||
struct Actual {
|
struct Actual {
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
extra_stmts: Vec<Stmt>,
|
extra_stmts: Vec<Stmt>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +57,6 @@ where
|
|||||||
Err(module_item) => buf.push(module_item),
|
Err(module_item) => buf.push(module_item),
|
||||||
Ok(stmt) => {
|
Ok(stmt) => {
|
||||||
let mut actual = Actual {
|
let mut actual = Actual {
|
||||||
helpers: self.helpers.clone(),
|
|
||||||
extra_stmts: vec![],
|
extra_stmts: vec![],
|
||||||
};
|
};
|
||||||
let stmt = stmt.fold_with(&mut actual);
|
let stmt = stmt.fold_with(&mut actual);
|
||||||
@ -84,16 +79,13 @@ impl Fold<MethodProp> for Actual {
|
|||||||
}
|
}
|
||||||
let params = prop.function.params;
|
let params = prop.function.params;
|
||||||
|
|
||||||
let fn_ref = make_fn_ref(
|
let fn_ref = make_fn_ref(FnExpr {
|
||||||
&self.helpers,
|
|
||||||
FnExpr {
|
|
||||||
ident: None,
|
ident: None,
|
||||||
function: Function {
|
function: Function {
|
||||||
params: vec![],
|
params: vec![],
|
||||||
..prop.function
|
..prop.function
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
);
|
|
||||||
let fn_ref = Expr::Call(CallExpr {
|
let fn_ref = Expr::Call(CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
callee: fn_ref.as_callee(),
|
callee: fn_ref.as_callee(),
|
||||||
@ -348,13 +340,10 @@ impl Fold<Method> for Actual {
|
|||||||
|
|
||||||
let mut folder = MethodFolder { vars: vec![] };
|
let mut folder = MethodFolder { vars: vec![] };
|
||||||
let function = m.function.fold_children(&mut folder);
|
let function = m.function.fold_children(&mut folder);
|
||||||
let expr = make_fn_ref(
|
let expr = make_fn_ref(FnExpr {
|
||||||
&self.helpers,
|
|
||||||
FnExpr {
|
|
||||||
ident: None,
|
ident: None,
|
||||||
function,
|
function,
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
let hoisted_super = if folder.vars.is_empty() {
|
let hoisted_super = if folder.vars.is_empty() {
|
||||||
None
|
None
|
||||||
@ -416,7 +405,7 @@ impl Fold<Expr> 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 ident = raw_ident.clone().unwrap_or_else(|| quote_ident!("ref"));
|
||||||
|
|
||||||
let real_fn_ident = private_ident!(ident.span, format!("_{}", ident.sym));
|
let real_fn_ident = private_ident!(ident.span, format!("_{}", ident.sym));
|
||||||
let right = make_fn_ref(
|
let right = make_fn_ref(FnExpr {
|
||||||
&self.helpers,
|
|
||||||
FnExpr {
|
|
||||||
ident: None,
|
ident: None,
|
||||||
function: f,
|
function: f,
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
if is_decl {
|
if is_decl {
|
||||||
let real_fn = FnDecl {
|
let real_fn = FnDecl {
|
||||||
@ -593,7 +579,7 @@ impl Actual {
|
|||||||
/// Creates
|
/// Creates
|
||||||
///
|
///
|
||||||
/// `_asyncToGenerator(function*() {})` from `async function() {}`;
|
/// `_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;
|
struct AwaitToYield;
|
||||||
|
|
||||||
impl Fold<Function> for AwaitToYield {
|
impl Fold<Function> for AwaitToYield {
|
||||||
@ -625,7 +611,7 @@ fn make_fn_ref(helpers: &Helpers, mut expr: FnExpr) -> Expr {
|
|||||||
expr.function.is_generator = true;
|
expr.function.is_generator = true;
|
||||||
|
|
||||||
let span = expr.span();
|
let span = expr.span();
|
||||||
helpers.async_to_generator();
|
helper!(async_to_generator);
|
||||||
|
|
||||||
let contains_this = contains_this_expr(&expr.function.body);
|
let contains_this = contains_this_expr(&expr.function.body);
|
||||||
let expr = if contains_this {
|
let expr = if contains_this {
|
||||||
|
@ -15,23 +15,21 @@ impl Fold<Expr> for ParenRemover {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tr(helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn tr() -> impl Fold<Module> {
|
||||||
chain!(
|
chain!(
|
||||||
ParenRemover,
|
ParenRemover,
|
||||||
arrow(),
|
arrow(),
|
||||||
parameters(),
|
parameters(),
|
||||||
destructuring(helpers.clone()),
|
destructuring(),
|
||||||
function_name(),
|
function_name(),
|
||||||
AsyncToGenerator {
|
AsyncToGenerator {},
|
||||||
helpers: helpers.clone()
|
|
||||||
},
|
|
||||||
fixer()
|
fixer()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
async_arrow_in_method,
|
async_arrow_in_method,
|
||||||
r#"
|
r#"
|
||||||
let TestClass = {
|
let TestClass = {
|
||||||
@ -64,7 +62,7 @@ let TestClass = {
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_,helpers|tr(helpers),
|
|_|tr(),
|
||||||
async_default_arguments,
|
async_default_arguments,
|
||||||
r#"
|
r#"
|
||||||
function mandatory(paramName) {
|
function mandatory(paramName) {
|
||||||
@ -94,7 +92,7 @@ function foo(param) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
async_iife,
|
async_iife,
|
||||||
r#"
|
r#"
|
||||||
(async function() { await 'ok' })();
|
(async function() { await 'ok' })();
|
||||||
@ -133,7 +131,7 @@ _asyncToGenerator(function*() {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
async,
|
async,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -155,7 +153,7 @@ class Foo {
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_,helpers|tr(helpers),
|
|_|tr(),
|
||||||
deeply_nested_asyncs,
|
deeply_nested_asyncs,
|
||||||
r#"
|
r#"
|
||||||
async function s(x, ...args) {
|
async function s(x, ...args) {
|
||||||
@ -217,7 +215,7 @@ function s(x) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
expression,
|
expression,
|
||||||
r#"
|
r#"
|
||||||
var foo = async function () {
|
var foo = async function () {
|
||||||
@ -263,7 +261,7 @@ var foo2 = function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_,helpers|tr(helpers),
|
|_|tr(),
|
||||||
function_arity,
|
function_arity,
|
||||||
r#"
|
r#"
|
||||||
async function one(a, b = 1) {}
|
async function one(a, b = 1) {}
|
||||||
@ -339,7 +337,7 @@ function six(a, param) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
named_expression,
|
named_expression,
|
||||||
r#"
|
r#"
|
||||||
var foo = async function bar() {
|
var foo = async function bar() {
|
||||||
@ -360,7 +358,7 @@ var foo = function() {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
no_parameters_and_no_id,
|
no_parameters_and_no_id,
|
||||||
r#"
|
r#"
|
||||||
foo(async function () {
|
foo(async function () {
|
||||||
@ -378,7 +376,7 @@ foo(function() {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
object_method_with_arrows,
|
object_method_with_arrows,
|
||||||
r#"
|
r#"
|
||||||
class Class {
|
class Class {
|
||||||
@ -453,7 +451,7 @@ class Class{
|
|||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(::swc_ecma_parser::Syntax::default(),
|
||||||
|_,helpers|tr(helpers),
|
|_|tr(),
|
||||||
object_method_with_super,
|
object_method_with_super,
|
||||||
r#"class Foo extends class {} {
|
r#"class Foo extends class {} {
|
||||||
async method() {
|
async method() {
|
||||||
@ -480,7 +478,7 @@ class Foo extends class{
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
class_method_this,
|
class_method_this,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -499,7 +497,7 @@ return foo.foo().then(cur => {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
class_method_super,
|
class_method_super,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -523,7 +521,7 @@ return bar.bar().then(cur => {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
class_getter_super,
|
class_getter_super,
|
||||||
r#"
|
r#"
|
||||||
let called = false;
|
let called = false;
|
||||||
@ -549,7 +547,7 @@ return bar.bar().then(foo => {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
class_setter_super,
|
class_setter_super,
|
||||||
r#"
|
r#"
|
||||||
let called = false;
|
let called = false;
|
||||||
@ -576,7 +574,7 @@ return bar.bar().then(bar => {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
class_method_this_complex,
|
class_method_this_complex,
|
||||||
r#"
|
r#"
|
||||||
class Class {
|
class Class {
|
||||||
@ -609,7 +607,7 @@ return c.method();
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
object_method,
|
object_method,
|
||||||
r#"
|
r#"
|
||||||
let obj = {
|
let obj = {
|
||||||
@ -633,7 +631,7 @@ let obj = {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
babel_parameters,
|
babel_parameters,
|
||||||
r#"
|
r#"
|
||||||
async function foo(bar) {
|
async function foo(bar) {
|
||||||
@ -653,7 +651,7 @@ function foo(bar) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
statement,
|
statement,
|
||||||
r#"
|
r#"
|
||||||
async function foo() {
|
async function foo() {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
pub use self::async_to_generator::async_to_generator;
|
pub use self::async_to_generator::async_to_generator;
|
||||||
use crate::{helpers::Helpers, pass::Pass};
|
use crate::pass::Pass;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
mod async_to_generator;
|
mod async_to_generator;
|
||||||
|
|
||||||
pub fn es2017(helpers: &Arc<Helpers>) -> impl Pass + Clone {
|
pub fn es2017() -> impl Pass + Clone {
|
||||||
async_to_generator(helpers.clone())
|
async_to_generator()
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
pub use self::object_rest_spread::object_rest_spread;
|
pub use self::object_rest_spread::object_rest_spread;
|
||||||
|
|
||||||
use crate::{helpers::Helpers, pass::Pass};
|
use crate::pass::Pass;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
mod object_rest_spread;
|
mod object_rest_spread;
|
||||||
|
|
||||||
pub fn es2018(helpers: &Arc<Helpers>) -> impl Pass + Clone {
|
pub fn es2018() -> impl Pass + Clone {
|
||||||
object_rest_spread(helpers.clone())
|
object_rest_spread()
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
helpers::Helpers,
|
|
||||||
pass::Pass,
|
pass::Pass,
|
||||||
util::{alias_ident_for, ExprFactory, StmtLike},
|
util::{alias_ident_for, ExprFactory, StmtLike},
|
||||||
};
|
};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::{iter, mem, sync::Arc};
|
use std::{iter, mem};
|
||||||
use swc_common::{
|
use swc_common::{
|
||||||
util::move_map::MoveMap, Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP,
|
util::move_map::MoveMap, Fold, FoldWith, Mark, Spanned, Visit, VisitWith, DUMMY_SP,
|
||||||
};
|
};
|
||||||
@ -13,22 +12,14 @@ use swc_common::{
|
|||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
/// `@babel/plugin-proposal-object-rest-spread`
|
/// `@babel/plugin-proposal-object-rest-spread`
|
||||||
pub fn object_rest_spread(helpers: Arc<Helpers>) -> impl Pass + Clone {
|
pub fn object_rest_spread() -> impl Pass + Clone {
|
||||||
chain!(
|
chain!(ObjectRest, ObjectSpread)
|
||||||
ObjectRest {
|
|
||||||
helpers: helpers.clone(),
|
|
||||||
},
|
|
||||||
ObjectSpread { helpers }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ObjectRest {
|
struct ObjectRest;
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct RestFolder {
|
struct RestFolder {
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
/// Injected before the original statement.
|
/// Injected before the original statement.
|
||||||
vars: Vec<VarDeclarator>,
|
vars: Vec<VarDeclarator>,
|
||||||
/// Variables which should ceclaraed using `var`
|
/// Variables which should ceclaraed using `var`
|
||||||
@ -376,7 +367,6 @@ where
|
|||||||
|
|
||||||
for stmt in stmts {
|
for stmt in stmts {
|
||||||
let mut folder = RestFolder {
|
let mut folder = RestFolder {
|
||||||
helpers: self.helpers.clone(),
|
|
||||||
vars: vec![],
|
vars: vec![],
|
||||||
mutable_vars: vec![],
|
mutable_vars: vec![],
|
||||||
exprs: vec![],
|
exprs: vec![],
|
||||||
@ -761,18 +751,14 @@ impl RestFolder {
|
|||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
left: PatOrExpr::Pat(last.arg),
|
left: PatOrExpr::Pat(last.arg),
|
||||||
op: op!("="),
|
op: op!("="),
|
||||||
right: box object_without_properties(&self.helpers, obj.clone(), excluded_props),
|
right: box object_without_properties(obj.clone(), excluded_props),
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
// println!("Var: rest = objectWithoutProperties()",);
|
// println!("Var: rest = objectWithoutProperties()",);
|
||||||
self.push_var_if_not_empty(VarDeclarator {
|
self.push_var_if_not_empty(VarDeclarator {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
name: *last.arg,
|
name: *last.arg,
|
||||||
init: Some(box object_without_properties(
|
init: Some(box object_without_properties(obj.clone(), excluded_props)),
|
||||||
&self.helpers,
|
|
||||||
obj.clone(),
|
|
||||||
excluded_props,
|
|
||||||
)),
|
|
||||||
definite: false,
|
definite: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -785,13 +771,9 @@ impl RestFolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn object_without_properties(
|
fn object_without_properties(obj: Box<Expr>, excluded_props: Vec<Option<ExprOrSpread>>) -> Expr {
|
||||||
helpers: &Helpers,
|
|
||||||
obj: Box<Expr>,
|
|
||||||
excluded_props: Vec<Option<ExprOrSpread>>,
|
|
||||||
) -> Expr {
|
|
||||||
if excluded_props.is_empty() {
|
if excluded_props.is_empty() {
|
||||||
helpers.extends();
|
helper!(extends);
|
||||||
|
|
||||||
return Expr::Call(CallExpr {
|
return Expr::Call(CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
@ -808,7 +790,7 @@ fn object_without_properties(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
helpers.object_without_properties();
|
helper!(object_without_properties);
|
||||||
|
|
||||||
Expr::Call(CallExpr {
|
Expr::Call(CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
@ -888,9 +870,7 @@ fn simplify_pat(pat: Pat) -> Pat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ObjectSpread {
|
struct ObjectSpread;
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Fold<Expr> for ObjectSpread {
|
impl Fold<Expr> for ObjectSpread {
|
||||||
fn fold(&mut self, expr: Expr) -> Expr {
|
fn fold(&mut self, expr: Expr) -> Expr {
|
||||||
@ -952,8 +932,8 @@ impl Fold<Expr> for ObjectSpread {
|
|||||||
buf
|
buf
|
||||||
};
|
};
|
||||||
|
|
||||||
self.helpers.define_property();
|
helper!(define_property);
|
||||||
self.helpers.object_spread();
|
helper!(object_spread);
|
||||||
Expr::Call(CallExpr {
|
Expr::Call(CallExpr {
|
||||||
span,
|
span,
|
||||||
callee: quote_ident!("_objectSpread").as_callee(),
|
callee: quote_ident!("_objectSpread").as_callee(),
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
use super::object_rest_spread;
|
use super::object_rest_spread;
|
||||||
use crate::{compat::es2015::Spread, helpers::Helpers};
|
use crate::compat::es2015::Spread;
|
||||||
use ast::Module;
|
use ast::Module;
|
||||||
use std::sync::Arc;
|
|
||||||
use swc_common::Fold;
|
use swc_common::Fold;
|
||||||
|
|
||||||
fn tr(helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn tr() -> impl Fold<Module> {
|
||||||
object_rest_spread(helpers.clone())
|
object_rest_spread()
|
||||||
}
|
}
|
||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_function_array,
|
rest_function_array,
|
||||||
r#"
|
r#"
|
||||||
function foo([{...bar}]) {
|
function foo([{...bar}]) {
|
||||||
@ -26,7 +25,7 @@ function foo([_param]) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_var_basic,
|
rest_var_basic,
|
||||||
r#"
|
r#"
|
||||||
var { a , ...b } = _ref;
|
var { a , ...b } = _ref;
|
||||||
@ -38,7 +37,7 @@ var { a } = _ref, b = _objectWithoutProperties(_ref, ['a']);
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_assignment_exec,
|
rest_assignment_exec,
|
||||||
r#"
|
r#"
|
||||||
let foo = {
|
let foo = {
|
||||||
@ -54,7 +53,7 @@ expect(c).toEqual({b: 2});
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_catch_exec,
|
rest_catch_exec,
|
||||||
r#"
|
r#"
|
||||||
try {
|
try {
|
||||||
@ -76,7 +75,7 @@ try {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_assignment_expression,
|
rest_assignment_expression,
|
||||||
r#"({ a1 } = c1);
|
r#"({ a1 } = c1);
|
||||||
({ a2, ...b2 } = c2);
|
({ a2, ...b2 } = c2);
|
||||||
@ -93,7 +92,7 @@ console.log(( _c3 = c3, b3 = _objectWithoutProperties(_c3, ['a3']), { a3 } = _c
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_catch_clause,
|
rest_catch_clause,
|
||||||
r#"
|
r#"
|
||||||
try {} catch({ ...a34 }) {}
|
try {} catch({ ...a34 }) {}
|
||||||
@ -135,7 +134,7 @@ try{
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_export,
|
rest_export,
|
||||||
r#"
|
r#"
|
||||||
// ExportNamedDeclaration
|
// ExportNamedDeclaration
|
||||||
@ -162,12 +161,7 @@ export var [dd, ee] = ads;
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| chain!(
|
|_| chain!(tr(), Spread {}),
|
||||||
tr(helpers.clone()),
|
|
||||||
Spread {
|
|
||||||
helpers: helpers.clone()
|
|
||||||
}
|
|
||||||
),
|
|
||||||
rest_for_x,
|
rest_for_x,
|
||||||
r#"
|
r#"
|
||||||
// ForXStatement
|
// ForXStatement
|
||||||
@ -243,7 +237,7 @@ async function a() {
|
|||||||
test_exec!(
|
test_exec!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_impure_computed_exec,
|
rest_impure_computed_exec,
|
||||||
r#"
|
r#"
|
||||||
var key, x, y, z;
|
var key, x, y, z;
|
||||||
@ -273,7 +267,7 @@ expect(z).toBe("zee");
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_impure_computed,
|
rest_impure_computed,
|
||||||
r#"
|
r#"
|
||||||
var key, x, y, z;
|
var key, x, y, z;
|
||||||
@ -354,7 +348,7 @@ expect(z).toBe("zee");"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_nested_2,
|
rest_nested_2,
|
||||||
r#"
|
r#"
|
||||||
const test = {
|
const test = {
|
||||||
@ -403,7 +397,7 @@ const {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_nested_computed_key,
|
rest_nested_computed_key,
|
||||||
r#"
|
r#"
|
||||||
const {
|
const {
|
||||||
@ -430,7 +424,7 @@ const _ref = {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_nested_default_value_exec,
|
rest_nested_default_value_exec,
|
||||||
r#"
|
r#"
|
||||||
const {
|
const {
|
||||||
@ -448,7 +442,7 @@ expect(d).toEqual({})
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_nested_default_value,
|
rest_nested_default_value,
|
||||||
r#"
|
r#"
|
||||||
const {
|
const {
|
||||||
@ -475,7 +469,7 @@ const _ref = {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_nested_order_exec,
|
rest_nested_order_exec,
|
||||||
r#"
|
r#"
|
||||||
var result = "";
|
var result = "";
|
||||||
@ -502,20 +496,22 @@ expect(result).toBe("barbazfoo");
|
|||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
test!(::swc_ecma_parser::Syntax::default(),
|
test!(
|
||||||
|_,helpers|tr(helpers),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|
|_| tr(),
|
||||||
rest_nested_order,
|
rest_nested_order,
|
||||||
r#"
|
r#"
|
||||||
const { a: { ...bar }, b: { ...baz }, ...foo } = obj;
|
const { a: { ...bar }, b: { ...baz }, ...foo } = obj;
|
||||||
"#,
|
"#,
|
||||||
r#"
|
r#"
|
||||||
const bar = _extends({}, obj.a), baz = _extends({}, obj.b), foo = _objectWithoutProperties(obj, ['a', 'b']);
|
const bar = _extends({}, obj.a), baz = _extends({}, obj.b), foo =
|
||||||
|
_objectWithoutProperties(obj, ['a', 'b']);
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_nested_1,
|
rest_nested_1,
|
||||||
r#"
|
r#"
|
||||||
const defunct = {
|
const defunct = {
|
||||||
@ -552,7 +548,7 @@ const {
|
|||||||
test_exec!(
|
test_exec!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_non_string_computed_exec,
|
rest_non_string_computed_exec,
|
||||||
r#"
|
r#"
|
||||||
const a = {
|
const a = {
|
||||||
@ -615,7 +611,7 @@ expect(dy).toBe("sy");
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_non_string_computed,
|
rest_non_string_computed,
|
||||||
r#"
|
r#"
|
||||||
const a = {
|
const a = {
|
||||||
@ -729,7 +725,7 @@ expect(dy).toBe("sy");"#
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_parameters,
|
rest_parameters,
|
||||||
r#"
|
r#"
|
||||||
function a({ ...a34 }) {}
|
function a({ ...a34 }) {}
|
||||||
@ -824,7 +820,7 @@ function b3({
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_symbol_exec,
|
rest_symbol_exec,
|
||||||
r#"
|
r#"
|
||||||
const sym = Symbol("test");
|
const sym = Symbol("test");
|
||||||
@ -852,7 +848,7 @@ expect(Object.getOwnPropertySymbols(noSym)).toEqual([]);"#
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_symbol,
|
rest_symbol,
|
||||||
r#"
|
r#"
|
||||||
let {
|
let {
|
||||||
@ -893,7 +889,7 @@ if (_ref3 = {}, _Symbol$for3 = Symbol.for("foo"), ({
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_variable_destructuring_1,
|
rest_variable_destructuring_1,
|
||||||
r#"
|
r#"
|
||||||
var z = {};
|
var z = {};
|
||||||
@ -948,7 +944,7 @@ const {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_variable_destructuring_2,
|
rest_variable_destructuring_2,
|
||||||
r#"
|
r#"
|
||||||
let {
|
let {
|
||||||
@ -972,7 +968,7 @@ let {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_variable_destructuring_3,
|
rest_variable_destructuring_3,
|
||||||
r#"
|
r#"
|
||||||
let { x4: { ...y4 } } = z;
|
let { x4: { ...y4 } } = z;
|
||||||
@ -984,7 +980,7 @@ let y4 = _extends({}, z.x4);
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_with_array_rest_exec,
|
rest_with_array_rest_exec,
|
||||||
r#"
|
r#"
|
||||||
let [{ a, ...foo}, ...bar] = [{ a: 1, b:2 }, 2, 3, 4];
|
let [{ a, ...foo}, ...bar] = [{ a: 1, b:2 }, 2, 3, 4];
|
||||||
@ -996,7 +992,7 @@ expect(bar).toEqual([2, 3, 4]);
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_with_array_rest_exec_2,
|
rest_with_array_rest_exec_2,
|
||||||
r#"
|
r#"
|
||||||
let {
|
let {
|
||||||
@ -1016,7 +1012,7 @@ expect(objectRest).toEqual({d: 'oyez'})
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
rest_with_array_rest,
|
rest_with_array_rest,
|
||||||
r#"
|
r#"
|
||||||
let {
|
let {
|
||||||
@ -1038,7 +1034,7 @@ let _ref = {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
spread_assignment,
|
spread_assignment,
|
||||||
r#"
|
r#"
|
||||||
z = { x, ...y };
|
z = { x, ...y };
|
||||||
@ -1058,7 +1054,7 @@ z = {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
spread_expression,
|
spread_expression,
|
||||||
r#"
|
r#"
|
||||||
({ x, ...y, a, ...b, c });
|
({ x, ...y, a, ...b, c });
|
||||||
@ -1093,8 +1089,9 @@ _objectSpread({}, {
|
|||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
test_exec!(::swc_ecma_parser::Syntax::default(),
|
test_exec!(
|
||||||
|_,helpers|tr(helpers),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|
|_| tr(),
|
||||||
spread_no_object_assign_exec,
|
spread_no_object_assign_exec,
|
||||||
r#"
|
r#"
|
||||||
Object.defineProperty(Object.prototype, 'NOSET', {
|
Object.defineProperty(Object.prototype, 'NOSET', {
|
||||||
@ -1115,7 +1112,8 @@ const objSpread = { ...obj };
|
|||||||
|
|
||||||
const obj2 = { NOSET: 123, NOWRITE: 456 };
|
const obj2 = { NOSET: 123, NOWRITE: 456 };
|
||||||
// this line would throw `TypeError: Cannot assign to read only property 'NOWRITE'`
|
// 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)
|
// (spread defines them)
|
||||||
const obj2Spread = { ...obj2 };
|
const obj2Spread = { ...obj2 };
|
||||||
|
|
||||||
@ -1142,7 +1140,7 @@ expect(Array.isArray(Object.getPrototypeOf(o2))).toBe(false);
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
spread_variable_declaration,
|
spread_variable_declaration,
|
||||||
r#"var z = { ...x };"#,
|
r#"var z = { ...x };"#,
|
||||||
r#"var z = _objectSpread({}, x);"#
|
r#"var z = _objectSpread({}, x);"#
|
||||||
|
@ -61,7 +61,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| MemberExprLit,
|
|_| MemberExprLit,
|
||||||
basic,
|
basic,
|
||||||
r#"obj["foo"] = "isValid";
|
r#"obj["foo"] = "isValid";
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| PropertyLiteral,
|
|_| PropertyLiteral,
|
||||||
babel_basic,
|
babel_basic,
|
||||||
r#"var foo = {
|
r#"var foo = {
|
||||||
// changed
|
// changed
|
||||||
|
@ -91,7 +91,7 @@ mod tests {
|
|||||||
($name:ident, $src:literal) => {
|
($name:ident, $src:literal) => {
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| ReservedWord,
|
|_| ReservedWord,
|
||||||
$name,
|
$name,
|
||||||
$src,
|
$src,
|
||||||
$src
|
$src
|
||||||
@ -101,7 +101,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| ReservedWord,
|
|_| ReservedWord,
|
||||||
babel_issue_6477,
|
babel_issue_6477,
|
||||||
r#"
|
r#"
|
||||||
function utf8CheckByte(byte) {
|
function utf8CheckByte(byte) {
|
||||||
|
@ -371,7 +371,7 @@ mod tests {
|
|||||||
macro_rules! test_fixer {
|
macro_rules! test_fixer {
|
||||||
($name:ident, $from:literal, $to:literal) => {
|
($name:ident, $from:literal, $to:literal) => {
|
||||||
// We use noop because fixer is invoked by tests::apply_transform.
|
// 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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
use ast::*;
|
use ast::*;
|
||||||
use std::sync::{
|
use scoped_tls::scoped_thread_local;
|
||||||
atomic::{AtomicBool, Ordering},
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
Arc,
|
|
||||||
};
|
|
||||||
use swc_common::{
|
use swc_common::{
|
||||||
errors::{ColorConfig, Handler},
|
errors::{ColorConfig, Handler},
|
||||||
sync::Lrc,
|
sync::Lrc,
|
||||||
@ -17,8 +15,15 @@ lazy_static! {
|
|||||||
static ref SESSION: Session<'static> = { Session { handler: &*HANDLER } };
|
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 {
|
macro_rules! add_to {
|
||||||
($buf:expr, $name:tt, $b:expr) => {{
|
($buf:expr, $name:ident, $b:expr) => {{
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref STMTS: Vec<Stmt> = {
|
static ref STMTS: Vec<Stmt> = {
|
||||||
let code = include_str!(concat!("_", stringify!($name), ".js"));
|
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 {
|
macro_rules! define_helpers {
|
||||||
(
|
(
|
||||||
Helpers {
|
Helpers {
|
||||||
$( $name:ident : ( $( $dep:ident ),* ), )*
|
$( $name:ident : ( $( $dep:ident ),* ), )*
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
/// Tracks used helper methods. (e.g. __extends)
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Helpers {
|
struct Inner {
|
||||||
$( $name: AtomicBool, )*
|
$( $name: AtomicBool, )*
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Helpers {
|
impl Helpers {
|
||||||
$(
|
$(
|
||||||
pub fn $name(&self) {
|
pub fn $name(&self) {
|
||||||
self.$name.store(true, Ordering::Relaxed);
|
self.inner.$name.store(true, Ordering::Relaxed);
|
||||||
|
|
||||||
$(
|
$(
|
||||||
self.$dep();
|
self.$dep();
|
||||||
)*
|
)*
|
||||||
@ -71,34 +84,18 @@ macro_rules! define_helpers {
|
|||||||
fn mk_helpers(&self) -> Vec<Stmt>{
|
fn mk_helpers(&self) -> Vec<Stmt>{
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
|
|
||||||
|
HELPERS.with(|helpers|{
|
||||||
$(
|
$(
|
||||||
add_to!(buf, $name, self.helpers.$name);
|
add_to!(buf, $name, helpers.inner.$name);
|
||||||
)*
|
)*
|
||||||
|
});
|
||||||
|
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fold<Module> 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<Helpers>,
|
|
||||||
}
|
|
||||||
|
|
||||||
define_helpers!(Helpers {
|
define_helpers!(Helpers {
|
||||||
apply_decorated_descriptor: (),
|
apply_decorated_descriptor: (),
|
||||||
array_with_holes: (),
|
array_with_holes: (),
|
||||||
@ -181,7 +178,6 @@ define_helpers!(Helpers {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct InjectHelpers {
|
pub struct InjectHelpers {
|
||||||
pub cm: Lrc<SourceMap>,
|
pub cm: Lrc<SourceMap>,
|
||||||
pub helpers: Arc<Helpers>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fold<Module> for InjectHelpers {
|
impl Fold<Module> for InjectHelpers {
|
||||||
|
@ -114,7 +114,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|tester, _| InlineGlobals {
|
|tester| InlineGlobals {
|
||||||
envs: envs(tester, &[("NODE_ENV", "development")]),
|
envs: envs(tester, &[("NODE_ENV", "development")]),
|
||||||
globals: globals(tester, &[]),
|
globals: globals(tester, &[]),
|
||||||
},
|
},
|
||||||
@ -125,7 +125,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|tester, _| InlineGlobals {
|
|tester| InlineGlobals {
|
||||||
envs: envs(tester, &[]),
|
envs: envs(tester, &[]),
|
||||||
globals: globals(tester, &[("__DEBUG__", "true")]),
|
globals: globals(tester, &[("__DEBUG__", "true")]),
|
||||||
},
|
},
|
||||||
@ -136,7 +136,7 @@ mod tests {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|tester, _| InlineGlobals {
|
|tester| InlineGlobals {
|
||||||
envs: envs(tester, &[]),
|
envs: envs(tester, &[]),
|
||||||
globals: globals(tester, &[("debug", "true")]),
|
globals: globals(tester, &[("debug", "true")]),
|
||||||
},
|
},
|
||||||
|
@ -18,6 +18,7 @@ extern crate fxhash;
|
|||||||
extern crate indexmap;
|
extern crate indexmap;
|
||||||
extern crate inflector;
|
extern crate inflector;
|
||||||
extern crate ordered_float;
|
extern crate ordered_float;
|
||||||
|
extern crate scoped_tls;
|
||||||
extern crate swc_ecma_ast as ast;
|
extern crate swc_ecma_ast as ast;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate swc_ecma_codegen;
|
extern crate swc_ecma_codegen;
|
||||||
@ -46,6 +47,8 @@ pub use self::{
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod tests;
|
mod tests;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
pub mod helpers;
|
||||||
|
#[macro_use]
|
||||||
mod quote;
|
mod quote;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
@ -53,7 +56,6 @@ mod macros;
|
|||||||
mod hygiene;
|
mod hygiene;
|
||||||
pub mod compat;
|
pub mod compat;
|
||||||
mod fixer;
|
mod fixer;
|
||||||
pub mod helpers;
|
|
||||||
mod inline_globals;
|
mod inline_globals;
|
||||||
pub mod modules;
|
pub mod modules;
|
||||||
pub mod pass;
|
pub mod pass;
|
||||||
|
@ -3,14 +3,13 @@ use super::util::{
|
|||||||
use_strict, Scope, VarCollector,
|
use_strict, Scope, VarCollector,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
helpers::Helpers,
|
|
||||||
pass::Pass,
|
pass::Pass,
|
||||||
util::{undefined, DestructuringFinder, ExprFactory, State},
|
util::{undefined, DestructuringFinder, ExprFactory, State},
|
||||||
};
|
};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use fxhash::FxHashSet;
|
use fxhash::FxHashSet;
|
||||||
use serde::{Deserialize, Serialize};
|
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_atoms::JsWord;
|
||||||
use swc_common::{Fold, FoldWith, VisitWith, DUMMY_SP};
|
use swc_common::{Fold, FoldWith, VisitWith, DUMMY_SP};
|
||||||
|
|
||||||
@ -67,9 +66,8 @@ impl Default for Lazy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn common_js(helpers: Arc<Helpers>, config: Config) -> impl Pass + Clone {
|
pub fn common_js(config: Config) -> impl Pass + Clone {
|
||||||
CommonJs {
|
CommonJs {
|
||||||
helpers,
|
|
||||||
config,
|
config,
|
||||||
scope: Default::default(),
|
scope: Default::default(),
|
||||||
in_top_level: Default::default(),
|
in_top_level: Default::default(),
|
||||||
@ -78,7 +76,6 @@ pub fn common_js(helpers: Arc<Helpers>, config: Config) -> impl Pass + Clone {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct CommonJs {
|
struct CommonJs {
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
scope: State<Scope>,
|
scope: State<Scope>,
|
||||||
in_top_level: State<bool>,
|
in_top_level: State<bool>,
|
||||||
@ -522,7 +519,7 @@ impl Fold<Vec<ModuleItem>> for CommonJs {
|
|||||||
|
|
||||||
let rhs = match ty {
|
let rhs = match ty {
|
||||||
Some(true) if !self.config.no_interop => {
|
Some(true) if !self.config.no_interop => {
|
||||||
self.helpers.interop_require_wildcard();
|
helper!(interop_require_wildcard);
|
||||||
box Expr::Call(CallExpr {
|
box Expr::Call(CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
callee: quote_ident!("_interopRequireWildcard").as_callee(),
|
callee: quote_ident!("_interopRequireWildcard").as_callee(),
|
||||||
@ -531,7 +528,7 @@ impl Fold<Vec<ModuleItem>> for CommonJs {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
Some(false) if !self.config.no_interop => {
|
Some(false) if !self.config.no_interop => {
|
||||||
self.helpers.interop_require_default();
|
helper!(interop_require_default);
|
||||||
box Expr::Call(CallExpr {
|
box Expr::Call(CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
callee: quote_ident!("_interopRequireDefault").as_callee(),
|
callee: quote_ident!("_interopRequireDefault").as_callee(),
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -5,24 +5,23 @@ use super::util::{
|
|||||||
make_descriptor, make_require_call, use_strict, Scope, VarCollector,
|
make_descriptor, make_require_call, use_strict, Scope, VarCollector,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
helpers::Helpers,
|
|
||||||
pass::Pass,
|
pass::Pass,
|
||||||
util::{prepend_stmts, DestructuringFinder, ExprFactory, State},
|
util::{prepend_stmts, DestructuringFinder, ExprFactory, State},
|
||||||
};
|
};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use fxhash::FxHashSet;
|
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};
|
use swc_common::{sync::Lrc, Fold, FoldWith, Mark, SourceMap, VisitWith, DUMMY_SP};
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
pub fn umd(cm: Lrc<SourceMap>, helpers: Arc<Helpers>, config: Config) -> impl Pass + Clone {
|
pub fn umd(cm: Lrc<SourceMap>, config: Config) -> impl Pass + Clone {
|
||||||
Umd {
|
Umd {
|
||||||
config: config.build(cm.clone()),
|
config: config.build(cm.clone()),
|
||||||
cm,
|
cm,
|
||||||
helpers,
|
|
||||||
scope: Default::default(),
|
scope: Default::default(),
|
||||||
exports: Default::default(),
|
exports: Default::default(),
|
||||||
}
|
}
|
||||||
@ -32,7 +31,6 @@ pub fn umd(cm: Lrc<SourceMap>, helpers: Arc<Helpers>, config: Config) -> impl Pa
|
|||||||
struct Umd {
|
struct Umd {
|
||||||
cm: Lrc<SourceMap>,
|
cm: Lrc<SourceMap>,
|
||||||
config: BuiltConfig,
|
config: BuiltConfig,
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
scope: State<Scope>,
|
scope: State<Scope>,
|
||||||
exports: State<Exports>,
|
exports: State<Exports>,
|
||||||
}
|
}
|
||||||
@ -443,9 +441,9 @@ impl Fold<Module> for Umd {
|
|||||||
match ty {
|
match ty {
|
||||||
Some(&wildcard) => {
|
Some(&wildcard) => {
|
||||||
if wildcard {
|
if wildcard {
|
||||||
self.helpers.interop_require_wildcard();
|
helper!(interop_require_wildcard);
|
||||||
} else {
|
} else {
|
||||||
self.helpers.interop_require_default();
|
helper!(interop_require_default);
|
||||||
}
|
}
|
||||||
let right = box Expr::Call(CallExpr {
|
let right = box Expr::Call(CallExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
|
@ -5,20 +5,15 @@ fn syntax() -> ::swc_ecma_parser::Syntax {
|
|||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tr(
|
fn tr(tester: &mut crate::tests::Tester, config: Config) -> impl Fold<Module> {
|
||||||
tester: &mut crate::tests::Tester,
|
chain!(resolver(), umd(tester.cm.clone(), config))
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
config: Config,
|
|
||||||
) -> impl Fold<Module> {
|
|
||||||
chain!(resolver(), umd(tester.cm.clone(), helpers, config))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// exports_variable
|
// exports_variable
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -90,9 +85,8 @@ export class foo9 {}
|
|||||||
// export_named
|
// export_named
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -133,9 +127,8 @@ export {foo};
|
|||||||
// export_default_11
|
// export_default_11
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -184,9 +177,8 @@ export function Cachier(databaseName) {}
|
|||||||
// export_from_4
|
// export_from_4
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -231,9 +223,8 @@ export {foo as bar} from "foo";
|
|||||||
// export_default_3
|
// export_default_3
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -277,9 +268,8 @@ export default [];
|
|||||||
// imports_default
|
// imports_default
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -320,9 +310,8 @@ foo2;
|
|||||||
// export_named_3
|
// export_named_3
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -364,9 +353,8 @@ export {foo as default, bar};
|
|||||||
// imports_glob
|
// imports_glob
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -404,9 +392,8 @@ foo;
|
|||||||
// export_default_6
|
// export_default_6
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -448,9 +435,8 @@ export default class {}
|
|||||||
// export_default_5
|
// export_default_5
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -489,9 +475,8 @@ export default function () {}
|
|||||||
// hoist_function_exports
|
// hoist_function_exports
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -552,9 +537,8 @@ export var isOdd = (function (isEven) {
|
|||||||
// export_from_2
|
// export_from_2
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -599,9 +583,8 @@ export {foo as default} from "foo";
|
|||||||
// export_default_8
|
// export_default_8
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -647,9 +630,8 @@ export default class Foo {}
|
|||||||
// export_named_5
|
// export_named_5
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -691,9 +673,8 @@ export {foo, bar};
|
|||||||
// imports_exact_globals_false
|
// imports_exact_globals_false
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -736,9 +717,8 @@ import fizzBuzz from "fizzbuzz";
|
|||||||
// export_default_10
|
// export_default_10
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -782,9 +762,8 @@ export default (function(){return "foo"})();
|
|||||||
// export_from
|
// export_from
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -827,9 +806,8 @@ export {foo} from "foo";
|
|||||||
// export_from_5
|
// export_from_5
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -880,9 +858,8 @@ export {foo, bar} from "foo";
|
|||||||
// export_default_2
|
// export_default_2
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -922,9 +899,8 @@ export default {};
|
|||||||
// imports_named
|
// imports_named
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -974,9 +950,8 @@ xyz;
|
|||||||
// imports_mixing
|
// imports_mixing
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1013,9 +988,8 @@ xyz;
|
|||||||
// remap
|
// remap
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1096,9 +1070,8 @@ d = 4;
|
|||||||
// export_named_2
|
// export_named_2
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1139,9 +1112,8 @@ export {foo as default};
|
|||||||
// export_default_7
|
// export_default_7
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1183,9 +1155,8 @@ export default function foo () {}
|
|||||||
// non_default_imports
|
// non_default_imports
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1218,9 +1189,8 @@ import { render } from "./lib/render";
|
|||||||
// imports
|
// imports
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1255,9 +1225,8 @@ import "./directory/foo-bar";
|
|||||||
// export_default
|
// export_default
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1297,9 +1266,8 @@ export default 42;
|
|||||||
// export_default_4
|
// export_default_4
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1339,9 +1307,8 @@ export default foo;
|
|||||||
// export_from_3
|
// export_from_3
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1390,9 +1357,8 @@ export {foo as default, bar} from "foo";
|
|||||||
// export_default_9
|
// export_default_9
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1434,9 +1400,8 @@ export { foo as default };
|
|||||||
// overview
|
// overview
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1499,9 +1464,8 @@ bar2;
|
|||||||
// export_named_4
|
// export_named_4
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
@ -1542,9 +1506,8 @@ export {foo as bar};
|
|||||||
// export_from_6
|
// export_from_6
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester,
|
tester,
|
||||||
helpers,
|
|
||||||
Config {
|
Config {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use crate::{helpers::Helpers, util::ExprFactory};
|
use crate::util::ExprFactory;
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use swc_common::{Fold, FoldWith, DUMMY_SP};
|
use swc_common::{Fold, FoldWith, DUMMY_SP};
|
||||||
|
|
||||||
pub(super) struct ClassNameTdzFolder<'a> {
|
pub(super) struct ClassNameTdzFolder<'a> {
|
||||||
pub helpers: &'a Helpers,
|
|
||||||
pub class_name: &'a Ident,
|
pub class_name: &'a Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,7 +13,7 @@ impl<'a> Fold<Expr> for ClassNameTdzFolder<'a> {
|
|||||||
//
|
//
|
||||||
|
|
||||||
if i.sym == self.class_name.sym {
|
if i.sym == self.class_name.sym {
|
||||||
self.helpers.class_name_tdz_error();
|
helper!(class_name_tdz_error);
|
||||||
|
|
||||||
return Expr::Seq(SeqExpr {
|
return Expr::Seq(SeqExpr {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
|
@ -4,7 +4,6 @@ use self::{
|
|||||||
used_name::{UsedNameCollector, UsedNameRenamer},
|
used_name::{UsedNameCollector, UsedNameRenamer},
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
helpers::Helpers,
|
|
||||||
pass::Pass,
|
pass::Pass,
|
||||||
util::{
|
util::{
|
||||||
alias_ident_for, constructor::inject_after_super, default_constructor, undefined,
|
alias_ident_for, constructor::inject_after_super, default_constructor, undefined,
|
||||||
@ -13,7 +12,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use fxhash::FxHashSet;
|
use fxhash::FxHashSet;
|
||||||
use std::sync::Arc;
|
|
||||||
use swc_atoms::JsWord;
|
use swc_atoms::JsWord;
|
||||||
use swc_common::{Fold, FoldWith, Mark, Spanned, VisitWith, DUMMY_SP};
|
use swc_common::{Fold, FoldWith, Mark, Spanned, VisitWith, DUMMY_SP};
|
||||||
|
|
||||||
@ -30,16 +28,12 @@ mod used_name;
|
|||||||
/// # Impl note
|
/// # Impl note
|
||||||
///
|
///
|
||||||
/// We use custom helper to handle export defaul class
|
/// We use custom helper to handle export defaul class
|
||||||
pub fn class_properties(helpers: Arc<Helpers>) -> impl Pass + Clone {
|
pub fn class_properties() -> impl Pass + Clone {
|
||||||
ClassProperties {
|
ClassProperties { mark: Mark::root() }
|
||||||
helpers,
|
|
||||||
mark: Mark::root(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ClassProperties {
|
struct ClassProperties {
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
mark: Mark,
|
mark: Mark,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,10 +264,8 @@ impl ClassProperties {
|
|||||||
// we handle computed key here to preserve the execution order
|
// we handle computed key here to preserve the execution order
|
||||||
let key = match method.key {
|
let key = match method.key {
|
||||||
PropName::Computed(expr) => {
|
PropName::Computed(expr) => {
|
||||||
let expr = expr.fold_with(&mut ClassNameTdzFolder {
|
let expr =
|
||||||
helpers: &self.helpers,
|
expr.fold_with(&mut ClassNameTdzFolder { class_name: &ident });
|
||||||
class_name: &ident,
|
|
||||||
});
|
|
||||||
let ident = private_ident!("tmp");
|
let ident = private_ident!("tmp");
|
||||||
// Handle computed property
|
// Handle computed property
|
||||||
vars.push(VarDeclarator {
|
vars.push(VarDeclarator {
|
||||||
@ -293,10 +285,9 @@ impl ClassProperties {
|
|||||||
|
|
||||||
ClassMember::ClassProp(mut prop) => {
|
ClassMember::ClassProp(mut prop) => {
|
||||||
let prop_span = prop.span();
|
let prop_span = prop.span();
|
||||||
prop.key = prop.key.fold_with(&mut ClassNameTdzFolder {
|
prop.key = prop
|
||||||
helpers: &self.helpers,
|
.key
|
||||||
class_name: &ident,
|
.fold_with(&mut ClassNameTdzFolder { class_name: &ident });
|
||||||
});
|
|
||||||
|
|
||||||
let key = match *prop.key {
|
let key = match *prop.key {
|
||||||
Expr::Ident(ref i) if !prop.computed => Lit::Str(Str {
|
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();
|
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();
|
let callee = quote_ident!(DUMMY_SP, "_defineProperty").as_callee();
|
||||||
|
|
||||||
if prop.is_static {
|
if prop.is_static {
|
||||||
@ -440,7 +431,6 @@ impl ClassProperties {
|
|||||||
statics: &statics,
|
statics: &statics,
|
||||||
vars: vec![],
|
vars: vec![],
|
||||||
class_name: &ident,
|
class_name: &ident,
|
||||||
helpers: &self.helpers,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::util::{alias_ident_for, prepend, ExprFactory};
|
||||||
helpers::Helpers,
|
|
||||||
util::{alias_ident_for, prepend, ExprFactory},
|
|
||||||
};
|
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use fxhash::FxHashSet;
|
use fxhash::FxHashSet;
|
||||||
use std::{iter, mem};
|
use std::{iter, mem};
|
||||||
@ -13,7 +10,6 @@ pub(super) struct FieldAccessFolder<'a> {
|
|||||||
pub class_name: &'a Ident,
|
pub class_name: &'a Ident,
|
||||||
pub vars: Vec<VarDeclarator>,
|
pub vars: Vec<VarDeclarator>,
|
||||||
pub statics: &'a FxHashSet<JsWord>,
|
pub statics: &'a FxHashSet<JsWord>,
|
||||||
pub helpers: &'a Helpers,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Fold<Expr> for FieldAccessFolder<'a> {
|
impl<'a> Fold<Expr> for FieldAccessFolder<'a> {
|
||||||
@ -123,7 +119,7 @@ impl<'a> Fold<Expr> for FieldAccessFolder<'a> {
|
|||||||
.as_arg()
|
.as_arg()
|
||||||
};
|
};
|
||||||
|
|
||||||
self.helpers.class_private_field_set();
|
helper!(class_private_field_set);
|
||||||
let set = quote_ident!("_classPrivateFieldSet").as_callee();
|
let set = quote_ident!("_classPrivateFieldSet").as_callee();
|
||||||
|
|
||||||
let expr = Expr::Call(CallExpr {
|
let expr = Expr::Call(CallExpr {
|
||||||
@ -248,7 +244,7 @@ impl<'a> Fold<Expr> for FieldAccessFolder<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if is_static {
|
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();
|
let set = quote_ident!("_classStaticPrivateFieldSpecSet").as_callee();
|
||||||
|
|
||||||
Expr::Call(CallExpr {
|
Expr::Call(CallExpr {
|
||||||
@ -264,7 +260,7 @@ impl<'a> Fold<Expr> for FieldAccessFolder<'a> {
|
|||||||
type_args: Default::default(),
|
type_args: Default::default(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
self.helpers.class_private_field_set();
|
helper!(class_private_field_set);
|
||||||
let set = quote_ident!("_classPrivateFieldSet").as_callee();
|
let set = quote_ident!("_classPrivateFieldSet").as_callee();
|
||||||
|
|
||||||
Expr::Call(CallExpr {
|
Expr::Call(CallExpr {
|
||||||
@ -345,7 +341,7 @@ impl<'a> FieldAccessFolder<'a> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if is_static {
|
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();
|
let get = quote_ident!("_classStaticPrivateFieldSpecGet").as_callee();
|
||||||
|
|
||||||
(
|
(
|
||||||
@ -362,7 +358,7 @@ impl<'a> FieldAccessFolder<'a> {
|
|||||||
Some(Expr::Ident(self.class_name.clone())),
|
Some(Expr::Ident(self.class_name.clone())),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.helpers.class_private_field_get();
|
helper!(class_private_field_get);
|
||||||
let get = quote_ident!("_classPrivateFieldGet").as_callee();
|
let get = quote_ident!("_classPrivateFieldGet").as_callee();
|
||||||
|
|
||||||
match *obj {
|
match *obj {
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::compat::{
|
||||||
compat::{
|
|
||||||
es2015::{block_scoping, function_name, resolver, Classes},
|
es2015::{block_scoping, function_name, resolver, Classes},
|
||||||
es3::ReservedWord,
|
es3::ReservedWord,
|
||||||
},
|
|
||||||
helpers::Helpers,
|
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
|
||||||
use swc_ecma_parser::{EsConfig, Syntax};
|
use swc_ecma_parser::{EsConfig, Syntax};
|
||||||
|
|
||||||
fn syntax() -> Syntax {
|
fn syntax() -> Syntax {
|
||||||
@ -17,12 +13,12 @@ fn syntax() -> Syntax {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tr(helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn tr() -> impl Fold<Module> {
|
||||||
chain!(
|
chain!(
|
||||||
resolver(),
|
resolver(),
|
||||||
function_name(),
|
function_name(),
|
||||||
class_properties(helpers.clone()),
|
class_properties(),
|
||||||
Classes { helpers },
|
Classes,
|
||||||
block_scoping(),
|
block_scoping(),
|
||||||
ReservedWord,
|
ReservedWord,
|
||||||
)
|
)
|
||||||
@ -30,7 +26,7 @@ fn tr(helpers: Arc<Helpers>) -> impl Fold<Module> {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_static_infer_name,
|
public_static_infer_name,
|
||||||
r#"
|
r#"
|
||||||
var Foo = class {
|
var Foo = class {
|
||||||
@ -51,7 +47,7 @@ var Foo = function() {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_call_exec,
|
public_call_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -75,7 +71,7 @@ expect(test[1]).toBe(o);
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_instance_computed,
|
public_instance_computed,
|
||||||
r#"
|
r#"
|
||||||
function test(x) {
|
function test(x) {
|
||||||
@ -117,7 +113,7 @@ test('foo');
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_super_statement,
|
public_super_statement,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -154,7 +150,7 @@ function (_Bar) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_foobar,
|
private_foobar,
|
||||||
r#"
|
r#"
|
||||||
class Child extends Parent {
|
class Child extends Parent {
|
||||||
@ -202,7 +198,7 @@ var _scopedFunctionWithThis = new WeakMap();
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_call_exec,
|
private_call_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -226,7 +222,7 @@ expect(test[1]).toBe(o);
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_derived_multiple_supers,
|
public_derived_multiple_supers,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -274,7 +270,7 @@ function (_Bar) {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_static_call_exec,
|
private_static_call_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -296,7 +292,7 @@ expect(f.test("bar")).toBe("bar");
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_instance_undefined_exec,
|
private_instance_undefined_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -314,7 +310,7 @@ expect(new Foo().test()).toBe(undefined);
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_instance_exec,
|
private_instance_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -358,7 +354,7 @@ expect(f.test()).toBe(4);
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_regression_t6719,
|
public_regression_t6719,
|
||||||
r#"
|
r#"
|
||||||
function withContext(ComposedComponent) {
|
function withContext(ComposedComponent) {
|
||||||
@ -404,7 +400,7 @@ function withContext(ComposedComponent) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_super_with_collision,
|
public_super_with_collision,
|
||||||
r#"
|
r#"
|
||||||
class A {
|
class A {
|
||||||
@ -429,7 +425,7 @@ var A = function A(force1) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_call,
|
public_call,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -472,7 +468,7 @@ function () {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_instance_computed_exec,
|
public_instance_computed_exec,
|
||||||
r#"
|
r#"
|
||||||
function test(x) {
|
function test(x) {
|
||||||
@ -494,7 +490,7 @@ test('foo');
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_declaration_order,
|
private_declaration_order,
|
||||||
r#"
|
r#"
|
||||||
class C {
|
class C {
|
||||||
@ -531,7 +527,7 @@ expect(() => {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
nested_class_super_call_in_key,
|
nested_class_super_call_in_key,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -599,7 +595,7 @@ expect(new Outer().hello).toBe('hello');
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_instance_undefined,
|
public_instance_undefined,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -620,7 +616,7 @@ var Foo = function Foo() {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_derived_multiple_supers,
|
private_derived_multiple_supers,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -678,7 +674,7 @@ var _bar = new WeakMap();
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_native_classes_exec,
|
public_native_classes_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -705,7 +701,7 @@ expect(f.test()).toBe("bar")
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_regression_t2983,
|
public_regression_t2983,
|
||||||
r#"
|
r#"
|
||||||
call(class {
|
call(class {
|
||||||
@ -735,7 +731,7 @@ export { _class as default }
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_static,
|
public_static,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -757,7 +753,7 @@ _defineProperty(Foo, "bar", "foo");
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_instance_undefined,
|
private_instance_undefined,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -784,7 +780,7 @@ var _bar = new WeakMap();
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_declaration_order_exec,
|
private_declaration_order_exec,
|
||||||
r#"
|
r#"
|
||||||
class C {
|
class C {
|
||||||
@ -801,7 +797,7 @@ expect(() => {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_update,
|
public_update,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
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 {
|
class A {
|
||||||
foo() {
|
foo() {
|
||||||
return "bar";
|
return "bar";
|
||||||
@ -895,7 +891,7 @@ function (_A) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_constructor_collision,
|
private_constructor_collision,
|
||||||
r#"
|
r#"
|
||||||
var foo = "bar";
|
var foo = "bar";
|
||||||
@ -932,7 +928,7 @@ var _bar = new WeakMap();
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_constructor_collision,
|
public_constructor_collision,
|
||||||
r#"
|
r#"
|
||||||
var foo = "bar";
|
var foo = "bar";
|
||||||
@ -967,7 +963,7 @@ _defineProperty(Foo, "bar", baz);
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_computed,
|
public_computed,
|
||||||
r#"
|
r#"
|
||||||
const foo = "foo";
|
const foo = "foo";
|
||||||
@ -1051,7 +1047,7 @@ _defineProperty(MyClass, _ref3, '247');
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_assignment,
|
public_assignment,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -1098,7 +1094,7 @@ function () {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_static_exec,
|
public_static_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -1119,7 +1115,7 @@ test_exec!(
|
|||||||
// TODO(kdy1): unignore
|
// TODO(kdy1): unignore
|
||||||
ignore,
|
ignore,
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
regression_7371_exec,
|
regression_7371_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -1227,7 +1223,7 @@ new ComputedField();
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_static_inherited_exec,
|
private_static_inherited_exec,
|
||||||
r#"
|
r#"
|
||||||
class Base {
|
class Base {
|
||||||
@ -1305,7 +1301,7 @@ expect(Sub2.getClass()).toBe(7);
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
nested_class_super_property_in_key_exec,
|
nested_class_super_property_in_key_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -1333,7 +1329,7 @@ expect(new Outer().hello).toBe('hello');
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_super_statement,
|
private_super_statement,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -1377,7 +1373,7 @@ var _bar = new WeakMap();
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_private_in_derived,
|
private_private_in_derived,
|
||||||
r#"
|
r#"
|
||||||
class Outer {
|
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 {
|
class Foo {
|
||||||
#foo = 0;
|
#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 {
|
class Foo extends Bar {
|
||||||
bar = "foo";
|
bar = "foo";
|
||||||
|
|
||||||
@ -1497,7 +1493,7 @@ var Foo = function (_Bar) {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_computed_initialization_order_exec,
|
public_computed_initialization_order_exec,
|
||||||
r#"
|
r#"
|
||||||
const actualOrder = [];
|
const actualOrder = [];
|
||||||
@ -1544,7 +1540,7 @@ expect(inst[9]).toBe(15);
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
nested_class_super_call_in_key_exec,
|
nested_class_super_call_in_key_exec,
|
||||||
r#"
|
r#"
|
||||||
|
|
||||||
@ -1575,7 +1571,7 @@ expect(new Outer().hello).toBe('hello');
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_update_exec,
|
private_update_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -1611,7 +1607,7 @@ expect(results[7]).toBe(4);
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_extracted_this,
|
public_extracted_this,
|
||||||
r#"
|
r#"
|
||||||
var foo = "bar";
|
var foo = "bar";
|
||||||
@ -1641,7 +1637,7 @@ var Foo = function Foo(foo1) {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_derived,
|
private_derived,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -1698,7 +1694,7 @@ var _prop2 = new WeakMap();
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_super_call,
|
private_super_call,
|
||||||
r#"
|
r#"
|
||||||
class A {
|
class A {
|
||||||
@ -1760,7 +1756,7 @@ var _foo = new WeakMap();
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_reference_in_other_property,
|
private_reference_in_other_property,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
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 {
|
class Hello {
|
||||||
toString() {
|
toString() {
|
||||||
@ -1870,7 +1866,7 @@ expect(new Outer().hello).toBe('hello');
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_reevaluated_exec,
|
private_reevaluated_exec,
|
||||||
r#"
|
r#"
|
||||||
function classFactory() {
|
function classFactory() {
|
||||||
@ -1930,7 +1926,7 @@ expect(() => {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_numeric,
|
public_numeric,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -1953,7 +1949,7 @@ var Foo = function Foo() {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_assignment,
|
private_assignment,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2004,7 +2000,7 @@ var _foo = new WeakMap();
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_constructor_collision_exec,
|
private_constructor_collision_exec,
|
||||||
r#"
|
r#"
|
||||||
var foo = "bar";
|
var foo = "bar";
|
||||||
@ -2030,7 +2026,7 @@ expect("bar" in f).toBe(false);
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_static_export,
|
public_static_export,
|
||||||
r#"
|
r#"
|
||||||
export class MyClass {
|
export class MyClass {
|
||||||
@ -2060,7 +2056,7 @@ export { MyClass2 as default };
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_multiple,
|
private_multiple,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2095,7 +2091,7 @@ var _y = new WeakMap();
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_derived,
|
public_derived,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -2128,7 +2124,7 @@ function (_Bar) {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_static_undefined_exec,
|
public_static_undefined_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2143,7 +2139,7 @@ expect(Foo.num).toBeUndefined();
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_instance,
|
public_instance,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2164,7 +2160,7 @@ var Foo = function Foo() {
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
static_property_tdz_edgest_case_exec,
|
static_property_tdz_edgest_case_exec,
|
||||||
r#"
|
r#"
|
||||||
expect(() => {
|
expect(() => {
|
||||||
@ -2178,7 +2174,7 @@ expect(() => {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_non_block_arrow_func,
|
public_non_block_arrow_func,
|
||||||
r#"
|
r#"
|
||||||
export default param =>
|
export default param =>
|
||||||
@ -2218,7 +2214,7 @@ export default (param)=>{
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_static_undefined,
|
public_static_undefined,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2240,7 +2236,7 @@ _defineProperty(Foo, "bar", void 0);
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_static_infer_name_exec,
|
public_static_infer_name_exec,
|
||||||
r#"
|
r#"
|
||||||
var Foo = class {
|
var Foo = class {
|
||||||
@ -2256,7 +2252,7 @@ expect(Foo.name).toBe("Foo");
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
static_property_tdz_general_exec,
|
static_property_tdz_general_exec,
|
||||||
r#"
|
r#"
|
||||||
expect(() => {
|
expect(() => {
|
||||||
@ -2270,7 +2266,7 @@ expect(() => {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_call,
|
private_call,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2320,7 +2316,7 @@ var _foo = new WeakMap();
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_derived_exec,
|
private_derived_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2351,7 +2347,7 @@ expect(b.bar()).toBe("bar");
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_extracted_this,
|
private_extracted_this,
|
||||||
r#"
|
r#"
|
||||||
var foo = "bar";
|
var foo = "bar";
|
||||||
@ -2393,7 +2389,7 @@ var _baz = new WeakMap();
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_canonical_exec,
|
private_canonical_exec,
|
||||||
r#"
|
r#"
|
||||||
class Point {
|
class Point {
|
||||||
@ -2475,7 +2471,7 @@ expect(p3.toString()).toBe("Point<0,0>")
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_static_undefined_exec,
|
private_static_undefined_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2499,7 +2495,7 @@ expect(Foo.test()).toBe(undefined);
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
public_update_exec,
|
public_update_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2535,7 +2531,7 @@ expect(results[7]).toBe(4);
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_static_call,
|
private_static_call,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2581,7 +2577,7 @@ var _foo = {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_super_expression,
|
private_super_expression,
|
||||||
r#"
|
r#"
|
||||||
class Foo extends Bar {
|
class Foo extends Bar {
|
||||||
@ -2624,7 +2620,7 @@ var _bar = new WeakMap();
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_native_classes_exec,
|
private_native_classes_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -2651,7 +2647,7 @@ expect(f.test()).toBe("bar")
|
|||||||
|
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(),
|
syntax(),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
private_multiple_exec,
|
private_multiple_exec,
|
||||||
r#"
|
r#"
|
||||||
class Foo {
|
class Foo {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
helpers::Helpers,
|
|
||||||
pass::Pass,
|
pass::Pass,
|
||||||
util::{
|
util::{
|
||||||
alias_ident_for, constructor::inject_after_super, prop_name_to_expr_value, undefined,
|
alias_ident_for, constructor::inject_after_super, prop_name_to_expr_value, undefined,
|
||||||
@ -7,7 +6,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use std::{iter, sync::Arc};
|
use std::iter;
|
||||||
use swc_common::{util::move_map::MoveMap, Fold, FoldWith, Spanned, Visit, VisitWith, DUMMY_SP};
|
use swc_common::{util::move_map::MoveMap, Fold, FoldWith, Spanned, Visit, VisitWith, DUMMY_SP};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -53,16 +52,14 @@ mod tests;
|
|||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn decorators(helpers: Arc<Helpers>) -> impl Pass + Clone {
|
pub fn decorators() -> impl Pass + Clone {
|
||||||
Decorators {
|
Decorators {
|
||||||
helpers,
|
|
||||||
is_in_strict: false,
|
is_in_strict: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Decorators {
|
struct Decorators {
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
is_in_strict: bool,
|
is_in_strict: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +462,7 @@ impl Decorators {
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
self.helpers.decorate();
|
helper!(decorate);
|
||||||
let decorate_call = Expr::Call(make_decorate_call(
|
let decorate_call = Expr::Call(make_decorate_call(
|
||||||
class.decorators,
|
class.decorators,
|
||||||
iter::once({
|
iter::once({
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{helpers::Helpers, proposals::class_properties};
|
use crate::proposals::class_properties;
|
||||||
use std::sync::Arc;
|
|
||||||
use swc_ecma_parser::{EsConfig, Syntax};
|
use swc_ecma_parser::{EsConfig, Syntax};
|
||||||
|
|
||||||
fn syntax(decorators_before_export: bool) -> Syntax {
|
fn syntax(decorators_before_export: bool) -> Syntax {
|
||||||
@ -12,25 +11,19 @@ fn syntax(decorators_before_export: bool) -> Syntax {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tr(helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn tr() -> impl Fold<Module> {
|
||||||
chain!(
|
chain!(decorators(), class_properties(),)
|
||||||
decorators(helpers.clone()),
|
|
||||||
class_properties(helpers.clone()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Folder for `transformation_*` tests
|
/// Folder for `transformation_*` tests
|
||||||
fn transformation(helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn transformation() -> impl Fold<Module> {
|
||||||
chain!(
|
chain!(decorators(), class_properties(),)
|
||||||
decorators(helpers.clone()),
|
|
||||||
class_properties(helpers.clone()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// transformation_declaration
|
// transformation_declaration
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_declaration,
|
transformation_declaration,
|
||||||
r#"
|
r#"
|
||||||
@dec()
|
@dec()
|
||||||
@ -58,7 +51,7 @@ let A = _decorate([dec()], function (_initialize) {
|
|||||||
// transformation_initialize_after_super_multiple
|
// transformation_initialize_after_super_multiple
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_initialize_after_super_multiple,
|
transformation_initialize_after_super_multiple,
|
||||||
r#"
|
r#"
|
||||||
@dec
|
@dec
|
||||||
@ -121,7 +114,7 @@ let B = _decorate([dec], function (_initialize, _A) {
|
|||||||
// transformation_export_default_anonymous
|
// transformation_export_default_anonymous
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_export_default_anonymous,
|
transformation_export_default_anonymous,
|
||||||
r#"
|
r#"
|
||||||
export default @dec() class {}
|
export default @dec() class {}
|
||||||
@ -147,7 +140,7 @@ export default _decorate([dec()], function (_initialize) {
|
|||||||
// transformation_initialize_after_super_statement
|
// transformation_initialize_after_super_statement
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_initialize_after_super_statement,
|
transformation_initialize_after_super_statement,
|
||||||
r#"
|
r#"
|
||||||
@dec
|
@dec
|
||||||
@ -182,7 +175,7 @@ let B = _decorate([dec], function (_initialize, _A) {
|
|||||||
// element_descriptors_created_own_method_exec
|
// element_descriptors_created_own_method_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_created_own_method_exec,
|
element_descriptors_created_own_method_exec,
|
||||||
r#"
|
r#"
|
||||||
function pushElement(e) {
|
function pushElement(e) {
|
||||||
@ -219,7 +212,7 @@ expect(Object.getOwnPropertyDescriptor(new A(), "foo")).toEqual({
|
|||||||
// finishers_return_class_exec
|
// finishers_return_class_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
finishers_return_class_exec,
|
finishers_return_class_exec,
|
||||||
r#"
|
r#"
|
||||||
class C {}
|
class C {}
|
||||||
@ -244,7 +237,7 @@ expect(A).toBe(C);
|
|||||||
// misc_method_name_not_shadow
|
// misc_method_name_not_shadow
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
misc_method_name_not_shadow,
|
misc_method_name_not_shadow,
|
||||||
r#"
|
r#"
|
||||||
var method = 1;
|
var method = 1;
|
||||||
@ -286,7 +279,7 @@ let Foo = _decorate([decorator], function (_initialize) {
|
|||||||
// element_descriptors_original_class_exec
|
// element_descriptors_original_class_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_original_class_exec,
|
element_descriptors_original_class_exec,
|
||||||
r#"
|
r#"
|
||||||
var el = null;
|
var el = null;
|
||||||
@ -314,7 +307,7 @@ expect(el.elements).toHaveLength(3);
|
|||||||
// duplicated_keys_create_existing_element_with_extras_exec
|
// duplicated_keys_create_existing_element_with_extras_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_create_existing_element_with_extras_exec,
|
duplicated_keys_create_existing_element_with_extras_exec,
|
||||||
r#"
|
r#"
|
||||||
function decorate(el) {
|
function decorate(el) {
|
||||||
@ -348,7 +341,7 @@ expect(() => {
|
|||||||
// finishers_no_in_extras_exec
|
// finishers_no_in_extras_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
finishers_no_in_extras_exec,
|
finishers_no_in_extras_exec,
|
||||||
r#"
|
r#"
|
||||||
class C {}
|
class C {}
|
||||||
@ -378,7 +371,7 @@ expect(() => {
|
|||||||
// duplicated_keys_computed_keys_same_value
|
// duplicated_keys_computed_keys_same_value
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_computed_keys_same_value,
|
duplicated_keys_computed_keys_same_value,
|
||||||
r#"
|
r#"
|
||||||
@(_ => desc = _)
|
@(_ => desc = _)
|
||||||
@ -427,7 +420,7 @@ let Foo = _decorate([_ => desc = _], function (_initialize) {
|
|||||||
// transformation_only_decorated
|
// transformation_only_decorated
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_only_decorated,
|
transformation_only_decorated,
|
||||||
r#"
|
r#"
|
||||||
class B {
|
class B {
|
||||||
@ -450,7 +443,7 @@ class B {
|
|||||||
// ordering_finishers_exec
|
// ordering_finishers_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
ordering_finishers_exec,
|
ordering_finishers_exec,
|
||||||
r#"
|
r#"
|
||||||
var log = [];
|
var log = [];
|
||||||
@ -493,7 +486,7 @@ expect(log).toEqual(numsFrom0to9);
|
|||||||
// transformation_initiailzer_after_super_bug_8808
|
// transformation_initiailzer_after_super_bug_8808
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_initiailzer_after_super_bug_8808,
|
transformation_initiailzer_after_super_bug_8808,
|
||||||
r#"
|
r#"
|
||||||
@decorator(parameter)
|
@decorator(parameter)
|
||||||
@ -527,7 +520,7 @@ let Sub = _decorate([decorator(parameter)], function (_initialize, _Super) {
|
|||||||
// duplicated_keys_original_method_overwritten_no_decorators_exec
|
// duplicated_keys_original_method_overwritten_no_decorators_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_original_method_overwritten_no_decorators_exec,
|
duplicated_keys_original_method_overwritten_no_decorators_exec,
|
||||||
r#"
|
r#"
|
||||||
var el;
|
var el;
|
||||||
@ -552,7 +545,7 @@ expect(A.prototype.method()).toBe(2);
|
|||||||
// transformation_arguments
|
// transformation_arguments
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_arguments,
|
transformation_arguments,
|
||||||
r#"
|
r#"
|
||||||
@dec(a, b, ...c)
|
@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
|
// duplicated_keys_original_method_overwritten_both_decorated_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_original_method_overwritten_both_decorated_exec,
|
duplicated_keys_original_method_overwritten_both_decorated_exec,
|
||||||
r#"
|
r#"
|
||||||
expect(() => {
|
expect(() => {
|
||||||
@ -611,7 +604,7 @@ test_exec!(
|
|||||||
// Babel 7.3.0 fails
|
// Babel 7.3.0 fails
|
||||||
ignore,
|
ignore,
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
ordering_field_initializers_after_methods_exec,
|
ordering_field_initializers_after_methods_exec,
|
||||||
r#"
|
r#"
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
@ -647,7 +640,7 @@ expect(counter).toBe(2);
|
|||||||
// misc_to_primitive_exec
|
// misc_to_primitive_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
misc_to_primitive_exec,
|
misc_to_primitive_exec,
|
||||||
r#"
|
r#"
|
||||||
let calls = 0;
|
let calls = 0;
|
||||||
@ -673,7 +666,7 @@ expect(calls).toBe(1);
|
|||||||
// transformation_initialize_after_super_expression
|
// transformation_initialize_after_super_expression
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_initialize_after_super_expression,
|
transformation_initialize_after_super_expression,
|
||||||
r#"
|
r#"
|
||||||
@dec
|
@dec
|
||||||
@ -708,7 +701,7 @@ let B = _decorate([dec], function (_initialize, _A) {
|
|||||||
// element_descriptors_not_reused_field_exec
|
// element_descriptors_not_reused_field_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_not_reused_field_exec,
|
element_descriptors_not_reused_field_exec,
|
||||||
r#"
|
r#"
|
||||||
var dec1, dec2;
|
var dec1, dec2;
|
||||||
@ -730,7 +723,7 @@ expect(dec1.initializer).toBe(dec2.initializer);
|
|||||||
// transformation_export_default_named
|
// transformation_export_default_named
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_export_default_named,
|
transformation_export_default_named,
|
||||||
r#"
|
r#"
|
||||||
export default @dec() class Foo {}
|
export default @dec() class Foo {}
|
||||||
@ -757,7 +750,7 @@ export { Foo as default };
|
|||||||
// element_descriptors_original_own_field_exec
|
// element_descriptors_original_own_field_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_original_own_field_exec,
|
element_descriptors_original_own_field_exec,
|
||||||
r#"
|
r#"
|
||||||
var el = null;
|
var el = null;
|
||||||
@ -788,7 +781,7 @@ expect(el.initializer()).toBe(val);
|
|||||||
// ordering_decorators_exec
|
// ordering_decorators_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
ordering_decorators_exec,
|
ordering_decorators_exec,
|
||||||
r#"
|
r#"
|
||||||
var log = [];
|
var log = [];
|
||||||
@ -829,7 +822,7 @@ expect(log).toEqual(numsFrom0to23);
|
|||||||
// element_descriptors_default_exec
|
// element_descriptors_default_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_default_exec,
|
element_descriptors_default_exec,
|
||||||
r#"
|
r#"
|
||||||
function decorate(el) {
|
function decorate(el) {
|
||||||
@ -852,7 +845,7 @@ expect(Foo.prototype.bar).toBe(2);
|
|||||||
// element_descriptors_original_prototype_method_exec
|
// element_descriptors_original_prototype_method_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_original_prototype_method_exec,
|
element_descriptors_original_prototype_method_exec,
|
||||||
r#"
|
r#"
|
||||||
var el = null;
|
var el = null;
|
||||||
@ -879,7 +872,7 @@ expect(el).toEqual(Object.defineProperty({
|
|||||||
// misc_method_name_exec
|
// misc_method_name_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
misc_method_name_exec,
|
misc_method_name_exec,
|
||||||
r#"
|
r#"
|
||||||
function decorator() {}
|
function decorator() {}
|
||||||
@ -897,7 +890,7 @@ expect(Foo.prototype.method.name).toBe("method");
|
|||||||
test!(
|
test!(
|
||||||
ignore,
|
ignore,
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_strict_directive,
|
transformation_strict_directive,
|
||||||
r#"
|
r#"
|
||||||
(() => {
|
(() => {
|
||||||
@ -967,7 +960,7 @@ test!(
|
|||||||
// element_descriptors_created_static_method_exec
|
// element_descriptors_created_static_method_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_created_static_method_exec,
|
element_descriptors_created_static_method_exec,
|
||||||
r#"
|
r#"
|
||||||
function pushElement(e) {
|
function pushElement(e) {
|
||||||
@ -1004,7 +997,7 @@ expect(Object.getOwnPropertyDescriptor(A, "foo")).toEqual({
|
|||||||
// misc_method_name_not_shadow_exec
|
// misc_method_name_not_shadow_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
misc_method_name_not_shadow_exec,
|
misc_method_name_not_shadow_exec,
|
||||||
r#"
|
r#"
|
||||||
function decorator() {}
|
function decorator() {}
|
||||||
@ -1027,7 +1020,7 @@ expect(Foo.prototype.method.name).toBe("method");
|
|||||||
// duplicated_keys_original_method_overwritten_second_decorated_exec
|
// duplicated_keys_original_method_overwritten_second_decorated_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_original_method_overwritten_second_decorated_exec,
|
duplicated_keys_original_method_overwritten_second_decorated_exec,
|
||||||
r#"
|
r#"
|
||||||
expect(() => {
|
expect(() => {
|
||||||
@ -1048,7 +1041,7 @@ expect(() => {
|
|||||||
// duplicated_keys_get_set_both_decorated_exec
|
// duplicated_keys_get_set_both_decorated_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_get_set_both_decorated_exec,
|
duplicated_keys_get_set_both_decorated_exec,
|
||||||
r#"
|
r#"
|
||||||
function dec(el) { return el }
|
function dec(el) { return el }
|
||||||
@ -1068,7 +1061,7 @@ expect(() => {
|
|||||||
// duplicated_keys_original_method_overwritten_first_decorated_exec
|
// duplicated_keys_original_method_overwritten_first_decorated_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_original_method_overwritten_first_decorated_exec,
|
duplicated_keys_original_method_overwritten_first_decorated_exec,
|
||||||
r#"
|
r#"
|
||||||
expect(() => {
|
expect(() => {
|
||||||
@ -1089,7 +1082,7 @@ expect(() => {
|
|||||||
// element_descriptors_created_prototype_field_exec
|
// element_descriptors_created_prototype_field_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_created_prototype_field_exec,
|
element_descriptors_created_prototype_field_exec,
|
||||||
r#"
|
r#"
|
||||||
function pushElement(e) {
|
function pushElement(e) {
|
||||||
@ -1127,7 +1120,7 @@ expect(Object.getOwnPropertyDescriptor(A.prototype, "foo")).toEqual({
|
|||||||
// transformation_extends
|
// transformation_extends
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_extends,
|
transformation_extends,
|
||||||
r#"
|
r#"
|
||||||
@dec class A extends B {}
|
@dec class A extends B {}
|
||||||
@ -1158,7 +1151,7 @@ let A = _decorate([dec], function (_initialize, _B) {
|
|||||||
// transformation_extends_await
|
// transformation_extends_await
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_extends_await,
|
transformation_extends_await,
|
||||||
r#"
|
r#"
|
||||||
async function g() {
|
async function g() {
|
||||||
@ -1192,7 +1185,7 @@ async function g() {
|
|||||||
// transformation_extends_yield
|
// transformation_extends_yield
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_extends_yield,
|
transformation_extends_yield,
|
||||||
r#"
|
r#"
|
||||||
function* g() {
|
function* g() {
|
||||||
@ -1226,7 +1219,7 @@ function* g() {
|
|||||||
// element_descriptors_created_static_field_exec
|
// element_descriptors_created_static_field_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_created_static_field_exec,
|
element_descriptors_created_static_field_exec,
|
||||||
r#"
|
r#"
|
||||||
function pushElement(e) {
|
function pushElement(e) {
|
||||||
@ -1265,7 +1258,7 @@ expect(Object.getOwnPropertyDescriptor(A, "foo")).toEqual({
|
|||||||
// element_descriptors_created_own_field_exec
|
// element_descriptors_created_own_field_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_created_own_field_exec,
|
element_descriptors_created_own_field_exec,
|
||||||
r#"
|
r#"
|
||||||
function pushElement(e) {
|
function pushElement(e) {
|
||||||
@ -1304,7 +1297,7 @@ expect(Object.getOwnPropertyDescriptor(new A(), "foo")).toEqual({
|
|||||||
// element_descriptors_not_reused_method_exec
|
// element_descriptors_not_reused_method_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_not_reused_method_exec,
|
element_descriptors_not_reused_method_exec,
|
||||||
r#"
|
r#"
|
||||||
var dec1, dec2;
|
var dec1, dec2;
|
||||||
@ -1326,7 +1319,7 @@ expect(dec1.descriptor.value).toBe(dec2.descriptor.value);
|
|||||||
// element_descriptors_not_reused_class_exec
|
// element_descriptors_not_reused_class_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_not_reused_class_exec,
|
element_descriptors_not_reused_class_exec,
|
||||||
r#"
|
r#"
|
||||||
var dec1, dec2;
|
var dec1, dec2;
|
||||||
@ -1343,7 +1336,7 @@ expect(dec1).not.toBe(dec2);
|
|||||||
// duplicated_keys_computed_keys_same_ast_exec
|
// duplicated_keys_computed_keys_same_ast_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_computed_keys_same_ast_exec,
|
duplicated_keys_computed_keys_same_ast_exec,
|
||||||
r#"
|
r#"
|
||||||
var i = 0;
|
var i = 0;
|
||||||
@ -1380,7 +1373,7 @@ expect(i).toBe(2);
|
|||||||
// transformation_initialize_after_super_bug_8931
|
// transformation_initialize_after_super_bug_8931
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_initialize_after_super_bug_8931,
|
transformation_initialize_after_super_bug_8931,
|
||||||
r#"
|
r#"
|
||||||
@dec
|
@dec
|
||||||
@ -1421,7 +1414,7 @@ test_exec!(
|
|||||||
// Babel 7.3.0 fails
|
// Babel 7.3.0 fails
|
||||||
ignore,
|
ignore,
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
ordering_static_field_initializers_after_methods_exec,
|
ordering_static_field_initializers_after_methods_exec,
|
||||||
r#"
|
r#"
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
@ -1453,7 +1446,7 @@ expect(counter).toBe(2);
|
|||||||
// element_descriptors_original_static_method_exec
|
// element_descriptors_original_static_method_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_original_static_method_exec,
|
element_descriptors_original_static_method_exec,
|
||||||
r#"
|
r#"
|
||||||
var el = null;
|
var el = null;
|
||||||
@ -1480,7 +1473,7 @@ expect(el).toEqual(Object.defineProperty({
|
|||||||
// duplicated_keys_extras_duplicated_exec
|
// duplicated_keys_extras_duplicated_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_extras_duplicated_exec,
|
duplicated_keys_extras_duplicated_exec,
|
||||||
r#"
|
r#"
|
||||||
function decorate(el) {
|
function decorate(el) {
|
||||||
@ -1521,7 +1514,7 @@ expect(() => {
|
|||||||
// duplicated_keys_extras_same_as_return_exec
|
// duplicated_keys_extras_same_as_return_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_extras_same_as_return_exec,
|
duplicated_keys_extras_same_as_return_exec,
|
||||||
r#"
|
r#"
|
||||||
function decorate(el) {
|
function decorate(el) {
|
||||||
@ -1561,7 +1554,7 @@ expect(() => {
|
|||||||
// finishers_class_as_parameter_exec
|
// finishers_class_as_parameter_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
finishers_class_as_parameter_exec,
|
finishers_class_as_parameter_exec,
|
||||||
r#"
|
r#"
|
||||||
var C;
|
var C;
|
||||||
@ -1586,7 +1579,7 @@ expect(C).toBe(A);
|
|||||||
// duplicated_keys_moved_and_created_exec
|
// duplicated_keys_moved_and_created_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_moved_and_created_exec,
|
duplicated_keys_moved_and_created_exec,
|
||||||
r#"
|
r#"
|
||||||
var value1, value2 = {};
|
var value1, value2 = {};
|
||||||
@ -1628,7 +1621,7 @@ expect(Foo.prototype.bar).toBe(value2);
|
|||||||
// transformation_expression
|
// transformation_expression
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| transformation(helpers),
|
|_| transformation(),
|
||||||
transformation_expression,
|
transformation_expression,
|
||||||
r#"
|
r#"
|
||||||
(@dec() class {});
|
(@dec() class {});
|
||||||
@ -1655,7 +1648,7 @@ _decorate([dec()], function (_initialize) {
|
|||||||
// duplicated_keys_original_method_prototype_and_static_exec
|
// duplicated_keys_original_method_prototype_and_static_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_original_method_prototype_and_static_exec,
|
duplicated_keys_original_method_prototype_and_static_exec,
|
||||||
r#"
|
r#"
|
||||||
var el;
|
var el;
|
||||||
@ -1682,7 +1675,7 @@ expect(A.method()).toBe(2);
|
|||||||
// duplicated_keys_computed_keys_same_ast
|
// duplicated_keys_computed_keys_same_ast
|
||||||
test!(
|
test!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_computed_keys_same_ast,
|
duplicated_keys_computed_keys_same_ast,
|
||||||
r#"
|
r#"
|
||||||
@(_ => desc = _)
|
@(_ => desc = _)
|
||||||
@ -1731,7 +1724,7 @@ let Foo = _decorate([_ => desc = _], function (_initialize) {
|
|||||||
// element_descriptors_created_prototype_method_exec
|
// element_descriptors_created_prototype_method_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_created_prototype_method_exec,
|
element_descriptors_created_prototype_method_exec,
|
||||||
r#"
|
r#"
|
||||||
function pushElement(e) {
|
function pushElement(e) {
|
||||||
@ -1767,7 +1760,7 @@ expect(Object.getOwnPropertyDescriptor(A.prototype, "foo")).toEqual({
|
|||||||
// duplicated_keys_create_existing_element_from_method_decorator_exec
|
// duplicated_keys_create_existing_element_from_method_decorator_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_create_existing_element_from_method_decorator_exec,
|
duplicated_keys_create_existing_element_from_method_decorator_exec,
|
||||||
r#"
|
r#"
|
||||||
function decorate() {
|
function decorate() {
|
||||||
@ -1799,7 +1792,7 @@ expect(() => {
|
|||||||
// element_descriptors_original_static_field_exec
|
// element_descriptors_original_static_field_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_original_static_field_exec,
|
element_descriptors_original_static_field_exec,
|
||||||
r#"
|
r#"
|
||||||
var el = null;
|
var el = null;
|
||||||
@ -1829,7 +1822,7 @@ expect(el.initializer()).toBe(val);
|
|||||||
// duplicated_keys_coalesce_get_set_exec
|
// duplicated_keys_coalesce_get_set_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_coalesce_get_set_exec,
|
duplicated_keys_coalesce_get_set_exec,
|
||||||
r#"
|
r#"
|
||||||
var el, el1;
|
var el, el1;
|
||||||
@ -1861,7 +1854,7 @@ expect(desc.set()).toBe(2);
|
|||||||
// transformation_extends_exec
|
// transformation_extends_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
transformation_extends_exec,
|
transformation_extends_exec,
|
||||||
r#"
|
r#"
|
||||||
class B {}
|
class B {}
|
||||||
@ -1877,7 +1870,7 @@ expect(new A).toBeInstanceOf(B);
|
|||||||
// duplicated_keys_create_existing_element_from_class_decorator_exec
|
// duplicated_keys_create_existing_element_from_class_decorator_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_create_existing_element_from_class_decorator_exec,
|
duplicated_keys_create_existing_element_from_class_decorator_exec,
|
||||||
r#"
|
r#"
|
||||||
function pushElement(e) {
|
function pushElement(e) {
|
||||||
@ -1907,7 +1900,7 @@ expect(() => {
|
|||||||
// duplicated_keys_computed_keys_same_value_exec
|
// duplicated_keys_computed_keys_same_value_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
duplicated_keys_computed_keys_same_value_exec,
|
duplicated_keys_computed_keys_same_value_exec,
|
||||||
r#"
|
r#"
|
||||||
var i = 0;
|
var i = 0;
|
||||||
@ -1946,7 +1939,7 @@ expect(j).toBe(1);
|
|||||||
// element_descriptors_original_own_field_without_initiailzer_exec
|
// element_descriptors_original_own_field_without_initiailzer_exec
|
||||||
test_exec!(
|
test_exec!(
|
||||||
syntax(false),
|
syntax(false),
|
||||||
|_, helpers| tr(helpers),
|
|_| tr(),
|
||||||
element_descriptors_original_own_field_without_initiailzer_exec,
|
element_descriptors_original_own_field_without_initiailzer_exec,
|
||||||
r#"
|
r#"
|
||||||
var el = null;
|
var el = null;
|
||||||
|
@ -6,7 +6,7 @@ fn tr() -> impl Fold<Module> {
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
assignment_expression,
|
assignment_expression,
|
||||||
r#"
|
r#"
|
||||||
foo = createReactClass({});
|
foo = createReactClass({});
|
||||||
@ -24,7 +24,7 @@ bar = React.createClass({
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
nested,
|
nested,
|
||||||
r#"
|
r#"
|
||||||
var foo = qux(createReactClass({}));
|
var foo = qux(createReactClass({}));
|
||||||
@ -42,7 +42,7 @@ var bar = qux(React.createClass({
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
object_property,
|
object_property,
|
||||||
r#"
|
r#"
|
||||||
({
|
({
|
||||||
@ -67,7 +67,7 @@ test!(
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
variable_declarator,
|
variable_declarator,
|
||||||
r#"
|
r#"
|
||||||
var foo = createReactClass({});
|
var foo = createReactClass({});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{helpers::Helpers, pass::Pass, util::ExprFactory};
|
use crate::{pass::Pass, util::ExprFactory};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{iter, mem, sync::Arc};
|
use std::{iter, mem};
|
||||||
use swc_atoms::JsWord;
|
use swc_atoms::JsWord;
|
||||||
use swc_common::{
|
use swc_common::{
|
||||||
errors::{ColorConfig, Handler},
|
errors::{ColorConfig, Handler},
|
||||||
@ -58,7 +58,7 @@ fn default_throw_if_namespace() -> bool {
|
|||||||
/// `@babel/plugin-transform-react-jsx`
|
/// `@babel/plugin-transform-react-jsx`
|
||||||
///
|
///
|
||||||
/// Turn JSX into React function calls
|
/// Turn JSX into React function calls
|
||||||
pub fn jsx(cm: Lrc<SourceMap>, options: Options, helpers: Arc<Helpers>) -> impl Pass + Clone {
|
pub fn jsx(cm: Lrc<SourceMap>, options: Options) -> impl Pass + Clone {
|
||||||
let handler = Handler::with_tty_emitter(ColorConfig::Always, false, true, Some(cm.clone()));
|
let handler = Handler::with_tty_emitter(ColorConfig::Always, false, true, Some(cm.clone()));
|
||||||
|
|
||||||
let session = Session { handler: &handler };
|
let session = Session { handler: &handler };
|
||||||
@ -81,7 +81,6 @@ pub fn jsx(cm: Lrc<SourceMap>, options: Options, helpers: Arc<Helpers>) -> impl
|
|||||||
expr: parse("pragma_frag", options.pragma_frag),
|
expr: parse("pragma_frag", options.pragma_frag),
|
||||||
},
|
},
|
||||||
use_builtins: options.use_builtins,
|
use_builtins: options.use_builtins,
|
||||||
helpers,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +89,6 @@ struct Jsx {
|
|||||||
pragma: ExprOrSuper,
|
pragma: ExprOrSuper,
|
||||||
pragma_frag: ExprOrSpread,
|
pragma_frag: ExprOrSpread,
|
||||||
use_builtins: bool,
|
use_builtins: bool,
|
||||||
helpers: Arc<Helpers>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Jsx {
|
impl Jsx {
|
||||||
@ -212,7 +210,7 @@ impl Jsx {
|
|||||||
if self.use_builtins {
|
if self.use_builtins {
|
||||||
member_expr!(DUMMY_SP, Object.assign).as_callee()
|
member_expr!(DUMMY_SP, Object.assign).as_callee()
|
||||||
} else {
|
} else {
|
||||||
self.helpers.extends();
|
helper!(extends);
|
||||||
quote_ident!("_extends").as_callee()
|
quote_ident!("_extends").as_callee()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -4,20 +4,11 @@ use crate::{
|
|||||||
es2015::{arrow, Classes},
|
es2015::{arrow, Classes},
|
||||||
es3::PropertyLiteral,
|
es3::PropertyLiteral,
|
||||||
},
|
},
|
||||||
helpers::Helpers,
|
|
||||||
react::display_name,
|
react::display_name,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
fn tr(cm: Lrc<SourceMap>, options: Options, helpers: Arc<Helpers>) -> impl Fold<Module> {
|
fn tr(cm: Lrc<SourceMap>, options: Options) -> impl Fold<Module> {
|
||||||
chain!(
|
chain!(jsx(cm.clone(), options), display_name(), Classes, arrow(),)
|
||||||
jsx(cm.clone(), options, helpers.clone()),
|
|
||||||
display_name(),
|
|
||||||
Classes {
|
|
||||||
helpers: helpers.clone()
|
|
||||||
},
|
|
||||||
arrow(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test!(
|
test!(
|
||||||
@ -25,7 +16,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_add_appropriate_newlines,
|
react_add_appropriate_newlines,
|
||||||
r#"
|
r#"
|
||||||
<Component
|
<Component
|
||||||
@ -44,7 +35,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_arrow_functions,
|
react_arrow_functions,
|
||||||
r#"
|
r#"
|
||||||
var foo = function () {
|
var foo = function () {
|
||||||
@ -74,7 +65,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_concatenates_adjacent_string_literals,
|
react_concatenates_adjacent_string_literals,
|
||||||
r#"
|
r#"
|
||||||
var x =
|
var x =
|
||||||
@ -102,7 +93,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_display_name_assignment_expression,
|
react_display_name_assignment_expression,
|
||||||
r#"var Component;
|
r#"var Component;
|
||||||
Component = React.createClass({
|
Component = React.createClass({
|
||||||
@ -125,7 +116,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_display_name_export_default,
|
react_display_name_export_default,
|
||||||
r#"
|
r#"
|
||||||
export default React.createClass({
|
export default React.createClass({
|
||||||
@ -149,7 +140,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_display_name_if_missing,
|
react_display_name_if_missing,
|
||||||
r#"
|
r#"
|
||||||
var Whateva = React.createClass({
|
var Whateva = React.createClass({
|
||||||
@ -187,7 +178,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_display_name_object_declaration,
|
react_display_name_object_declaration,
|
||||||
r#"
|
r#"
|
||||||
exports = {
|
exports = {
|
||||||
@ -213,7 +204,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_display_name_property_assignment,
|
react_display_name_property_assignment,
|
||||||
r#"
|
r#"
|
||||||
exports.Component = React.createClass({
|
exports.Component = React.createClass({
|
||||||
@ -237,7 +228,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_display_name_variable_declaration,
|
react_display_name_variable_declaration,
|
||||||
r#"
|
r#"
|
||||||
var Component = React.createClass({
|
var Component = React.createClass({
|
||||||
@ -258,7 +249,7 @@ var Component = React.createClass({
|
|||||||
|
|
||||||
test!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::Es(::swc_ecma_parser::EsConfig{jsx:true,..Default::default()}),
|
::swc_ecma_parser::Syntax::Es(::swc_ecma_parser::EsConfig{jsx:true,..Default::default()}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_dont_coerce_expression_containers,
|
react_dont_coerce_expression_containers,
|
||||||
r#"
|
r#"
|
||||||
<Text>
|
<Text>
|
||||||
@ -275,7 +266,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_honor_custom_jsx_comment_if_jsx_pragma_option_set,
|
||||||
r#"/** @jsx dom */
|
r#"/** @jsx dom */
|
||||||
|
|
||||||
@ -300,7 +291,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_honor_custom_jsx_comment,
|
react_honor_custom_jsx_comment,
|
||||||
r#"
|
r#"
|
||||||
/** @jsx dom */
|
/** @jsx dom */
|
||||||
@ -327,13 +318,12 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester.cm.clone(),
|
tester.cm.clone(),
|
||||||
Options {
|
Options {
|
||||||
pragma: "dom".into(),
|
pragma: "dom".into(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
}
|
||||||
helpers
|
|
||||||
),
|
),
|
||||||
react_honor_custom_jsx_pragma_option,
|
react_honor_custom_jsx_pragma_option,
|
||||||
r#"
|
r#"
|
||||||
@ -357,7 +347,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_jsx_with_retainlines_option,
|
react_jsx_with_retainlines_option,
|
||||||
r#"var div = <div>test</div>;"#,
|
r#"var div = <div>test</div>;"#,
|
||||||
r#"var div = React.createElement("div", null, "test");"#
|
r#"var div = React.createElement("div", null, "test");"#
|
||||||
@ -368,7 +358,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_jsx_without_retainlines_option,
|
react_jsx_without_retainlines_option,
|
||||||
r#"var div = <div>test</div>;"#,
|
r#"var div = <div>test</div>;"#,
|
||||||
r#"var div = React.createElement("div", null, "test");"#
|
r#"var div = React.createElement("div", null, "test");"#
|
||||||
@ -381,7 +371,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_optimisation_react_constant_elements,
|
react_optimisation_react_constant_elements,
|
||||||
r#"
|
r#"
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
@ -445,10 +435,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| chain!(
|
|tester| chain!(tr(tester.cm.clone(), Default::default()), PropertyLiteral),
|
||||||
tr(tester.cm.clone(), Default::default(), helpers),
|
|
||||||
PropertyLiteral
|
|
||||||
),
|
|
||||||
react_should_add_quotes_es3,
|
react_should_add_quotes_es3,
|
||||||
r#"var es3 = <F aaa new const var default foo-bar/>;"#,
|
r#"var es3 = <F aaa new const var default foo-bar/>;"#,
|
||||||
r#"
|
r#"
|
||||||
@ -468,7 +455,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_allow_constructor_as_prop,
|
react_should_allow_constructor_as_prop,
|
||||||
r#"<Component constructor="foo" />;"#,
|
r#"<Component constructor="foo" />;"#,
|
||||||
r#"
|
r#"
|
||||||
@ -483,7 +470,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_allow_deeper_js_namespacing,
|
react_should_allow_deeper_js_namespacing,
|
||||||
r#"<Namespace.DeepNamespace.Component />;"#,
|
r#"<Namespace.DeepNamespace.Component />;"#,
|
||||||
r#"React.createElement(Namespace.DeepNamespace.Component, null);"#
|
r#"React.createElement(Namespace.DeepNamespace.Component, null);"#
|
||||||
@ -494,7 +481,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_allow_elements_as_attributes,
|
react_should_allow_elements_as_attributes,
|
||||||
r#"<div attr=<div /> />"#,
|
r#"<div attr=<div /> />"#,
|
||||||
r#"
|
r#"
|
||||||
@ -508,7 +495,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_allow_js_namespacing,
|
react_should_allow_js_namespacing,
|
||||||
r#"<Namespace.Component />;"#,
|
r#"<Namespace.Component />;"#,
|
||||||
r#"React.createElement(Namespace.Component, null);"#
|
r#"React.createElement(Namespace.Component, null);"#
|
||||||
@ -519,7 +506,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_allow_nested_fragments,
|
react_should_allow_nested_fragments,
|
||||||
r#"
|
r#"
|
||||||
<div>
|
<div>
|
||||||
@ -555,7 +542,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_should_allow_no_pragmafrag_if_frag_unused,
|
||||||
r#"
|
r#"
|
||||||
/** @jsx dom */
|
/** @jsx dom */
|
||||||
@ -574,7 +561,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_allow_pragmafrag_and_frag,
|
react_should_allow_pragmafrag_and_frag,
|
||||||
r#"
|
r#"
|
||||||
/** @jsx dom */
|
/** @jsx dom */
|
||||||
@ -595,7 +582,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_should_avoid_wrapping_in_extra_parens_if_not_needed,
|
||||||
r#"
|
r#"
|
||||||
var x = <div>
|
var x = <div>
|
||||||
@ -627,7 +614,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_convert_simple_tags,
|
react_should_convert_simple_tags,
|
||||||
r#"var x = <div></div>;"#,
|
r#"var x = <div></div>;"#,
|
||||||
r#"var x = React.createElement("div", null);"#
|
r#"var x = React.createElement("div", null);"#
|
||||||
@ -638,7 +625,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_convert_simple_text,
|
react_should_convert_simple_text,
|
||||||
r#"var x = <div>text</div>;"#,
|
r#"var x = <div>text</div>;"#,
|
||||||
r#"var x = React.createElement("div", null, "text");"#
|
r#"var x = React.createElement("div", null, "text");"#
|
||||||
@ -649,7 +636,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_escape_xhtml_jsxattribute,
|
react_should_escape_xhtml_jsxattribute,
|
||||||
r#"
|
r#"
|
||||||
<div id="wôw" />;
|
<div id="wôw" />;
|
||||||
@ -675,7 +662,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_escape_xhtml_jsxtext_1,
|
react_should_escape_xhtml_jsxtext_1,
|
||||||
r#"
|
r#"
|
||||||
<div>wow</div>;
|
<div>wow</div>;
|
||||||
@ -706,7 +693,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_escape_xhtml_jsxtext_2,
|
react_should_escape_xhtml_jsxtext_2,
|
||||||
r#"
|
r#"
|
||||||
<div>this should not parse as unicode: \u00a0</div>;
|
<div>this should not parse as unicode: \u00a0</div>;
|
||||||
@ -724,7 +711,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_escape_xhtml_jsxtext_3,
|
react_should_escape_xhtml_jsxtext_3,
|
||||||
r#"
|
r#"
|
||||||
<div>this should parse as nbsp: </div>;
|
<div>this should parse as nbsp: </div>;
|
||||||
@ -739,7 +726,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_handle_attributed_elements,
|
react_should_handle_attributed_elements,
|
||||||
r#"
|
r#"
|
||||||
var HelloMessage = React.createClass({
|
var HelloMessage = React.createClass({
|
||||||
@ -772,7 +759,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_should_handle_has_own_property_correctly,
|
||||||
r#"<hasOwnProperty>testing</hasOwnProperty>;"#,
|
r#"<hasOwnProperty>testing</hasOwnProperty>;"#,
|
||||||
r#"React.createElement("hasOwnProperty", null, "testing");"#
|
r#"React.createElement("hasOwnProperty", null, "testing");"#
|
||||||
@ -783,7 +770,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_should_have_correct_comma_in_nested_children,
|
||||||
r#"
|
r#"
|
||||||
var x = <div>
|
var x = <div>
|
||||||
@ -807,7 +794,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_should_insert_commas_after_expressions_before_whitespace,
|
||||||
r#"
|
r#"
|
||||||
var x =
|
var x =
|
||||||
@ -842,7 +829,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_should_not_add_quotes_to_identifier_names,
|
||||||
r#"var e = <F aaa new const var default foo-bar/>;"#,
|
r#"var e = <F aaa new const var default foo-bar/>;"#,
|
||||||
r#"
|
r#"
|
||||||
@ -862,7 +849,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_should_not_mangle_expressioncontainer_attribute_values,
|
||||||
r#"<button data-value={"a value\n with\nnewlines\n and spaces"}>Button</button>;"#,
|
r#"<button data-value={"a value\n with\nnewlines\n and spaces"}>Button</button>;"#,
|
||||||
r#"
|
r#"
|
||||||
@ -877,7 +864,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_should_not_strip_nbsp_even_coupled_with_other_whitespace,
|
||||||
r#"<div> </div>;"#,
|
r#"<div> </div>;"#,
|
||||||
r#"React.createElement("div", null, "\xA0 ");"#,
|
r#"React.createElement("div", null, "\xA0 ");"#,
|
||||||
@ -889,7 +876,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_should_not_strip_tags_with_a_single_child_of_nbsp,
|
||||||
r#"<div> </div>;"#,
|
r#"<div> </div>;"#,
|
||||||
r#"React.createElement("div", null, "\xA0");"#,
|
r#"React.createElement("div", null, "\xA0");"#,
|
||||||
@ -903,7 +890,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_should_properly_handle_comments_between_props,
|
||||||
r#"
|
r#"
|
||||||
var x = (
|
var x = (
|
||||||
@ -934,7 +921,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_quote_jsx_attributes,
|
react_should_quote_jsx_attributes,
|
||||||
r#"<button data-value='a value'>Button</button>;"#,
|
r#"<button data-value='a value'>Button</button>;"#,
|
||||||
r#"
|
r#"
|
||||||
@ -949,14 +936,13 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester.cm.clone(),
|
tester.cm.clone(),
|
||||||
Options {
|
Options {
|
||||||
pragma: "h".into(),
|
pragma: "h".into(),
|
||||||
throw_if_namespace: false,
|
throw_if_namespace: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
helpers
|
|
||||||
),
|
),
|
||||||
react_should_support_xml_namespaces_if_flag,
|
react_should_support_xml_namespaces_if_flag,
|
||||||
r#"<f:image n:attr />;"#,
|
r#"<f:image n:attr />;"#,
|
||||||
@ -970,7 +956,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(tester.cm.clone(), Default::default(), helpers),
|
|tester| tr(tester.cm.clone(), Default::default()),
|
||||||
react_should_transform_known_hyphenated_tags,
|
react_should_transform_known_hyphenated_tags,
|
||||||
r#"<font-face />;"#,
|
r#"<font-face />;"#,
|
||||||
r#"React.createElement("font-face", null);"#
|
r#"React.createElement("font-face", null);"#
|
||||||
@ -981,7 +967,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_wraps_props_in_react_spread_for_first_spread_attributes,
|
||||||
r#"
|
r#"
|
||||||
<Component { ... x } y
|
<Component { ... x } y
|
||||||
@ -1000,7 +986,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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_last_spread_attributes,
|
react_wraps_props_in_react_spread_for_last_spread_attributes,
|
||||||
r#"<Component y={2} z { ... x } />"#,
|
r#"<Component y={2} z { ... x } />"#,
|
||||||
r#"
|
r#"
|
||||||
@ -1016,7 +1002,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..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,
|
react_wraps_props_in_react_spread_for_middle_spread_attributes,
|
||||||
r#"<Component y={2} { ... x } z />"#,
|
r#"<Component y={2} { ... x } z />"#,
|
||||||
r#"
|
r#"
|
||||||
@ -1032,13 +1018,12 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|tester, helpers| tr(
|
|tester| tr(
|
||||||
tester.cm.clone(),
|
tester.cm.clone(),
|
||||||
Options {
|
Options {
|
||||||
use_builtins: true,
|
use_builtins: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
helpers
|
|
||||||
),
|
),
|
||||||
use_builtins_assignment,
|
use_builtins_assignment,
|
||||||
r#"var div = <Component {...props} foo="bar" />"#,
|
r#"var div = <Component {...props} foo="bar" />"#,
|
||||||
|
@ -9,7 +9,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
basic_sample,
|
basic_sample,
|
||||||
r#"var x = <sometag />"#,
|
r#"var x = <sometag />"#,
|
||||||
r#"var x = <sometag __self={this} />;"#
|
r#"var x = <sometag __self={this} />;"#
|
||||||
|
@ -12,7 +12,7 @@ test_exec!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
basic_sample,
|
basic_sample,
|
||||||
r#"
|
r#"
|
||||||
var actual = transform(
|
var actual = transform(
|
||||||
@ -37,7 +37,7 @@ test!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
no_jsx,
|
no_jsx,
|
||||||
r#"var x = 42;"#,
|
r#"var x = 42;"#,
|
||||||
r#"var x = 42;"#
|
r#"var x = 42;"#
|
||||||
@ -49,7 +49,7 @@ test_exec!(
|
|||||||
jsx: true,
|
jsx: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|_, _| tr(),
|
|_| tr(),
|
||||||
with_source,
|
with_source,
|
||||||
r#"
|
r#"
|
||||||
var actual = transform(
|
var actual = transform(
|
||||||
|
@ -4,8 +4,7 @@ pub use self::{
|
|||||||
jsx_self::jsx_self,
|
jsx_self::jsx_self,
|
||||||
jsx_src::jsx_src,
|
jsx_src::jsx_src,
|
||||||
};
|
};
|
||||||
use crate::{helpers::Helpers, pass::Pass};
|
use crate::pass::Pass;
|
||||||
use std::sync::Arc;
|
|
||||||
use swc_common::{sync::Lrc, SourceMap};
|
use swc_common::{sync::Lrc, SourceMap};
|
||||||
|
|
||||||
mod display_name;
|
mod display_name;
|
||||||
@ -16,11 +15,11 @@ mod jsx_src;
|
|||||||
/// `@babel/preset-react`
|
/// `@babel/preset-react`
|
||||||
///
|
///
|
||||||
/// Preset for all React plugins.
|
/// Preset for all React plugins.
|
||||||
pub fn react(cm: Lrc<SourceMap>, options: Options, helpers: Arc<Helpers>) -> impl Pass + Clone {
|
pub fn react(cm: Lrc<SourceMap>, options: Options) -> impl Pass + Clone {
|
||||||
let Options { development, .. } = options;
|
let Options { development, .. } = options;
|
||||||
|
|
||||||
chain!(
|
chain!(
|
||||||
jsx(cm.clone(), options, helpers),
|
jsx(cm.clone(), options),
|
||||||
display_name(),
|
display_name(),
|
||||||
jsx_src(development, cm),
|
jsx_src(development, cm),
|
||||||
jsx_self(development)
|
jsx_self(development)
|
||||||
|
@ -3,7 +3,7 @@ use super::SimplifyExpr;
|
|||||||
fn test_expr(src: &str, expected: &str) {
|
fn test_expr(src: &str, expected: &str) {
|
||||||
test_transform!(
|
test_transform!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| SimplifyExpr,
|
|_| SimplifyExpr,
|
||||||
src,
|
src,
|
||||||
expected,
|
expected,
|
||||||
true
|
true
|
||||||
|
@ -5,7 +5,7 @@ macro_rules! test_stmt {
|
|||||||
($l:expr, $r:expr) => {
|
($l:expr, $r:expr) => {
|
||||||
test_transform!(
|
test_transform!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_, _| Simplifier { enable: true },
|
|_| Simplifier { enable: true },
|
||||||
$l,
|
$l,
|
||||||
$r
|
$r
|
||||||
)
|
)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::helpers::{Helpers, InjectHelpers};
|
use crate::helpers::{InjectHelpers, HELPERS};
|
||||||
use ast::*;
|
use ast::*;
|
||||||
use sourcemap::SourceMapBuilder;
|
use sourcemap::SourceMapBuilder;
|
||||||
use std::{
|
use std::{
|
||||||
@ -28,7 +28,9 @@ impl<'a> Tester<'a> {
|
|||||||
where
|
where
|
||||||
F: FnOnce(&mut Tester) -> Result<(), ()>,
|
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 {
|
match out {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
@ -150,12 +152,12 @@ impl<'a> Tester<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_tr<F, P>(op: F, tester: &mut Tester, helpers: Arc<Helpers>) -> P
|
fn make_tr<F, P>(op: F, tester: &mut Tester) -> P
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Tester, Arc<Helpers>) -> P,
|
F: FnOnce(&mut Tester) -> P,
|
||||||
P: Fold<Module>,
|
P: Fold<Module>,
|
||||||
{
|
{
|
||||||
op(tester, helpers)
|
op(tester)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -176,15 +178,15 @@ pub(crate) fn test_transform<F, P>(
|
|||||||
expected: &str,
|
expected: &str,
|
||||||
ok_if_code_eq: bool,
|
ok_if_code_eq: bool,
|
||||||
) where
|
) where
|
||||||
F: FnOnce(&mut Tester, Arc<Helpers>) -> P,
|
F: FnOnce(&mut Tester) -> P,
|
||||||
{
|
{
|
||||||
crate::tests::Tester::run(|tester| {
|
crate::tests::Tester::run(|tester| {
|
||||||
let expected =
|
let expected =
|
||||||
tester.apply_transform(::testing::DropSpan, "output.js", syntax, expected)?;
|
tester.apply_transform(::testing::DropSpan, "output.js", syntax, expected)?;
|
||||||
|
|
||||||
eprintln!("----- Actual -----");
|
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
|
let actual = tester
|
||||||
.apply_transform(tr, "input.js", syntax, input)?
|
.apply_transform(tr, "input.js", syntax, input)?
|
||||||
.fold_with(&mut crate::hygiene::hygiene())
|
.fold_with(&mut crate::hygiene::hygiene())
|
||||||
@ -258,11 +260,10 @@ macro_rules! exec_tr {
|
|||||||
|
|
||||||
pub(crate) fn exec_tr<F, P>(test_name: &str, syntax: Syntax, tr: F, input: &str)
|
pub(crate) fn exec_tr<F, P>(test_name: &str, syntax: Syntax, tr: F, input: &str)
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Tester, Arc<Helpers>) -> P,
|
F: FnOnce(&mut Tester) -> P,
|
||||||
{
|
{
|
||||||
Tester::run(|tester| {
|
Tester::run(|tester| {
|
||||||
let helpers = Arc::new(Helpers::default());
|
let tr = make_tr(tr, tester);
|
||||||
let tr = make_tr(tr, tester, helpers.clone());
|
|
||||||
|
|
||||||
let module = tester.apply_transform(
|
let module = tester.apply_transform(
|
||||||
tr,
|
tr,
|
||||||
@ -282,7 +283,6 @@ where
|
|||||||
let src_without_helpers = tester.print(&module);
|
let src_without_helpers = tester.print(&module);
|
||||||
let module = module.fold_with(&mut InjectHelpers {
|
let module = module.fold_with(&mut InjectHelpers {
|
||||||
cm: tester.cm.clone(),
|
cm: tester.cm.clone(),
|
||||||
helpers: helpers.clone(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let src = tester.print(&module);
|
let src = tester.print(&module);
|
||||||
|
Loading…
Reference in New Issue
Block a user