From 7b1546bb66085dfe680b99e64410f6cd0278cb48 Mon Sep 17 00:00:00 2001 From: Boshen Date: Sat, 24 Aug 2024 13:49:34 +0800 Subject: [PATCH] fix(codegen): do not print comments when `--minify` --- crates/oxc_codegen/src/annotation_comment.rs | 4 ++-- crates/oxc_codegen/src/lib.rs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/oxc_codegen/src/annotation_comment.rs b/crates/oxc_codegen/src/annotation_comment.rs index 048bb5b06..e42cd70f4 100644 --- a/crates/oxc_codegen/src/annotation_comment.rs +++ b/crates/oxc_codegen/src/annotation_comment.rs @@ -50,7 +50,7 @@ impl<'a> Codegen<'a> { &mut self, node_start: u32, ) -> Vec { - if !self.comment_options.preserve_annotate_comments { + if !self.preserve_annotate_comments() { return vec![]; } let mut latest_comment_start = node_start; @@ -127,7 +127,7 @@ impl<'a> Codegen<'a> { } pub(crate) fn gen_comments(&mut self, node_start: u32) { - if !self.comment_options.preserve_annotate_comments { + if !self.preserve_annotate_comments() { return; } let mut annotation_kind_set = AnnotationKind::empty(); diff --git a/crates/oxc_codegen/src/lib.rs b/crates/oxc_codegen/src/lib.rs index 36072583d..333a94c7c 100644 --- a/crates/oxc_codegen/src/lib.rs +++ b/crates/oxc_codegen/src/lib.rs @@ -519,6 +519,10 @@ impl<'a> Codegen<'a> { // Comment related impl<'a> Codegen<'a> { + fn preserve_annotate_comments(&self) -> bool { + self.comment_options.preserve_annotate_comments && !self.options.minify + } + /// Avoid issue related to rustc borrow checker . /// Since if you want to print a range of source code, you need to borrow the source code /// as immutable first, and call the [Self::print_str] which is a mutable borrow.