Skip to content

Commit

Permalink
Use let/const
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Apr 30, 2018
1 parent ff338f9 commit e90b000
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 96 deletions.
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
66 changes: 33 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
* Module dependencies
*/

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 @@ -41,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 @@ -58,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 @@ -93,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 @@ -124,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 @@ -133,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 @@ -155,7 +155,7 @@ extglob.contains = function(str, pattern, options) {
return pattern === str;
}

var opts = Object.assign({}, options, {contains: true});
const opts = Object.assign({}, options, {contains: true});
opts.strictClose = false;
opts.strictOpen = false;
return extglob.isMatch(str, pattern, opts);
Expand All @@ -166,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 @@ -186,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 @@ -200,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 @@ -216,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 @@ -229,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 @@ -245,11 +245,11 @@ extglob.create = function(pattern, options) {
*/

extglob.capture = function(pattern, str, options) {
var re = extglob.makeRe(pattern, Object.assign({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 @@ -258,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 @@ -291,13 +291,13 @@ extglob.makeRe = function(pattern, options) {
}

function makeRe() {
var opts = Object.assign({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
30 changes: 15 additions & 15 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 = node.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 = node.prev;
var prefix = prev.type !== 'text' && prev.type !== 'escape'
const prev = node.prev;
const prefix = prev.type !== 'text' && prev.type !== 'escape'
? '(?!\\.)'
: '';

Expand All @@ -106,7 +106,7 @@ module.exports = function(extglob) {
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);
});
};
18 changes: 9 additions & 9 deletions lib/extglob.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
* Module dependencies
*/

var Snapdragon = require('snapdragon');
var capture = require('snapdragon-capture');
var define = require('define-property');
const Snapdragon = require('snapdragon');
const capture = require('snapdragon-capture');
const define = require('define-property');

/**
* Local dependencies
*/

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

/**
* Customize Snapdragon parser and renderer
Expand All @@ -35,15 +35,15 @@ function Extglob(options) {
*/

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

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

0 comments on commit e90b000

Please sign in to comment.