File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
crates/rspack_plugin_javascript/src/parser_and_generator Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 1- use std:: { borrow:: Cow , sync:: Arc } ;
1+ use std:: {
2+ borrow:: Cow ,
3+ sync:: { Arc , LazyLock } ,
4+ } ;
25
36use regex:: Regex ;
47use rspack_cacheable:: { cacheable, cacheable_dyn, with:: Skip } ;
@@ -45,9 +48,13 @@ pub struct ParserRuntimeRequirementsData {
4548 pub module : String ,
4649 pub exports : String ,
4750 pub require : String ,
48- pub require_regex : Regex ,
51+ pub require_regex : & ' static LazyLock < Regex > ,
4952}
5053
54+ static LEGACY_REQUIRE_REGEX : LazyLock < Regex > = LazyLock :: new ( || {
55+ Regex :: new ( "__webpack_require__\\ s*(!?\\ .)" ) . expect ( "should init `REQUIRE_FUNCTION_REGEX`" )
56+ } ) ;
57+
5158impl ParserRuntimeRequirementsData {
5259 pub fn new ( runtime_template : & ModuleCodegenRuntimeTemplate ) -> Self {
5360 let require_name =
@@ -57,8 +64,7 @@ impl ParserRuntimeRequirementsData {
5764 let exports_name =
5865 runtime_template. render_runtime_globals_without_adding ( & RuntimeGlobals :: EXPORTS ) ;
5966 Self {
60- require_regex : Regex :: new ( & format ! ( "{}\\ s*(!?\\ .)" , & require_name) )
61- . expect ( "should init `REQUIRE_FUNCTION_REGEX`" ) ,
67+ require_regex : & LEGACY_REQUIRE_REGEX ,
6268 module : module_name,
6369 exports : exports_name,
6470 require : require_name,
You can’t perform that action at this time.
0 commit comments