From 435f74bfd3b5e971bfeb931090a7684f35502487 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Tue, 24 Oct 2023 16:07:58 +0800 Subject: [PATCH] fix --- .../visitors/dependency/common_js_export_scanner.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs index ac6f55cc334..5c053180af6 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs @@ -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); } @@ -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; @@ -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; @@ -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();