Skip to content

Commit db76b56

Browse files
committed
fix(minifier): preserve outer paren start when unwrapping SequenceExpression
1 parent d97b033 commit db76b56

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

crates/oxc_minifier/src/peephole/normalize.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use oxc_ecmascript::{
66
side_effects::is_valid_regexp,
77
};
88
use oxc_semantic::IsGlobalReference;
9+
use oxc_span::GetSpanMut;
910
use oxc_syntax::scope::ScopeFlags;
1011

1112
use crate::{ReusableTraverseCtx, Traverse, TraverseCtx, minifier_traverse::traverse_mut_with_ctx};
@@ -86,7 +87,18 @@ impl<'a> Traverse<'a> for Normalize {
8687

8788
fn exit_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {
8889
if let Expression::ParenthesizedExpression(paren_expr) = expr {
90+
let outer_start = paren_expr.span.start;
91+
let is_sequence = matches!(&paren_expr.expression, Expression::SequenceExpression(_));
8992
*expr = paren_expr.expression.take_in(ctx.ast);
93+
// For `SequenceExpression`, the surrounding parens are syntactically required
94+
// when re-emitted in expression context, so any comments attached to the outer
95+
// `(` should remain reachable via the inner expression's span.
96+
if is_sequence {
97+
let span = expr.span_mut();
98+
if outer_start < span.start {
99+
span.start = outer_start;
100+
}
101+
}
90102
}
91103
if let Some(e) = match expr {
92104
Expression::Identifier(ident) => Self::try_compress_identifier(ident, ctx),

tasks/coverage/snapshots/minifier_test262.snap

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ commit: ff0d1611
22

33
minifier_test262 Summary:
44
AST Parsed : 44642/44642 (100.00%)
5-
Positive Passed: 44632/44642 (99.98%)
6-
Compress: tasks/coverage/test262/test/built-ins/Array/prototype/forEach/15.4.4.18-7-c-ii-5.js
7-
8-
Compress: tasks/coverage/test262/test/built-ins/Array/prototype/reduce/15.4.4.21-9-c-ii-5.js
9-
10-
Compress: tasks/coverage/test262/test/built-ins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-5.js
11-
5+
Positive Passed: 44635/44642 (99.98%)
126
Compress: tasks/coverage/test262/test/intl402/Temporal/PlainDate/prototype/toLocaleString/lone-options-accepted.js
137

148
Compress: tasks/coverage/test262/test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/lone-options-accepted.js

0 commit comments

Comments
 (0)