Skip to content

Commit

Permalink
fix(bundler): Fix bundler (#1318)
Browse files Browse the repository at this point in the history
swc_bundler:
 - Use two-context system properly.
 - Remove old logic.
 - keywords: Handle assignment pattern property.
 - keywords: Handle shorthand property.
 - keywords: Handle identifiers in declarations.

swc_ecma_transforms_typescript:
 - Do not remove import if there's non-type usage. (Related to denoland/deno#8978)

swc_ecma_transforms_optimization:
 - dce: Handle new expression correctly.
  • Loading branch information
kdy1 authored Jan 11, 2021
1 parent dc0d226 commit 23aebac
Show file tree
Hide file tree
Showing 136 changed files with 2,308 additions and 1,693 deletions.
5 changes: 3 additions & 2 deletions bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ build = "build.rs"
description = "Very fast ecmascript bundler"
documentation = "https://swc.rs/rustdoc/swc_bundler/"
edition = "2018"
include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc_bundler"
repository = "https://github.com/swc-project/swc.git"
version = "0.19.1"
version = "0.19.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
Expand All @@ -33,7 +34,7 @@ swc_common = {version = "0.10.0", path = "../common"}
swc_ecma_ast = {version = "0.36.0", path = "../ecmascript/ast"}
swc_ecma_codegen = {version = "0.42.0", path = "../ecmascript/codegen"}
swc_ecma_parser = {version = "0.44.0", path = "../ecmascript/parser"}
swc_ecma_transforms = {version = "0.32.0", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_transforms = {version = "0.32.1", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_utils = {version = "0.26.0", path = "../ecmascript/utils"}
swc_ecma_visit = {version = "0.22.0", path = "../ecmascript/visit"}

Expand Down
22 changes: 2 additions & 20 deletions bundler/src/bundler/chunk/circular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,6 @@ where
}
_ => {}
},
ModuleDecl::ExportNamed(export) => {
for specifier in &mut export.specifiers {
match specifier {
ExportSpecifier::Namespace(_) => {}
ExportSpecifier::Default(_) => {}
ExportSpecifier::Named(named) => {
let mut orig = named.orig.clone();
orig.span.ctxt = entry_module.export_ctxt();

exports.push(ExportSpecifier::Named(ExportNamedSpecifier {
span: export.span,
orig,
exported: named.exported.clone(),
}));
}
}
}
}
ModuleDecl::ExportDefaultDecl(_) => {}
ModuleDecl::ExportDefaultExpr(_) => {}
ModuleDecl::ExportAll(_) => {}
Expand All @@ -99,7 +81,7 @@ where

// print_hygiene("[circular] entry:init", &self.cm, &entry);

self.handle_import_deps(ctx, &entry_module, &mut entry, true);
// self.handle_import_deps(ctx, &entry_module, &mut entry, true);

// print_hygiene("[circular] entry:reexport", &self.cm, &entry);

Expand Down Expand Up @@ -167,7 +149,7 @@ where

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

entry.prepend_all(dep);
entry.push_all(dep);
}

// print_hygiene("before circular sort", &self.cm, &entry.clone().into());
Expand Down
37 changes: 36 additions & 1 deletion bundler/src/bundler/chunk/computed_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::bundler::modules::Modules;
use crate::util::ExprExt;
use crate::util::VarDeclaratorExt;
use crate::{bundler::chunk::merge::Ctx, Bundler, Load, ModuleId, Resolve};
use anyhow::{bail, Error};
use std::mem::take;
Expand Down Expand Up @@ -40,7 +42,40 @@ where
Some(v) => v,
None => bail!("{:?} should not be wrapped with a function", id),
};
module.sort();
let injected_ctxt = self.injected_ctxt;
let mut injected_vars = vec![];
module.iter_mut().for_each(|item| match item {
ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(export)) => {
//
for s in export.specifiers.iter_mut() {
match s {
ExportSpecifier::Named(ExportNamedSpecifier {
span,
exported: Some(exported),
orig,
..
}) => {
// Allow using variables within the wrapped es module.
injected_vars.push(
orig.clone().assign_to(exported.clone()).into_module_item(
injected_ctxt,
"wrapped esm -> aliased export",
),
);
*s = ExportSpecifier::Named(ExportNamedSpecifier {
span: *span,
exported: None,
orig: exported.clone(),
})
}
_ => {}
}
}
}
_ => {}
});
module.inject_all(injected_vars);
module.sort(&self.cm);

let is_async = {
let mut v = TopLevelAwaitFinder { found: false };
Expand Down
Loading

0 comments on commit 23aebac

Please sign in to comment.