perf(es/compat): Add tracing support to transforms for from es2017 to es2019 (#3844)

This commit is contained in:
OJ Kwon 2022-03-03 23:28:58 -08:00 committed by GitHub
parent 88ee527917
commit a933db5a1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 0 deletions

View File

@ -12,6 +12,7 @@ use swc_ecma_utils::{
use swc_ecma_visit::{
as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith,
};
use swc_trace_macro::swc_trace;
/// `@babel/plugin-transform-async-to-generator`
///
@ -33,6 +34,7 @@ use swc_ecma_visit::{
/// yield bar();
/// });
/// ```
#[tracing::instrument(level = "trace", skip_all)]
pub fn async_to_generator() -> impl Fold + VisitMut {
as_folder(AsyncToGenerator)
}
@ -45,6 +47,7 @@ struct Actual {
hoist_stmts: Vec<Stmt>,
}
#[swc_trace]
#[fast_path(ShouldWork)]
impl VisitMut for AsyncToGenerator {
noop_visit_mut_type!();
@ -58,6 +61,7 @@ impl VisitMut for AsyncToGenerator {
}
}
#[swc_trace]
impl AsyncToGenerator {
fn visit_mut_stmt_like<T>(&mut self, stmts: &mut Vec<T>)
where
@ -83,6 +87,7 @@ impl AsyncToGenerator {
}
}
#[swc_trace]
#[fast_path(ShouldWork)]
impl VisitMut for Actual {
noop_visit_mut_type!();
@ -276,6 +281,7 @@ impl VisitMut for Actual {
}
}
#[swc_trace]
impl Actual {
fn visit_mut_expr_with_binding(&mut self, expr: &mut Expr, binding_ident: Option<Ident>) {
expr.visit_mut_children_with(self);
@ -321,6 +327,7 @@ impl Actual {
/// Creates
///
/// `_asyncToGenerator(function*() {})` from `async function() {}`;
#[tracing::instrument(level = "trace", skip_all)]
fn make_fn_ref(mut expr: FnExpr) -> Expr {
expr.function.body.visit_mut_with(&mut AsyncFnBodyHandler {
is_async_generator: expr.function.is_generator,
@ -360,6 +367,7 @@ macro_rules! noop {
};
}
#[swc_trace]
impl VisitMut for AsyncFnBodyHandler {
noop_visit_mut_type!();
@ -410,6 +418,7 @@ struct ShouldWork {
found: bool,
}
#[swc_trace]
impl Visit for ShouldWork {
noop_visit_type!();
@ -436,6 +445,7 @@ impl Check for ShouldWork {
}
}
#[tracing::instrument(level = "trace", skip_all)]
fn handle_await_for(stmt: &mut Stmt, is_async_generator: bool) {
let s = match stmt {
Stmt::ForOf(

View File

@ -4,6 +4,7 @@ pub use self::async_to_generator::async_to_generator;
mod async_to_generator;
#[tracing::instrument(level = "trace", skip_all)]
pub fn es2017() -> impl Fold {
async_to_generator()
}

View File

@ -5,6 +5,7 @@ pub use self::object_rest_spread::object_rest_spread;
pub mod object_rest_spread;
#[tracing::instrument(level = "trace", skip_all)]
pub fn es2018(c: Config) -> impl Fold {
object_rest_spread(c.object_rest_spread)
}

View File

@ -15,11 +15,13 @@ use swc_ecma_utils::{
use swc_ecma_visit::{
as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith,
};
use swc_trace_macro::swc_trace;
// TODO: currently swc behaves like babel with
// `ignoreFunctionLength` and `pureGetters` on
/// `@babel/plugin-proposal-object-rest-spread`
#[tracing::instrument(level = "trace", skip_all)]
pub fn object_rest_spread(c: Config) -> impl Fold + VisitMut {
chain!(
as_folder(ObjectRest {
@ -176,6 +178,7 @@ struct RestVisitor {
found: bool,
}
#[swc_trace]
impl Visit for RestVisitor {
noop_visit_type!();
@ -202,6 +205,7 @@ where
v.found
}
#[swc_trace]
#[fast_path(RestVisitor)]
impl VisitMut for ObjectRest {
noop_visit_mut_type!();
@ -452,6 +456,7 @@ impl VisitMut for ObjectRest {
}
}
#[swc_trace]
impl ObjectRest {
fn visit_mut_stmt_like<T>(&mut self, stmts: &mut Vec<T>)
where
@ -905,6 +910,7 @@ impl ObjectRest {
}
}
#[tracing::instrument(level = "trace", skip_all)]
fn object_without_properties(
obj: Box<Expr>,
excluded_props: Vec<Option<ExprOrSpread>>,
@ -981,6 +987,7 @@ fn object_without_properties(
})
}
#[tracing::instrument(level = "trace", skip_all)]
fn excluded_props(props: &[ObjectPatProp]) -> Vec<Option<ExprOrSpread>> {
props
.iter()
@ -1032,6 +1039,7 @@ fn excluded_props(props: &[ObjectPatProp]) -> Vec<Option<ExprOrSpread>> {
/// - `{ x4: {} }` -> `{}`
struct PatSimplifier;
#[swc_trace]
impl VisitMut for PatSimplifier {
noop_visit_mut_type!();
@ -1068,6 +1076,7 @@ impl Parallel for ObjectSpread {
fn merge(&mut self, _: Self) {}
}
#[swc_trace]
#[parallel]
impl VisitMut for ObjectSpread {
noop_visit_mut_type!();

View File

@ -4,6 +4,7 @@ pub use self::optional_catch_binding::optional_catch_binding;
mod optional_catch_binding;
#[tracing::instrument(level = "trace", skip_all)]
pub fn es2019() -> impl Fold {
optional_catch_binding()
}

View File

@ -1,13 +1,16 @@
use swc_ecma_ast::*;
use swc_ecma_utils::private_ident;
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
use swc_trace_macro::swc_trace;
struct OptionalCatchBinding;
#[tracing::instrument(level = "trace", skip_all)]
pub fn optional_catch_binding() -> impl Fold + VisitMut {
as_folder(OptionalCatchBinding)
}
#[swc_trace]
impl VisitMut for OptionalCatchBinding {
noop_visit_mut_type!();