You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
9.6 KiB
1 line
9.6 KiB
1 month ago
|
{"version":3,"names":["_regexpuCore","require","_core","_helperAnnotateAsPure","_semver","_features","_util","versionKey","createRegExpFeaturePlugin","name","feature","options","manipulateOptions","pre","_file$get","file","features","get","featuresKey","newFeatures","enableFeature","FEATURES","useUnicodeFlag","runtime","unicodeFlag","set","undefined","has","runtimeKey","hasFeature","duplicateNamedCaptureGroups","Error","semver","lt","visitor","RegExpLiteral","path","_file$get2","_newFlags","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 { types as t, type PluginObject, type NodePath } from \"@babel/core\";\nimport annotateAsPure from \"@babel/helper-annotate-as-pure\";\n\nimport semver from \"semver\";\n\nimport {\n featuresKey,\n FEATURES,\n enableFeature,\n runtimeKey,\n hasFeature,\n} from \"./features.ts\";\nimport {\n generateRegexpuOptions,\n canSkipRegexpu,\n transformFlags,\n} from \"./util.ts\";\n\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 (process.env.BABEL_8_BREAKING ||\n // This check. Is necessary because in Babel 7 we allow multiple\n // copies of transform-named-capturing-groups-regex with\n // 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-transform-duplicate-named-capturing-groups-regex'.`,\n );\n }\n\n if (process.env.BABEL_8_BREAKING) {\n file.set(runtimeKey, runtime);\n } else if (\n // This check. Is necessary because in Babel 7 we allow multiple\n // copies of transform-named-capturing-groups-regex with\n // conflicting 'runtime' options.\n feature === \"namedCaptureGroups\"\n ) {\n if (!runtime || !file.has(runtimeKey)) file.set(runtimeKey, runtime);\n } else {\n file.set(runtimeKey, runtime);\n }\n }\n\n if (!process.env.BABEL_8_BREAKING) {\n // Until 7.21.4, we used to encode the version as a number.\n // If file.get(versionKey) is a number, it has thus been\n // set by an older version of this plugin.\n if (typeof file.get(versionKey) === \"number\") {\n file.set(versionKey, PACKAGE_JSON.version);\n return;\n }\n }\n if (\n !file.get(versionKey) ||\n semver.lt(file.get(versionKey), PACKAGE_JSON.versi
|