diff options
Diffstat (limited to 'node_modules/nanomatch/lib/compilers.js')
-rw-r--r-- | node_modules/nanomatch/lib/compilers.js | 76 |
1 files changed, 49 insertions, 27 deletions
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); |