Unverified Commit 4249afd7 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

perf(turbopack): Use `Pass` API for `styled-jsx` SWC plugin (#75271)

### What?

It **removes** needless allocations.

### Why?

To avoid allocating memory needlessly.
parent 2c1f68eb
use anyhow::Result; use anyhow::Result;
use async_trait::async_trait; use async_trait::async_trait;
use swc_core::{ use swc_core::{
common::{util::take::Take, FileName}, common::FileName,
ecma::{ ecma::{ast::Program, preset_env::Versions},
ast::{Module, Program},
preset_env::Versions,
visit::FoldWith,
},
}; };
use turbopack_ecmascript::{CustomTransformer, TransformContext}; use turbopack_ecmascript::{CustomTransformer, TransformContext};
...@@ -25,8 +21,7 @@ impl StyledJsxTransformer { ...@@ -25,8 +21,7 @@ impl StyledJsxTransformer {
impl CustomTransformer for StyledJsxTransformer { impl CustomTransformer for StyledJsxTransformer {
#[tracing::instrument(level = tracing::Level::TRACE, name = "styled_jsx", skip_all)] #[tracing::instrument(level = tracing::Level::TRACE, name = "styled_jsx", skip_all)]
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> { async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
let p = std::mem::replace(program, Program::Module(Module::dummy())); program.mutate(styled_jsx::visitor::styled_jsx(
*program = p.fold_with(&mut styled_jsx::visitor::styled_jsx(
ctx.source_map.clone(), ctx.source_map.clone(),
// styled_jsx don't really use that in a relevant way // styled_jsx don't really use that in a relevant way
FileName::Anon, FileName::Anon,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment