Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: TypeScript string enum members based on an imported enum should not have a reverse mapping #16249

Open
1 task
MohammadYounes opened this issue Jan 30, 2024 · 3 comments

Comments

@MohammadYounes
Copy link

MohammadYounes commented Jan 30, 2024

馃捇

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

// enum.ts
export enum MainEnum {
  itemA = 'A',
  itemB = 'B',
  itemC = 'C'
}
export enum SameFileSubEnum {
  itemA = MainEnum.itemA,
  itemB = MainEnum.itemB
}

//another-file.ts
import { MainEnum } from './enum'
export enum AnotherFileSubEnum {
  itemA = MainEnum.itemA,
  itemB = MainEnum.itemB
}

//main.ts
import { SameFileSubEnum } from './enum'
import { AnotherFileSubEnum } from './another-file'
console.log('SameFileSubEnum [No Reverse Mapping]', SameFileSubEnum)
console.log('AnotherFileSubEnum [Reverse Mapping Applied]', AnotherFileSubEnum)

Configuration file name

.babelrc

Configuration

{
  "presets": [["@babel/preset-env"], "babel-preset-typescript-vue3", "@babel/preset-typescript"],
  "plugins": [
    "@babel/transform-typescript",
    "@babel/plugin-transform-async-to-generator",
    "@babel/proposal-object-rest-spread",
    ["@babel/plugin-proposal-decorators", { "legacy": true }],
    ["@babel/plugin-proposal-class-properties", { "loose": true }],
    ["@babel/plugin-proposal-private-property-in-object", { "loose": true }],
    ["@babel/plugin-proposal-private-methods", { "loose": true }],
    "@babel/plugin-syntax-dynamic-import"
  ]
}

Current and expected behavior

Current
image

Expected
Both enums to be the same without reverse mapping

Environment

  System:
    OS: Windows 11 10.0.22631
  Binaries:
    Node: 14.21.3 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.18 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    @babel/core: ^7.23.7 => 7.23.9
    @babel/plugin-proposal-decorators: ^7.23.9 => 7.23.9
    @babel/plugin-syntax-dynamic-import: ^7.8.3 => 7.8.3
    @babel/plugin-transform-async-to-generator: ^7.23.3 => 7.23.3
    @babel/plugin-transform-class-properties: ^7.23.3 => 7.23.3
    @babel/plugin-transform-object-rest-spread: ^7.23.4 => 7.23.4
    @babel/plugin-transform-private-methods: ^7.23.3 => 7.23.3
    @babel/plugin-transform-private-property-in-object: ^7.23.4 => 7.23.4
    @babel/preset-env: ^7.23.8 => 7.23.9
    @babel/preset-typescript: ^7.23.3 => 7.23.3
    babel-loader: ^9.1.3 => 9.1.3
    babel-plugin-add-module-exports: ^1.0.4 => 1.0.4
    babel-plugin-dynamic-import-node: ^2.3.3 => 2.3.3
    babel-preset-typescript-vue: ^1.1.1 => 1.1.1
    babel-preset-typescript-vue3: ^2.0.17 => 2.0.17
    webpack: ^5.89.0 => 5.90.0

Possible solution

No response

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @MohammadYounes! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@MohammadYounes
Copy link
Author

Sample https://playcode.io/1743524

@nicolo-ribaudo
Copy link
Member

Let's wait for microsoft/TypeScript#56153 to be solved before changing Babel's behavior here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants