Skip to content

Commit

Permalink
fix(next-swc): Do not reuse compiler instance (#65602)
Browse files Browse the repository at this point in the history
### What?

Do not reuse `Compiler` instance.

### Why?

It exists only to support preserving comments from `print()` API for
modules created with `parse()` API, but it causes a problem for
`transform()` for very huge apps.

### How?

 - Closes swc-project/swc#8932
 - Fixes #48960
 - Fixes #65436
  • Loading branch information
kdy1 committed May 13, 2024
1 parent 9296434 commit fedb675
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/next-swc/crates/napi/src/lib.rs
Expand Up @@ -44,7 +44,7 @@ use fxhash::FxHashSet;
use napi::bindgen_prelude::*;
use turbopack_binding::swc::core::{
base::{Compiler, TransformOutput},
common::{sync::Lazy, FilePathMapping, SourceMap},
common::{FilePathMapping, SourceMap},
};

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -82,12 +82,6 @@ static ALLOC: turbopack_binding::turbo::malloc::TurboMalloc =
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;

static COMPILER: Lazy<Arc<Compiler>> = Lazy::new(|| {
let cm = Arc::new(SourceMap::new(FilePathMapping::empty()));

Arc::new(Compiler::new(cm))
});

#[cfg(not(target_arch = "wasm32"))]
#[napi::module_init]
fn init() {
Expand All @@ -101,7 +95,9 @@ fn init() {

#[inline]
fn get_compiler() -> Arc<Compiler> {
COMPILER.clone()
let cm = Arc::new(SourceMap::new(FilePathMapping::empty()));

Arc::new(Compiler::new(cm))
}

pub fn complete_output(
Expand Down

0 comments on commit fedb675

Please sign in to comment.