mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(minifier): temporarily bail constant folding for tagged template (#4842)
closes #4341
This commit is contained in:
parent
e1ce17f0d8
commit
fae8a62a62
2 changed files with 18 additions and 0 deletions
|
|
@ -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<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;
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in a new issue