Sha256: dd69c38099ec2138bce84c4eb02dc9cd11731a998917930eb6dab77fc1db9ac9

Contents?: true

Size: 599 Bytes

Versions: 10

Compression:

Stored size: 599 Bytes

Contents

/**
 * 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();
    }
  }
};

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
condenser-0.0.8 lib/condenser/processors/node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
jester-data-8.0.0 node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
ezii-os-5.2.1 node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
ezii-os-2.0.1 node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
ezii-os-1.1.0 node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
ezii-os-1.0.0 node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
condenser-0.0.7 lib/condenser/processors/node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
ezii-os-0.0.0.1.0 node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
ezii-os-0.0.0.0.1 node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js
condenser-0.0.5 lib/condenser/processors/node_modules/regexp-tree/dist/optimizer/transforms/remove-empty-group-transform.js