-
-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
276 additions
and
237 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
61 changes: 61 additions & 0 deletions
61
crates/rspack_plugin_javascript/src/visitors/dependency/parser/call_hooks_name.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,61 @@ | ||
use swc_core::atoms::Atom; | ||
|
||
use super::{ExportedVariableInfo, JavascriptParser}; | ||
use crate::visitors::scope_info::{FreeName, VariableInfo}; | ||
|
||
/// callHooksForName/callHooksForInfo in webpack | ||
/// webpack use HookMap and filter at callHooksForName/callHooksForInfo | ||
/// we need to pass the name to hook to filter in the hook | ||
pub trait CallHooksName { | ||
fn call_hooks_name(&self, parser: &mut JavascriptParser) -> Option<String>; | ||
} | ||
|
||
impl CallHooksName for &str { | ||
fn call_hooks_name(&self, parser: &mut JavascriptParser) -> Option<String> { | ||
if let Some(info) = parser.get_variable_info(self.as_ref()) { | ||
call_hooks_info(info) | ||
} else { | ||
Some(self.to_string()) | ||
} | ||
} | ||
} | ||
|
||
impl CallHooksName for String { | ||
fn call_hooks_name(&self, parser: &mut JavascriptParser) -> Option<String> { | ||
self.as_str().call_hooks_name(parser) | ||
} | ||
} | ||
|
||
impl CallHooksName for Atom { | ||
fn call_hooks_name(&self, parser: &mut JavascriptParser) -> Option<String> { | ||
self.as_str().call_hooks_name(parser) | ||
} | ||
} | ||
|
||
impl CallHooksName for VariableInfo { | ||
fn call_hooks_name(&self, _parser: &mut JavascriptParser) -> Option<String> { | ||
call_hooks_info(self) | ||
} | ||
} | ||
|
||
impl CallHooksName for ExportedVariableInfo { | ||
fn call_hooks_name(&self, parser: &mut JavascriptParser) -> Option<String> { | ||
match self { | ||
ExportedVariableInfo::Name(n) => n.call_hooks_name(parser), | ||
ExportedVariableInfo::VariableInfo(v) => { | ||
let info = parser.definitions_db.expect_get_variable(v); | ||
call_hooks_info(info) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn call_hooks_info(info: &VariableInfo) -> Option<String> { | ||
// TODO: tag_info with hooks | ||
if let Some(FreeName::String(free_name)) = &info.free_name { | ||
Some(free_name.to_string()) | ||
} else { | ||
// should run `defined ? defined() : None` | ||
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.