Skip to content

Commit 66c5e0d

Browse files
authored
revert: fix: align amd option behavior with webpack (#9103)
1 parent 9df4956 commit 66c5e0d

88 files changed

Lines changed: 218 additions & 145 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,6 @@ impl AMDDefineDependencyParserPlugin {
289289
}
290290
} else {
291291
// define([…], …)
292-
if !first_arg.expr.is_array() {
293-
return None;
294-
}
295-
296292
array = Some(&first_arg.expr);
297293

298294
if is_callable(&second_arg.expr) {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ impl JavascriptParserPlugin for AMDParserPlugin {
141141
None
142142
}
143143

144+
fn identifier(
145+
&self,
146+
parser: &mut JavascriptParser,
147+
ident: &swc_core::ecma::ast::Ident,
148+
for_name: &str,
149+
) -> Option<bool> {
150+
if for_name == DEFINE {
151+
parser
152+
.presentational_dependencies
153+
.push(Box::new(ConstDependency::new(
154+
ident.span().real_lo(),
155+
ident.span().real_hi(),
156+
RuntimeGlobals::AMD_DEFINE.name().into(),
157+
Some(RuntimeGlobals::AMD_DEFINE),
158+
)));
159+
return Some(true);
160+
}
161+
None
162+
}
163+
144164
fn evaluate_identifier(
145165
&self,
146166
_parser: &mut JavascriptParser,

packages/rspack-test-tools/tests/normalCases/amd/define-function/index.js renamed to packages/rspack-test-tools/tests/configCases/amd/define-function/index.js

File renamed without changes.

packages/rspack-test-tools/tests/normalCases/amd/define-function/lib.js renamed to packages/rspack-test-tools/tests/configCases/amd/define-function/lib.js

File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import("@rspack/core").Configuration} */
2+
module.exports = {
3+
amd: {},
4+
};

packages/rspack-test-tools/tests/normalCases/amd/define-object/index.js renamed to packages/rspack-test-tools/tests/configCases/amd/define-object/index.js

File renamed without changes.

packages/rspack-test-tools/tests/normalCases/amd/define-object/lib.js renamed to packages/rspack-test-tools/tests/configCases/amd/define-object/lib.js

File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import("@rspack/core").Configuration} */
2+
module.exports = {
3+
amd: {},
4+
};

packages/rspack-test-tools/tests/normalCases/amd/define-others/hello.js renamed to packages/rspack-test-tools/tests/configCases/amd/define-others/hello.js

File renamed without changes.

packages/rspack-test-tools/tests/normalCases/amd/define-others/index.js renamed to packages/rspack-test-tools/tests/configCases/amd/define-others/index.js

File renamed without changes.

0 commit comments

Comments
 (0)