
Security News
Node.js Considers Public Workflow for Security Reports Amid AI-Driven Surge
Node.js is debating whether AI-driven security report volume warrants moving more vulnerability reports into public workflows.
babel-plugin-typescript-const-enum
Advanced tools
A babel plugin to replace typescript const enum expression as TS does.
This plugin is to resolve typescript const enum declaration to hard code.
some.d.ts
declare namespace N.S {
export const enum STATUS {
success = 0,
fail = 1,
}
}
declare const enum OUT_NS_STATUS {
success = 0,
fail = 1,
}
index.ts
import NS2 = NS;
import NS = N.S;
import ONS = OUT_NS_STATUS;
export function foo() {
const a = N.S.STATUS.fail; // => 1
const b = NS.STATUS.success; // => 0
const c = NS2.STATUS.fail; // => 1
const d = ONS.success; // => 0
function baz1() {
const NS = { STATUS: { success: 'success', fail: 'fail' } };
return NS.STATUS.success; // keep
}
function baz2() {
const ONS = { success: 'success', fail: 'fail' };
return ONS.success; // keep
}
function baz3() {
const N = { S: { STATUS: { success: 'success', fail: 'fail' } } };
function bas3Closure() {
return N.S.STATUS.fail; // keep
}
return bas3Closure();
}
function haha() {
return function () {
return NS.STATUS.success; // => 0
};
}
return;
}
Add plugin in babel config
babel.config.json
{
...
"plugins": [
[
"babel-plugin-typescript-const-enum",
{
"enumFile": "./my-const-enum.json",
"enums": {
"a.b.c.xxx": "xxx"
}
}
]
]
...
}
enumFile string
a pathname to the enums json data
enums
an object of enums map like follows:
{
"my.namespace.student.grade.LEVEL_ENUM.one": "一年级",
"my.namespace.student.grade.LEVEL_ENUM.two": "二年级",
"my.namespace.student.grade.LEVEL_ENUM.three": "三年级",
"real.world.common.sense.DAY.SUNDAY": 7,
"real.world.common.sense.DAY.MONDAY": 1,
"real.world.common.sense.DAY.TUSEDAY": 2,
}
the upon json may be from some idl, and there should be some d.ts file as following to ensure TS Language Server works OK:
declare namespace my.namespace.student {
export namespace grade {
export const enum LEVEL_ENUM {
one = '一年级',
two = '二年级',
three = '三年级'
}
}
}
declare namespace real.world.common.sense {
export const enum DAY {
SUNDAY = 7,
MONDAY = 1,
TUSEDAY = 2
}
}
FAQs
A babel plugin to replace typescript const enum expression as TS does.
The npm package babel-plugin-typescript-const-enum receives a total of 8 weekly downloads. As such, babel-plugin-typescript-const-enum popularity was classified as not popular.
We found that babel-plugin-typescript-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
Node.js is debating whether AI-driven security report volume warrants moving more vulnerability reports into public workflows.

Security News
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.

Security News
Open source attacks are accelerating as AI coding agents pull in dependencies faster, with less human review.