Skip to content

Commit 88e51c3

Browse files
authored
refactor: commonjs export parser plugin (#11488)
1 parent 22d291d commit 88e51c3

File tree

16 files changed

+438
-519
lines changed

16 files changed

+438
-519
lines changed

crates/rspack_plugin_javascript/src/parser_plugin/amd/amd_define_dependency_parser_plugin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn lookup<'a>(parent: &str, module: &'a str) -> Cow<'a, str> {
9595
const REQUIRE: &str = "require";
9696
const MODULE: &str = "module";
9797
const EXPORTS: &str = "exports";
98-
const RESERVED_NAMES: [&str; 3] = [REQUIRE, MODULE, EXPORTS];
98+
const RESERVED_NAMES: [&str; 3] = [REQUIRE, EXPORTS, MODULE];
9999

100100
fn get_lit_str(expr: &Expr) -> Option<Atom> {
101101
expr.as_lit().and_then(|lit| match lit {
@@ -124,9 +124,9 @@ impl AMDDefineDependencyParserPlugin {
124124
let items = param.items();
125125
for (idx, item) in items.iter().enumerate() {
126126
if item.is_string() {
127-
let item = item.string();
128-
if let Some(i) = RESERVED_NAMES.iter().position(|s| s == item) {
129-
identifiers.insert(idx, RESERVED_NAMES[i].into());
127+
let item = item.string().as_str();
128+
if RESERVED_NAMES.contains(&item) {
129+
identifiers.insert(idx, item.into());
130130
}
131131
}
132132
let result = self.process_item(parser, call_expr, item, named_module);

0 commit comments

Comments
 (0)