first commit

This commit is contained in:
monjack
2025-06-20 18:01:48 +08:00
commit 6daa6d65c1
24611 changed files with 2512443 additions and 0 deletions

View File

@ -0,0 +1,22 @@
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
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.

View File

@ -0,0 +1,19 @@
# @babel/helper-create-regexp-features-plugin
> Compile ESNext Regular Expressions to ES5
See our website [@babel/helper-create-regexp-features-plugin](https://babeljs.io/docs/babel-helper-create-regexp-features-plugin) for more information.
## Install
Using npm:
```sh
npm install --save @babel/helper-create-regexp-features-plugin
```
or using yarn:
```sh
yarn add @babel/helper-create-regexp-features-plugin
```

View File

@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.FEATURES = void 0;
exports.enableFeature = enableFeature;
exports.featuresKey = void 0;
exports.hasFeature = hasFeature;
exports.runtimeKey = void 0;
const FEATURES = exports.FEATURES = Object.freeze({
unicodeFlag: 1 << 0,
dotAllFlag: 1 << 1,
unicodePropertyEscape: 1 << 2,
namedCaptureGroups: 1 << 3,
unicodeSetsFlag_syntax: 1 << 4,
unicodeSetsFlag: 1 << 5,
duplicateNamedCaptureGroups: 1 << 6,
modifiers: 1 << 7
});
const featuresKey = exports.featuresKey = "@babel/plugin-regexp-features/featuresKey";
const runtimeKey = exports.runtimeKey = "@babel/plugin-regexp-features/runtimeKey";
function enableFeature(features, feature) {
return features | feature;
}
function hasFeature(features, feature) {
return !!(features & feature);
}
//# sourceMappingURL=features.js.map

View File

@ -0,0 +1 @@
{"version":3,"names":["FEATURES","exports","Object","freeze","unicodeFlag","dotAllFlag","unicodePropertyEscape","namedCaptureGroups","unicodeSetsFlag_syntax","unicodeSetsFlag","duplicateNamedCaptureGroups","modifiers","featuresKey","runtimeKey","enableFeature","features","feature","hasFeature"],"sources":["../src/features.ts"],"sourcesContent":["export const FEATURES = Object.freeze({\n unicodeFlag: 1 << 0,\n dotAllFlag: 1 << 1,\n unicodePropertyEscape: 1 << 2,\n namedCaptureGroups: 1 << 3,\n // Not used, for backward compatibility with syntax-unicode-sets-regex\n unicodeSetsFlag_syntax: 1 << 4,\n unicodeSetsFlag: 1 << 5,\n duplicateNamedCaptureGroups: 1 << 6,\n modifiers: 1 << 7,\n});\n\n// We can't use a symbol because this needs to always be the same, even if\n// this package isn't deduped by npm. e.g.\n// - node_modules/\n// - @babel/plugin-regexp-features\n// - @babel/plugin-transform-unicode-property-regex\n// - node_modules\n// - @babel-plugin-regexp-features\nexport const featuresKey = \"@babel/plugin-regexp-features/featuresKey\";\nexport const runtimeKey = \"@babel/plugin-regexp-features/runtimeKey\";\n\ntype FeatureType = (typeof FEATURES)[keyof typeof FEATURES];\n\nexport function enableFeature(features: number, feature: FeatureType): number {\n return features | feature;\n}\n\nexport function hasFeature(features: number, feature: FeatureType) {\n return !!(features & feature);\n}\n"],"mappings":";;;;;;;;;;AAAO,MAAMA,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAGE,MAAM,CAACC,MAAM,CAAC;EACpCC,WAAW,EAAE,CAAC,IAAI,CAAC;EACnBC,UAAU,EAAE,CAAC,IAAI,CAAC;EAClBC,qBAAqB,EAAE,CAAC,IAAI,CAAC;EAC7BC,kBAAkB,EAAE,CAAC,IAAI,CAAC;EAE1BC,sBAAsB,EAAE,CAAC,IAAI,CAAC;EAC9BC,eAAe,EAAE,CAAC,IAAI,CAAC;EACvBC,2BAA2B,EAAE,CAAC,IAAI,CAAC;EACnCC,SAAS,EAAE,CAAC,IAAI;AAClB,CAAC,CAAC;AASK,MAAMC,WAAW,GAAAX,OAAA,CAAAW,WAAA,GAAG,2CAA2C;AAC/D,MAAMC,UAAU,GAAAZ,OAAA,CAAAY,UAAA,GAAG,0CAA0C;AAI7D,SAASC,aAAaA,CAACC,QAAgB,EAAEC,OAAoB,EAAU;EAC5E,OAAOD,QAAQ,GAAGC,OAAO;AAC3B;AAEO,SAASC,UAAUA,CAACF,QAAgB,EAAEC,OAAoB,EAAE;EACjE,OAAO,CAAC,EAAED,QAAQ,GAAGC,OAAO,CAAC;AAC/B","ignoreList":[]}

View File

@ -0,0 +1,116 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createRegExpFeaturePlugin = createRegExpFeaturePlugin;
var _regexpuCore = require("regexpu-core");
var _core = require("@babel/core");
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
var _semver = require("semver");
var _features = require("./features.js");
var _util = require("./util.js");
const versionKey = "@babel/plugin-regexp-features/version";
function createRegExpFeaturePlugin({
name,
feature,
options = {},
manipulateOptions = () => {}
}) {
return {
name,
manipulateOptions,
pre() {
var _file$get;
const {
file
} = this;
const features = (_file$get = file.get(_features.featuresKey)) != null ? _file$get : 0;
let newFeatures = (0, _features.enableFeature)(features, _features.FEATURES[feature]);
const {
useUnicodeFlag,
runtime
} = options;
if (useUnicodeFlag === false) {
newFeatures = (0, _features.enableFeature)(newFeatures, _features.FEATURES.unicodeFlag);
}
if (newFeatures !== features) {
file.set(_features.featuresKey, newFeatures);
}
if (runtime !== undefined) {
if (file.has(_features.runtimeKey) && file.get(_features.runtimeKey) !== runtime && (0, _features.hasFeature)(newFeatures, _features.FEATURES.duplicateNamedCaptureGroups)) {
throw new Error(`The 'runtime' option must be the same for ` + `'@babel/plugin-transform-named-capturing-groups-regex' and ` + `'@babel/plugin-transform-duplicate-named-capturing-groups-regex'.`);
}
if (feature === "namedCaptureGroups") {
if (!runtime || !file.has(_features.runtimeKey)) file.set(_features.runtimeKey, runtime);
} else {
file.set(_features.runtimeKey, runtime);
}
}
{
if (typeof file.get(versionKey) === "number") {
file.set(versionKey, "7.27.1");
return;
}
}
if (!file.get(versionKey) || _semver.lt(file.get(versionKey), "7.27.1")) {
file.set(versionKey, "7.27.1");
}
},
visitor: {
RegExpLiteral(path) {
var _file$get2;
const {
node
} = path;
const {
file
} = this;
const features = file.get(_features.featuresKey);
const runtime = (_file$get2 = file.get(_features.runtimeKey)) != null ? _file$get2 : true;
const regexpuOptions = (0, _util.generateRegexpuOptions)(node.pattern, features);
if ((0, _util.canSkipRegexpu)(node, regexpuOptions)) {
return;
}
const namedCaptureGroups = {
__proto__: null
};
if (regexpuOptions.namedGroups === "transform") {
regexpuOptions.onNamedGroup = (name, index) => {
const prev = namedCaptureGroups[name];
if (typeof prev === "number") {
namedCaptureGroups[name] = [prev, index];
} else if (Array.isArray(prev)) {
prev.push(index);
} else {
namedCaptureGroups[name] = index;
}
};
}
let newFlags;
if (regexpuOptions.modifiers === "transform") {
regexpuOptions.onNewFlags = flags => {
newFlags = flags;
};
}
node.pattern = _regexpuCore(node.pattern, node.flags, regexpuOptions);
if (regexpuOptions.namedGroups === "transform" && Object.keys(namedCaptureGroups).length > 0 && runtime && !isRegExpTest(path)) {
const call = _core.types.callExpression(this.addHelper("wrapRegExp"), [node, _core.types.valueToNode(namedCaptureGroups)]);
(0, _helperAnnotateAsPure.default)(call);
path.replaceWith(call);
}
node.flags = (0, _util.transformFlags)(regexpuOptions, newFlags != null ? newFlags : node.flags);
}
}
};
}
function isRegExpTest(path) {
return path.parentPath.isMemberExpression({
object: path.node,
computed: false
}) && path.parentPath.get("property").isIdentifier({
name: "test"
});
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,71 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.canSkipRegexpu = canSkipRegexpu;
exports.generateRegexpuOptions = generateRegexpuOptions;
exports.transformFlags = transformFlags;
var _features = require("./features.js");
function generateRegexpuOptions(pattern, toTransform) {
const feat = name => {
return (0, _features.hasFeature)(toTransform, _features.FEATURES[name]) ? "transform" : false;
};
const featDuplicateNamedGroups = () => {
if (!feat("duplicateNamedCaptureGroups")) return false;
const regex = /\(\?<([^>]+)(>|$)/g;
const seen = new Set();
for (let match; (match = regex.exec(pattern)) && match[2]; seen.add(match[1])) {
if (seen.has(match[1])) return "transform";
}
return false;
};
return {
unicodeFlag: feat("unicodeFlag"),
unicodeSetsFlag: feat("unicodeSetsFlag"),
dotAllFlag: feat("dotAllFlag"),
unicodePropertyEscapes: feat("unicodePropertyEscape"),
namedGroups: feat("namedCaptureGroups") || featDuplicateNamedGroups(),
onNamedGroup: () => {},
modifiers: feat("modifiers")
};
}
function canSkipRegexpu(node, options) {
const {
flags,
pattern
} = node;
if (flags.includes("v")) {
if (options.unicodeSetsFlag === "transform") return false;
}
if (flags.includes("u")) {
if (options.unicodeFlag === "transform") return false;
if (options.unicodePropertyEscapes === "transform" && /\\p\{/i.test(pattern)) {
return false;
}
}
if (flags.includes("s")) {
if (options.dotAllFlag === "transform") return false;
}
if (options.namedGroups === "transform" && /\(\?<(?![=!])/.test(pattern)) {
return false;
}
if (options.modifiers === "transform" && /\(\?[\w-]+:/.test(pattern)) {
return false;
}
return true;
}
function transformFlags(regexpuOptions, flags) {
if (regexpuOptions.unicodeSetsFlag === "transform") {
flags = flags.replace("v", "u");
}
if (regexpuOptions.unicodeFlag === "transform") {
flags = flags.replace("u", "");
}
if (regexpuOptions.dotAllFlag === "transform") {
flags = flags.replace("s", "");
}
return flags;
}
//# sourceMappingURL=util.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,36 @@
{
"name": "@babel/helper-create-regexp-features-plugin",
"version": "7.27.1",
"author": "The Babel Team (https://babel.dev/team)",
"license": "MIT",
"description": "Compile ESNext Regular Expressions to ES5",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-create-regexp-features-plugin"
},
"main": "./lib/index.js",
"publishConfig": {
"access": "public"
},
"keywords": [
"babel",
"babel-plugin"
],
"dependencies": {
"@babel/helper-annotate-as-pure": "^7.27.1",
"regexpu-core": "^6.2.0",
"semver": "^6.3.1"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.27.1",
"@babel/helper-plugin-test-runner": "^7.27.1"
},
"engines": {
"node": ">=6.9.0"
},
"type": "commonjs"
}