Skip to content

Commit

Permalink
fix: HMR scanner should only visit dependencies related to HMR (web-i…
Browse files Browse the repository at this point in the history
…nfra-dev#2911)

fix: fix hmr scanner
  • Loading branch information
h-a-n-a authored and siyou committed May 14, 2023
1 parent 3e3654f commit 07e0f02
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
22 changes: 11 additions & 11 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@

/* auto-generated by NAPI-RS */

export interface NodeFS {
writeFile: (...args: any[]) => any
mkdir: (...args: any[]) => any
mkdirp: (...args: any[]) => any
}
export interface ThreadsafeNodeFS {
writeFile: (...args: any[]) => any
mkdir: (...args: any[]) => any
mkdirp: (...args: any[]) => any
removeDirAll: (...args: any[]) => any
}
export interface RawBannerCondition {
type: "string" | "regexp"
stringMatcher?: string
Expand Down Expand Up @@ -441,17 +452,6 @@ export interface RawOptions {
experiments: RawExperiments
node?: RawNodeOption
}
export interface NodeFS {
writeFile: (...args: any[]) => any
mkdir: (...args: any[]) => any
mkdirp: (...args: any[]) => any
}
export interface ThreadsafeNodeFS {
writeFile: (...args: any[]) => any
mkdir: (...args: any[]) => any
mkdirp: (...args: any[]) => any
removeDirAll: (...args: any[]) => any
}
export interface JsAssetInfoRelated {
sourceMap?: string
}
Expand Down
3 changes: 2 additions & 1 deletion crates/rspack_core/src/normal_module_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ impl NormalModuleFactory {
&specifier[pos..]
},
None=> {
unreachable!()
let dependency = data.dependency;
unreachable!("Invalid dependency: {dependency:?}")
}
};
s.split('!').filter(|item| !item.is_empty()).collect::<Vec<_>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bitflags::bitflags;
use rspack_core::ModuleDependency;
use swc_core::common::pass::AstNodePath;
use swc_core::ecma::ast::{CallExpr, Expr, Lit, Str};
use swc_core::ecma::visit::fields::{CallExprField, ExprField, ExprOrSpreadField};
use swc_core::ecma::visit::{AstParentNodeRef, VisitAstPath, VisitWithPath};

use super::{as_parent_path, is_module_hot_accept_call, is_module_hot_decline_call};
Expand Down Expand Up @@ -99,15 +100,38 @@ impl VisitAstPath for HmrDependencyScanner<'_> {
macro_rules! visit_node_children {
() => {
if let Some(first_arg) = node.args.get(0) {
match first_arg.expr.as_ref() {
Expr::Lit(Lit::Str(_)) => {
node.visit_children_with_path(self, ast_path);
}
Expr::Array(_) => {
node.visit_children_with_path(self, ast_path);
}
_ => {}
}
ast_path.with(
AstParentNodeRef::CallExpr(node, CallExprField::Args(0)),
|ast_path| match first_arg.expr.as_ref() {
Expr::Lit(Lit::Str(s)) => {
ast_path.with(
AstParentNodeRef::ExprOrSpread(&first_arg, ExprOrSpreadField::Expr),
|ast_path| {
ast_path.with(
AstParentNodeRef::Expr(first_arg.expr.as_ref(), ExprField::Lit),
|ast_path| {
s.visit_with_path(self, ast_path);
},
)
},
);
}
Expr::Array(arr) => {
ast_path.with(
AstParentNodeRef::ExprOrSpread(&first_arg, ExprOrSpreadField::Expr),
|ast_path| {
ast_path.with(
AstParentNodeRef::Expr(first_arg.expr.as_ref(), ExprField::Array),
|ast_path| {
arr.visit_with_path(self, ast_path);
},
)
},
);
}
_ => {}
},
);
}
};
}
Expand Down

0 comments on commit 07e0f02

Please sign in to comment.