Skip to content

[Bug]: Private Brand Check incorrectly allowed as RHS of in operator #13726

@jridgewell

Description

@jridgewell

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

Found this while reading https://github.com/evanw/esbuild/releases/tag/v0.12.25 (esbuild continues to have wonderful changelogs):

class Foo {
  #a;
  #b;
  constructor(c) {
    #a in #b in c
  }
}

Because of the way the in operator works, this is parsing the same as (#a in #b) in c, which isn't a valid program.

Configuration file name

No response

Configuration

Only default settings are needed.

{}

Current and expected behavior

This should throw a parse error.

Environment

Babel 7.15.3

Possible solution

This issue is in

const { value, start } = this.state;
node = this.parsePrivateName();
if (this.match(tt._in)) {
this.classScope.usePrivateName(value, start);
} else {
this.raise(start, Errors.PrivateInExpectedIn, value);
}
return node;
. We're not checking whether we're already in the RHS of an in expression.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions