Skip to content

[@babel/parser@7.12.1]: unexpected SyntaxError omitted from function params destructuring #12195

@shhider

Description

@shhider

Bug Report

Common object deconstruction code:

interface ISomeObj {
  prop1: string;
  prop2: string;
}

const clone = (
  { prop1, prop2 }: ISomeObj,
): ISomeObj => ({ prop1, prop2 });

but babel/parser@7.12.1:

/repl.ts: Unexpected token (8:0)

  6 | const clone = (
  7 |   { prop1, prop2 }: ISomeObj,
> 8 | ): ISomeObj => ({ prop1, prop2 });
    | ^
  9 | 

You can try it in babel website Try It Out.

And,

There is no error if param has only one prop:

interface ISomeObj {
  prop1: string;
  prop2: string;
}

const clone = (
  { prop1 }: ISomeObj,
): ISomeObj => ({ prop1 });

This bug blocks my development, please fix it ASAP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: regressionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions