mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-10-10 05:21:30 +07:00
Improve code quality and write tests
This commit is contained in:
67
node_modules/@babel/plugin-transform-named-capturing-groups-regex/lib/index.js
generated
vendored
Normal file
67
node_modules/@babel/plugin-transform-named-capturing-groups-regex/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _default;
|
||||
|
||||
function _regexpTree() {
|
||||
const data = _interopRequireDefault(require("regexp-tree"));
|
||||
|
||||
_regexpTree = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _default({
|
||||
types: t
|
||||
}, options) {
|
||||
const {
|
||||
runtime = true
|
||||
} = options;
|
||||
|
||||
if (typeof runtime !== "boolean") {
|
||||
throw new Error("The 'runtime' option must be boolean");
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-named-capturing-groups-regex",
|
||||
visitor: {
|
||||
RegExpLiteral(path) {
|
||||
const node = path.node;
|
||||
|
||||
if (!/\(\?<(?![=!])/.test(node.pattern)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = _regexpTree().default.compatTranspile(node.extra.raw, ["namedCapturingGroups"]);
|
||||
|
||||
const {
|
||||
namedCapturingGroups
|
||||
} = result.getExtra();
|
||||
|
||||
if (namedCapturingGroups && Object.keys(namedCapturingGroups).length > 0) {
|
||||
node.pattern = result.getSource();
|
||||
|
||||
if (runtime && !isRegExpTest(path)) {
|
||||
path.replaceWith(t.callExpression(this.addHelper("wrapRegExp"), [node, t.valueToNode(namedCapturingGroups)]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function isRegExpTest(path) {
|
||||
return path.parentPath.isMemberExpression({
|
||||
object: path.node,
|
||||
computed: false
|
||||
}) && path.parentPath.get("property").isIdentifier({
|
||||
name: "test"
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user