Skip to content

Commit bc81ea4

Browse files
Copilotsapphi-red
andcommitted
revert(parser): remove RParen from trailing comment exclusion and add documentation
Co-authored-by: sapphi-red <[email protected]>
1 parent 1d5e8a9 commit bc81ea4

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

crates/oxc_codegen/tests/integration/comments.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ catch (err) /* v8 ignore next */ { console.error(err); }",
187187
// Multiple comments between catch param and body
188188
"try { something(); }
189189
catch (err) /* c8 ignore next */ /* istanbul ignore next */ { handle(err); }",
190-
// Line comment between catch param and body
190+
// Line comment between catch param and body.
191+
// NOTE: Line comments after `)` are classified as trailing comments by the parser,
192+
// so they are not preserved. Use block comments instead.
193+
// See: https://github.com/oxc-project/oxc/pull/16167#discussion_r2567604139
191194
"try { something(); }
192195
catch (err) // v8 ignore next
193196
{ handle(err); }",

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ catch (err) // v8 ignore next
137137
----------
138138
try {
139139
something();
140-
} catch (err) // v8 ignore next
141-
{
140+
} catch (err) {
142141
handle(err);
143142
}
144143

crates/oxc_parser/src/lexer/trivia_builder.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,9 @@ 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-
/// { ... }
121118
/// ```
122119
fn should_be_treated_as_trailing_comment(&self) -> bool {
123-
!self.saw_newline && !matches!(self.previous_kind, Kind::Eq | Kind::LParen | Kind::RParen)
120+
!self.saw_newline && !matches!(self.previous_kind, Kind::Eq | Kind::LParen)
124121
}
125122

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

0 commit comments

Comments
 (0)