Skip to content

Symbol required for Private Static Field in check can be shadowed #12960

@acutmore

Description

@acutmore

Bug Report

  • I would like to work on a fix!

Current behavior
When accessing or checking for a private static field, the generated code references the class constructor, which could be shadowed.

https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&spec=false&loose=false&code_lz=FAYwNghgzlAEAqBTKAXWBvYtZdqiKAliLAMQAesAvLAIy64C2iKAFgPYAmAFAJQa5sIdgDtUCZGhq0A3ILKVCI2ADcZsAPQaJ4wnCisIndgHdEnWEtgBzRCMQAnAudjDOiefJUA6Cuq06aHp4hsZmFla29k4oLm4e2AC-wIlAA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Creact%2Cstage-2&prettier=false&targets=&version=7.13.7&externalPlugins=

Input Code

class Test {
  
  static #x = 1
  
  method() {
    const Test = 1;
    #x in v; // Test is shadowed in generated code
    
    v.#x; // Test is shadowed in generated code
  }
}

Expected behavior
Either a warning, or generated code avoids the issue.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

presets: 'stage-2'

Environment
babel playground

Possible Solution

Perhaps the generated code could capture a separate reference in a temp variable before it's shadowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Spec: Private MethodsoutdatedA 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