Skip to content

Commit 4840625

Browse files
committed
Change lets to consts. Move root import up.
1 parent 7816c64 commit 4840625

File tree

4 files changed

+52
-51
lines changed

4 files changed

+52
-51
lines changed

lib/parse.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ const parse = (input, options) => {
318318
}
319319

320320
// collapse slashes to reduce potential for exploits
321-
let match = /^\\+/.exec(input.slice(state.index + 1));
321+
const match = /^\\+/.exec(input.slice(state.index + 1));
322322
let slashes = 0;
323323

324324
if (match && match[0].length > 2) {
@@ -348,15 +348,15 @@ const parse = (input, options) => {
348348

349349
if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
350350
if (opts.posix !== false && value === ':') {
351-
let inner = prev.value.slice(1);
351+
const inner = prev.value.slice(1);
352352
if (inner.includes('[')) {
353353
prev.posix = true;
354354

355355
if (inner.includes(':')) {
356-
let idx = prev.value.lastIndexOf('[');
357-
let pre = prev.value.slice(0, idx);
358-
let rest = prev.value.slice(idx + 2);
359-
let posix = POSIX_REGEX_SOURCE[rest];
356+
const idx = prev.value.lastIndexOf('[');
357+
const pre = prev.value.slice(0, idx);
358+
const rest = prev.value.slice(idx + 2);
359+
const posix = POSIX_REGEX_SOURCE[rest];
360360
if (posix) {
361361
prev.value = pre + posix;
362362
state.backtrack = true;
@@ -427,7 +427,7 @@ const parse = (input, options) => {
427427
throw new SyntaxError(syntaxError('opening', '('));
428428
}
429429

430-
let extglob = extglobs[extglobs.length - 1];
430+
const extglob = extglobs[extglobs.length - 1];
431431
if (extglob && state.parens === extglob.parens + 1) {
432432
extglobClose(extglobs.pop());
433433
continue;
@@ -474,7 +474,7 @@ const parse = (input, options) => {
474474

475475
decrement('brackets');
476476

477-
let prevValue = prev.value.slice(1);
477+
const prevValue = prev.value.slice(1);
478478
if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
479479
value = '/' + value;
480480
}
@@ -488,7 +488,7 @@ const parse = (input, options) => {
488488
continue;
489489
}
490490

491-
let escaped = utils.escapeRegex(prev.value);
491+
const escaped = utils.escapeRegex(prev.value);
492492
state.output = state.output.slice(0, -prev.value.length);
493493

494494
// when literal brackets are explicitly enabled
@@ -524,8 +524,8 @@ const parse = (input, options) => {
524524
let output = ')';
525525

526526
if (state.dots === true) {
527-
let arr = tokens.slice();
528-
let range = [];
527+
const arr = tokens.slice();
528+
const range = [];
529529

530530
for (let i = arr.length - 1; i >= 0; i--) {
531531
tokens.pop();
@@ -619,7 +619,7 @@ const parse = (input, options) => {
619619

620620
if (value === '?') {
621621
if (prev && prev.type === 'paren') {
622-
let next = peek();
622+
const next = peek();
623623
let output = value;
624624

625625
if (next === '<' && !utils.supportsLookbehinds()) {
@@ -677,7 +677,7 @@ const parse = (input, options) => {
677677
}
678678

679679
if (prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace')) {
680-
let output = prev.extglob === true ? '\\' + value : value;
680+
const output = prev.extglob === true ? '\\' + value : value;
681681
push({ type: 'plus', value, output });
682682
continue;
683683
}
@@ -715,7 +715,7 @@ const parse = (input, options) => {
715715
value = '\\' + value;
716716
}
717717

718-
let match = REGEX_NON_SPECIAL_CHAR.exec(input.slice(state.index + 1));
718+
const match = REGEX_NON_SPECIAL_CHAR.exec(input.slice(state.index + 1));
719719
if (match) {
720720
value += match[0];
721721
state.index += match[0].length;
@@ -750,26 +750,26 @@ const parse = (input, options) => {
750750
continue;
751751
}
752752

753-
let prior = prev.prev;
754-
let before = prior.prev;
755-
let isStart = prior.type === 'slash' || prior.type === 'bos';
756-
let afterStar = before && (before.type === 'star' || before.type === 'globstar');
753+
const prior = prev.prev;
754+
const before = prior.prev;
755+
const isStart = prior.type === 'slash' || prior.type === 'bos';
756+
const afterStar = before && (before.type === 'star' || before.type === 'globstar');
757757

758758
if (opts.bash === true && (!isStart || (!eos() && peek() !== '/'))) {
759759
push({ type: 'star', value, output: '' });
760760
continue;
761761
}
762762

763-
let isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
764-
let isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
763+
const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
764+
const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
765765
if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
766766
push({ type: 'star', value, output: '' });
767767
continue;
768768
}
769769

770770
// strip consecutive `/**/`
771771
while (input.slice(state.index + 1, state.index + 4) === '/**') {
772-
let after = input[state.index + 4];
772+
const after = input[state.index + 4];
773773
if (after && after !== '/') {
774774
break;
775775
}
@@ -799,9 +799,9 @@ const parse = (input, options) => {
799799
continue;
800800
}
801801

802-
let next = peek();
802+
const next = peek();
803803
if (prior.type === 'slash' && prior.prev.type !== 'bos' && next === '/') {
804-
let end = peek(2) !== void 0 ? '|$' : '';
804+
const end = peek(2) !== void 0 ? '|$' : '';
805805

806806
state.output = state.output.slice(0, -(prior.output + prev.output).length);
807807
prior.output = '(?:' + prior.output;
@@ -926,15 +926,15 @@ const parse = (input, options) => {
926926
*/
927927

928928
parse.fastpaths = (input, options) => {
929-
let opts = { ...options };
930-
let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
931-
let len = input.length;
929+
const opts = { ...options };
930+
const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
931+
const len = input.length;
932932
if (len > max) {
933933
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
934934
}
935935

936936
input = REPLACEMENTS[input] || input;
937-
let win32 = utils.isWindows(options);
937+
const win32 = utils.isWindows(options);
938938

939939
// create constants based on platform, for windows or posix
940940
const {
@@ -949,10 +949,10 @@ parse.fastpaths = (input, options) => {
949949
START_ANCHOR
950950
} = constants.globChars(win32);
951951

952-
let capture = opts.capture ? '' : '?:';
952+
const capture = opts.capture ? '' : '?:';
953953
let star = opts.bash === true ? '.*?' : STAR;
954-
let nodot = opts.dot ? NO_DOTS : NO_DOT;
955-
let slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
954+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
955+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
956956

957957
if (opts.capture) {
958958
star = `(${star})`;

lib/picomatch.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require('path');
44
const scan = require('./scan');
55
const parse = require('./parse');
66
const utils = require('./utils');
7+
const constants = require('./constants');
78

89
/**
910
* Creates a matcher function from one or more glob patterns. The
@@ -29,10 +30,10 @@ const utils = require('./utils');
2930

3031
const picomatch = (glob, options, returnState = false) => {
3132
if (Array.isArray(glob)) {
32-
let fns = glob.map(input => picomatch(input, options, returnState));
33+
const fns = glob.map(input => picomatch(input, options, returnState));
3334
return str => {
3435
for (let isMatch of fns) {
35-
let state = isMatch(str);
36+
const state = isMatch(str);
3637
if (state) return state;
3738
}
3839
return false;
@@ -43,10 +44,10 @@ const picomatch = (glob, options, returnState = false) => {
4344
throw new TypeError('Expected pattern to be a non-empty string');
4445
}
4546

46-
let opts = options || {};
47-
let posix = utils.isWindows(options);
48-
let regex = picomatch.makeRe(glob, options, false, true);
49-
let state = regex.state;
47+
const opts = options || {};
48+
const posix = utils.isWindows(options);
49+
const regex = picomatch.makeRe(glob, options, false, true);
50+
const state = regex.state;
5051
delete regex.state;
5152

5253
let isIgnored = () => false;
@@ -115,8 +116,8 @@ picomatch.test = (input, regex, options, { glob, posix } = {}) => {
115116
return { isMatch: false, output: '' };
116117
}
117118

118-
let opts = options || {};
119-
let format = opts.format || (posix ? utils.toPosixSlashes : null);
119+
const opts = options || {};
120+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
120121
let match = input === glob;
121122
let output = (match && format) ? format(input) : input;
122123

@@ -151,7 +152,7 @@ picomatch.test = (input, regex, options, { glob, posix } = {}) => {
151152
*/
152153

153154
picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
154-
let regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
155+
const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
155156
return regex.test(path.basename(input));
156157
};
157158

@@ -235,9 +236,9 @@ picomatch.makeRe = (input, options, returnOutput = false, returnState = false) =
235236
throw new TypeError('Expected a non-empty string');
236237
}
237238

238-
let opts = options || {};
239-
let prepend = opts.contains ? '' : '^';
240-
let append = opts.contains ? '' : '$';
239+
const opts = options || {};
240+
const prepend = opts.contains ? '' : '^';
241+
const append = opts.contains ? '' : '$';
241242
let state = { negated: false, fastpaths: true };
242243
let prefix = '';
243244
let output;
@@ -266,7 +267,7 @@ picomatch.makeRe = (input, options, returnOutput = false, returnState = false) =
266267
source = `^(?!${source}).*$`;
267268
}
268269

269-
let regex = picomatch.toRegex(source, options);
270+
const regex = picomatch.toRegex(source, options);
270271
if (returnState === true) {
271272
regex.state = state;
272273
}
@@ -293,7 +294,7 @@ picomatch.makeRe = (input, options, returnOutput = false, returnState = false) =
293294

294295
picomatch.toRegex = (source, options) => {
295296
try {
296-
let opts = options || {};
297+
const opts = options || {};
297298
return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
298299
} catch (err) {
299300
if (options && options.debug === true) throw err;
@@ -306,7 +307,7 @@ picomatch.toRegex = (source, options) => {
306307
* @return {Object}
307308
*/
308309

309-
picomatch.constants = require('./constants');
310+
picomatch.constants = constants;
310311

311312
/**
312313
* Expose "picomatch"

lib/scan.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const isPathSeparator = code => {
4141
*/
4242

4343
module.exports = (input, options) => {
44-
let opts = options || {};
45-
let length = input.length - 1;
44+
const opts = options || {};
45+
const length = input.length - 1;
4646
let index = -1;
4747
let start = 0;
4848
let lastIndex = 0;
@@ -55,8 +55,8 @@ module.exports = (input, options) => {
5555

5656
let braceEscaped = false;
5757

58-
let eos = () => index >= length;
59-
let advance = () => {
58+
const eos = () => index >= length;
59+
const advance = () => {
6060
prev = code;
6161
return input.charCodeAt(++index);
6262
};

lib/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exports.removeBackslashes = str => {
1919
}
2020

2121
exports.supportsLookbehinds = () => {
22-
let segs = process.version.slice(1).split('.');
22+
const segs = process.version.slice(1).split('.');
2323
if (segs.length === 3 && +segs[0] >= 9 || (+segs[0] === 8 && +segs[1] >= 10)) {
2424
return true;
2525
}
@@ -34,7 +34,7 @@ exports.isWindows = options => {
3434
};
3535

3636
exports.escapeLast = (input, char, lastIdx) => {
37-
let idx = input.lastIndexOf(char, lastIdx);
37+
const idx = input.lastIndexOf(char, lastIdx);
3838
if (idx === -1) return input;
3939
if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
4040
return input.slice(0, idx) + '\\' + input.slice(idx);

0 commit comments

Comments
 (0)