diff options
Diffstat (limited to 'node_modules/nanomatch/lib')
-rw-r--r-- | node_modules/nanomatch/lib/.DS_Store | bin | 0 -> 6148 bytes | |||
-rw-r--r-- | node_modules/nanomatch/lib/compilers.js | 76 | ||||
-rw-r--r-- | node_modules/nanomatch/lib/parsers.js | 15 | ||||
-rw-r--r-- | node_modules/nanomatch/lib/utils.js | 29 |
4 files changed, 72 insertions, 48 deletions
diff --git a/node_modules/nanomatch/lib/.DS_Store b/node_modules/nanomatch/lib/.DS_Store Binary files differnew file mode 100644 index 000000000..5008ddfcf --- /dev/null +++ b/node_modules/nanomatch/lib/.DS_Store diff --git a/node_modules/nanomatch/lib/compilers.js b/node_modules/nanomatch/lib/compilers.js index 1edcff0fd..c2331b287 100644 --- a/node_modules/nanomatch/lib/compilers.js +++ b/node_modules/nanomatch/lib/compilers.js @@ -1,7 +1,5 @@ 'use strict'; -var isExtglob = require('is-extglob'); - /** * Nanomatch compilers */ @@ -12,13 +10,11 @@ module.exports = function(nanomatch, options) { var ast = nanomatch.ast = nanomatch.parser.ast; ast.state = nanomatch.parser.state; nanomatch.compiler.state = ast.state; - nanomatch.compiler /** * Negation / escaping */ - .set('not', function(node) { var prev = this.prev(); if (this.options.nonegate === true || prev.type !== 'bos') { @@ -64,25 +60,33 @@ module.exports = function(nanomatch, options) { return this.emit(node.val, node); }) .set('slash', function(node, nodes, i) { + var val = '\\' + node.val; var parent = node.parent; + var prev = this.prev(); + + // set "node.hasSlash" to true on all ancestor parens nodes while (parent.type === 'paren' && !parent.hasSlash) { parent.hasSlash = true; parent = parent.parent; } + if (prev.addQmark) { + val += '?'; + } + // word boundary if (node.rest.slice(0, 2) === '\\b') { - return this.emit(node.val, node); + return this.emit(val, node); } - var parsed = node.parsed; - var val = '\\' + node.val; - - if (parsed === '**' || parsed === './**') { - this.output = '(^(?=.)|' + this.output; - return this.emit(val + ')', node); + // globstars + if (node.parsed === '**' || node.parsed === './**') { + this.output = '(?:' + this.output; + return this.emit(val + ')?', node); } - if (parsed === '!**' && this.options.nonegate !== true) { + + // negation + if (node.parsed === '!**' && this.options.nonegate !== true) { return this.emit(val + '?\\b', node); } return this.emit(val, node); @@ -176,12 +180,27 @@ module.exports = function(nanomatch, options) { */ .set('globstar', function(node, nodes, i) { - if (!this.output) this.output = '(?=.)' + this.output; + if (!this.output) { + this.state.leadingGlobstar = true; + } + var next = this.next(); var prev = this.prev(); + var next2 = this.next(2); + var prev2 = this.prev(2); var type = prev.type; var val = node.val; + if (prev.type === 'slash' && next.type === 'slash') { + if (prev2.type === 'text') { + this.output += '?'; + + if (next2.type !== 'text') { + this.output += '\\b'; + } + } + } + var parsed = node.parsed; if (parsed.charAt(0) === '!') { parsed = parsed.slice(1); @@ -195,18 +214,18 @@ module.exports = function(nanomatch, options) { : '(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/))(?!\\.{2}).)*?'; } - var prior = nodes[i - 2] || {}; - if (type === 'slash' && this.output !== '\\/' && node.rest.charAt(0) === '/' && prior.type !== 'qmark' && !isExtglob(node.rest)) { - this.output += '?\\b'; - } - if ((type === 'slash' || type === 'bos') && this.options.dot !== true) { val = '(?!\\.)' + val; } - if (this.output === '\\/' && nodes[i + 1].type !== 'eos') { - this.output = '(\\/|'; - return this.emit('\\/' + val + ')?(?=.)', node); + if (prev.type === 'slash' && next.type === 'slash' && prev2.type !== 'text') { + if (next2.type === 'text' || next2.type === 'star') { + node.addQmark = true; + } + } + + if (this.options.capture) { + val = '(' + val + ')'; } return this.emit(val, node); @@ -255,7 +274,12 @@ module.exports = function(nanomatch, options) { this.output = '(?!\\.)' + this.output; } - return this.emit(prefix + star, node); + var output = prefix + star; + if (this.options.capture) { + output = '(' + output + ')'; + } + + return this.emit(output, node); }) /** @@ -271,14 +295,12 @@ module.exports = function(nanomatch, options) { */ .set('eos', function(node) { - if (this.output.slice(-2) === '/?' || this.output.slice(-6) === '(\\/|$)') { - return this.emit(node.val, node); - } - var prev = this.prev(); var val = node.val; + + this.output = '(?:(?:\\.(?:\\/|\\\\))(?=.))?' + this.output; if (this.state.metachar && prev.type !== 'qmark' && prev.type !== 'slash') { - val += (this.options.contains ? '\\/?' : '(\\/|$)'); + val += (this.options.contains ? '(?:\\/|\\\\)?' : '(?:(?:\\/|\\\\)|$)'); } return this.emit(val, node); diff --git a/node_modules/nanomatch/lib/parsers.js b/node_modules/nanomatch/lib/parsers.js index b98ef3746..0b0a59a59 100644 --- a/node_modules/nanomatch/lib/parsers.js +++ b/node_modules/nanomatch/lib/parsers.js @@ -39,13 +39,8 @@ module.exports = function(nanomatch, options) { var m = this.match(/^\.[\\/]/); if (!m) return; - this.ast.strictOpen = !!this.options.strictOpen; - this.ast.addPrefix = true; - - return pos({ - type: 'bos', - val: '' - }); + this.state.strictOpen = !!this.options.strictOpen; + this.state.addPrefix = true; }) /** @@ -130,11 +125,11 @@ module.exports = function(nanomatch, options) { if (!m) return; var val = m[0]; - this.ast.dot = val === '.' && (parsed === '' || parsed.slice(-1) === '/'); + this.state.dot = val === '.' && (parsed === '' || parsed.slice(-1) === '/'); return pos({ type: 'dot', - dotfiles: this.ast.dot, + dotfiles: this.state.dot, val: val }); }) @@ -175,7 +170,7 @@ module.exports = function(nanomatch, options) { var m = this.match(/^\*{2}(?![*(])(?=[,\/)]|$)/); if (!m) return; - var type = opts.noglobstar !== true ? 'globstar': 'star'; + var type = opts.noglobstar !== true ? 'globstar' : 'star'; var node = pos({type: type, parsed: parsed}); if (this.input.slice(0, 4) === '/**/') { diff --git a/node_modules/nanomatch/lib/utils.js b/node_modules/nanomatch/lib/utils.js index 962523be7..6fc434012 100644 --- a/node_modules/nanomatch/lib/utils.js +++ b/node_modules/nanomatch/lib/utils.js @@ -16,6 +16,14 @@ utils.typeOf = require('kind-of'); utils.unique = require('array-unique'); /** + * Returns true if the given value is effectively an empty string + */ + +utils.isEmptyString = function(val) { + return String(val) === '' || String(val) === './'; +}; + +/** * Returns true if the platform is windows, or `path.sep` is `\\`. * This is defined as a function to allow `path.sep` to be set in unit tests, * or by the user, if there is a reason to do so. @@ -204,11 +212,7 @@ utils.stripDrive = function(fp) { */ utils.stripPrefix = function(str) { - if (str.charAt(0) !== '.') { - return str; - } - var ch = str.charAt(1); - if (utils.isSlash(ch)) { + if (str.charAt(0) === '.' && (str.charAt(1) === '/' || str.charAt(1) === '\\')) { return str.slice(2); } return str; @@ -342,6 +346,9 @@ utils.value = function(str, unixify, options) { if (options && options.unixify === false) { return str; } + if (options && typeof options.unixify === 'function') { + return options.unixify(str); + } return unixify(str); }; @@ -353,17 +360,17 @@ utils.value = function(str, unixify, options) { */ utils.unixify = function(options) { - options = options || {}; + var opts = options || {}; return function(filepath) { - if (utils.isWindows() || options.unixify === true) { - filepath = utils.toPosixPath(filepath); - } - if (options.stripPrefix !== false) { + if (opts.stripPrefix !== false) { filepath = utils.stripPrefix(filepath); } - if (options.unescape === true) { + if (opts.unescape === true) { filepath = utils.unescape(filepath); } + if (opts.unixify === true || utils.isWindows()) { + filepath = utils.toPosixPath(filepath); + } return filepath; }; }; |