Skip to content

[Bug]: Incorrect parantases removal for TSAsExpression on the lhs #16676

Closed
@nicojs

Description

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

import { parseAsync } from "@babel/core";
import generator from "@babel/generator";
const ast = await parseAsync(
  "(key as any) = value",
  {
    filename: "main.ts",
    presets: [
      [
        "@babel/preset-typescript",
        { isTSX: false, allExtensions: true },
      ],
    ],
  }
);

if (!ast) {
  throw new Error("no ast");
}

const out = generator.default(ast, { sourceMaps: false }).code;
console.log(out);

Configuration file name

No response

Configuration

none

Current and expected behavior

Expected output: (key as any) = value
Actual output: key as any = value.

Note that the actual output is invalid TypeScript

image

Environment

    "@babel/core": "7.24.9",
    "@babel/generator": "7.24.10",
    "@babel/preset-typescript": "7.24.7"

Possible solution

No response

Additional context

No response

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions