Socket
Socket
Sign inDemoInstall

@babel/helper-create-regexp-features-plugin

Package Overview
Dependencies
68
Maintainers
4
Versions
48
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.22.9 to 8.0.0-alpha.0

23

lib/features.js

@@ -1,12 +0,2 @@

"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({
export const FEATURES = Object.freeze({
unicodeFlag: 1 << 0,

@@ -21,11 +11,8 @@ dotAllFlag: 1 << 1,

});
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) {
export const featuresKey = "@babel/plugin-regexp-features/featuresKey";
export const runtimeKey = "@babel/plugin-regexp-features/runtimeKey";
export function enableFeature(features, feature) {
return features | feature;
}
function hasFeature(features, feature) {
export function hasFeature(features, feature) {
return !!(features & feature);

@@ -32,0 +19,0 @@ }

@@ -1,13 +0,86 @@

"use strict";
import rewritePattern from 'regexpu-core';
import { types } from '@babel/core';
import annotateAsPure from '@babel/helper-annotate-as-pure';
import semver from 'semver';
Object.defineProperty(exports, "__esModule", {
value: true
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.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");
var _util = require("./util");
const featuresKey = "@babel/plugin-regexp-features/featuresKey";
const runtimeKey = "@babel/plugin-regexp-features/runtimeKey";
function enableFeature(features, feature) {
return features | feature;
}
function hasFeature(features, feature) {
return !!(features & feature);
}
function generateRegexpuOptions(pattern, toTransform) {
const feat = (name, ok = "transform") => {
return hasFeature(toTransform, 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") || "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;
}
const versionKey = "@babel/plugin-regexp-features/version";

@@ -24,8 +97,7 @@ function createRegExpFeaturePlugin({

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 features = file.get(featuresKey) ?? 0;
let newFeatures = enableFeature(features, FEATURES[feature]);
const {

@@ -36,30 +108,21 @@ useUnicodeFlag,

if (useUnicodeFlag === false) {
newFeatures = (0, _features.enableFeature)(newFeatures, _features.FEATURES.unicodeFlag);
newFeatures = enableFeature(newFeatures, FEATURES.unicodeFlag);
}
if (newFeatures !== features) {
file.set(_features.featuresKey, newFeatures);
file.set(featuresKey, newFeatures);
}
if (runtime !== undefined) {
if (file.has(_features.runtimeKey) && file.get(_features.runtimeKey) !== runtime && (0, _features.hasFeature)(newFeatures, _features.FEATURES.duplicateNamedCaptureGroups)) {
if (file.has(runtimeKey) && file.get(runtimeKey) !== runtime && true) {
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);
{
file.set(runtimeKey, runtime);
}
}
{
if (typeof file.get(versionKey) === "number") {
file.set(versionKey, "7.22.9");
return;
}
if (!file.get(versionKey) || semver.lt(file.get(versionKey), "8.0.0-alpha.0")) {
file.set(versionKey, "8.0.0-alpha.0");
}
if (!file.get(versionKey) || _semver.lt(file.get(versionKey), "7.22.9")) {
file.set(versionKey, "7.22.9");
}
},
visitor: {
RegExpLiteral(path) {
var _file$get2, _newFlags;
const {

@@ -71,6 +134,6 @@ node

} = 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)) {
const features = file.get(featuresKey);
const runtime = file.get(runtimeKey) ?? true;
const regexpuOptions = generateRegexpuOptions(node.pattern, features);
if (canSkipRegexpu(node, regexpuOptions)) {
return;

@@ -99,9 +162,9 @@ }

}
node.pattern = _regexpuCore(node.pattern, node.flags, regexpuOptions);
node.pattern = rewritePattern(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);
const call = types.callExpression(this.addHelper("wrapRegExp"), [node, types.valueToNode(namedCaptureGroups)]);
annotateAsPure(call);
path.replaceWith(call);
}
node.flags = (0, _util.transformFlags)(regexpuOptions, (_newFlags = newFlags) != null ? _newFlags : node.flags);
node.flags = transformFlags(regexpuOptions, newFlags ?? node.flags);
}

@@ -120,2 +183,3 @@ }

export { createRegExpFeaturePlugin };
//# sourceMappingURL=index.js.map

@@ -1,13 +0,5 @@

"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) {
import { FEATURES, hasFeature } from "./features.js";
export function generateRegexpuOptions(pattern, toTransform) {
const feat = (name, ok = "transform") => {
return (0, _features.hasFeature)(toTransform, _features.FEATURES[name]) ? ok : false;
return hasFeature(toTransform, FEATURES[name]) ? ok : false;
};

@@ -33,3 +25,3 @@ const featDuplicateNamedGroups = () => {

}
function canSkipRegexpu(node, options) {
export function canSkipRegexpu(node, options) {
const {

@@ -59,3 +51,3 @@ flags,

}
function transformFlags(regexpuOptions, flags) {
export function transformFlags(regexpuOptions, flags) {
if (regexpuOptions.unicodeSetsFlag === "transform") {

@@ -62,0 +54,0 @@ flags = flags.replace("v", "u");

{
"name": "@babel/helper-create-regexp-features-plugin",
"version": "7.22.9",
"version": "8.0.0-alpha.0",
"author": "The Babel Team (https://babel.dev/team)",

@@ -21,17 +21,21 @@ "license": "MIT",

"dependencies": {
"@babel/helper-annotate-as-pure": "^7.22.5",
"@babel/helper-annotate-as-pure": "^8.0.0-alpha.0",
"regexpu-core": "^5.3.1",
"semver": "^6.3.1"
"semver": "^7.3.4"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
"@babel/core": "^8.0.0-alpha.0"
},
"devDependencies": {
"@babel/core": "^7.22.9",
"@babel/helper-plugin-test-runner": "^7.22.5"
"@babel/core": "^8.0.0-alpha.0",
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.0"
},
"engines": {
"node": ">=6.9.0"
"node": "^16.20.0 || ^18.16.0 || >=20.0.0"
},
"type": "commonjs"
"exports": {
".": "./lib/index.js",
"./package.json": "./package.json"
},
"type": "module"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc