diff --git a/crates/oxc_minifier/src/ast_passes/fold_constants.rs b/crates/oxc_minifier/src/ast_passes/fold_constants.rs index 7d9ae9c153b16..9e915a76ae00f 100644 --- a/crates/oxc_minifier/src/ast_passes/fold_constants.rs +++ b/crates/oxc_minifier/src/ast_passes/fold_constants.rs @@ -592,7 +592,19 @@ impl<'a> FoldConstants<'a> { if !matches!(op, LogicalOperator::And | LogicalOperator::Or) { return None; } + if let Some(boolean_value) = ctx.get_boolean_value(&logical_expr.left) { + // Bail `0 && (module.exports = {})` for `cjs-module-lexer`. + if !boolean_value { + if let Expression::AssignmentExpression(assign_expr) = &logical_expr.right { + if let Some(member_expr) = assign_expr.left.as_member_expression() { + if member_expr.is_specific_member_access("module", "exports") { + return None; + } + } + } + } + // (TRUE || x) => TRUE (also, (3 || x) => 3) // (FALSE && x) => FALSE if (boolean_value && op == LogicalOperator::Or) diff --git a/crates/oxc_minifier/tests/ast_passes/fold_constants.rs b/crates/oxc_minifier/tests/ast_passes/fold_constants.rs index 1e0ab58742a17..848e69d944505 100644 --- a/crates/oxc_minifier/tests/ast_passes/fold_constants.rs +++ b/crates/oxc_minifier/tests/ast_passes/fold_constants.rs @@ -29,6 +29,8 @@ fn cjs() { } });", ); + // Bail `cjs-module-lexer`. + test_same("0 && (module.exports = { version });"); } #[test] // https://github.com/oxc-project/oxc/issues/4341