Skip to content

Commit 1d5e8a9

Browse files
Copilotsapphi-red
andcommitted
fix(parser): treat line comments after ) as leading comments for catch clause support
Co-authored-by: sapphi-red <[email protected]>
1 parent e4d70d4 commit 1d5e8a9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

crates/oxc_codegen/tests/integration/snapshots/coverage.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ catch (err) // v8 ignore next
137137
----------
138138
try {
139139
something();
140-
} catch (err) {
140+
} catch (err) // v8 ignore next
141+
{
141142
handle(err);
142143
}
143144

crates/oxc_parser/src/lexer/trivia_builder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ impl TriviaBuilder {
115115
/// function foo( // This should not be treated as trailing (follows `(`)
116116
/// param
117117
/// ) {}
118+
///
119+
/// catch (err) // This should not be treated as trailing (follows `)`)
120+
/// { ... }
118121
/// ```
119122
fn should_be_treated_as_trailing_comment(&self) -> bool {
120-
!self.saw_newline && !matches!(self.previous_kind, Kind::Eq | Kind::LParen)
123+
!self.saw_newline && !matches!(self.previous_kind, Kind::Eq | Kind::LParen | Kind::RParen)
121124
}
122125

123126
fn add_comment(&mut self, mut comment: Comment, source_text: &str) {

0 commit comments

Comments
 (0)