Skip to content

[Bug]: weird behaviour on resolving enum member references #17049

@branchseer

Description

@branchseer

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

REPL

(() => {
  var A = 'hello';
  enum Foo {
    A = 1,
    B = A, // A is resolved to the enum member if it's constant
  }
})();

(() => {
  var A = 'hello';
  enum Bar {
    A = Math.random(),
    B = A, // Otherwise, A is resolved to the outer scope's binding
  }
})();


enum Baz {
  A = Math.random(),
  B = A, // If there's no outer scope's binding, it's again resolved to the enum member
}

Configuration file name

No response

Configuration

No response

Current and expected behavior

The current behavior is commented in the input code.

I would expect the enum transformation to follow what tsc does (which is more consistent and simpler): https://www.typescriptlang.org/play/?#code/PTAEEFQSwZ1BDANgd3gTzgJwKYwPaIBu2AJqAC54UAW2o2AdgK4C2oL2LARtpgHQAoIQAphASlABeAHygA3gNChC8TBCmgA5AHNEeLkk0BuRfWZsAYnioKlSyJNABGADSmlAIQ3gXoUwF8BfzFxEwFRCRl5UxU1By1dfUMTJUZWUA9VaLt1RwBZeHJqPkx4BhI8FnE3HK9HHwCgkLEwgTS2TIAvbNzQAqKSsoqqsRqM7zdAoA

Environment

Babel v7.26.4
@babel/plugin-transform-typescript v7.26.3

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescriptoutdatedA 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