Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(minifier): temporarily bail constant folding for tagged template #4842

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/oxc_minifier/src/ast_passes/fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -582,6 +585,9 @@ impl<'a> FoldConstants<'a> {
logical_expr: &mut LogicalExpression<'a>,
ctx: &mut TraverseCtx<'a>,
) -> Option<Expression<'a>> {
if ctx.ancestry.parent().is_tagged_template_expression() {
return None;
}
let op = logical_expr.operator;
if !matches!(op, LogicalOperator::And | LogicalOperator::Or) {
return None;
Expand Down
12 changes: 12 additions & 0 deletions crates/oxc_minifier/tests/ast_passes/fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down