Skip to content

[Bug]: Wrong refrences of merging enum #16134

@magic-akari

Description

@magic-akari

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

const Cat = 10;
const Dog = 20;

enum Animals {
	Cat = 1
}

enum Animals {
	Dog = 2
}

enum Animals {
	CatDog =  Cat | Dog
}

console.log(Animals.CatDog);

Configuration file name

No response

Configuration

No response

Current and expected behavior

const Cat = 10;
const Dog = 20;
var Animals = /*#__PURE__*/function (Animals) {
  Animals[Animals["Cat"] = 1] = "Cat";
  return Animals;
}(Animals || {});
Animals = /*#__PURE__*/function (Animals) {
  Animals[Animals["Dog"] = 2] = "Dog";
  return Animals;
}(Animals || {});
Animals = /*#__PURE__*/function (Animals) {
  Animals[Animals["CatDog"] = 30] = "CatDog";
  return Animals;
}(Animals || {});
console.log(Animals.CatDog);

Current:
30 is logged

Expected:
3 should be logged

Environment

Playground:
https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=MYewdgzgLgBAwgQ1gXhgRgAwG4BQpKwAiIA5jKgEzY44CmYArgLYwCCYAlkwgDYQwBvHAEhEKdDgC-NeszadufQSOJlKUmYxbsuvfkNFJV5GPCQwAPjFUa84CCB60AdD1IAKHYojOxqgJRYQA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Ctypescript&prettier=false&targets=&version=7.23.4&externalPlugins=&assumptions=%7B%7D

Possible solution

No response

Additional context

No response

Metadata

Metadata

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