Skip to content

Commit

Permalink
Revert "Fix"
Browse files Browse the repository at this point in the history
This reverts commit 082e766.
  • Loading branch information
timneutkens committed Sep 28, 2022
1 parent 08066f6 commit 62f996e
Showing 1 changed file with 40 additions and 41 deletions.
81 changes: 40 additions & 41 deletions packages/next-swc/crates/napi/src/bundle/mod.rs
Expand Up @@ -13,7 +13,7 @@ use swc_core::{
common::{
collections::AHashMap,
errors::{ColorConfig, Handler},
BytePos, FileName, Globals, SourceMap, Span, GLOBALS,
BytePos, FileName, SourceMap, Span,
},
ecma::ast::*,
ecma::atoms::JsWord,
Expand Down Expand Up @@ -69,11 +69,10 @@ impl Task for BundleTask {
.map(JsWord::from)
.collect::<Vec<_>>();

let globals = Globals::default();
let comments = self.c.comments().clone();
//
let mut bundler = Bundler::new(
&globals,
self.c.globals(),
self.c.cm.clone(),
CustomLoader {
cm: self.c.cm.clone(),
Expand All @@ -89,46 +88,46 @@ impl Task for BundleTask {
},
Box::new(CustomHook),
);
GLOBALS.set(&globals, || {
let mut entries = HashMap::default();
let path: PathBuf = option.entry;
let path = path
.canonicalize()
.context("failed to canonicalize entry file")?;
entries.insert("main".to_string(), FileName::Real(path));
let outputs = bundler.bundle(entries)?;

let output = outputs.into_iter().next().ok_or_else(|| {
anyhow!("swc_bundler::Bundle::bundle returned empty result")
})?;

let source_map_names = {
let mut v = SourceMapIdentCollector {
names: Default::default(),
};

output.module.visit_with(&mut v);

v.names

let mut entries = HashMap::default();
let path: PathBuf = option.entry;
let path = path
.canonicalize()
.context("failed to canonicalize entry file")?;
entries.insert("main".to_string(), FileName::Real(path));
let outputs = bundler.bundle(entries)?;

let output = outputs
.into_iter()
.next()
.ok_or_else(|| anyhow!("swc_bundler::Bundle::bundle returned empty result"))?;

let source_map_names = {
let mut v = SourceMapIdentCollector {
names: Default::default(),
};

let code = self.c.print(
&output.module,
None,
None,
true,
EsVersion::Es5,
SourceMapsConfig::Bool(true),
&source_map_names,
None,
false,
Some(&comments),
true,
false,
)?;

Ok(code)
})
output.module.visit_with(&mut v);

v.names
};

let code = self.c.print(
&output.module,
None,
None,
true,
EsVersion::Es5,
SourceMapsConfig::Bool(true),
&source_map_names,
None,
false,
Some(&comments),
true,
false,
)?;

Ok(code)
},
)
.convert_err()
Expand Down

0 comments on commit 62f996e

Please sign in to comment.