Skip to content

Commit

Permalink
chore: 🤖 lint
Browse files Browse the repository at this point in the history
  • Loading branch information
IWANABETHATGUY committed Oct 17, 2023
1 parent 6992918 commit 3a6d7be
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 70 deletions.
7 changes: 0 additions & 7 deletions crates/rspack_core/src/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,14 +1187,7 @@ impl Compilation {
// https://github.com/webpack/webpack/blob/d15c73469fd71cf98734685225250148b68ddc79/lib/Compilation.js#L2812-L2814
while plugin_driver.optimize_dependencies(self).await?.is_some() {}
logger.time_end(start);

// if self.options.is_new_tree_shaking() {
// // for module in self.module_graph.module_graph_modules().values() {}
// // self
// // .module_graph
// // .module_graph_modules()
// // .values()
// // .foreach(|item| {});
// debug_exports_info(&self.module_graph);
// }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,12 @@ impl ModuleDependency for HarmonyImportSpecifierDependency {
}

fn get_condition(&self) -> Option<DependencyCondition> {
dbg!(&self.ids, self.request(), self.used_by_exports.as_ref());
// dbg!(
// &self.ids,
// &self.specifier,
// self.request(),
// self.used_by_exports.as_ref()
// );
get_dependency_used_by_exports_condition(self.id, self.used_by_exports.as_ref())
}

