-
-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use
BasicEvaluatedExpression
(#4854)
- Loading branch information
Showing
16 changed files
with
513 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
crates/rspack_plugin_javascript/src/dependency/commonjs/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
mod common_js_exports_dependency; | ||
mod common_js_require_dependency; | ||
// mod common_js | ||
mod module_decorator_dependency; | ||
mod require_header_dependency; | ||
mod require_resolve_dependency; | ||
|
||
pub use common_js_exports_dependency::CommonJsExportsDependency; | ||
pub use common_js_exports_dependency::ExportsBase; | ||
pub use common_js_require_dependency::CommonJsRequireDependency; | ||
mod require_resolve_dependency; | ||
pub use require_resolve_dependency::RequireResolveDependency; | ||
mod module_decorator_dependency; | ||
pub use module_decorator_dependency::ModuleDecoratorDependency; | ||
pub use require_header_dependency::RequireHeaderDependency; | ||
pub use require_resolve_dependency::RequireResolveDependency; |
52 changes: 52 additions & 0 deletions
52
crates/rspack_plugin_javascript/src/dependency/commonjs/require_header_dependency.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use rspack_core::{AsContextDependency, AsModuleDependency, Dependency}; | ||
use rspack_core::{DependencyId, DependencyLocation}; | ||
use rspack_core::{DependencyTemplate, RuntimeGlobals, TemplateContext}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct RequireHeaderDependency { | ||
id: DependencyId, | ||
loc: DependencyLocation, | ||
} | ||
|
||
impl RequireHeaderDependency { | ||
pub fn new(start: u32, end: u32) -> Self { | ||
let loc = DependencyLocation::new(start, end); | ||
Self { | ||
id: DependencyId::new(), | ||
loc, | ||
} | ||
} | ||
} | ||
|
||
impl Dependency for RequireHeaderDependency { | ||
fn dependency_debug_name(&self) -> &'static str { | ||
"RequireHeaderDependency" | ||
} | ||
|
||
fn id(&self) -> &DependencyId { | ||
&self.id | ||
} | ||
} | ||
|
||
impl AsModuleDependency for RequireHeaderDependency {} | ||
impl AsContextDependency for RequireHeaderDependency {} | ||
|
||
impl DependencyTemplate for RequireHeaderDependency { | ||
fn apply( | ||
&self, | ||
source: &mut rspack_core::TemplateReplaceSource, | ||
code_generatable_context: &mut rspack_core::TemplateContext, | ||
) { | ||
let TemplateContext { | ||
runtime_requirements, | ||
.. | ||
} = code_generatable_context; | ||
runtime_requirements.insert(RuntimeGlobals::REQUIRE); | ||
source.replace( | ||
self.loc.start(), | ||
self.loc.end() - 1, | ||
RuntimeGlobals::REQUIRE.name(), | ||
None, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.