Skip to content

Commit

Permalink
fix: out of index problem in arco-pro, using clean ast in codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed May 16, 2022
1 parent 146b101 commit 0975150
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions crates/rspack_core/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ use crate::{
use crate::{path::normalize_path, SWC_GLOBALS};
use dashmap::{DashMap, DashSet};
use rspack_swc::{
swc_atoms, swc_common, swc_ecma_ast as ast, swc_ecma_transforms_base, swc_ecma_visit,
swc_atoms, swc_common,
swc_ecma_ast::{self as ast, Ident},
swc_ecma_transforms_base,
swc_ecma_visit::{self, VisitMut},
};
use swc_atoms::JsWord;
use swc_common::GLOBALS;
use swc_common::{SyntaxContext, GLOBALS};
use swc_ecma_transforms_base::resolver::resolver_with_mark;
use swc_ecma_visit::VisitMutWith;
use swc_ecma_visit::{noop_visit_mut_type, VisitMutWith};
use tokio::sync::mpsc::UnboundedSender;
use tracing::instrument;

Expand Down Expand Up @@ -88,6 +91,11 @@ impl Task {
}
let mut ast = plugin_hook::transform(Path::new(module_id), raw_ast, &self.plugin_driver);

{
// FIXME: This will slow the performance. A non-clean ast will panic in codegen. Maybe it's an bug of swc.
ast.visit_mut_with(&mut ClearMark);
}

self.pre_analyze_imported_module(&uri_resolver, &ast).await;

ast.visit_mut_with(&mut dependency_scanner);
Expand Down Expand Up @@ -175,3 +183,13 @@ impl Task {
}
}
}

#[derive(Clone, Copy)]
struct ClearMark;
impl VisitMut for ClearMark {
noop_visit_mut_type!();

fn visit_mut_ident(&mut self, ident: &mut Ident) {
ident.span.ctxt = SyntaxContext::empty();
}
}

0 comments on commit 0975150

Please sign in to comment.