Skip to content

Commit

Permalink
Merge pull request #12 from micromatch/snap-11
Browse files Browse the repository at this point in the history
Update snapdragon to 0.12
  • Loading branch information
danez committed Apr 30, 2018
2 parents b00d865 + e90b000 commit dedd109
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 136 deletions.
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ os:
- osx
language: node_js
node_js:
- node
- '9'
- '10'
- '8'
- '7'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
6 changes: 2 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
environment:
matrix:
# node.js
- nodejs_version: "10.0"
- nodejs_version: "8.0"
- nodejs_version: "7.0"
- nodejs_version: "6.0"
- nodejs_version: "5.0"
- nodejs_version: "0.12"
- nodejs_version: "0.10"
- nodejs_version: "4.0"

# Install scripts. (runs after repo cloning)
install:
Expand Down
10 changes: 5 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

var gulp = require('gulp');
var mocha = require('gulp-mocha');
var unused = require('gulp-unused');
var istanbul = require('gulp-istanbul');
var eslint = require('gulp-eslint');
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const unused = require('gulp-unused');
const istanbul = require('gulp-istanbul');
const eslint = require('gulp-eslint');

gulp.task('coverage', function() {
return gulp.src(['index.js', 'lib/*.js'])
Expand Down
67 changes: 33 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
* Module dependencies
*/

var extend = require('extend-shallow');
var unique = require('array-unique');
var toRegex = require('to-regex');
const unique = require('array-unique');
const toRegex = require('to-regex');

/**
* Local dependencies
*/

var compilers = require('./lib/compilers');
var parsers = require('./lib/parsers');
var Extglob = require('./lib/extglob');
var utils = require('./lib/utils');
var MAX_LENGTH = 1024 * 64;
const compilers = require('./lib/compilers');
const parsers = require('./lib/parsers');
const Extglob = require('./lib/extglob');
const utils = require('./lib/utils');
const MAX_LENGTH = 1024 * 64;

/**
* Convert the given `extglob` pattern into a regex-compatible string. Returns
* an object with the compiled result and the parsed AST.
*
* ```js
* var extglob = require('extglob');
* const extglob = require('extglob');
* console.log(extglob('*.!(*a)'));
* //=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?'
* ```
Expand All @@ -42,7 +41,7 @@ function extglob(pattern, options) {
* array that contains only the strings that match the pattern.
*
* ```js
* var extglob = require('extglob');
* const extglob = require('extglob');
* console.log(extglob.match(['a.a', 'a.b', 'a.c'], '*.!(*a)'));
* //=> ['a.b', 'a.c']
* ```
Expand All @@ -59,13 +58,13 @@ extglob.match = function(list, pattern, options) {
}

list = utils.arrayify(list);
var isMatch = extglob.matcher(pattern, options);
var len = list.length;
var idx = -1;
var matches = [];
const isMatch = extglob.matcher(pattern, options);
const len = list.length;
let idx = -1;
const matches = [];

while (++idx < len) {
var ele = list[idx];
const ele = list[idx];

if (isMatch(ele)) {
matches.push(ele);
Expand Down Expand Up @@ -94,7 +93,7 @@ extglob.match = function(list, pattern, options) {
* extglob `pattern`.
*
* ```js
* var extglob = require('extglob');
* const extglob = require('extglob');
*
* console.log(extglob.isMatch('a.a', '*.!(*a)'));
* //=> false
Expand Down Expand Up @@ -125,7 +124,7 @@ extglob.isMatch = function(str, pattern, options) {
return pattern === str;
}

var isMatch = utils.memoize('isMatch', pattern, options, extglob.matcher);
const isMatch = utils.memoize('isMatch', pattern, options, extglob.matcher);
return isMatch(str);
};

Expand All @@ -134,7 +133,7 @@ extglob.isMatch = function(str, pattern, options) {
* the pattern can match any part of the string.
*
* ```js
* var extglob = require('extglob');
* const extglob = require('extglob');
* console.log(extglob.contains('aa/bb/cc', '*b'));
* //=> true
* console.log(extglob.contains('aa/bb/cc', '*d'));
Expand All @@ -156,7 +155,7 @@ extglob.contains = function(str, pattern, options) {
return pattern === str;
}

var opts = extend({}, options, {contains: true});
const opts = Object.assign({}, options, {contains: true});
opts.strictClose = false;
opts.strictOpen = false;
return extglob.isMatch(str, pattern, opts);
Expand All @@ -167,8 +166,8 @@ extglob.contains = function(str, pattern, options) {
* function takes the string to match as its only argument.
*
* ```js
* var extglob = require('extglob');
* var isMatch = extglob.matcher('*.!(*a)');
* const extglob = require('extglob');
* const isMatch = extglob.matcher('*.!(*a)');
*
* console.log(isMatch('a.a'));
* //=> false
Expand All @@ -187,7 +186,7 @@ extglob.matcher = function(pattern, options) {
}

function matcher() {
var re = extglob.makeRe(pattern, options);
const re = extglob.makeRe(pattern, options);
return function(str) {
return re.test(str);
};
Expand All @@ -201,7 +200,7 @@ extglob.matcher = function(pattern, options) {
* an object with the compiled result and the parsed AST.
*
* ```js
* var extglob = require('extglob');
* const extglob = require('extglob');
* console.log(extglob.create('*.!(*a)').output);
* //=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?'
* ```
Expand All @@ -217,8 +216,8 @@ extglob.create = function(pattern, options) {
}

function create() {
var ext = new Extglob(options);
var ast = ext.parse(pattern, options);
const ext = new Extglob(options);
const ast = ext.parse(pattern, options);
return ext.compile(ast, options);
}

Expand All @@ -230,7 +229,7 @@ extglob.create = function(pattern, options) {
* if the pattern did not match.
*
* ```js
* var extglob = require('extglob');
* const extglob = require('extglob');
* extglob.capture(pattern, string[, options]);
*
* console.log(extglob.capture('test/*.js', 'test/foo.js'));
Expand All @@ -246,11 +245,11 @@ extglob.create = function(pattern, options) {
*/

extglob.capture = function(pattern, str, options) {
var re = extglob.makeRe(pattern, extend({capture: true}, options));
const re = extglob.makeRe(pattern, Object.assign({capture: true}, options));

function match() {
return function(string) {
var match = re.exec(string);
const match = re.exec(string);
if (!match) {
return null;
}
Expand All @@ -259,16 +258,16 @@ extglob.capture = function(pattern, str, options) {
};
}

var capture = utils.memoize('capture', pattern, options, match);
const capture = utils.memoize('capture', pattern, options, match);
return capture(str);
};

/**
* Create a regular expression from the given `pattern` and `options`.
*
* ```js
* var extglob = require('extglob');
* var re = extglob.makeRe('*.!(*a)');
* const extglob = require('extglob');
* const re = extglob.makeRe('*.!(*a)');
* console.log(re);
* //=> /^[^\/]*?\.(?![^\/]*?a)[^\/]*?$/
* ```
Expand All @@ -292,13 +291,13 @@ extglob.makeRe = function(pattern, options) {
}

function makeRe() {
var opts = extend({strictErrors: false}, options);
const opts = Object.assign({strictErrors: false}, options);
if (opts.strictErrors === true) opts.strict = true;
var res = extglob.create(pattern, opts);
const res = extglob.create(pattern, opts);
return toRegex(res.output, opts);
}

var regex = utils.memoize('makeRe', pattern, options, makeRe);
const regex = utils.memoize('makeRe', pattern, options, makeRe);
if (regex.source.length > MAX_LENGTH) {
throw new SyntaxError('potentially malicious regex detected');
}
Expand Down
32 changes: 16 additions & 16 deletions lib/compilers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var brackets = require('expand-brackets');
const brackets = require('expand-brackets');

/**
* Extglob compilers
Expand Down Expand Up @@ -45,11 +45,11 @@ module.exports = function(extglob) {
*/

.set('qmark', function(node) {
var val = '[^\\\\/.]';
var prev = this.prev();
let val = '[^\\\\/.]';
const prev = node.prev;

if (node.parsed.slice(-1) === '(') {
var ch = node.rest.charAt(0);
const ch = node.rest.charAt(0);
if (ch !== '!' && ch !== '=' && ch !== ':') {
return this.emit(val, node);
}
Expand All @@ -71,11 +71,11 @@ module.exports = function(extglob) {
*/

.set('plus', function(node) {
var prev = node.parsed.slice(-1);
const prev = node.parsed.slice(-1);
if (prev === ']' || prev === ')') {
return this.emit(node.val, node);
}
var ch = this.output.slice(-1);
const ch = this.output.slice(-1);
if (!this.output || (/[?*+]/.test(ch) && node.parent.type !== 'bracket')) {
return this.emit('\\+', node);
}
Expand All @@ -90,8 +90,8 @@ module.exports = function(extglob) {
*/

.set('star', function(node) {
var prev = this.prev();
var prefix = prev.type !== 'text' && prev.type !== 'escape'
const prev = node.prev;
const prefix = prev.type !== 'text' && prev.type !== 'escape'
? '(?!\\.)'
: '';

Expand All @@ -103,10 +103,10 @@ module.exports = function(extglob) {
*/

.set('paren', function(node) {
return this.mapVisit(node.nodes);
this.mapVisit(node);
})
.set('paren.open', function(node) {
var capture = this.options.capture ? '(' : '';
const capture = this.options.capture ? '(' : '';

switch (node.parent.prefix) {
case '!':
Expand All @@ -118,7 +118,7 @@ module.exports = function(extglob) {
case '@':
return this.emit(capture + '(?:', node);
default: {
var val = node.val;
let val = node.val;
if (this.options.bash === true) {
val = '\\' + val;
} else if (!this.options.capture && val === '(' && node.parent.rest[0] !== '?') {
Expand All @@ -130,13 +130,13 @@ module.exports = function(extglob) {
}
})
.set('paren.close', function(node) {
var capture = this.options.capture ? ')' : '';
const capture = this.options.capture ? ')' : '';

switch (node.prefix) {
case '!':
case '^':
var prefix = /^(\)|$)/.test(node.rest) ? '$' : '';
var str = star.call(this, node);
const prefix = /^(\)|$)/.test(node.rest) ? '$' : '';
let str = star.call(this, node);

// if the extglob has a slash explicitly defined, we know the user wants
// to match slashes, so we need to ensure the "star" regex allows for it
Expand All @@ -152,7 +152,7 @@ module.exports = function(extglob) {
case '@':
return this.emit(')' + capture, node);
default: {
var val = (this.options.bash === true ? '\\' : '') + ')';
const val = (this.options.bash === true ? '\\' : '') + ')';
return this.emit(val, node);
}
}
Expand All @@ -163,7 +163,7 @@ module.exports = function(extglob) {
*/

.set('text', function(node) {
var val = node.val.replace(/[\[\]]/g, '\\$&');
const val = node.val.replace(/[\[\]]/g, '\\$&');
return this.emit(val, node);
});
};
Loading

0 comments on commit dedd109

Please sign in to comment.