feat(codegen): always print legal comments on its own line (#7089)

This commit is contained in:
Boshen 2024-11-02 15:55:23 +08:00 committed by GitHub
parent a8dc75d6ba
commit 001058a8e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 3 deletions

View file

@ -190,9 +190,13 @@ impl<'a> Codegen<'a> {
}
for (i, comment) in comments.iter().enumerate() {
if i >= 1 && comment.preceded_by_newline {
self.print_hard_newline();
self.print_indent();
if i >= 1 {
if comment.preceded_by_newline {
self.print_hard_newline();
self.print_indent();
} else if comment.is_legal(self.source_text) {
self.print_hard_newline();
}
}
self.print_comment(comment);

View file

@ -8,6 +8,7 @@ fn cases() -> Vec<&'static str> {
"/* @license */\n/* @preserve */\nfoo;bar;",
"/* @license */\n//! KEEP\nfoo;bar;",
"/* @license */\n/*! KEEP */\nfoo;bar;",
"/* @license *//*! KEEP */\nfoo;bar;",
]
}

View file

@ -1,5 +1,6 @@
---
source: crates/oxc_codegen/tests/integration/main.rs
snapshot_kind: text
---
########## 0
/* @license */
@ -40,3 +41,12 @@ foo;
bar;
/* @license */
/*! KEEP */
########## 4
/* @license *//*! KEEP */
foo;bar;
----------
foo;
bar;
/* @license */
/*! KEEP */

View file

@ -1,5 +1,6 @@
---
source: crates/oxc_codegen/tests/integration/main.rs
snapshot_kind: text
---
########## 0
/* @license */
@ -40,3 +41,12 @@ foo;bar;
/*! KEEP */
foo;
bar;
########## 4
/* @license *//*! KEEP */
foo;bar;
----------
/* @license */
/*! KEEP */
foo;
bar;

View file

@ -1,5 +1,6 @@
---
source: crates/oxc_codegen/tests/integration/main.rs
snapshot_kind: text
---
########## 0
/* @license */
@ -33,3 +34,10 @@ foo;bar;
foo;
bar;
/*! For license information please see test.js */
########## 4
/* @license *//*! KEEP */
foo;bar;
----------
foo;
bar;
/*! For license information please see test.js */