This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/regexp-tree/dist/compat-transpiler/transforms/compat-named-capturing-groups-transform.js
2019-08-11 20:48:02 +02:00

58 lines
No EOL
1 KiB
JavaScript

/**
* The MIT License (MIT)
* Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*/
'use strict';
/**
* A regexp-tree plugin to translate `/(?<name>a)\k<name>/` to `/(a)\1/`.
*/
module.exports = {
// To track the names of the groups, and return them
// in the transform result state.
//
// A map from name to number: {foo: 2, bar: 4}
_groupNames: {},
/**
* Initialises the trasnform.
*/
init: function init() {
this._groupNames = {};
},
/**
* Returns extra state, which eventually is returned to
*/
getExtra: function getExtra() {
return this._groupNames;
},
Group: function Group(path) {
var node = path.node;
if (!node.name) {
return;
}
// Record group name.
this._groupNames[node.name] = node.number;
delete node.name;
},
Backreference: function Backreference(path) {
var node = path.node;
if (node.kind !== 'name') {
return;
}
node.kind = 'number';
node.reference = node.number;
}
};