![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
babel-preset-const-enum
Advanced tools
Babel preset for TypeScript
const
enums
Using npm:
npm install --save-dev babel-preset-const-enum
or using yarn:
yarn add babel-preset-const-enum --dev
This preset runs
babel-plugin-const-enum
only on files with extensions .ts
or .tsx
. This prevents SyntaxError
s from
happening when mistakenly running babel-plugin-const-enum
on non-TypeScript
files such as flow, which uses a .js
extension.
A babel preset is required because plugins don't have access to the file extension of the file the plugin may run on.
You are most likely using
@babel/preset-typescript
as along with this preset. Make sure that babel-preset-const-enum
comes after
@babel/preset-typescript
in the preset array so that
babel-preset-const-enum
runs first.
This preset needs to run first to transform the const enum
s into code that
@babel/preset-typescript
allows.
.babelrc
{
"presets": ["@babel/typescript", "const-enum"]
}
allExtensions
boolean
, defaults to false
.
Indicates that every file extension should be parsed.
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
{
"presets": ["const-enum"]
}
Or Explicitly:
.babelrc
{
"presets": [
[
"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
{
"presets": [
[
"const-enum",
{
"transform": "constObject"
}
]
]
}
FAQs
Babel preset for TypeScript `const` enums
The npm package babel-preset-const-enum receives a total of 0 weekly downloads. As such, babel-preset-const-enum popularity was classified as not popular.
We found that babel-preset-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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.