fix(codegen): do not print comments when --minify

This commit is contained in:
Boshen 2024-08-24 13:49:34 +08:00
parent 0410314278
commit 7b1546bb66
No known key found for this signature in database
GPG key ID: 67715A371E534061
2 changed files with 6 additions and 2 deletions

View file

@ -50,7 +50,7 @@ impl<'a> Codegen<'a> {
&mut self,
node_start: u32,
) -> Vec<AnnotationComment> {
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();

View file

@ -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.