Expand All @@ -250,6 +255,7 @@ impl ModuleDependency for HarmonyImportSpecifierDependency {
module_graph: &ModuleGraph,
_runtime: Option<&RuntimeSpec>,
) -> Vec<ExtendedReferencedExport> {
// TODO: use self.getIds() instead
// namespace import
if self.ids.is_empty() {
return self.get_referenced_exports_in_destructuring(None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator {
RawSource::from(content).boxed()
}
if let Some(mut inner_graph) = inner_graph {
dbg!(module_identifier);
inner_graph.infer_dependency_usage();
}

Expand Down
95 changes: 42 additions & 53 deletions crates/rspack_plugin_javascript/src/plugin/inner_graph_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,16 @@ impl<'a> Visit for InnerGraphPlugin<'a> {
}

fn visit_member_expr(&mut self, member_expr: &MemberExpr) {
match self.rewrite_usage_span.get(&member_expr.span) {
Some(ExtraSpanInfo::ReWriteUsedByExports) => {
let span = member_expr.span;
self.on_usage(Box::new(move |deps, used_by_exports| {
let target_dep = deps.iter_mut().find(|item| item.is_span_equal(&span));
if let Some(dep) = target_dep {
dep.set_used_by_exports(used_by_exports);
}
}));
}
// member_expr is not possible to add a variable usage
_ => {}
if let Some(ExtraSpanInfo::ReWriteUsedByExports) =
self.rewrite_usage_span.get(&member_expr.span)
{
let span = member_expr.span;
self.on_usage(Box::new(move |deps, used_by_exports| {
let target_dep = deps.iter_mut().find(|item| item.is_span_equal(&span));
if let Some(dep) = target_dep {
dep.set_used_by_exports(used_by_exports);
}
}));
};
}

Expand Down Expand Up @@ -181,19 +179,14 @@ impl<'a> Visit for InnerGraphPlugin<'a> {
}

fn visit_ident(&mut self, ident: &Ident) {
match self.rewrite_usage_span.get(&ident.span) {
Some(ExtraSpanInfo::ReWriteUsedByExports) => {
let span = ident.span;
let sym = ident.sym.clone();
self.on_usage(Box::new(move |deps, used_by_exports| {
let target_dep = deps.iter_mut().find(|item| item.is_span_equal(&span));
if let Some(dep) = target_dep {
dep.set_used_by_exports(used_by_exports);
}
}));
}
// ident is impossible to add a variable usage
_ => {}
if let Some(ExtraSpanInfo::ReWriteUsedByExports) = self.rewrite_usage_span.get(&ident.span) {
let span = ident.span;
self.on_usage(Box::new(move |deps, used_by_exports| {
let target_dep = deps.iter_mut().find(|item| item.is_span_equal(&span));
if let Some(dep) = target_dep {
dep.set_used_by_exports(used_by_exports);
}
}));
};
// imported binding isn't considered as a top level symbol.
if self.import_map.contains_key(&ident.to_id()) {
Expand Down Expand Up @@ -252,29 +245,26 @@ impl<'a> Visit for InnerGraphPlugin<'a> {
fn visit_prop(&mut self, n: &Prop) {
match n {
Prop::Shorthand(shorthand) => {
match self.rewrite_usage_span.get(&shorthand.span) {
Some(ExtraSpanInfo::ReWriteUsedByExports) => {
let span = shorthand.span;
self.on_usage(Box::new(move |deps, used_by_exports| {
let target_dep = deps.iter_mut().find(|item| item.is_span_equal(&span));
if let Some(dep) = target_dep {
dep.set_used_by_exports(used_by_exports);
}
}));
}
// prop is impossible to add a variable usage
_ => {}
if let Some(ExtraSpanInfo::ReWriteUsedByExports) =
self.rewrite_usage_span.get(&shorthand.span)
{
let span = shorthand.span;
self.on_usage(Box::new(move |deps, used_by_exports| {
let target_dep = deps.iter_mut().find(|item| item.is_span_equal(&span));
if let Some(dep) = target_dep {
dep.set_used_by_exports(used_by_exports);
}
}));
};
}
_ => n.visit_children_with(self),
}
}
fn visit_export_decl(&mut self, export_decl: &ExportDecl) {
match self.rewrite_usage_span.get(&export_decl.span) {
Some(ExtraSpanInfo::AddVariableUsage(sym, usage)) => {
self.add_variable_usage(sym.clone(), InnerGraphMapUsage::Value(usage.clone()));
}
_ => {}
if let Some(ExtraSpanInfo::AddVariableUsage(sym, usage)) =
self.rewrite_usage_span.get(&export_decl.span)
{
self.add_variable_usage(sym.clone(), InnerGraphMapUsage::Value(usage.clone()));
}
// match &export_decl.decl {
// Decl::Class(ClassDecl { ident, .. }) | Decl::Fn(FnDecl { ident, .. }) => {
Expand All @@ -298,12 +288,13 @@ impl<'a> Visit for InnerGraphPlugin<'a> {
.specifiers
.iter()
.for_each(|specifier| match specifier {
ExportSpecifier::Named(named) => match self.rewrite_usage_span.get(&named.span) {
Some(ExtraSpanInfo::AddVariableUsage(sym, usage)) => {
ExportSpecifier::Named(named) => {
if let Some(ExtraSpanInfo::AddVariableUsage(sym, usage)) =
self.rewrite_usage_span.get(&named.span)
{
self.add_variable_usage(sym.clone(), InnerGraphMapUsage::Value(usage.clone()));
}
_ => {}
},
}
_ => unreachable!(),
});
}
Expand All @@ -312,13 +303,11 @@ impl<'a> Visit for InnerGraphPlugin<'a> {
if !self.is_enabled() {
return;
}
match self.rewrite_usage_span.get(&node.span) {
Some(ExtraSpanInfo::AddVariableUsage(sym, usage)) => {
self.add_variable_usage(sym.clone(), InnerGraphMapUsage::Value(usage.clone()));
}
_ => {}
if let Some(ExtraSpanInfo::AddVariableUsage(sym, usage)) =
self.rewrite_usage_span.get(&node.span)
{
self.add_variable_usage(sym.clone(), InnerGraphMapUsage::Value(usage.clone()));
}
// TODO:
match node.expr {
box Expr::Fn(_) | box Expr::Arrow(_) | box Expr::Lit(_) => {
self.set_symbol_if_is_top_level(DEFAULT_EXPORT.into());
Expand Down Expand Up @@ -603,7 +592,7 @@ impl<'a> InnerGraphPlugin<'a> {
}
}

dbg!(&state.inner_graph);
// dbg!(&state.inner_graph);
for (symbol, cbs) in state.usage_callback_map.iter() {
let usage = state.inner_graph.get(symbol);
for cb in cbs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ use swc_core::{
};

use super::{harmony_import_dependency_scanner::ImportMap, ExtraSpanInfo};
use crate::{
dependency::{
AnonymousFunctionRangeInfo, HarmonyExportExpressionDependency, HarmonyExportHeaderDependency,
HarmonyExportImportedSpecifierDependency, HarmonyExportSpecifierDependency, Specifier,
DEFAULT_EXPORT,
},
inner_graph_plugin::InnerGraphMapUsage,
use crate::dependency::{
AnonymousFunctionRangeInfo, HarmonyExportExpressionDependency, HarmonyExportHeaderDependency,
HarmonyExportImportedSpecifierDependency, HarmonyExportSpecifierDependency, Specifier,
DEFAULT_EXPORT,
};

pub struct HarmonyExportDependencyScanner<'a> {
Expand Down Expand Up @@ -147,7 +144,7 @@ impl Visit for HarmonyExportDependencyScanner<'_> {
}
self.rewrite_usage_span.insert(
named.span(),
ExtraSpanInfo::AddVariableUsage(orig.sym.clone(), export.clone()),
ExtraSpanInfo::AddVariableUsage(orig.sym.clone(), export),
);
}
}
Expand Down

0 comments on commit 3a6d7be

Please sign in to comment.