Skip to content

@babel/plugin-syntax-typescript generates illegal typescript code #17152

@jzhan-canva

Description

@jzhan-canva

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

const source = `
      abstract class Foo extends FooBase {
        abstract override bar(): any;
      }
    `;
    const result = babel.transformSync(source, {
      plugins: [require.resolve('@babel/plugin-syntax-typescript')],
    });
    if (result) {
      console.log(result.code);
    }

Configuration file name

No response

Configuration

No response

Current and expected behavior

Current output:

  abstract class Foo extends FooBase {
    override abstract bar(): any;
  }

It's illegal to put override before abstract

Expected output:

  abstract class Foo extends FooBase {
    abstract override bar(): any;
  }

Environment

"@babel/core": "^7.17.10",
"@babel/plugin-syntax-typescript": "^7.25.9",

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: generator

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions