3 var brackets = require('expand-brackets');
9 module.exports = function(extglob) {
11 if (typeof extglob.options.star === 'function') {
12 return extglob.options.star.apply(this, arguments);
14 if (typeof extglob.options.star === 'string') {
15 return extglob.options.star;
21 * Use `expand-brackets` compilers
24 extglob.use(brackets.compilers);
31 .set('escape', function(node) {
32 return this.emit(node.val, node);
39 .set('dot', function(node) {
40 return this.emit('\\' + node.val, node);
47 .set('qmark', function(node) {
48 var val = '[^\\\\/.]';
49 var prev = this.prev();
51 if (node.parsed.slice(-1) === '(') {
52 var ch = node.rest.charAt(0);
53 if (ch !== '!' && ch !== '=' && ch !== ':') {
54 return this.emit(val, node);
56 return this.emit(node.val, node);
59 if (prev.type === 'text' && prev.val) {
60 return this.emit(val, node);
63 if (node.val.length > 1) {
64 val += '{' + node.val.length + '}';
66 return this.emit(val, node);
73 .set('plus', function(node) {
74 var prev = node.parsed.slice(-1);
75 if (prev === ']' || prev === ')') {
76 return this.emit(node.val, node);
78 var ch = this.output.slice(-1);
79 if (!this.output || (/[?*+]/.test(ch) && node.parent.type !== 'bracket')) {
80 return this.emit('\\+', node);
82 if (/\w/.test(ch) && !node.inside) {
83 return this.emit('+\\+?', node);
85 return this.emit('+', node);
92 .set('star', function(node) {
93 var prev = this.prev();
94 var prefix = prev.type !== 'text' && prev.type !== 'escape'
98 return this.emit(prefix + star.call(this, node), node);
105 .set('paren', function(node) {
106 return this.mapVisit(node.nodes);
108 .set('paren.open', function(node) {
109 var capture = this.options.capture ? '(' : '';
111 switch (node.parent.prefix) {
114 return this.emit(capture + '(?:(?!(?:', node);
119 return this.emit(capture + '(?:', node);
122 if (this.options.bash === true) {
124 } else if (!this.options.capture && val === '(' && node.parent.rest[0] !== '?') {
128 return this.emit(val, node);
132 .set('paren.close', function(node) {
133 var capture = this.options.capture ? ')' : '';
135 switch (node.prefix) {
138 var prefix = /^(\)|$)/.test(node.rest) ? '$' : '';
139 var str = star.call(this, node);
141 // if the extglob has a slash explicitly defined, we know the user wants
142 // to match slashes, so we need to ensure the "star" regex allows for it
143 if (node.parent.hasSlash && !this.options.star && this.options.slash !== false) {
147 return this.emit(prefix + ('))' + str + ')') + capture, node);
151 return this.emit(')' + node.prefix + capture, node);
153 return this.emit(')' + capture, node);
155 var val = (this.options.bash === true ? '\\' : '') + ')';
156 return this.emit(val, node);
165 .set('text', function(node) {
166 var val = node.val.replace(/[\[\]]/g, '\\$&');
167 return this.emit(val, node);