1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::prelude::*;
use biome_formatter::{FormatOwnedWithRule, FormatRefWithRule};

use crate::{AsFormat, IntoFormat, JsFormatContext};
use biome_js_syntax::{map_syntax_node, JsSyntaxNode};

#[derive(Debug, Copy, Clone, Default)]
pub struct FormatJsSyntaxNode;

impl biome_formatter::FormatRule<JsSyntaxNode> for FormatJsSyntaxNode {
    type Context = JsFormatContext;

    fn fmt(&self, node: &JsSyntaxNode, f: &mut JsFormatter) -> FormatResult<()> {
        map_syntax_node!(node.clone(), node => node.format().fmt(f))
    }
}

impl AsFormat<JsFormatContext> for JsSyntaxNode {
    type Format<'a> = FormatRefWithRule<'a, JsSyntaxNode, FormatJsSyntaxNode>;

    fn format(&self) -> Self::Format<'_> {
        FormatRefWithRule::new(self, FormatJsSyntaxNode)
    }
}

impl IntoFormat<JsFormatContext> for JsSyntaxNode {
    type Format = FormatOwnedWithRule<JsSyntaxNode, FormatJsSyntaxNode>;

    fn into_format(self) -> Self::Format {
        FormatOwnedWithRule::new(self, FormatJsSyntaxNode)
    }
}