Skip to content

Commit e90b000

Browse files
committedApr 30, 2018
Use let/const
1 parent ff338f9 commit e90b000

File tree

6 files changed

+96
-96
lines changed

6 files changed

+96
-96
lines changed
 

‎gulpfile.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3-
var gulp = require('gulp');
4-
var mocha = require('gulp-mocha');
5-
var unused = require('gulp-unused');
6-
var istanbul = require('gulp-istanbul');
7-
var eslint = require('gulp-eslint');
3+
const gulp = require('gulp');
4+
const mocha = require('gulp-mocha');
5+
const unused = require('gulp-unused');
6+
const istanbul = require('gulp-istanbul');
7+
const eslint = require('gulp-eslint');
88

99
gulp.task('coverage', function() {
1010
return gulp.src(['index.js', 'lib/*.js'])

‎index.js

+33-33
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
* Module dependencies
55
*/
66

7-
var unique = require('array-unique');
8-
var toRegex = require('to-regex');
7+
const unique = require('array-unique');
8+
const toRegex = require('to-regex');
99

1010
/**
1111
* Local dependencies
1212
*/
1313

14-
var compilers = require('./lib/compilers');
15-
var parsers = require('./lib/parsers');
16-
var Extglob = require('./lib/extglob');
17-
var utils = require('./lib/utils');
18-
var MAX_LENGTH = 1024 * 64;
14+
const compilers = require('./lib/compilers');
15+
const parsers = require('./lib/parsers');
16+
const Extglob = require('./lib/extglob');
17+
const utils = require('./lib/utils');
18+
const MAX_LENGTH = 1024 * 64;
1919

2020
/**
2121
* Convert the given `extglob` pattern into a regex-compatible string. Returns
2222
* an object with the compiled result and the parsed AST.
2323
*
2424
* ```js
25-
* var extglob = require('extglob');
25+
* const extglob = require('extglob');
2626
* console.log(extglob('*.!(*a)'));
2727
* //=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?'
2828
* ```
@@ -41,7 +41,7 @@ function extglob(pattern, options) {
4141
* array that contains only the strings that match the pattern.
4242
*
4343
* ```js
44-
* var extglob = require('extglob');
44+
* const extglob = require('extglob');
4545
* console.log(extglob.match(['a.a', 'a.b', 'a.c'], '*.!(*a)'));
4646
* //=> ['a.b', 'a.c']
4747
* ```
@@ -58,13 +58,13 @@ extglob.match = function(list, pattern, options) {
5858
}
5959

6060
list = utils.arrayify(list);
61-
var isMatch = extglob.matcher(pattern, options);
62-
var len = list.length;
63-
var idx = -1;
64-
var matches = [];
61+
const isMatch = extglob.matcher(pattern, options);
62+
const len = list.length;
63+
let idx = -1;
64+
const matches = [];
6565

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

6969
if (isMatch(ele)) {
7070
matches.push(ele);
@@ -93,7 +93,7 @@ extglob.match = function(list, pattern, options) {
9393
* extglob `pattern`.
9494
*
9595
* ```js
96-
* var extglob = require('extglob');
96+
* const extglob = require('extglob');
9797
*
9898
* console.log(extglob.isMatch('a.a', '*.!(*a)'));
9999
* //=> false
@@ -124,7 +124,7 @@ extglob.isMatch = function(str, pattern, options) {
124124
return pattern === str;
125125
}
126126

127-
var isMatch = utils.memoize('isMatch', pattern, options, extglob.matcher);
127+
const isMatch = utils.memoize('isMatch', pattern, options, extglob.matcher);
128128
return isMatch(str);
129129
};
130130

@@ -133,7 +133,7 @@ extglob.isMatch = function(str, pattern, options) {
133133
* the pattern can match any part of the string.
134134
*
135135
* ```js
136-
* var extglob = require('extglob');
136+
* const extglob = require('extglob');
137137
* console.log(extglob.contains('aa/bb/cc', '*b'));
138138
* //=> true
139139
* console.log(extglob.contains('aa/bb/cc', '*d'));
@@ -155,7 +155,7 @@ extglob.contains = function(str, pattern, options) {
155155
return pattern === str;
156156
}
157157

158-
var opts = Object.assign({}, options, {contains: true});
158+
const opts = Object.assign({}, options, {contains: true});
159159
opts.strictClose = false;
160160
opts.strictOpen = false;
161161
return extglob.isMatch(str, pattern, opts);
@@ -166,8 +166,8 @@ extglob.contains = function(str, pattern, options) {
166166
* function takes the string to match as its only argument.
167167
*
168168
* ```js
169-
* var extglob = require('extglob');
170-
* var isMatch = extglob.matcher('*.!(*a)');
169+
* const extglob = require('extglob');
170+
* const isMatch = extglob.matcher('*.!(*a)');
171171
*
172172
* console.log(isMatch('a.a'));
173173
* //=> false
@@ -186,7 +186,7 @@ extglob.matcher = function(pattern, options) {
186186
}
187187

188188
function matcher() {
189-
var re = extglob.makeRe(pattern, options);
189+
const re = extglob.makeRe(pattern, options);
190190
return function(str) {
191191
return re.test(str);
192192
};
@@ -200,7 +200,7 @@ extglob.matcher = function(pattern, options) {
200200
* an object with the compiled result and the parsed AST.
201201
*
202202
* ```js
203-
* var extglob = require('extglob');
203+
* const extglob = require('extglob');
204204
* console.log(extglob.create('*.!(*a)').output);
205205
* //=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?'
206206
* ```
@@ -216,8 +216,8 @@ extglob.create = function(pattern, options) {
216216
}
217217

218218
function create() {
219-
var ext = new Extglob(options);
220-
var ast = ext.parse(pattern, options);
219+
const ext = new Extglob(options);
220+
const ast = ext.parse(pattern, options);
221221
return ext.compile(ast, options);
222222
}
223223

@@ -229,7 +229,7 @@ extglob.create = function(pattern, options) {
229229
* if the pattern did not match.
230230
*
231231
* ```js
232-
* var extglob = require('extglob');
232+
* const extglob = require('extglob');
233233
* extglob.capture(pattern, string[, options]);
234234
*
235235
* console.log(extglob.capture('test/*.js', 'test/foo.js'));
@@ -245,11 +245,11 @@ extglob.create = function(pattern, options) {
245245
*/
246246

247247
extglob.capture = function(pattern, str, options) {
248-
var re = extglob.makeRe(pattern, Object.assign({capture: true}, options));
248+
const re = extglob.makeRe(pattern, Object.assign({capture: true}, options));
249249

250250
function match() {
251251
return function(string) {
252-
var match = re.exec(string);
252+
const match = re.exec(string);
253253
if (!match) {
254254
return null;
255255
}
@@ -258,16 +258,16 @@ extglob.capture = function(pattern, str, options) {
258258
};
259259
}
260260

261-
var capture = utils.memoize('capture', pattern, options, match);
261+
const capture = utils.memoize('capture', pattern, options, match);
262262
return capture(str);
263263
};
264264

265265
/**
266266
* Create a regular expression from the given `pattern` and `options`.
267267
*
268268
* ```js
269-
* var extglob = require('extglob');
270-
* var re = extglob.makeRe('*.!(*a)');
269+
* const extglob = require('extglob');
270+
* const re = extglob.makeRe('*.!(*a)');
271271
* console.log(re);
272272
* //=> /^[^\/]*?\.(?![^\/]*?a)[^\/]*?$/
273273
* ```
@@ -291,13 +291,13 @@ extglob.makeRe = function(pattern, options) {
291291
}
292292

293293
function makeRe() {
294-
var opts = Object.assign({strictErrors: false}, options);
294+
const opts = Object.assign({strictErrors: false}, options);
295295
if (opts.strictErrors === true) opts.strict = true;
296-
var res = extglob.create(pattern, opts);
296+
const res = extglob.create(pattern, opts);
297297
return toRegex(res.output, opts);
298298
}
299299

300-
var regex = utils.memoize('makeRe', pattern, options, makeRe);
300+
const regex = utils.memoize('makeRe', pattern, options, makeRe);
301301
if (regex.source.length > MAX_LENGTH) {
302302
throw new SyntaxError('potentially malicious regex detected');
303303
}

‎lib/compilers.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var brackets = require('expand-brackets');
3+
const brackets = require('expand-brackets');
44

55
/**
66
* Extglob compilers
@@ -45,11 +45,11 @@ module.exports = function(extglob) {
4545
*/
4646

4747
.set('qmark', function(node) {
48-
var val = '[^\\\\/.]';
49-
var prev = node.prev;
48+
let val = '[^\\\\/.]';
49+
const prev = node.prev;
5050

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

7373
.set('plus', function(node) {
74-
var prev = node.parsed.slice(-1);
74+
const prev = node.parsed.slice(-1);
7575
if (prev === ']' || prev === ')') {
7676
return this.emit(node.val, node);
7777
}
78-
var ch = this.output.slice(-1);
78+
const ch = this.output.slice(-1);
7979
if (!this.output || (/[?*+]/.test(ch) && node.parent.type !== 'bracket')) {
8080
return this.emit('\\+', node);
8181
}
@@ -90,8 +90,8 @@ module.exports = function(extglob) {
9090
*/
9191

9292
.set('star', function(node) {
93-
var prev = node.prev;
94-
var prefix = prev.type !== 'text' && prev.type !== 'escape'
93+
const prev = node.prev;
94+
const prefix = prev.type !== 'text' && prev.type !== 'escape'
9595
? '(?!\\.)'
9696
: '';
9797

@@ -106,7 +106,7 @@ module.exports = function(extglob) {
106106
this.mapVisit(node);
107107
})
108108
.set('paren.open', function(node) {
109-
var capture = this.options.capture ? '(' : '';
109+
const capture = this.options.capture ? '(' : '';
110110

111111
switch (node.parent.prefix) {
112112
case '!':
@@ -118,7 +118,7 @@ module.exports = function(extglob) {
118118
case '@':
119119
return this.emit(capture + '(?:', node);
120120
default: {
121-
var val = node.val;
121+
let val = node.val;
122122
if (this.options.bash === true) {
123123
val = '\\' + val;
124124
} else if (!this.options.capture && val === '(' && node.parent.rest[0] !== '?') {
@@ -130,13 +130,13 @@ module.exports = function(extglob) {
130130
}
131131
})
132132
.set('paren.close', function(node) {
133-
var capture = this.options.capture ? ')' : '';
133+
const capture = this.options.capture ? ')' : '';
134134

135135
switch (node.prefix) {
136136
case '!':
137137
case '^':
138-
var prefix = /^(\)|$)/.test(node.rest) ? '$' : '';
139-
var str = star.call(this, node);
138+
const prefix = /^(\)|$)/.test(node.rest) ? '$' : '';
139+
let str = star.call(this, node);
140140

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

165165
.set('text', function(node) {
166-
var val = node.val.replace(/[\[\]]/g, '\\$&');
166+
const val = node.val.replace(/[\[\]]/g, '\\$&');
167167
return this.emit(val, node);
168168
});
169169
};

‎lib/extglob.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
* Module dependencies
55
*/
66

7-
var Snapdragon = require('snapdragon');
8-
var capture = require('snapdragon-capture');
9-
var define = require('define-property');
7+
const Snapdragon = require('snapdragon');
8+
const capture = require('snapdragon-capture');
9+
const define = require('define-property');
1010

1111
/**
1212
* Local dependencies
1313
*/
1414

15-
var compilers = require('./compilers');
16-
var parsers = require('./parsers');
15+
const compilers = require('./compilers');
16+
const parsers = require('./parsers');
1717

1818
/**
1919
* Customize Snapdragon parser and renderer
@@ -35,15 +35,15 @@ function Extglob(options) {
3535
*/
3636

3737
define(this.snapdragon, 'parse', function(str, options) {
38-
var parsed = Snapdragon.prototype.parse.apply(this, arguments);
38+
const parsed = Snapdragon.prototype.parse.apply(this, arguments);
3939
parsed.input = str;
4040

4141
// escape unmatched brace/bracket/parens
42-
var last = this.parser.stack.pop();
42+
const last = this.parser.stack.pop();
4343
if (last && this.options.strict !== true) {
44-
var node = last.nodes[0];
44+
const node = last.nodes[0];
4545
node.val = '\\' + node.val;
46-
var sibling = node.parent.nodes[1];
46+
const sibling = node.parent.nodes[1];
4747
if (sibling.type === 'star') {
4848
sibling.loose = true;
4949
}

‎lib/parsers.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict';
22

3-
var brackets = require('expand-brackets');
4-
var utils = require('./utils');
3+
const brackets = require('expand-brackets');
4+
const utils = require('./utils');
55

66
/**
77
* Characters to use in text regex (we want to "not" match
88
* characters that are matched by other parsers)
99
*/
1010

11-
var TEXT_REGEX = '([!@*?+]?\\(|\\)|[*?.+\\\\]|\\[:?(?=.*\\])|:?\\])+';
12-
var not = utils.createRegex(TEXT_REGEX);
11+
const TEXT_REGEX = '([!@*?+]?\\(|\\)|[*?.+\\\\]|\\[:?(?=.*\\])|:?\\])+';
12+
const not = utils.createRegex(TEXT_REGEX);
1313

1414
/**
1515
* Extglob parsers
@@ -31,22 +31,22 @@ function parsers(extglob) {
3131
*/
3232

3333
.set('paren.open', function() {
34-
var pos = this.position();
35-
var m = this.match(/^([!@*?+])?\(/);
34+
const pos = this.position();
35+
const m = this.match(/^([!@*?+])?\(/);
3636
if (!m) return;
3737

38-
var prev = this.prev();
39-
var prefix = m[1];
40-
var val = m[0];
38+
const prev = this.prev();
39+
const prefix = m[1];
40+
const val = m[0];
4141

42-
var open = pos({
42+
const open = pos({
4343
type: 'paren.open',
44-
val: val
44+
val
4545
});
4646

47-
var node = pos({
47+
const node = pos({
4848
type: 'paren',
49-
prefix: prefix,
49+
prefix,
5050
nodes: []
5151
});
5252

@@ -66,16 +66,16 @@ function parsers(extglob) {
6666
*/
6767

6868
.set('paren.close', function() {
69-
var parsed = this.parsed;
70-
var pos = this.position();
71-
var m = this.match(/^\)/);
69+
const parsed = this.parsed;
70+
const pos = this.position();
71+
const m = this.match(/^\)/);
7272
if (!m) return;
7373

74-
var parent = this.pop('paren');
75-
var node = pos({
74+
const parent = this.pop('paren');
75+
const node = pos({
7676
type: 'paren.close',
7777
rest: this.input,
78-
parsed: parsed,
78+
parsed,
7979
val: m[0]
8080
});
8181

@@ -96,8 +96,8 @@ function parsers(extglob) {
9696
*/
9797

9898
.set('escape', function() {
99-
var pos = this.position();
100-
var m = this.match(/^\\(.)/);
99+
const pos = this.position();
100+
const m = this.match(/^\\(.)/);
101101
if (!m) return;
102102

103103
return pos({
@@ -112,15 +112,15 @@ function parsers(extglob) {
112112
*/
113113

114114
.set('qmark', function() {
115-
var parsed = this.parsed;
116-
var pos = this.position();
117-
var m = this.match(/^\?+(?!\()/);
115+
const parsed = this.parsed;
116+
const pos = this.position();
117+
const m = this.match(/^\?+(?!\()/);
118118
if (!m) return;
119119
extglob.state.metachar = true;
120120
return pos({
121121
type: 'qmark',
122122
rest: this.input,
123-
parsed: parsed,
123+
parsed,
124124
val: m[0]
125125
});
126126
})

‎lib/utils.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

3-
var regex = require('regex-not');
4-
var Cache = require('fragment-cache');
3+
const regex = require('regex-not');
4+
const Cache = require('fragment-cache');
55

66
/**
77
* Utils
88
*/
99

10-
var utils = module.exports;
11-
var cache = utils.cache = new Cache();
10+
const utils = module.exports;
11+
const cache = utils.cache = new Cache();
1212

1313
/**
1414
* Cast `val` to an array
@@ -27,13 +27,13 @@ utils.arrayify = function(val) {
2727
*/
2828

2929
utils.memoize = function(type, pattern, options, fn) {
30-
var key = utils.createKey(type + pattern, options);
30+
const key = utils.createKey(type + pattern, options);
3131

3232
if (cache.has(type, key)) {
3333
return cache.get(type, key);
3434
}
3535

36-
var val = fn(pattern, options);
36+
const val = fn(pattern, options);
3737
if (options && options.cache === false) {
3838
return val;
3939
}
@@ -49,11 +49,11 @@ utils.memoize = function(type, pattern, options, fn) {
4949
*/
5050

5151
utils.createKey = function(pattern, options) {
52-
var key = pattern;
52+
let key = pattern;
5353
if (typeof options === 'undefined') {
5454
return key;
5555
}
56-
for (var prop in options) {
56+
for (const prop in options) {
5757
key += ';' + prop + '=' + String(options[prop]);
5858
}
5959
return key;
@@ -64,6 +64,6 @@ utils.createKey = function(pattern, options) {
6464
*/
6565

6666
utils.createRegex = function(str) {
67-
var opts = {contains: true, strictClose: false};
67+
const opts = {contains: true, strictClose: false};
6868
return regex(str, opts);
6969
};

0 commit comments

Comments
 (0)
Please sign in to comment.