Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed May 21, 2024
1 parent d96d817 commit 8e963c6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl JavascriptParserPlugin for ProviderPlugin {
let names = self.cached_names.get_or_init(|| {
let names = parser.compiler_options.builtins.provide.keys();
names
.map(|name| {
.flat_map(|name| {
let splitted: Vec<&str> = name.split('.').collect();
if !splitted.is_empty() {
(0..splitted.len() - 1)
Expand All @@ -50,11 +50,10 @@ impl JavascriptParserPlugin for ProviderPlugin {
vec![]
}
})
.flatten()
.collect::<Vec<_>>()
});

if names.iter().any(|l| &*l == str) {
if names.iter().any(|l| *l == str) {
return Some(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl<'parser> JavascriptParser<'parser> {

if module_type.is_js_auto() || module_type.is_js_dynamic() || module_type.is_js_esm() {
if !compiler_options.builtins.provide.is_empty() {
plugins.push(Box::new(parser_plugin::ProviderPlugin::default()));
plugins.push(Box::<parser_plugin::ProviderPlugin>::default());
}
plugins.push(Box::new(parser_plugin::WebpackIsIncludedPlugin));
plugins.push(Box::new(parser_plugin::ExportsInfoApiPlugin));
Expand Down Expand Up @@ -772,14 +772,14 @@ impl JavascriptParser<'_> {
// use `ident.sym` as fallback for global variable(or maybe just a undefined variable)
return drive
.evaluate_identifier(self, "this", this.span.real_lo(), this.span.hi.0)
.or_else(|| default_eval());
.or_else(default_eval);
};
if let Some(FreeName::String(name)) = info.free_name.as_ref() {
// avoid ownership
let name = name.to_string();
return drive
.evaluate_identifier(self, &name, this.span.real_lo(), this.span.hi.0)
.or_else(|| default_eval());
.or_else(default_eval);
}
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,12 @@ impl<'parser> JavascriptParser<'parser> {
let ident = param.as_ident().expect("should be a `BindingIdent`");
fn_params.push(ident);
if get_variable_info(self, &Expr::Ident(ident.id.clone())).is_none() {
scope_params.push(Cow::Borrowed(&param));
scope_params.push(Cow::Borrowed(param));
}
}
};
let variable_info_for_args = params
.map(|param| get_variable_name(self, &param))
.map(|param| get_variable_name(self, param))
.collect::<Vec<_>>();
if let Some(expr) = expr.as_fn_expr() {
if let Some(ident) = &expr.ident {
Expand Down Expand Up @@ -876,7 +876,7 @@ impl<'parser> JavascriptParser<'parser> {
&& is_simple_function(&fn_expr.function.params)
{
// (function(…) { }(…))
self._walk_iife(&**callee, expr.args.iter().map(|arg| &*arg.expr), None)
self._walk_iife(callee, expr.args.iter().map(|arg| &*arg.expr), None)
} else {
if let Expr::Member(member) = &**callee
&& let Some(MemberExpressionInfo::Call(expr_info)) =
Expand Down Expand Up @@ -1398,44 +1398,40 @@ fn get_variable_info<'p>(
parser: &'p mut JavascriptParser,
expr: &Expr,
) -> Option<&'p VariableInfo> {
if let Some(rename_identifier) = parser.get_rename_identifier(&expr)
if let Some(rename_identifier) = parser.get_rename_identifier(expr)
&& let drive = parser.plugin_drive.clone()
&& rename_identifier
.call_hooks_name(parser, |this, for_name| drive.can_rename(this, for_name))
.unwrap_or_default()
{
if !rename_identifier
.call_hooks_name(parser, |this, for_name| drive.rename(this, &expr, for_name))
&& !rename_identifier
.call_hooks_name(parser, |this, for_name| drive.rename(this, expr, for_name))
.unwrap_or_default()
{
return parser.get_variable_info(&rename_identifier);
}
{
return parser.get_variable_info(&rename_identifier);
}
return None;
None
}

fn get_variable_name(parser: &mut JavascriptParser, expr: &Expr) -> Option<String> {
if let Some(rename_identifier) = parser.get_rename_identifier(&expr)
if let Some(rename_identifier) = parser.get_rename_identifier(expr)
&& let drive = parser.plugin_drive.clone()
&& rename_identifier
.call_hooks_name(parser, |this, for_name| drive.can_rename(this, for_name))
.unwrap_or_default()
{
if !rename_identifier
.call_hooks_name(parser, |this, for_name| drive.rename(this, &expr, for_name))
&& !rename_identifier
.call_hooks_name(parser, |this, for_name| drive.rename(this, expr, for_name))
.unwrap_or_default()
{
let variable = parser
.get_variable_info(&rename_identifier)
.map(|info| info.free_name.as_ref())
.and_then(|free_name| free_name)
.and_then(|free_name| match free_name {
FreeName::String(s) => Some(s.to_string()),
FreeName::True => None,
})
.unwrap_or(rename_identifier);
return Some(variable);
}
}
return None;
{
let variable = parser
.get_variable_info(&rename_identifier)
.map(|info| info.free_name.as_ref())
.and_then(|free_name| free_name)
.and_then(|free_name| match free_name {
FreeName::String(s) => Some(s.to_string()),
FreeName::True => None,
})
.unwrap_or(rename_identifier);
return Some(variable);
}
None
}

0 comments on commit 8e963c6

Please sign in to comment.