https://github.com/morlay/typescript-plugin-iife-enum
https://github.com/morlay/typescript-plugin-iife-enum
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/morlay/typescript-plugin-iife-enum
- Owner: morlay
- Created: 2017-08-04T03:13:30.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-04T06:33:13.000Z (almost 9 years ago)
- Last Synced: 2025-07-09T08:05:01.427Z (11 months ago)
- Language: TypeScript
- Size: 29.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## typescript-plugin-iife-enum
A TypeScript transform to wrapper enum in IIFE.
### Purpose
For now TypeScript will transform enum from
```ts
enum Test {
Key = 1
}
```
to
```ts
var Test;
(function (Test) {
Test[Test["Key"] = 1] = "Key";
})(Test || (Test = {}));
```
This result is not friendly for uglyify.
So just wrapper IIFE for enum
```
const Test = (() => {
enum Test {
Key = 1
}
return Test
})
```
## Usage
```ts
// 1. import default from the plugin module
import { createIIFEEnumTransformer } from 'typescript-plugin-iife-enum');
// 2. add getCustomTransformer method to the loader config
var config = {
...
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
... // other loader's options
getCustomTransformers: () => ({ before: [createIIFEEnumTransformer()] })
}
}
]
}
...
};
```
## Know Issue
TypeScript will drop leading comments of call expression,
can use babel with [plugin](https://github.com/morlay/babel-plugin-annotate-pure-call-in-variable-declarator) to annotate `#__PURE__```