Skip to content

Commit 4249afd

Browse files
authored
perf(turbopack): Use Pass API for styled-jsx SWC plugin (#75271)
### What? It **removes** needless allocations. ### Why? To avoid allocating memory needlessly.
1 parent 2c1f68e commit 4249afd

File tree

1 file changed

+3
-8
lines changed
  • turbopack/crates/turbopack-ecmascript-plugins/src/transform

1 file changed

+3
-8
lines changed

turbopack/crates/turbopack-ecmascript-plugins/src/transform/styled_jsx.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
use anyhow::Result;
22
use async_trait::async_trait;
33
use swc_core::{
4-
common::{util::take::Take, FileName},
5-
ecma::{
6-
ast::{Module, Program},
7-
preset_env::Versions,
8-
visit::FoldWith,
9-
},
4+
common::FileName,
5+
ecma::{ast::Program, preset_env::Versions},
106
};
117
use turbopack_ecmascript::{CustomTransformer, TransformContext};
128

@@ -25,8 +21,7 @@ impl StyledJsxTransformer {
2521
impl CustomTransformer for StyledJsxTransformer {
2622
#[tracing::instrument(level = tracing::Level::TRACE, name = "styled_jsx", skip_all)]
2723
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
28-
let p = std::mem::replace(program, Program::Module(Module::dummy()));
29-
*program = p.fold_with(&mut styled_jsx::visitor::styled_jsx(
24+
program.mutate(styled_jsx::visitor::styled_jsx(
3025
ctx.source_map.clone(),
3126
// styled_jsx don't really use that in a relevant way
3227
FileName::Anon,

0 commit comments

Comments
 (0)