Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Oct 24, 2023
1 parent bd01e6c commit 435f74b
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ impl Visit for CommonJsExportDependencyScanner<'_> {
// ...
if self.is_exports_or_module_exports_or_this_expr(expr) {
self.bailout();
return;
}
expr.visit_children_with(self);
}
Expand All @@ -121,7 +120,7 @@ impl Visit for CommonJsExportDependencyScanner<'_> {
// const flagIt = () => { exports.__esModule = true }; => stmt_level = 2, last_stmt_is_expr_stmt = true
// (exports.__esModule = true); => stmt_level = 1, last_stmt_is_expr_stmt = true
self.stmt_level == 1 && self.last_stmt_is_expr_stmt,
&assign_expr.right,
Some(&assign_expr.right),
);
assign_expr.right.visit_children_with(self);
return;
Expand Down Expand Up @@ -165,9 +164,8 @@ impl Visit for CommonJsExportDependencyScanner<'_> {
self.enable();

if let Some(ExprOrSpread { expr: box Expr::Lit(Lit::Str(str)), .. }) = call_expr.args.get(1)
&& &str.value == "__esModule"
&& let Some(value) = get_value_of_property_description(arg2) {
self.check_namespace(self.stmt_level == 1, value);
&& str.value == "__esModule" {
self.check_namespace(self.stmt_level == 1, get_value_of_property_description(arg2));
}

self.enter_call += 1;
Expand Down Expand Up @@ -213,11 +211,11 @@ impl<'a> CommonJsExportDependencyScanner<'a> {
matches!(expr, Expr::Ident(ident) if &ident.sym == "exports" && ident.span.ctxt == *self.unresolved_ctxt)
}

fn check_namespace(&mut self, top_level: bool, value_expr: &Expr) {
fn check_namespace(&mut self, top_level: bool, value_expr: Option<&Expr>) {
if matches!(self.parser_exports_state, Some(false)) || self.parser_exports_state.is_none() {
return;
}
if is_truthy_literal(value_expr) && top_level {
if let Some(value_expr) = value_expr && is_truthy_literal(value_expr) && top_level {
self.set_flagged();
} else {
self.set_dynamic();
Expand Down

0 comments on commit 435f74b

Please sign in to comment.