Repository: swc-project/swc
File: crates/swc_ecma_parser/src/syntax.rs (Rust)

Code before:
    }

    pub fn into_flags(self) -> SyntaxFlags {
        match self {
            Syntax::Es(es) => es.into_flags(),
            #[cfg(feature = "typescript")]
            Syntax::Typescript(ts) => ts.into_flags(),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TsSyntax {
    #[serde(default)]
    pub tsx: bool,

    #[serde(default)]
    pub decorators: bool,

    /// `.d.ts`
    #[serde(skip, default)]
    pub dts: bool,

    #[serde(default)]
    /// Unwrap parenthesized expression in parser
    pub no_paren: bool,

    #[serde(skip, default)]
    pub no_early_errors: bool,

    /// babel: `disallowAmbiguousJSXLike`
    /// Even when JSX parsing is not enabled, this option disallows using syntax
    /// that would be ambiguous with JSX (`<X> y` type assertions and
    /// `<X>()=>{}` type arguments)
    /// see: https://babeljs.io/docs/en/babel-plugin-transform-typescript#disallowambiguousjsxlike
    #[serde(skip, default)]
    pub disallow_ambiguous_jsx_like: bool,
}

impl TsSyntax {
    fn into_flags(self) -> SyntaxFlags {
        let mut flags = SyntaxFlags::TS
            .union(SyntaxFlags::AUTO_ACCESSORS)
            .union(SyntaxFlags::IMPORT_ATTRIBUTES)
            .union(SyntaxFlags::DECORATORS_BEFORE_EXPORT)
            .union(SyntaxFlags::ALLOW_SUPER_OUTSIDE_METHOD)
            .union(SyntaxFlags::EXPLICIT_RESOURCE_MANAGEMENT);

        if self.tsx {
            flags |= SyntaxFlags::JSX;

Review comment (suggestion):
[nitpick] The documentation comment could be more descriptive. Consider expanding it to clarify the behavior and relationship to the ESTree spec, for example: "When enabled, the parser will not create ParenExpr nodes for parenthesized expressions. Instead, it returns the inner expression directly. This aligns with the ESTree spec which does not have a ParenthesizedExpression type."
```suggestion
    /// When enabled, the parser will not create ParenExpr nodes for parenthesized expressions.
    /// Instead, it returns the inner expression directly. This aligns with the ESTree spec,
    /// which does not have a ParenthesizedExpression type.
```

Code after:
    }

    pub fn into_flags(self) -> SyntaxFlags {
        match self {
            Syntax::Es(es) => es.into_flags(),
            #[cfg(feature = "typescript")]
            Syntax::Typescript(ts) => ts.into_flags(),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TsSyntax {
    #[serde(default)]
    pub tsx: bool,

    #[serde(default)]
    pub decorators: bool,

    /// `.d.ts`
    #[serde(skip, default)]
    pub dts: bool,

    #[serde(default)]
    /// When enabled, the parser will not create ParenExpr nodes for
    /// parenthesized expressions. Instead, it returns the inner expression
    /// directly. This aligns with the ESTree spec, which does not have a
    /// ParenthesizedExpression type.
    pub no_paren: bool,

    #[serde(skip, default)]
    pub no_early_errors: bool,

    /// babel: `disallowAmbiguousJSXLike`
    /// Even when JSX parsing is not enabled, this option disallows using syntax
    /// that would be ambiguous with JSX (`<X> y` type assertions and
    /// `<X>()=>{}` type arguments)
    /// see: https://babeljs.io/docs/en/babel-plugin-transform-typescript#disallowambiguousjsxlike
    #[serde(skip, default)]
    pub disallow_ambiguous_jsx_like: bool,
}

impl TsSyntax {
    fn into_flags(self) -> SyntaxFlags {
        let mut flags = SyntaxFlags::TS
            .union(SyntaxFlags::AUTO_ACCESSORS)
            .union(SyntaxFlags::IMPORT_ATTRIBUTES)
            .union(SyntaxFlags::DECORATORS_BEFORE_EXPORT)
            .union(SyntaxFlags::ALLOW_SUPER_OUTSIDE_METHOD)
            .union(SyntaxFlags::EXPLICIT_RESOURCE_MANAGEMENT);