-
-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(js_syntax): add
TsDeclarationModule
node
- Loading branch information
Showing
22 changed files
with
419 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
crates/biome_js_formatter/src/ts/auxiliary/declaration_module.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::prelude::*; | ||
use biome_formatter::write; | ||
|
||
use crate::utils::FormatInterpreterToken; | ||
|
||
use biome_js_syntax::{TsDeclarationModule, TsDeclarationModuleFields}; | ||
use biome_rowan::AstNode; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatTsDeclarationModule; | ||
impl FormatNodeRule<TsDeclarationModule> for FormatTsDeclarationModule { | ||
fn fmt_fields(&self, node: &TsDeclarationModule, f: &mut JsFormatter) -> FormatResult<()> { | ||
let TsDeclarationModuleFields { | ||
bom_token, | ||
interpreter_token, | ||
directives, | ||
items, | ||
eof_token, | ||
} = node.as_fields(); | ||
|
||
write![ | ||
f, | ||
[ | ||
bom_token.format(), | ||
FormatInterpreterToken::new(interpreter_token.as_ref()), | ||
format_leading_comments(node.syntax()), | ||
directives.format() | ||
] | ||
]?; | ||
|
||
write!( | ||
f, | ||
[ | ||
items.format(), | ||
format_trailing_comments(node.syntax()), | ||
format_removed(&eof_token?), | ||
hard_line_break() | ||
] | ||
) | ||
} | ||
|
||
fn fmt_leading_comments( | ||
&self, | ||
_: &TsDeclarationModule, | ||
_: &mut JsFormatter, | ||
) -> FormatResult<()> { | ||
// Formatted as part of `fmt_fields` | ||
Ok(()) | ||
} | ||
|
||
fn fmt_dangling_comments( | ||
&self, | ||
module: &TsDeclarationModule, | ||
f: &mut JsFormatter, | ||
) -> FormatResult<()> { | ||
debug_assert!( | ||
!f.comments().has_dangling_comments(module.syntax()), | ||
"Module should never have dangling comments." | ||
); | ||
Ok(()) | ||
} | ||
|
||
fn fmt_trailing_comments( | ||
&self, | ||
_: &TsDeclarationModule, | ||
_: &mut JsFormatter, | ||
) -> FormatResult<()> { | ||
// Formatted as part of `fmt_fields` | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.