@babel/helper-create-regexp-features-plugin
Advanced tools
Comparing version 7.16.7 to 7.17.0
@@ -15,3 +15,5 @@ "use strict"; | ||
unicodePropertyEscape: 1 << 2, | ||
namedCaptureGroups: 1 << 3 | ||
namedCaptureGroups: 1 << 3, | ||
unicodeSetsFlag_syntax: 1 << 4, | ||
unicodeSetsFlag: 1 << 5 | ||
}); | ||
@@ -18,0 +20,0 @@ exports.FEATURES = FEATURES; |
@@ -18,7 +18,3 @@ "use strict"; | ||
function pullFlag(node, flag) { | ||
node.flags = node.flags.replace(flag, ""); | ||
} | ||
const version = "7.16.7".split(".").reduce((v, x) => v * 1e5 + +x, 0); | ||
const version = "7.17.0".split(".").reduce((v, x) => v * 1e5 + +x, 0); | ||
const versionKey = "@babel/plugin-regexp-features/version"; | ||
@@ -29,6 +25,8 @@ | ||
feature, | ||
options = {} | ||
options = {}, | ||
manipulateOptions = () => {} | ||
}) { | ||
return { | ||
name, | ||
manipulateOptions, | ||
@@ -77,11 +75,7 @@ pre() { | ||
const runtime = (_file$get2 = file.get(_features.runtimeKey)) != null ? _file$get2 : true; | ||
const regexpuOptions = (0, _util.generateRegexpuOptions)(node, features); | ||
if (regexpuOptions === null) { | ||
return; | ||
} | ||
const regexpuOptions = (0, _util.generateRegexpuOptions)(features); | ||
if ((0, _util.canSkipRegexpu)(node, regexpuOptions)) return; | ||
const namedCaptureGroups = {}; | ||
if (regexpuOptions.namedGroup) { | ||
if (regexpuOptions.namedGroups === "transform") { | ||
regexpuOptions.onNamedGroup = (name, index) => { | ||
@@ -94,3 +88,3 @@ namedCaptureGroups[name] = index; | ||
if (regexpuOptions.namedGroup && Object.keys(namedCaptureGroups).length > 0 && runtime && !isRegExpTest(path)) { | ||
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)]); | ||
@@ -102,9 +96,3 @@ | ||
if ((0, _features.hasFeature)(features, _features.FEATURES.unicodeFlag)) { | ||
pullFlag(node, "u"); | ||
} | ||
if ((0, _features.hasFeature)(features, _features.FEATURES.dotAllFlag)) { | ||
pullFlag(node, "s"); | ||
} | ||
node.flags = (0, _util.transformFlags)(regexpuOptions, node.flags); | ||
} | ||
@@ -111,0 +99,0 @@ |
@@ -6,11 +6,24 @@ "use strict"; | ||
}); | ||
exports.canSkipRegexpu = canSkipRegexpu; | ||
exports.generateRegexpuOptions = generateRegexpuOptions; | ||
exports.transformFlags = transformFlags; | ||
var _features = require("./features"); | ||
function generateRegexpuOptions(node, features) { | ||
let useUnicodeFlag = false, | ||
dotAllFlag = false, | ||
unicodePropertyEscape = false, | ||
namedGroup = false; | ||
function generateRegexpuOptions(toTransform) { | ||
const feat = (name, ok = "transform") => { | ||
return (0, _features.hasFeature)(toTransform, _features.FEATURES[name]) ? ok : false; | ||
}; | ||
return { | ||
unicodeFlag: feat("unicodeFlag"), | ||
unicodeSetsFlag: feat("unicodeSetsFlag") || feat("unicodeSetsFlag_syntax", "parse"), | ||
dotAllFlag: feat("dotAllFlag"), | ||
unicodePropertyEscapes: feat("unicodePropertyEscape"), | ||
namedGroups: feat("namedCaptureGroups"), | ||
onNamedGroup: () => {} | ||
}; | ||
} | ||
function canSkipRegexpu(node, options) { | ||
const { | ||
@@ -20,38 +33,40 @@ flags, | ||
} = node; | ||
const flagsIncludesU = flags.includes("u"); | ||
if (flagsIncludesU) { | ||
if (!(0, _features.hasFeature)(features, _features.FEATURES.unicodeFlag)) { | ||
useUnicodeFlag = true; | ||
} | ||
if (flags.includes("v")) { | ||
if (options.unicodeSetsFlag === "transform") return false; | ||
} | ||
if ((0, _features.hasFeature)(features, _features.FEATURES.unicodePropertyEscape) && /\\[pP]{/.test(pattern)) { | ||
unicodePropertyEscape = true; | ||
if (flags.includes("u")) { | ||
if (options.unicodeFlag === "transform") return false; | ||
if (options.unicodePropertyEscapes === "transform" && /\\[pP]{/.test(pattern)) { | ||
return false; | ||
} | ||
} | ||
if ((0, _features.hasFeature)(features, _features.FEATURES.dotAllFlag) && flags.indexOf("s") >= 0) { | ||
dotAllFlag = true; | ||
if (flags.includes("s")) { | ||
if (options.dotAllFlag === "transform") return false; | ||
} | ||
if ((0, _features.hasFeature)(features, _features.FEATURES.namedCaptureGroups) && /\(\?<(?![=!])/.test(pattern)) { | ||
namedGroup = true; | ||
if (options.namedGroups === "transform" && /\(\?<(?![=!])/.test(pattern)) { | ||
return false; | ||
} | ||
if (!namedGroup && !unicodePropertyEscape && !dotAllFlag && (!flagsIncludesU || useUnicodeFlag)) { | ||
return null; | ||
return true; | ||
} | ||
function transformFlags(regexpuOptions, flags) { | ||
if (regexpuOptions.unicodeSetsFlag === "transform") { | ||
flags = flags.replace("v", "u"); | ||
} | ||
if (flagsIncludesU && flags.indexOf("s") >= 0) { | ||
dotAllFlag = true; | ||
if (regexpuOptions.unicodeFlag === "transform") { | ||
flags = flags.replace("u", ""); | ||
} | ||
return { | ||
useUnicodeFlag, | ||
onNamedGroup: () => {}, | ||
namedGroup, | ||
unicodePropertyEscape, | ||
dotAllFlag, | ||
lookbehind: true | ||
}; | ||
if (regexpuOptions.dotAllFlag === "transform") { | ||
flags = flags.replace("s", ""); | ||
} | ||
return flags; | ||
} |
{ | ||
"name": "@babel/helper-create-regexp-features-plugin", | ||
"version": "7.16.7", | ||
"version": "7.17.0", | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
@@ -22,3 +22,3 @@ "license": "MIT", | ||
"@babel/helper-annotate-as-pure": "^7.16.7", | ||
"regexpu-core": "^4.7.1" | ||
"regexpu-core": "^5.0.1" | ||
}, | ||
@@ -29,3 +29,3 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "^7.16.7", | ||
"@babel/core": "^7.17.0", | ||
"@babel/helper-plugin-test-runner": "^7.16.7" | ||
@@ -32,0 +32,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7771
163
+ Added@babel/regjsgen@0.8.0(transitive)
+ Addedregenerate-unicode-properties@10.2.0(transitive)
+ Addedregexpu-core@5.3.2(transitive)
+ Addedregjsparser@0.9.1(transitive)
- Removedregenerate-unicode-properties@9.0.0(transitive)
- Removedregexpu-core@4.8.0(transitive)
- Removedregjsgen@0.5.2(transitive)
- Removedregjsparser@0.7.0(transitive)
Updatedregexpu-core@^5.0.1