diff --git a/crates/oxc_minifier/src/ast_passes/fold_constants.rs b/crates/oxc_minifier/src/ast_passes/fold_constants.rs index 77473b41d77c9..7d9ae9c153b16 100644 --- a/crates/oxc_minifier/src/ast_passes/fold_constants.rs +++ b/crates/oxc_minifier/src/ast_passes/fold_constants.rs @@ -98,6 +98,9 @@ impl<'a> FoldConstants<'a> { let Expression::ConditionalExpression(conditional_expr) = expr else { return; }; + if ctx.ancestry.parent().is_tagged_template_expression() { + return; + } match self.fold_expression_and_get_boolean_value(&mut conditional_expr.test, ctx) { Some(true) => { *expr = self.ast.move_expression(&mut conditional_expr.consequent); @@ -582,6 +585,9 @@ impl<'a> FoldConstants<'a> { logical_expr: &mut LogicalExpression<'a>, ctx: &mut TraverseCtx<'a>, ) -> Option> { + if ctx.ancestry.parent().is_tagged_template_expression() { + return None; + } let op = logical_expr.operator; if !matches!(op, LogicalOperator::And | LogicalOperator::Or) { return None; diff --git a/crates/oxc_minifier/tests/ast_passes/fold_constants.rs b/crates/oxc_minifier/tests/ast_passes/fold_constants.rs index f79c8863b7195..1e0ab58742a17 100644 --- a/crates/oxc_minifier/tests/ast_passes/fold_constants.rs +++ b/crates/oxc_minifier/tests/ast_passes/fold_constants.rs @@ -31,6 +31,18 @@ fn cjs() { ); } +#[test] // https://github.com/oxc-project/oxc/issues/4341 +fn tagged_template() { + test_same("(1, o.f)()"); + test_same("(1, o.f)``"); + + test("(true && o.f)()", "o.f()"); + test_same("(true && o.f)``"); + + test("(true ? o.f : false)()", "o.f()"); + test_same("(true ? o.f : false)``"); +} + // Google Closure Compiler #[test]