WIP - add extractor, generate snippet_data
This commit is contained in:
34
node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
generated
vendored
Normal file
34
node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* A regexp-tree plugin to remove non-capturing empty groups.
|
||||
*
|
||||
* /(?:)a/ -> /a/
|
||||
* /a|(?:)/ -> /a|/
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
Group: function Group(path) {
|
||||
var node = path.node,
|
||||
parent = path.parent;
|
||||
|
||||
var childPath = path.getChild();
|
||||
|
||||
if (node.capturing || childPath) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (parent.type === 'Repetition') {
|
||||
|
||||
path.getParent().replace(node);
|
||||
} else if (parent.type !== 'RegExp') {
|
||||
|
||||
path.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user