Skip to content

[Bug]:generate() modified parentheses in array with type assertions  #15257

@mrgreenward

Description

@mrgreenward

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

import { parse } from "@babel/parser";
import generate from "@babel/generator";

const code = "onEdit([(point1 ?? point2) as Point, point3])";

const ast = parse(code, {
  plugins: ["typescript", "jsx"],
});

console.log(generate(ast, {}, code).code);

Configuration file name

No response

Configuration

  "devDependencies": {
    "@babel/generator": "^7.18.2",
    "@babel/parser": "^7.18.4",
    "@babel/traverse": "^7.18.2",
    "@babel/types": "^7.18.4",
    ....
  },

Current and expected behavior

Actual

onEdit([(point1 ?? point2 as Point), point3])

Expected

onEdit([(point1 ?? point2) as Point, point3])

Environment

System:
OS: macOS 12.2.1
Binaries:
Node: 18.12.1 - /usr/local/bin/node
Yarn: 3.3.0 - ~/node_modules/.bin/yarn
npm: 8.19.2 - /usr/local/bin/npm
Monorepos:
Yarn Workspaces: 3.3.0

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions