8889841cREADME.md000066600000000651150513176440006037 0ustar00# @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/en/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 ``` lib/features.js000066600000001625150513176440007504 0ustar00"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 = 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 }); exports.FEATURES = FEATURES; const featuresKey = "@babel/plugin-regexp-features/featuresKey"; exports.featuresKey = featuresKey; const runtimeKey = "@babel/plugin-regexp-features/runtimeKey"; exports.runtimeKey = runtimeKey; function enableFeature(features, feature) { return features | feature; } function hasFeature(features, feature) { return !!(features & feature); } //# sourceMappingURL=features.js.map lib/index.js000066600000007733150513176440007003 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createRegExpFeaturePlugin = createRegExpFeaturePlugin; var _regexpuCore = require("regexpu-core"); var _features = require("./features"); var _util = require("./util"); var _core = require("@babel/core"); var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure"); const version = "7.21.0".split(".").reduce((v, x) => v * 1e5 + +x, 0); 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-proposal-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 (!file.has(versionKey) || file.get(versionKey) < version) { file.set(versionKey, version); } }, visitor: { RegExpLiteral(path) { var _file$get2, _newFlags; 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 = 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 lib/features.js.map000066600000003636150513176440010264 0ustar00{"version":3,"names":["FEATURES","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 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-proposal-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,GAAGC,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;EAC1BC,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;AAAC;AASI,MAAMC,WAAW,GAAG,2CAA2C;AAAC;AAChE,MAAMC,UAAU,GAAG,0CAA0C;AAAC;AAI9D,SAASC,aAAa,CAACC,QAAgB,EAAEC,OAAoB,EAAU;EAC5E,OAAOD,QAAQ,GAAGC,OAAO;AAC3B;AAEO,SAASC,UAAU,CAACF,QAAgB,EAAEC,OAAoB,EAAE;EACjE,OAAO,CAAC,EAAED,QAAQ,GAAGC,OAAO,CAAC;AAC/B"}lib/index.js.map000066600000022140150513176440007544 0ustar00{"version":3,"names":["version","split","reduce","v","x","versionKey","createRegExpFeaturePlugin","name","feature","options","manipulateOptions","pre","file","features","get","featuresKey","newFeatures","enableFeature","FEATURES","useUnicodeFlag","runtime","unicodeFlag","set","undefined","has","runtimeKey","hasFeature","duplicateNamedCaptureGroups","Error","visitor","RegExpLiteral","path","node","regexpuOptions","generateRegexpuOptions","pattern","canSkipRegexpu","namedCaptureGroups","__proto__","namedGroups","onNamedGroup","index","prev","Array","isArray","push","newFlags","modifiers","onNewFlags","flags","rewritePattern","Object","keys","length","isRegExpTest","call","t","callExpression","addHelper","valueToNode","annotateAsPure","replaceWith","transformFlags","parentPath","isMemberExpression","object","computed","isIdentifier"],"sources":["../src/index.ts"],"sourcesContent":["import rewritePattern from \"regexpu-core\";\nimport {\n featuresKey,\n FEATURES,\n enableFeature,\n runtimeKey,\n hasFeature,\n} from \"./features\";\nimport { generateRegexpuOptions, canSkipRegexpu, transformFlags } from \"./util\";\nimport type { NodePath } from \"@babel/traverse\";\n\nimport { types as t } from \"@babel/core\";\nimport type { PluginObject } from \"@babel/core\";\nimport annotateAsPure from \"@babel/helper-annotate-as-pure\";\n\ndeclare const PACKAGE_JSON: { name: string; version: string };\n\n// Note: Versions are represented as an integer. e.g. 7.1.5 is represented\n// as 70000100005. This method is easier than using a semver-parsing\n// package, but it breaks if we release x.y.z where x, y or z are\n// greater than 99_999.\nconst version = PACKAGE_JSON.version\n .split(\".\")\n .reduce((v, x) => v * 1e5 + +x, 0);\nconst versionKey = \"@babel/plugin-regexp-features/version\";\n\nexport interface Options {\n name: string;\n feature: keyof typeof FEATURES;\n options?: {\n useUnicodeFlag?: boolean;\n runtime?: boolean;\n };\n manipulateOptions?: PluginObject[\"manipulateOptions\"];\n}\n\nexport function createRegExpFeaturePlugin({\n name,\n feature,\n options = {},\n manipulateOptions = () => {},\n}: Options): PluginObject {\n return {\n name,\n\n manipulateOptions,\n\n pre() {\n const { file } = this;\n const features = file.get(featuresKey) ?? 0;\n let newFeatures = enableFeature(features, FEATURES[feature]);\n\n const { useUnicodeFlag, runtime } = options;\n if (useUnicodeFlag === false) {\n newFeatures = enableFeature(newFeatures, FEATURES.unicodeFlag);\n }\n if (newFeatures !== features) {\n file.set(featuresKey, newFeatures);\n }\n\n if (runtime !== undefined) {\n if (\n file.has(runtimeKey) &&\n file.get(runtimeKey) !== runtime &&\n // TODO(Babel 8): Remove this check. It's necessary because in Babel 7\n // we allow multiple copies of transform-named-capturing-groups-regex\n // with conflicting 'runtime' options.\n hasFeature(newFeatures, FEATURES.duplicateNamedCaptureGroups)\n ) {\n throw new Error(\n `The 'runtime' option must be the same for ` +\n `'@babel/plugin-transform-named-capturing-groups-regex' and ` +\n `'@babel/plugin-proposal-duplicate-named-capturing-groups-regex'.`,\n );\n }\n // TODO(Babel 8): Remove this check and always set it.\n // It's necessary because in Babel 7 we allow multiple copies of\n // transform-named-capturing-groups-regex with conflicting 'runtime' options.\n if (feature === \"namedCaptureGroups\") {\n if (!runtime || !file.has(runtimeKey)) file.set(runtimeKey, runtime);\n } else {\n file.set(runtimeKey, runtime);\n }\n }\n\n if (!file.has(versionKey) || file.get(versionKey) < version) {\n file.set(versionKey, version);\n }\n },\n\n visitor: {\n RegExpLiteral(path) {\n const { node } = path;\n const { file } = this;\n const features = file.get(featuresKey);\n const runtime = file.get(runtimeKey) ?? true;\n\n const regexpuOptions = generateRegexpuOptions(node.pattern, features);\n if (canSkipRegexpu(node, regexpuOptions)) {\n return;\n }\n\n const namedCaptureGroups: Record = {\n __proto__: null,\n };\n if (regexpuOptions.namedGroups === \"transform\") {\n regexpuOptions.onNamedGroup = (name, index) => {\n const prev = namedCaptureGroups[name];\n if (typeof prev === \"number\") {\n namedCaptureGroups[name] = [prev, index];\n } else if (Array.isArray(prev)) {\n prev.push(index);\n } else {\n namedCaptureGroups[name] = index;\n }\n };\n }\n\n let newFlags;\n if (regexpuOptions.modifiers === \"transform\") {\n regexpuOptions.onNewFlags = flags => {\n newFlags = flags;\n };\n }\n\n node.pattern = rewritePattern(node.pattern, node.flags, regexpuOptions);\n\n if (\n regexpuOptions.namedGroups === \"transform\" &&\n Object.keys(namedCaptureGroups).length > 0 &&\n runtime &&\n !isRegExpTest(path)\n ) {\n const call = t.callExpression(this.addHelper(\"wrapRegExp\"), [\n node,\n t.valueToNode(namedCaptureGroups),\n ]);\n annotateAsPure(call);\n\n path.replaceWith(call);\n }\n\n node.flags = transformFlags(regexpuOptions, newFlags ?? node.flags);\n },\n },\n };\n}\n\nfunction isRegExpTest(path: NodePath) {\n return (\n path.parentPath.isMemberExpression({\n object: path.node,\n computed: false,\n }) && path.parentPath.get(\"property\").isIdentifier({ name: \"test\" })\n );\n}\n"],"mappings":";;;;;;AAAA;AACA;AAOA;AAGA;AAEA;AAQA,MAAMA,OAAO,GAAG,SACbC,KAAK,CAAC,GAAG,CAAC,CACVC,MAAM,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,GAAG,GAAG,GAAG,CAACC,CAAC,EAAE,CAAC,CAAC;AACpC,MAAMC,UAAU,GAAG,uCAAuC;AAYnD,SAASC,yBAAyB,CAAC;EACxCC,IAAI;EACJC,OAAO;EACPC,OAAO,GAAG,CAAC,CAAC;EACZC,iBAAiB,GAAG,MAAM,CAAC;AACpB,CAAC,EAAgB;EACxB,OAAO;IACLH,IAAI;IAEJG,iBAAiB;IAEjBC,GAAG,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AAO,GAAGe,YAAc,CAAClB,IAAI,CAACG,OAAO,EAAEH,IAAI,CAACiB,KAAK,EAAEhB,cAAc,CAAC;QAEvE,IACEA,cAAc,CAACM,WAAW,KAAK,WAAW,IAC1CY,MAAM,CAACC,IAAI,CAACf,kBAAkB,CAAC,CAACgB,MAAM,GAAG,CAAC,IAC1CjC,OAAO,IACP,CAACkC,YAAY,CAACvB,IAAI,CAAC,EACnB;UACA,MAAMwB,IAAI,GAAGC,WAAC,CAACC,cAAc,CAAC,IAAI,CAACC,SAAS,CAAC,YAAY,CAAC,EAAE,CAC1D1B,IAAI,EACJwB,WAAC,CAACG,WAAW,CAACtB,kBAAkB,CAAC,CAClC,CAAC;UACF,IAAAuB,6BAAc,EAACL,IAAI,CAAC;UAEpBxB,IAAI,CAAC8B,WAAW,CAACN,IAAI,CAAC;QACxB;QAEAvB,IAAI,CAACiB,KAAK,GAAG,IAAAa,oBAAc,EAAC7B,cAAc,eAAEa,QAAQ,wBAAId,IAAI,CAACiB,KAAK,CAAC;MACrE;IACF;EACF,CAAC;AACH;AAEA,SAASK,YAAY,CAACvB,IAA+B,EAAE;EACrD,OACEA,IAAI,CAACgC,UAAU,CAACC,kBAAkB,CAAC;IACjCC,MAAM,EAAElC,IAAI,CAACC,IAAI;IACjBkC,QAAQ,EAAE;EACZ,CAAC,CAAC,IAAInC,IAAI,CAACgC,UAAU,CAACjD,GAAG,CAAC,UAAU,CAAC,CAACqD,YAAY,CAAC;IAAE5D,IAAI,EAAE;EAAO,CAAC,CAAC;AAExE"}lib/util.js000066600000004251150513176440006641 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.canSkipRegexpu = canSkipRegexpu; exports.generateRegexpuOptions = generateRegexpuOptions; exports.transformFlags = transformFlags; var _features = require("./features"); function generateRegexpuOptions(pattern, toTransform) { const feat = (name, ok = "transform") => { return (0, _features.hasFeature)(toTransform, _features.FEATURES[name]) ? ok : false; }; const featDuplicateNamedGroups = () => { if (!feat("duplicateNamedCaptureGroups")) return false; const regex = /\(\?<([^>]+)>/g; const seen = new Set(); for (let match; match = regex.exec(pattern); seen.add(match[1])) { if (seen.has(match[1])) return "transform"; } return false; }; return { unicodeFlag: feat("unicodeFlag"), unicodeSetsFlag: feat("unicodeSetsFlag") || feat("unicodeSetsFlag_syntax", "parse"), 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" && /\\[pP]{/.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 lib/util.js.map000066600000012410150513176440007411 0ustar00{"version":3,"names":["generateRegexpuOptions","pattern","toTransform","feat","name","ok","hasFeature","FEATURES","featDuplicateNamedGroups","regex","seen","Set","match","exec","add","has","unicodeFlag","unicodeSetsFlag","dotAllFlag","unicodePropertyEscapes","namedGroups","onNamedGroup","modifiers","canSkipRegexpu","node","options","flags","includes","test","transformFlags","regexpuOptions","replace"],"sources":["../src/util.ts"],"sourcesContent":["import type { types as t } from \"@babel/core\";\nimport { FEATURES, hasFeature } from \"./features\";\n\nimport type { RegexpuOptions } from \"regexpu-core\";\n\nexport function generateRegexpuOptions(\n pattern: string,\n toTransform: number,\n): RegexpuOptions {\n type Experimental = 1;\n\n const feat = (\n name: keyof typeof FEATURES,\n ok: \"transform\" | (Stability extends 0 ? never : \"parse\") = \"transform\",\n ) => {\n return hasFeature(toTransform, FEATURES[name]) ? ok : false;\n };\n\n const featDuplicateNamedGroups = (): \"transform\" | false => {\n if (!feat(\"duplicateNamedCaptureGroups\")) return false;\n\n // This can return false positive, for example for /\\(?\\)/.\n // However, it's such a rare occurrence that it's ok to compile\n // the regexp even if we only need to compile regexps with\n // duplicate named capturing groups.\n const regex = /\\(\\?<([^>]+)>/g;\n const seen = new Set();\n for (let match; (match = regex.exec(pattern)); seen.add(match[1])) {\n if (seen.has(match[1])) return \"transform\";\n }\n return false;\n };\n\n return {\n unicodeFlag: feat(\"unicodeFlag\"),\n unicodeSetsFlag:\n feat(\"unicodeSetsFlag\") ||\n feat(\"unicodeSetsFlag_syntax\", \"parse\"),\n dotAllFlag: feat(\"dotAllFlag\"),\n unicodePropertyEscapes: feat(\"unicodePropertyEscape\"),\n namedGroups: feat(\"namedCaptureGroups\") || featDuplicateNamedGroups(),\n onNamedGroup: () => {},\n modifiers: feat(\"modifiers\"),\n };\n}\n\nexport function canSkipRegexpu(\n node: t.RegExpLiteral,\n options: RegexpuOptions,\n): boolean {\n const { flags, pattern } = node;\n\n if (flags.includes(\"v\")) {\n if (options.unicodeSetsFlag === \"transform\") return false;\n }\n\n if (flags.includes(\"u\")) {\n if (options.unicodeFlag === \"transform\") return false;\n if (\n options.unicodePropertyEscapes === \"transform\" &&\n /\\\\[pP]{/.test(pattern)\n ) {\n return false;\n }\n }\n\n if (flags.includes(\"s\")) {\n if (options.dotAllFlag === \"transform\") return false;\n }\n\n if (options.namedGroups === \"transform\" && /\\(\\?<(?![=!])/.test(pattern)) {\n return false;\n }\n\n if (options.modifiers === \"transform\" && /\\(\\?[\\w-]+:/.test(pattern)) {\n return false;\n }\n\n return true;\n}\n\nexport function transformFlags(regexpuOptions: RegexpuOptions, flags: string) {\n if (regexpuOptions.unicodeSetsFlag === \"transform\") {\n flags = flags.replace(\"v\", \"u\");\n }\n if (regexpuOptions.unicodeFlag === \"transform\") {\n flags = flags.replace(\"u\", \"\");\n }\n if (regexpuOptions.dotAllFlag === \"transform\") {\n flags = flags.replace(\"s\", \"\");\n }\n return flags;\n}\n"],"mappings":";;;;;;;;AACA;AAIO,SAASA,sBAAsB,CACpCC,OAAe,EACfC,WAAmB,EACH;EAGhB,MAAMC,IAAI,GAAG,CACXC,IAA2B,EAC3BC,EAAyD,GAAG,WAAW,KACpE;IACH,OAAO,IAAAC,oBAAU,EAACJ,WAAW,EAAEK,kBAAQ,CAACH,IAAI,CAAC,CAAC,GAAGC,EAAE,GAAG,KAAK;EAC7D,CAAC;EAED,MAAMG,wBAAwB,GAAG,MAA2B;IAC1D,IAAI,CAACL,IAAI,CAAC,6BAA6B,CAAC,EAAE,OAAO,KAAK;IAMtD,MAAMM,KAAK,GAAG,gBAAgB;IAC9B,MAAMC,IAAI,GAAG,IAAIC,GAAG,EAAE;IACtB,KAAK,IAAIC,KAAK,EAAGA,KAAK,GAAGH,KAAK,CAACI,IAAI,CAACZ,OAAO,CAAC,EAAGS,IAAI,CAACI,GAAG,CAACF,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;MACjE,IAAIF,IAAI,CAACK,GAAG,CAACH,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,WAAW;IAC5C;IACA,OAAO,KAAK;EACd,CAAC;EAED,OAAO;IACLI,WAAW,EAAEb,IAAI,CAAC,aAAa,CAAC;IAChCc,eAAe,EACbd,IAAI,CAAe,iBAAiB,CAAC,IACrCA,IAAI,CAAe,wBAAwB,EAAE,OAAO,CAAC;IACvDe,UAAU,EAAEf,IAAI,CAAC,YAAY,CAAC;IAC9BgB,sBAAsB,EAAEhB,IAAI,CAAC,uBAAuB,CAAC;IACrDiB,WAAW,EAAEjB,IAAI,CAAC,oBAAoB,CAAC,IAAIK,wBAAwB,EAAE;IACrEa,YAAY,EAAE,MAAM,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C;EACA,IAAID,cAAc,CAACZ,UAAU,KAAK,WAAW,EAAE;IAC7CQ,KAAK,GAAGA,KAAK,CAACK,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;EAChC;EACA,OAAOL,KAAK;AACd"}LICENSE000066600000002122150513176440005560 0ustar00MIT 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. package.json000066600000001513150513176440007044 0ustar00{ "name": "@babel/helper-create-regexp-features-plugin", "version": "7.21.0", "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.18.6", "regexpu-core": "^5.3.1" }, "peerDependencies": { "@babel/core": "^7.0.0" }, "devDependencies": { "@babel/core": "^7.21.0", "@babel/helper-plugin-test-runner": "^7.18.6" }, "engines": { "node": ">=6.9.0" }, "type": "commonjs" }