Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
babel-plugin-const-enum
Advanced tools
Transform TypeScript
const
enums
Using npm:
npm install --save-dev babel-plugin-const-enum
or using yarn:
yarn add babel-plugin-const-enum --dev
You are most likely using
@babel/preset-typescript
or
@babel/plugin-transform-typescript
along with this plugin.
If you are using @babel/preset-typescript
, then nothing special needs to be
done since
plugins run before presets.
If you are using @babel/plugin-transform-typescript
, then make sure that
babel-plugin-const-enum
comes before
@babel/plugin-transform-typescript
in the plugin array so that
babel-plugin-const-enum
runs first.
This plugin needs to run first to transform the const enum
s into code that
@babel/plugin-transform-typescript
allows.
.babelrc
{
"plugins": ["const-enum", "@babel/transform-typescript"]
}
transform: removeConst
(default)Removes the const
keyword to use regular enum
.
Can be used in a slower dev build to allow const
, while prod still uses tsc
.
See babel#6476.
// Before:
const enum MyEnum {
A = 1,
B = A,
C,
D = C,
E = 1,
F,
G = A * E,
H = A ** B ** C,
I = A << 20
}
// After:
enum MyEnum {
A = 1,
B = A,
C,
D = C,
E = 1,
F,
G = A * E,
H = A ** B ** C,
I = A << 20
}
.babelrc
{
"plugins": [
"const-enum"
]
}
Or Explicitly:
.babelrc
{
"plugins": [
[
"const-enum",
{
"transform": "removeConst"
}
]
]
}
transform: constObject
Transforms into a const
object literal.
Can be further compressed using Uglify/Terser to inline enum
access.
See babel#8741.
// Before:
const enum MyEnum {
A = 1,
B = A,
C,
D = C,
E = 1,
F,
G = A * E,
H = A ** B ** C,
I = A << 20
}
// After:
const MyEnum = {
A: 1,
B: 1,
C: 2,
D: 2,
E: 1,
F: 2,
G: 1,
H: 1,
I: 1048576
};
.babelrc
{
"plugins": [
[
"const-enum",
{
"transform": "constObject"
}
]
]
}
SyntaxError
You may be getting a SyntaxError
because you are running this plugin on
non-TypeScript source. You might have run into this problem in react-native
,
see:
babel-plugin-const-enum#2
babel-plugin-const-enum#3
This seems to be caused by react-native
transpiling
flow
code in node_modules
.
To fix this issue, please use
babel-preset-const-enum
to only run babel-plugin-const-enum
on TypeScript files.
If you wish to fix the issue manually, check out the
solution in babel-plugin-const-enum#2.
FAQs
Transform TypeScript `const` enums
The npm package babel-plugin-const-enum receives a total of 1,316,125 weekly downloads. As such, babel-plugin-const-enum popularity was classified as popular.
We found that babel-plugin-const-enum demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.