Skip to content

Commit

Permalink
fix bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jul 23, 2024
1 parent f6b5de7 commit 1276336
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
14 changes: 13 additions & 1 deletion crates/swc_bundler/src/bundler/chunk/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use swc_common::{
FileName, SyntaxContext, DUMMY_SP,
};
use swc_ecma_ast::*;
use swc_ecma_transforms_base::helpers::Helpers;
use swc_ecma_utils::{find_pat_ids, prepend_stmt, private_ident, quote_ident, ExprFactory};
use swc_ecma_visit::{VisitMut, VisitMutWith};
use EdgeDirection::Outgoing;
Expand Down Expand Up @@ -104,7 +105,18 @@ where
let deps = all_deps_of_entry.iter().map(|id| {
let dep_info = self.scope.get_module(*id).unwrap();
entry_info.helpers.extend(&dep_info.helpers);
entry_info.swc_helpers.extend_from(&dep_info.swc_helpers);

{
let helpers = *entry_info.swc_helpers.lock();
let dep_helpers = *dep_info.swc_helpers.lock();

let helpers = Helpers::from_data(helpers);
let dep_helpers = Helpers::from_data(dep_helpers);

helpers.extend_from(&dep_helpers);

*entry_info.swc_helpers.lock() = helpers.data();
}

if *id == entry_id {
return Modules::empty(injected_ctxt);
Expand Down
9 changes: 5 additions & 4 deletions crates/swc_bundler/src/bundler/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use swc_common::{collections::AHashMap, util::move_map::MoveMap, FileName, Mark,
use swc_ecma_ast::*;
use swc_ecma_transforms_base::{
fixer::fixer,
helpers::{inject_helpers, HELPERS},
helpers::{inject_helpers, Helpers, HELPERS},
hygiene::hygiene,
};
use swc_ecma_utils::{contains_top_level_await, find_pat_ids, private_ident, ExprFactory};
Expand Down Expand Up @@ -48,15 +48,16 @@ where

{
// Inject swc helpers
let swc_helpers = self
let swc_helpers = *self
.scope
.get_module(bundle.id)
.expect("module should exist at this point")
.swc_helpers;
.swc_helpers
.lock();

let module = bundle.module;

bundle.module = HELPERS.set(&swc_helpers, || {
bundle.module = HELPERS.set(&Helpers::from_data(swc_helpers), || {
module.fold_with(&mut inject_helpers(unresolved_mark))
});
}
Expand Down
9 changes: 6 additions & 3 deletions crates/swc_bundler/src/bundler/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use anyhow::{Context, Error};
use is_macro::Is;
#[cfg(feature = "rayon")]
use rayon::iter::ParallelIterator;
use swc_common::{sync::Lrc, FileName, SourceFile, SyntaxContext};
use swc_common::{
sync::{Lock, Lrc},
FileName, SourceFile, SyntaxContext,
};
use swc_ecma_ast::{
CallExpr, Callee, Expr, Ident, ImportDecl, ImportSpecifier, MemberExpr, MemberProp, Module,
ModuleDecl, ModuleExportName, Str, SuperProp, SuperPropExpr,
Expand Down Expand Up @@ -38,7 +41,7 @@ pub(crate) struct TransformedModule {
/// Used helpers
pub helpers: Lrc<Helpers>,

pub swc_helpers: Lrc<swc_ecma_transforms_base::helpers::Helpers>,
pub swc_helpers: Lrc<Lock<swc_ecma_transforms_base::helpers::HelperData>>,

local_ctxt: SyntaxContext,
export_ctxt: SyntaxContext,
Expand Down Expand Up @@ -208,7 +211,7 @@ where
exports: Lrc::new(exports),
is_es6,
helpers: Default::default(),
swc_helpers: Lrc::new(data.helpers),
swc_helpers: Lrc::new(Lock::new(data.helpers.data())),
local_ctxt: SyntaxContext::empty().apply_mark(local_mark),
export_ctxt: SyntaxContext::empty().apply_mark(export_mark),
},
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_transforms_base/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ macro_rules! define_helpers {


impl Helpers {
pub fn extend_from(&mut self, other: &Self) {
pub fn extend_from(&self, other: &Self) {
let other = other.inner.borrow();
let mut me = self.inner.borrow_mut();
$(
Expand Down

0 comments on commit 1276336

Please sign in to comment.