Skip to content

Commit

Permalink
fix(bundler): Fix bugs (#1382)
Browse files Browse the repository at this point in the history
swc_bundler:
 - Improve performance
 - Use `Vec<AHashSet<usize>>` instead of `AHashSet<(usize, usize)>`.
 - Fix statement orderings. (denoland/deno#9464) 
 - Fix wrapped esm mixed with circular imports. (denoland/deno#8224)
 - Store content of wrapped esm at top level. (denoland/deno#8224)
  • Loading branch information
kdy1 authored Feb 22, 2021
1 parent adcca03 commit 7f5bfdc
Show file tree
Hide file tree
Showing 243 changed files with 13,122 additions and 12,235 deletions.
2 changes: 1 addition & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[build]
rustflags = [
"--cfg", "procmacro2_semver_exempt",
"-C", "target-feature=+sse2",
"-C", "target-feature=+sse2,+aes",
]

rustdocflags = [
Expand Down
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.6.1"
version = "0.7.0"

[lib]
name = "swc"
Expand All @@ -29,21 +29,21 @@ serde_json = "1"
sourcemap = "6"
swc_atoms = {version = "0.2", path = "./atoms"}
swc_common = {version = "0.10.10", path = "./common", features = ["sourcemap", "concurrent"]}
swc_ecma_ast = {version = "0.39.1", path = "./ecmascript/ast"}
swc_ecma_codegen = {version = "0.46.1", path = "./ecmascript/codegen"}
swc_ecma_ext_transforms = {version = "0.5.1", path = "./ecmascript/ext-transforms"}
swc_ecma_parser = {version = "0.48.1", path = "./ecmascript/parser"}
swc_ecma_preset_env = {version = "0.7.1", path = "./ecmascript/preset_env"}
swc_ecma_transforms = {version = "0.37.1", path = "./ecmascript/transforms", features = [
swc_ecma_ast = {version = "0.40.0", path = "./ecmascript/ast"}
swc_ecma_codegen = {version = "0.47.0", path = "./ecmascript/codegen"}
swc_ecma_ext_transforms = {version = "0.6.0", path = "./ecmascript/ext-transforms"}
swc_ecma_parser = {version = "0.49.0", path = "./ecmascript/parser"}
swc_ecma_preset_env = {version = "0.8.0", path = "./ecmascript/preset_env"}
swc_ecma_transforms = {version = "0.38.0", path = "./ecmascript/transforms", features = [
"compat",
"module",
"optimization",
"proposal",
"react",
"typescript",
]}
swc_ecma_utils = {version = "0.29.1", path = "./ecmascript/utils"}
swc_ecma_visit = {version = "0.25.1", path = "./ecmascript/visit"}
swc_ecma_utils = {version = "0.30.0", path = "./ecmascript/utils"}
swc_ecma_visit = {version = "0.26.0", path = "./ecmascript/visit"}
swc_visit = {version = "0.2.3", path = "./visit"}

[dev-dependencies]
Expand Down
17 changes: 9 additions & 8 deletions bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "src/**/*.js"]
license = "Apache-2.0/MIT"
name = "swc_bundler"
repository = "https://github.com/swc-project/swc.git"
version = "0.24.1"
version = "0.25.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
concurrent = ["swc_common/concurrent", "dashmap", "rayon", "indexmap/rayon"]
default = []

[dependencies]
ahash = "0.7"
anyhow = "1"
crc = "1.8"
dashmap = {version = "3", optional = true}
Expand All @@ -31,19 +32,19 @@ relative-path = "1.2"
retain_mut = "0.1.2"
swc_atoms = {version = "0.2.4", path = "../atoms"}
swc_common = {version = "0.10.10", path = "../common"}
swc_ecma_ast = {version = "0.39.1", path = "../ecmascript/ast"}
swc_ecma_codegen = {version = "0.46.1", path = "../ecmascript/codegen"}
swc_ecma_parser = {version = "0.48.1", path = "../ecmascript/parser"}
swc_ecma_transforms = {version = "0.37.1", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_utils = {version = "0.29.1", path = "../ecmascript/utils"}
swc_ecma_visit = {version = "0.25.1", path = "../ecmascript/visit"}
swc_ecma_ast = {version = "0.40.0", path = "../ecmascript/ast"}
swc_ecma_codegen = {version = "0.47.0", path = "../ecmascript/codegen"}
swc_ecma_parser = {version = "0.49.0", path = "../ecmascript/parser"}
swc_ecma_transforms = {version = "0.38.0", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_utils = {version = "0.30.0", path = "../ecmascript/utils"}
swc_ecma_visit = {version = "0.26.0", path = "../ecmascript/visit"}

[dev-dependencies]
hex = "0.4"
ntest = "0.7.2"
reqwest = {version = "0.10.8", features = ["blocking"]}
sha-1 = "0.9"
swc_ecma_transforms = {version = "0.37.1", path = "../ecmascript/transforms", features = ["react", "typescript"]}
swc_ecma_transforms = {version = "0.38.0", path = "../ecmascript/transforms", features = ["react", "typescript"]}
tempfile = "3.1.0"
testing = {version = "0.10.3", path = "../testing"}
url = "2.1.1"
Expand Down
34 changes: 21 additions & 13 deletions bundler/src/bundler/chunk/circular.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::plan::CircularPlan;
use crate::bundler::modules::Modules;
use crate::modules::Modules;
use crate::{bundler::chunk::merge::Ctx, id::Id, Bundler, Load, ModuleId, Resolve};
use anyhow::{Context, Error};
use swc_common::DUMMY_SP;
Expand Down Expand Up @@ -30,8 +30,9 @@ where
log::debug!("[circular] skip: {:?}", entry_id);
return Ok(Modules::empty(self.injected_ctxt));
}
// TODO: Handle wrapped esms

log::debug!("[circular] Stsrting with: {:?}", entry_id);
log::debug!("[circular] Starting with: {:?}", entry_id);

let entry_module = self.scope.get_module(entry_id).unwrap();

Expand All @@ -40,7 +41,7 @@ where
.context("failed to merge dependency of a cyclic module")?;

let mut exports = vec![];
for item in entry.iter_mut() {
for (_, item) in entry.iter_mut() {
match item {
ModuleItem::ModuleDecl(decl) => match decl {
ModuleDecl::ExportDecl(export) => match &export.decl {
Expand Down Expand Up @@ -97,15 +98,16 @@ where
entry = new_module;

if !exports.is_empty() {
entry.inject(ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(
NamedExport {
entry.append(
entry_id,
ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(NamedExport {
span: DUMMY_SP.with_ctxt(self.synthesized_ctxt),
specifiers: exports,
src: None,
type_only: false,
asserts: None,
},
)));
})),
);
}

// print_hygiene("[circular] done", &self.cm, &entry);
Expand Down Expand Up @@ -135,14 +137,20 @@ where

true
});
deps.sort();
// deps.sort();

self.run(|| {
for dep in deps {
let dep_info = self.scope.get_module(dep).unwrap();
let mut dep = self
.merge_modules(ctx, dep, false, false)
.context("failed to merge dependency of a cyclic module")?;
for dep_id in deps {
let dep_info = self.scope.get_module(dep_id).unwrap();
let mut dep = if self.scope.should_be_wrapped_with_a_fn(dep_id) {
let mut dep: Modules = self.get_module_for_merging(ctx, dep_id, false)?;
dep = self.wrap_esm(ctx, dep_id, dep.into())?.into();
self.prepare(&dep_info, &mut dep);
dep
} else {
self.merge_modules(ctx, dep_id, false, false)
.context("failed to merge dependency of a cyclic module")?
};

// print_hygiene("[circular] dep:init 1", &self.cm, &dep.clone().into());

Expand Down
22 changes: 13 additions & 9 deletions bundler/src/bundler/chunk/cjs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::merge::Unexporter;
use crate::bundler::modules::Modules;
use crate::modules::Modules;
use crate::{
bundler::{
chunk::{merge::Ctx, plan::Dependancy},
Expand Down Expand Up @@ -80,13 +80,17 @@ where
dep.visit_mut_with(&mut DefaultHandler {
local_ctxt: dep_info.local_ctxt(),
});
dep.sort(info.id, &ctx.graph, &self.cm);

entry.prepend(ModuleItem::Stmt(wrap_module(
SyntaxContext::empty(),
dep_info.local_ctxt(),
load_var,
dep.into(),
)));
entry.prepend(
info.id,
ModuleItem::Stmt(wrap_module(
SyntaxContext::empty(),
dep_info.local_ctxt(),
load_var,
dep.into(),
)),
);

log::warn!("Injecting load");
}
Expand All @@ -103,7 +107,7 @@ where
false,
entry,
info,
Modules::from((*dep_info.module).clone(), self.injected_ctxt),
Modules::from(dep_info.id, (*dep_info.module).clone(), self.injected_ctxt),
&dep_info,
targets,
)?;
Expand Down Expand Up @@ -341,7 +345,7 @@ impl VisitMut for RequireReplacer {
}

fn drop_module_decls(modules: &mut Modules) {
modules.retain_mut(|i| match i {
modules.retain_mut(|_, i| match i {
ModuleItem::ModuleDecl(..) => false,
ModuleItem::Stmt(_) => true,
})
Expand Down
Loading

0 comments on commit 7f5bfdc

Please sign in to comment.