mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 20:28:58 +00:00
feat(codegen): always print legal comments on its own line (#7089)
This commit is contained in:
parent
a8dc75d6ba
commit
001058a8e4
5 changed files with 36 additions and 3 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;",
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Reference in a new issue