Skip to content

Commit

Permalink
fix: Add missing code for compatibility plugin (#7079)
Browse files Browse the repository at this point in the history
* Add missing code for compatibility plugin

* Add testcase
  • Loading branch information
CPunisher authored Jul 9, 2024
1 parent b37692f commit 81b26f8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ impl JavascriptParserPlugin for CompatibilityPlugin {
}),
);
return Some(true);
} else if for_name == RuntimeGlobals::REQUIRE.name() {
let low = ident.span().lo().0;
let hi = ident.span().hi().0;
parser.tag_variable(
ident.sym.to_string(),
NESTED_WEBPACK_IDENTIFIER_TAG,
Some(NestedRequireData {
name: format!("__nested_webpack_require_{low}_{hi}__"),
update: false,
loc: DependencyLocation::new(
ident.span().real_lo(),
ident.span().real_hi(),
Some(parser.source_map.clone()),
),
}),
);
return Some(true);
}
None
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function f(__webpack_require__) {
require('./b.js');
return __webpack_require__ + 1
}

module.exports = f;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "b"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
it("compatibility plugin", async () => {
const f = require("./a.js");
expect(f(1)).toBe(2);
});

2 comments on commit 81b26f8

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ✅ success
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-07-09 f2bc023) Current Change
10000_development-mode + exec 2.18 s ± 17 ms 2.16 s ± 17 ms -0.99 %
10000_development-mode_hmr + exec 688 ms ± 7.5 ms 691 ms ± 5.4 ms +0.40 %
10000_production-mode + exec 2.81 s ± 26 ms 2.77 s ± 24 ms -1.14 %
arco-pro_development-mode + exec 1.91 s ± 55 ms 1.9 s ± 63 ms -0.61 %
arco-pro_development-mode_hmr + exec 433 ms ± 1.8 ms 433 ms ± 1.5 ms -0.08 %
arco-pro_production-mode + exec 3.46 s ± 90 ms 3.4 s ± 78 ms -1.77 %
threejs_development-mode_10x + exec 1.57 s ± 16 ms 1.57 s ± 16 ms -0.18 %
threejs_development-mode_10x_hmr + exec 795 ms ± 8.4 ms 797 ms ± 8.7 ms +0.35 %
threejs_production-mode_10x + exec 5.58 s ± 22 ms 5.58 s ± 29 ms +0.04 %

Please sign in to comment.