Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

21
node_modules/babel-plugin-const-enum/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Kevin Lau
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

169
node_modules/babel-plugin-const-enum/README.md generated vendored Normal file
View File

@@ -0,0 +1,169 @@
# babel-plugin-const-enum · [![npm version](https://img.shields.io/npm/v/babel-plugin-const-enum.svg?style=flat)](https://www.npmjs.com/package/babel-plugin-const-enum) [![npm downloads](https://img.shields.io/npm/dm/babel-plugin-const-enum.svg?style=flat)](https://www.npmjs.com/package/babel-plugin-const-enum)
> Transform TypeScript `const` enums
## Install
Using npm:
```sh
npm install --save-dev babel-plugin-const-enum
```
or using yarn:
```sh
yarn add babel-plugin-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)
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-const-enum` comes before
`@babel/plugin-transform-typescript` in the plugin array so that
`babel-plugin-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": ["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](https://github.com/babel/babel/issues/6476).
```ts
// 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`
```json
{
"plugins": [
"const-enum"
]
}
```
Or Explicitly:
`.babelrc`
```json
{
"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](https://github.com/babel/babel/issues/8741).
```ts
// 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`
```json
{
"plugins": [
[
"const-enum",
{
"transform": "constObject"
}
]
]
}
```
## Troubleshooting
### `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:<br>
[babel-plugin-const-enum#2](https://github.com/dosentmatter/babel-plugin-const-enum/issues/2)<br>
[babel-plugin-const-enum#3](https://github.com/dosentmatter/babel-plugin-const-enum/issues/3)
This seems to be caused by `react-native` transpiling
[`flow`](https://flow.org/) code in `node_modules`.
To fix this issue, please use
[`babel-preset-const-enum`](https://github.com/dosentmatter/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](https://github.com/dosentmatter/babel-plugin-const-enum/issues/2#issuecomment-542859348).

View File

@@ -0,0 +1,246 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.NON_NUMERIC_EXPRESSION_ERROR_MESSAGE = exports.DISALLOWED_NAN_ERROR_MESSAGE = exports.DISALLOWED_INFINITY_ERROR_MESSAGE = void 0;
var _core = require("@babel/core");
var _traverse = _interopRequireDefault(require("@babel/traverse"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const DISALLOWED_NAN_ERROR_MESSAGE = "'const' enum member initializer was evaluated to disallowed value 'NaN'.";
exports.DISALLOWED_NAN_ERROR_MESSAGE = DISALLOWED_NAN_ERROR_MESSAGE;
const DISALLOWED_INFINITY_ERROR_MESSAGE = "'const' enum member initializer was evaluated to a non-finite value.";
exports.DISALLOWED_INFINITY_ERROR_MESSAGE = DISALLOWED_INFINITY_ERROR_MESSAGE;
const NON_NUMERIC_EXPRESSION_ERROR_MESSAGE = 'Must be numeric expression.';
exports.NON_NUMERIC_EXPRESSION_ERROR_MESSAGE = NON_NUMERIC_EXPRESSION_ERROR_MESSAGE;
var _default = {
TSEnumDeclaration(path) {
if (path.node.const) {
// `path === constObjectPath` for `replaceWith`.
const [constObjectPath] = path.replaceWith(_core.types.variableDeclaration('const', [_core.types.variableDeclarator(_core.types.identifier(path.node.id.name), _core.types.objectExpression(TSEnumMembersToObjectProperties(path.get('members'))))]));
path.scope.registerDeclaration(constObjectPath);
}
}
};
exports.default = _default;
const TSEnumMembersToObjectProperties = memberPaths => {
const isStringEnum = memberPaths.some(memberPath => _core.types.isStringLiteral(memberPath.node.initializer));
const constEnum = {};
let currentValue = 0;
return memberPaths.map(tsEnumMemberPath => {
const keyNode = computeKeyNodeFromIdPath(tsEnumMemberPath.get('id'));
const key = getKeyFromKeyNode(keyNode);
const valueNode = computeValueNodeFromEnumMemberPath(tsEnumMemberPath, isStringEnum, constEnum, currentValue);
const value = getValueFromValueNode(valueNode);
constEnum[key] = value;
if (_core.types.isNumericLiteral(valueNode)) {
currentValue = value + 1;
} else if (_core.types.isStringLiteral(valueNode)) {
currentValue = null;
}
return _core.types.objectProperty(keyNode, valueNode);
});
};
const computeKeyNodeFromIdPath = idPath => {
const id = idPath.node;
let keyNode;
if (_core.types.isIdentifier(id)) {
const key = id.name;
keyNode = _core.types.identifier(key);
} else if (_core.types.isStringLiteral(id)) {
const key = id.value;
keyNode = _core.types.stringLiteral(key);
} else if (_core.types.isNumericLiteral(id)) {
throw idPath.buildCodeFrameError('An enum member cannot have a numeric name.');
} else {
throw idPath.buildCodeFrameError('Enum member expected.');
}
return keyNode;
};
const getKeyFromKeyNode = keyNode => {
let key;
if (_core.types.isIdentifier(keyNode)) {
key = keyNode.name;
} else if (_core.types.isStringLiteral(keyNode)) {
key = keyNode.value;
}
return key;
};
const computeValueNodeFromEnumMemberPath = (tsEnumMemberPath, isStringEnum, constEnum, currentValue) => {
const initializerPath = tsEnumMemberPath.get('initializer');
const initializer = initializerPath.node;
let value;
if (initializer) {
if (_core.types.isNumericLiteral(initializer) || _core.types.isStringLiteral(initializer)) {
value = initializer.value;
} else if (_core.types.isIdentifier(initializer)) {
validateIdentifierName(initializerPath);
value = constEnum[initializer.name];
validateConstEnumMemberAccess(tsEnumMemberPath, value);
} else if (_core.types.isUnaryExpression(initializer) || _core.types.isBinaryExpression(initializer)) {
if (isStringEnum) {
throw initializerPath.buildCodeFrameError('Computed values are not permitted in an enum with string valued members.');
}
traverseFromRoot(initializerPath, accessConstEnumMemberVisitor, {
constEnum
});
value = evaluateInitializer(initializerPath);
} else {
throw initializerPath.buildCodeFrameError('const enum member initializers can only contain literal values and other computed enum values.');
}
} else {
if (currentValue === null) {
throw tsEnumMemberPath.buildCodeFrameError('Enum member must have initializer.');
}
value = currentValue;
}
let valueNode;
if (Number.isFinite(value)) {
valueNode = _core.types.numericLiteral(value);
} else if (typeof value === 'string') {
valueNode = _core.types.stringLiteral(value);
} else if (Number.isNaN(value)) {
throw tsEnumMemberPath.buildCodeFrameError(DISALLOWED_NAN_ERROR_MESSAGE);
} else if (value === Infinity || value === -Infinity) {
throw tsEnumMemberPath.buildCodeFrameError(DISALLOWED_INFINITY_ERROR_MESSAGE);
} else {
// Should not get here.
throw new Error('`value` is not a number or string');
}
return valueNode;
};
const getValueFromValueNode = valueNode => {
let value;
if (_core.types.isNumericLiteral(valueNode) || _core.types.isStringLiteral(valueNode)) {
value = valueNode.value;
}
return value;
};
const UNARY_OPERATORS = {
'+': a => +a,
'-': a => -a,
'~': a => ~a
};
const BINARY_OPERATORS = {
'+': (a, b) => a + b,
'-': (a, b) => a - b,
'/': (a, b) => a / b,
'%': (a, b) => a % b,
'*': (a, b) => a * b,
'**': (a, b) => a ** b,
'&': (a, b) => a & b,
'|': (a, b) => a | b,
'>>': (a, b) => a >> b,
'>>>': (a, b) => a >>> b,
'<<': (a, b) => a << b,
'^': (a, b) => a ^ b
};
const isNumericUnaryExpression = node => _core.types.isUnaryExpression(node) && Object.prototype.hasOwnProperty.call(UNARY_OPERATORS, node.operator);
const isNumericBinaryExpression = node => _core.types.isBinaryExpression(node) && Object.prototype.hasOwnProperty.call(BINARY_OPERATORS, node.operator);
const validateIdentifierName = identifierPath => {
switch (identifierPath.node.name) {
case 'NaN':
throw identifierPath.buildCodeFrameError(DISALLOWED_NAN_ERROR_MESSAGE);
case 'Infinity':
throw identifierPath.buildCodeFrameError(DISALLOWED_INFINITY_ERROR_MESSAGE);
}
};
const validateConstEnumMemberAccess = (path, value) => {
if (value === undefined) {
throw path.buildCodeFrameError('Enum initializer identifier must reference a previously defined enum member.');
}
};
const traverseFromRoot = (path, visitor, state) => {
visitor = _traverse.default.visitors.explode(visitor);
if (visitor.enter) {
visitor.enter[0].call(state, path, state);
}
if (visitor[path.type] && visitor[path.type].enter) {
visitor[path.type].enter[0].call(state, path, state);
}
path.traverse(visitor, state);
if (visitor.exit) {
visitor.exit[0].call(state, path, state);
}
if (visitor[path.type] && visitor[path.type].exit) {
visitor[path.type].exit[0].call(state, path, state);
}
};
const accessConstEnumMemberVisitor = {
enter(path) {
if (_core.types.isIdentifier(path.node)) {
validateIdentifierName(path);
const constEnum = this.constEnum;
const value = constEnum[path.node.name];
validateConstEnumMemberAccess(path, value);
path.replaceWith(_core.types.numericLiteral(value));
path.skip();
} else if (!(_core.types.isNumericLiteral(path.node) || isNumericUnaryExpression(path.node) || isNumericBinaryExpression(path.node))) {
throw path.buildCodeFrameError(NON_NUMERIC_EXPRESSION_ERROR_MESSAGE);
}
}
};
const evaluateInitializer = initializerPath => {
traverseFromRoot(initializerPath, evaluateInitializerVisitor);
return initializerPath.node.value;
};
const evaluateInitializerVisitor = {
UnaryExpression: {
exit(path) {
const {
node
} = path;
path.replaceWith(_core.types.numericLiteral(UNARY_OPERATORS[node.operator](node.argument.value)));
}
},
BinaryExpression: {
exit(path) {
const {
node
} = path;
path.replaceWith(_core.types.numericLiteral(BINARY_OPERATORS[node.operator](node.left.value, node.right.value)));
}
}
};

39
node_modules/babel-plugin-const-enum/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _pluginSyntaxTypescript = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
var _removeConst = _interopRequireDefault(require("./remove-const"));
var _constObject = _interopRequireDefault(require("./const-object"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = (0, _helperPluginUtils.declare)((api, {
transform = 'removeConst'
}) => {
api.assertVersion(7);
let visitor;
if (transform === 'removeConst') {
visitor = _removeConst.default;
} else if (transform === 'constObject') {
visitor = _constObject.default;
} else {
throw Error('transform option must be removeConst|constObject');
}
return {
name: 'const-enum',
inherits: _pluginSyntaxTypescript.default,
visitor
};
});
exports.default = _default;

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = {
TSEnumDeclaration(path) {
if (path.node.const) {
path.node.const = false;
}
}
};
exports.default = _default;

47
node_modules/babel-plugin-const-enum/package.json generated vendored Normal file
View File

@@ -0,0 +1,47 @@
{
"name": "babel-plugin-const-enum",
"version": "1.2.0",
"description": "Transform TypeScript `const` enums",
"repository": "https://github.com/dosentmatter/babel-plugin-const-enum",
"author": "Kevin Lau",
"license": "MIT",
"main": "lib/index.js",
"keywords": [
"babel-plugin",
"typescript",
"const",
"enum",
"terser",
"uglify",
"minify",
"compress"
],
"scripts": {
"build": "babel src --out-dir lib",
"prepublishOnly": "yarn run build",
"test": "jest",
"lint-fix": "eslint --fix 'src/**/*.js' '__tests__/**/*.js'",
"prettier-fix": "prettier --write 'src/**/*.js' '__tests__/**/*.js'"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"dependencies": {
"@babel/helper-plugin-utils": "^7.0.0",
"@babel/plugin-syntax-typescript": "^7.3.3",
"@babel/traverse": "^7.16.0"
},
"devDependencies": {
"@babel/cli": "^7.5.0",
"@babel/core": "^7.5.0",
"@babel/plugin-transform-typescript": "^7.9.4",
"@babel/preset-env": "^7.5.0",
"babel-jest": "^27.0.6",
"eslint": "^7.7.0",
"jest": "^27.0.6",
"prettier": "^2.0.4"
},
"files": [
"lib"
]
}