# babel-plugin-use-const-enum

> Use TypeScript `const` enums, Fix babel not support const enum

Latest version **0.0.12** (published 2024-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-use-const-enum
pnpm add babel-plugin-use-const-enum
yarn add babel-plugin-use-const-enum
bun add babel-plugin-use-const-enum
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.12 |
| Published | 2024-09-24 |
| First published | 2019-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | YunQiang Wu |
| Maintainers | waynew |
| Keywords | babel-plugin, typescript, const, enum, terser, uglify, minify, compress, choerodon-ui |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-use-const-enum
- Repository: https://github.com/wuyun1/babel-plugin-use-const-enum
- Homepage: https://github.com/wuyun1/babel-plugin-use-const-enum#readme
- Issues: https://github.com/wuyun1/babel-plugin-use-const-enum/issues
- npm.io page: https://npm.io/package/babel-plugin-use-const-enum

## Dependencies (2)

- [@babel/helper-plugin-utils](https://npm.io/package/@babel/helper-plugin-utils.md) ^7.0.0
- [@babel/plugin-syntax-typescript](https://npm.io/package/@babel/plugin-syntax-typescript.md) ^7.3.3

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.12 (latest) — 2024-09-24
- 0.0.11 — 2024-09-24
- 0.0.10 — 2024-09-24
- 0.0.9 — 2020-03-20
- 0.0.8 — 2019-12-10
- 0.0.7 — 2019-12-10
- 0.0.6 — 2019-12-10
- 0.0.5 — 2019-12-10
- 0.0.4 — 2019-12-10

## README

# babel-plugin-use-const-enum

> Use TypeScript `const` enums, Fix babel not support const enum

## Install

Using npm:

```sh
npm install --save-dev babel-plugin-use-const-enum
```

or using yarn:

```sh
yarn add babel-plugin-use-const-enum --dev
```

## Usage

You are most likely using
[`@babel/preset-typescript`](https://babeljs.io/docs/en/babel-preset-typescript)
or
[`@babel/plugin-transform-typescript`](https://babeljs.io/docs/en/babel-plugin-transform-typescript)
as along with this plugin.

If you are using `@babel/preset-typescript`, then nothing special needs to be
done since
[plugins run before presets](https://babeljs.io/docs/en/plugins/#plugin-ordering).

If you are using `@babel/plugin-transform-typescript`, then make sure that
`babel-plugin-use-const-enum` comes before
`@babel/plugin-transform-typescript` in the plugin array so that
`babel-plugin-use-const-enum` [runs first](https://babeljs.io/docs/en/plugins/#plugin-ordering).
This plugin needs to run first to transform the `const enum`s into code that
`@babel/plugin-transform-typescript` allows.

`.babelrc`

```json
{
  "plugins": ["use-const-enum", "@babel/transform-typescript"]
}
```

### `transform: importRegStr`

filter `importRegStr` .
Specify the scope of the `const enum` by `importRegStr`

```ts
// Before:
import { FieldType } from 'choerodon-ui/pro/lib/data-set/enum';

enum Status {
  pending = 'pending',
  end = 'end',
  start = 'start'
}

console.log(FieldType.string);
console.log(FieldType["string-aaa"]);
console.log(Status.end);


// After:
import { FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
var Status;

(function (Status) {
  Status["pending"] = "pending";
  Status["end"] = "end";
  Status["start"] = "start";
})(Status || (Status = {}));

console.log("string");
console.log("string-aaa");
console.log(Status.end);

```

`.babelrc`
```json
{
  "plugins": [
    ["use-const-enum", { "importRegStr": "choerodon-ui\/.*\/enum" }]
  ]
}
```

---
_Source: https://npm.io/package/babel-plugin-use-const-enum · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
