From 20a4a8ccd5dcd059dc176a926570447240695ee4 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 19 May 2025 11:44:09 +0000 Subject: [PATCH] refactor(ast): shorten `CommentNewlines` methods (#11152) Follow-on after #11096. Pure refactor. Shorten the setter methods. Also move them to after the getters and in same order. --- crates/oxc_ast/src/ast/comment.rs | 32 ++++++++++++------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/crates/oxc_ast/src/ast/comment.rs b/crates/oxc_ast/src/ast/comment.rs index f3edd2cfe5e0c..0b47c39420926 100644 --- a/crates/oxc_ast/src/ast/comment.rs +++ b/crates/oxc_ast/src/ast/comment.rs @@ -249,26 +249,6 @@ impl Comment { self.annotation == CommentAnnotation::CoverageIgnore && self.is_leading() } - /// Sets the state of `newlines` to include/exclude a newline after the comment. - #[inline] - pub fn set_followed_by_newline(&mut self, followed_by_newline: bool) { - if followed_by_newline { - self.newlines.insert(CommentNewlines::Trailing); - } else { - self.newlines.remove(CommentNewlines::Trailing); - } - } - - /// Sets the state of `newlines` to include/exclude a newline before the comment. - #[inline] - pub fn set_preceded_by_newline(&mut self, preceded_by_newline: bool) { - if preceded_by_newline { - self.newlines.insert(CommentNewlines::Leading); - } else { - self.newlines.remove(CommentNewlines::Leading); - } - } - /// Returns `true` if this comment is preceded by a newline. #[inline] pub fn preceded_by_newline(self) -> bool { @@ -280,4 +260,16 @@ impl Comment { pub fn followed_by_newline(self) -> bool { self.newlines.contains(CommentNewlines::Trailing) } + + /// Sets the state of `newlines` to include/exclude a newline before the comment. + #[inline] + pub fn set_preceded_by_newline(&mut self, preceded_by_newline: bool) { + self.newlines.set(CommentNewlines::Leading, preceded_by_newline); + } + + /// Sets the state of `newlines` to include/exclude a newline after the comment. + #[inline] + pub fn set_followed_by_newline(&mut self, followed_by_newline: bool) { + self.newlines.set(CommentNewlines::Trailing, followed_by_newline); + } }