Sha256: a0f42540434b0fa82c11d75cfc1dabf5d95221ecaaee0a2996a5c48d963c1e07

Contents?: true

Size: 1.69 KB

Versions: 59

Compression:

Stored size: 1.69 KB

Contents

'use strict';

/**
 * Module dependencies
 */

var Snapdragon = require('snapdragon');
var define = require('define-property');
var extend = require('extend-shallow');

/**
 * Local dependencies
 */

var compilers = require('./compilers');
var parsers = require('./parsers');

/**
 * Customize Snapdragon parser and renderer
 */

function Extglob(options) {
  this.options = extend({source: 'extglob'}, options);
  this.snapdragon = this.options.snapdragon || new Snapdragon(this.options);
  this.snapdragon.patterns = this.snapdragon.patterns || {};
  this.compiler = this.snapdragon.compiler;
  this.parser = this.snapdragon.parser;

  compilers(this.snapdragon);
  parsers(this.snapdragon);

  /**
   * Override Snapdragon `.parse` method
   */

  define(this.snapdragon, 'parse', function(str, options) {
    var parsed = Snapdragon.prototype.parse.apply(this, arguments);
    parsed.input = str;

    // escape unmatched brace/bracket/parens
    var last = this.parser.stack.pop();
    if (last && this.options.strict !== true) {
      var node = last.nodes[0];
      node.val = '\\' + node.val;
      var sibling = node.parent.nodes[1];
      if (sibling.type === 'star') {
        sibling.loose = true;
      }
    }

    // add non-enumerable parser reference
    define(parsed, 'parser', this.parser);
    return parsed;
  });

  /**
   * Decorate `.parse` method
   */

  define(this, 'parse', function(ast, options) {
    return this.snapdragon.parse.apply(this.snapdragon, arguments);
  });

  /**
   * Decorate `.compile` method
   */

  define(this, 'compile', function(ast, options) {
    return this.snapdragon.compile.apply(this.snapdragon, arguments);
  });

}

/**
 * Expose `Extglob`
 */

module.exports = Extglob;

Version data entries

59 entries across 38 versions & 12 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/extglob/lib/extglob.js
disco_app-0.18.0 test/dummy/node_modules/extglob/lib/extglob.js
disco_app-0.18.2 test/dummy/node_modules/extglob/lib/extglob.js
disco_app-0.16.1 test/dummy/node_modules/extglob/lib/extglob.js
disco_app-0.15.2 test/dummy/node_modules/extglob/lib/extglob.js
disco_app-0.18.4 test/dummy/node_modules/extglob/lib/extglob.js
disco_app-0.18.1 test/dummy/node_modules/extglob/lib/extglob.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/extglob/lib/extglob.js
disco_app-0.14.0 test/dummy/node_modules/extglob/lib/extglob.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/extglob/lib/extglob.js
tang-0.2.1 spec/tang_app/node_modules/extglob/lib/extglob.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/extglob/lib/extglob.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/extglob/lib/extglob.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/extglob/lib/extglob.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/extglob/lib/extglob.js
tang-0.2.0 spec/tang_app/node_modules/extglob/lib/extglob.js
tang-0.1.0 spec/tang_app/node_modules/extglob/lib/extglob.js
tang-0.0.9 spec/tang_app/node_modules/extglob/lib/extglob.js
enju_library-0.3.8 spec/dummy/node_modules/extglob/lib/extglob.js
ilog-0.4.1 node_modules/readdirp/node_modules/extglob/lib/extglob.js