Skip to content

Commit 4ec6bfc

Browse files
committed
fix(amd_require_dependency): generate correct code for require([deps])
chore: add more test cases for amd require
1 parent 37a736d commit 4ec6bfc

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

crates/rspack_plugin_javascript/src/dependency/amd/amd_require_dependency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl DependencyTemplate for AMDRequireDependency {
8181
{
8282
let start_block = promise + ".then(function() {";
8383
let end_block = format!(
84-
";}})['catch']{}",
84+
";}})['catch']({})",
8585
RuntimeGlobals::UNCAUGHT_ERROR_HANDLER.name()
8686
);
8787
code_generatable_context
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import fn from './fn';
2+
3+
fn(123);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
module.exports = jest.fn();

packages/rspack-test-tools/tests/configCases/amd/require/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
it("require([...]) should work well", async function () {
2+
const p = require(['./dep']);
3+
expect(p).toBeInstanceOf(Promise);
4+
5+
await p;
6+
7+
expect(require('./fn')).toHaveBeenCalledWith(123);
8+
});
19

210
it("require([...], function () {}) should work well", function (done) {
311
require(['./add'], function (add) {

0 commit comments

Comments
 (0)