mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(minifier): do not fold 0 && (module.exports = {}) for cjs-module-lexer (#4878)
This commit is contained in:
parent
48a1c32ed3
commit
81fd6379e8
2 changed files with 14 additions and 0 deletions
|
|
@ -592,7 +592,19 @@ impl<'a> FoldConstants<'a> {
|
||||||
if !matches!(op, LogicalOperator::And | LogicalOperator::Or) {
|
if !matches!(op, LogicalOperator::And | LogicalOperator::Or) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(boolean_value) = ctx.get_boolean_value(&logical_expr.left) {
|
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)
|
// (TRUE || x) => TRUE (also, (3 || x) => 3)
|
||||||
// (FALSE && x) => FALSE
|
// (FALSE && x) => FALSE
|
||||||
if (boolean_value && op == LogicalOperator::Or)
|
if (boolean_value && op == LogicalOperator::Or)
|
||||||
|
|
|
||||||
|
|
@ -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
|
#[test] // https://github.com/oxc-project/oxc/issues/4341
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue