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)]
    /// 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);

        if self.tsx {

Review comment (suggestion):
[nitpick] The documentation comment format is inconsistent with the detailed comment added for the same field in `EsSyntax` (lines 240-243). Consider using the same multi-line format here:

```rust
/// 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,
```

This provides better clarity and maintains consistency across the codebase.

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);