Sha256: d72147b24cf6b14dd8964d96e58977a5c965cd8f970fdb9a9d6260493e58b17a

Contents?: true

Size: 1.38 KB

Versions: 104

Compression:

Stored size: 1.38 KB

Contents

'use strict';

const fill = require('fill-range');
const utils = require('./utils');

const compile = (ast, options = {}) => {
  let walk = (node, parent = {}) => {
    let invalidBlock = utils.isInvalidBrace(parent);
    let invalidNode = node.invalid === true && options.escapeInvalid === true;
    let invalid = invalidBlock === true || invalidNode === true;
    let prefix = options.escapeInvalid === true ? '\\' : '';
    let output = '';

    if (node.isOpen === true) {
      return prefix + node.value;
    }
    if (node.isClose === true) {
      return prefix + node.value;
    }

    if (node.type === 'open') {
      return invalid ? (prefix + node.value) : '(';
    }

    if (node.type === 'close') {
      return invalid ? (prefix + node.value) : ')';
    }

    if (node.type === 'comma') {
      return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
    }

    if (node.value) {
      return node.value;
    }

    if (node.nodes && node.ranges > 0) {
      let args = utils.reduce(node.nodes);
      let range = fill(...args, { ...options, wrap: false, toRegex: true });

      if (range.length !== 0) {
        return args.length > 1 && range.length > 1 ? `(${range})` : range;
      }
    }

    if (node.nodes) {
      for (let child of node.nodes) {
        output += walk(child, node);
      }
    }
    return output;
  };

  return walk(ast);
};

module.exports = compile;

Version data entries

104 entries across 95 versions & 10 rubygems

Version Path
disco_app-0.18.4 test/dummy/node_modules/sass/node_modules/braces/lib/compile.js
disco_app-0.18.4 test/dummy/node_modules/watchpack/node_modules/braces/lib/compile.js
disco_app-0.18.1 test/dummy/node_modules/watchpack/node_modules/braces/lib/compile.js
disco_app-0.18.1 test/dummy/node_modules/sass/node_modules/braces/lib/compile.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/sass/node_modules/braces/lib/compile.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/watchpack/node_modules/braces/lib/compile.js
disco_app-0.14.0 test/dummy/node_modules/watchpack/node_modules/braces/lib/compile.js
disco_app-0.14.0 test/dummy/node_modules/sass/node_modules/braces/lib/compile.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/watchpack/node_modules/braces/lib/compile.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/sass/node_modules/braces/lib/compile.js
appmap-0.66.2 ./node_modules/braces/lib/compile.js
trusty-cms-5.0.1 node_modules/braces/lib/compile.js
trusty-cms-4.3.5 node_modules/braces/lib/compile.js
trusty-cms-5.0.0 node_modules/braces/lib/compile.js
appmap-0.66.1 ./node_modules/braces/lib/compile.js
appmap-0.66.0 ./node_modules/braces/lib/compile.js
appmap-0.65.1 ./node_modules/braces/lib/compile.js
appmap-0.65.0 ./node_modules/braces/lib/compile.js
trusty-cms-4.3.4 node_modules/braces/lib/compile.js
appmap-0.64.0 ./node_modules/braces/lib/compile.js