From ed10fb2d2fb330b657b3c9a82015b9dcfe4d6839 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Mon, 9 Apr 2018 14:45:14 +0200 Subject: [PATCH 1/5] Update snapdragon to 0.11 --- lib/compilers.js | 6 +++--- lib/extglob.js | 2 ++ lib/parsers.js | 24 ++++++++---------------- package.json | 9 +++++---- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/compilers.js b/lib/compilers.js index d7bed25..6f5b947 100644 --- a/lib/compilers.js +++ b/lib/compilers.js @@ -46,7 +46,7 @@ module.exports = function(extglob) { .set('qmark', function(node) { var val = '[^\\\\/.]'; - var prev = this.prev(); + var prev = node.prev; if (node.parsed.slice(-1) === '(') { var ch = node.rest.charAt(0); @@ -90,7 +90,7 @@ module.exports = function(extglob) { */ .set('star', function(node) { - var prev = this.prev(); + var prev = node.prev; var prefix = prev.type !== 'text' && prev.type !== 'escape' ? '(?!\\.)' : ''; @@ -103,7 +103,7 @@ 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 ? '(' : ''; diff --git a/lib/extglob.js b/lib/extglob.js index 015f928..513afbb 100644 --- a/lib/extglob.js +++ b/lib/extglob.js @@ -5,6 +5,7 @@ */ var Snapdragon = require('snapdragon'); +var capture = require('snapdragon-capture'); var define = require('define-property'); var extend = require('extend-shallow'); @@ -22,6 +23,7 @@ var parsers = require('./parsers'); function Extglob(options) { this.options = extend({source: 'extglob'}, options); this.snapdragon = this.options.snapdragon || new Snapdragon(this.options); + this.snapdragon.use(capture()); this.snapdragon.patterns = this.snapdragon.patterns || {}; this.compiler = this.snapdragon.compiler; this.parser = this.snapdragon.parser; diff --git a/lib/parsers.js b/lib/parsers.js index 2ba7352..97109e6 100644 --- a/lib/parsers.js +++ b/lib/parsers.js @@ -1,7 +1,6 @@ 'use strict'; var brackets = require('expand-brackets'); -var define = require('define-property'); var utils = require('./utils'); /** @@ -31,8 +30,7 @@ function parsers(extglob) { * Extglob open: "*(" */ - .capture('paren.open', function() { - var parsed = this.parsed; + .set('paren.open', function() { var pos = this.position(); var m = this.match(/^([!@*?+])?\(/); if (!m) return; @@ -43,14 +41,13 @@ function parsers(extglob) { var open = pos({ type: 'paren.open', - parsed: parsed, val: val }); var node = pos({ type: 'paren', prefix: prefix, - nodes: [open] + nodes: [] }); // if nested negation extglobs, just cancel them out to simplify @@ -59,20 +56,16 @@ function parsers(extglob) { node.prefix = '@'; } - define(node, 'rest', this.input); - define(node, 'parsed', parsed); - define(node, 'parent', prev); - define(open, 'parent', node); - + this.pushNode(node, prev); + this.pushNode(open, node); this.push('paren', node); - prev.nodes.push(node); }) /** * Extglob close: ")" */ - .capture('paren.close', function() { + .set('paren.close', function() { var parsed = this.parsed; var pos = this.position(); var m = this.match(/^\)/); @@ -95,15 +88,14 @@ function parsers(extglob) { } node.prefix = parent.prefix; - parent.nodes.push(node); - define(node, 'parent', parent); + this.pushNode(node, parent); }) /** * Escape: "\\." */ - .capture('escape', function() { + .set('escape', function() { var pos = this.position(); var m = this.match(/^\\(.)/); if (!m) return; @@ -119,7 +111,7 @@ function parsers(extglob) { * Question marks: "?" */ - .capture('qmark', function() { + .set('qmark', function() { var parsed = this.parsed; var pos = this.position(); var m = this.match(/^\?+(?!\()/); diff --git a/package.json b/package.json index afe5157..b42348f 100644 --- a/package.json +++ b/package.json @@ -30,12 +30,13 @@ }, "dependencies": { "array-unique": "^0.3.2", - "define-property": "^1.0.0", - "expand-brackets": "^2.1.4", - "extend-shallow": "^2.0.1", + "define-property": "^2.0.2", + "expand-brackets": "^3.0.0", + "extend-shallow": "^3.0.2", "fragment-cache": "^0.2.1", "regex-not": "^1.0.0", - "snapdragon": "^0.8.1", + "snapdragon": "^0.11.4", + "snapdragon-capture": "^0.2.0", "to-regex": "^3.0.1" }, "devDependencies": { From 841c540ccf770b2a2462af76fdf0200c0b633999 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Mon, 30 Apr 2018 14:08:42 +0200 Subject: [PATCH 2/5] Update dependencies --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b42348f..6cec5d5 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "Isiah Meadows (https://www.isiahmeadows.com)", "Jon Schlinkert (http://twitter.com/jonschlinkert)", "Matt Bierner (http://mattbierner.com)", - "Shinnosuke Watanabe (https://shinnn.github.io)" + "Shinnosuke Watanabe (https://shinnn.github.io)", + "Daniel Tschinder (https://github.com/danez)" ], "repository": "micromatch/extglob", "bugs": { @@ -31,11 +32,11 @@ "dependencies": { "array-unique": "^0.3.2", "define-property": "^2.0.2", - "expand-brackets": "^3.0.0", + "expand-brackets": "^4.0.0", "extend-shallow": "^3.0.2", "fragment-cache": "^0.2.1", "regex-not": "^1.0.0", - "snapdragon": "^0.11.4", + "snapdragon": "^0.12.0", "snapdragon-capture": "^0.2.0", "to-regex": "^3.0.1" }, From 8fdd4e23247f5d4a2a99dad954b2a1846034d363 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Mon, 30 Apr 2018 14:13:23 +0200 Subject: [PATCH 3/5] Drop support for node <4 --- .travis.yml | 7 +------ appveyor.yml | 6 ++---- index.js | 7 +++---- lib/extglob.js | 3 +-- package.json | 3 +-- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1686664..7653484 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,7 @@ os: - osx language: node_js node_js: - - node - - '9' + - '10' - '8' - - '7' - '6' - - '5' - '4' - - '0.12' - - '0.10' diff --git a/appveyor.yml b/appveyor.yml index dbe483d..cef1503 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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: diff --git a/index.js b/index.js index 116e6d5..3f47ee7 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,6 @@ * Module dependencies */ -var extend = require('extend-shallow'); var unique = require('array-unique'); var toRegex = require('to-regex'); @@ -156,7 +155,7 @@ extglob.contains = function(str, pattern, options) { return pattern === str; } - var opts = extend({}, options, {contains: true}); + var opts = Object.assign({}, options, {contains: true}); opts.strictClose = false; opts.strictOpen = false; return extglob.isMatch(str, pattern, opts); @@ -246,7 +245,7 @@ extglob.create = function(pattern, options) { */ extglob.capture = function(pattern, str, options) { - var re = extglob.makeRe(pattern, extend({capture: true}, options)); + var re = extglob.makeRe(pattern, Object.assign({capture: true}, options)); function match() { return function(string) { @@ -292,7 +291,7 @@ extglob.makeRe = function(pattern, options) { } function makeRe() { - var opts = extend({strictErrors: false}, options); + var opts = Object.assign({strictErrors: false}, options); if (opts.strictErrors === true) opts.strict = true; var res = extglob.create(pattern, opts); return toRegex(res.output, opts); diff --git a/lib/extglob.js b/lib/extglob.js index 513afbb..0e55079 100644 --- a/lib/extglob.js +++ b/lib/extglob.js @@ -7,7 +7,6 @@ var Snapdragon = require('snapdragon'); var capture = require('snapdragon-capture'); var define = require('define-property'); -var extend = require('extend-shallow'); /** * Local dependencies @@ -21,7 +20,7 @@ var parsers = require('./parsers'); */ function Extglob(options) { - this.options = extend({source: 'extglob'}, options); + this.options = Object.assign({source: 'extglob'}, options); this.snapdragon = this.options.snapdragon || new Snapdragon(this.options); this.snapdragon.use(capture()); this.snapdragon.patterns = this.snapdragon.patterns || {}; diff --git a/package.json b/package.json index 6cec5d5..4feed8e 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ], "main": "index.js", "engines": { - "node": ">=0.10.0" + "node": ">=4.0.0" }, "scripts": { "test": "mocha" @@ -33,7 +33,6 @@ "array-unique": "^0.3.2", "define-property": "^2.0.2", "expand-brackets": "^4.0.0", - "extend-shallow": "^3.0.2", "fragment-cache": "^0.2.1", "regex-not": "^1.0.0", "snapdragon": "^0.12.0", From ff338f948b9cd658fb45b3dab127999b246ec584 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Mon, 30 Apr 2018 14:20:25 +0200 Subject: [PATCH 4/5] Fix linting --- test/_negations.js | 6 +++--- test/bash.extglob2.js | 2 +- test/reference.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/_negations.js b/test/_negations.js index db95e55..174f5cf 100644 --- a/test/_negations.js +++ b/test/_negations.js @@ -52,7 +52,7 @@ module.exports = { 'asd.jss.xyz': { '*.!(js)*.!(xy)': false, '*.!(js)*.!(xy)*': false, - '*.!(js).!(xy)': false, + '*.!(js).!(xy)': false }, 'asd.jss.xy': { @@ -102,8 +102,8 @@ module.exports = { '*.!(js)+': false, '!(*(.js.js))': true, '*.!(js)': true, - '*.!(js)*': false, // Bash 4.3 disagrees! - '*.!(js)*.js': false // Bash 4.3 disagrees! + '*.!(js)*': false, // Bash 4.3 disagrees! + '*.!(js)*.js': false // Bash 4.3 disagrees! }, 'a/foo.js.js': { diff --git a/test/bash.extglob2.js b/test/bash.extglob2.js index 5b72a67..8119a36 100644 --- a/test/bash.extglob2.js +++ b/test/bash.extglob2.js @@ -58,7 +58,7 @@ describe('bash extglob2 tests', function() { [ 'foo', '!(foo)*', false ], // Bash 4.3 disagrees! [ 'foobar', '!(foo)', true ], [ 'foobar', '!(foo)*', false ], // Bash 4.3 disagrees! - [ 'moo.cow', '!(*.*).!(*.*)', false ], // Bash 4.3 disagrees! + [ 'moo.cow', '!(*.*).!(*.*)', false ], // Bash 4.3 disagrees! [ 'mad.moo.cow', '!(*.*).!(*.*)', false ], [ 'mucca.pazza', 'mu!(*(c))?.pa!(*(z))?', false ], [ 'fff', '!(f)', true ], diff --git a/test/reference.js b/test/reference.js index fb47eb1..3b616fd 100644 --- a/test/reference.js +++ b/test/reference.js @@ -8,7 +8,7 @@ var negations = require('./_negations'); describe('running extglob against minimatch tests', function() { forOwn(negations, function(val, fixture) { - if (fixture !== 'asd.jss.xyz') return + if (fixture !== 'asd.jss.xyz') return; describe('"' + fixture + '"', function() { forOwn(val, function(expected, pattern) { var exp = expected === false ? ' not' : ''; From e90b0006b8db021b6a7034760d705a5a6e284eff Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Mon, 30 Apr 2018 14:21:21 +0200 Subject: [PATCH 5/5] Use let/const --- gulpfile.js | 10 ++++---- index.js | 66 ++++++++++++++++++++++++------------------------ lib/compilers.js | 30 +++++++++++----------- lib/extglob.js | 18 ++++++------- lib/parsers.js | 50 ++++++++++++++++++------------------ lib/utils.js | 18 ++++++------- 6 files changed, 96 insertions(+), 96 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 857a63e..0a4edcb 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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']) diff --git a/index.js b/index.js index 3f47ee7..5ddcbf7 100644 --- a/index.js +++ b/index.js @@ -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).*?' * ``` @@ -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'] * ``` @@ -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); @@ -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 @@ -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); }; @@ -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')); @@ -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); @@ -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 @@ -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); }; @@ -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).*?' * ``` @@ -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); } @@ -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')); @@ -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; } @@ -258,7 +258,7 @@ 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); }; @@ -266,8 +266,8 @@ extglob.capture = function(pattern, str, options) { * 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)[^\/]*?$/ * ``` @@ -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'); } diff --git a/lib/compilers.js b/lib/compilers.js index 6f5b947..2be28f1 100644 --- a/lib/compilers.js +++ b/lib/compilers.js @@ -1,6 +1,6 @@ 'use strict'; -var brackets = require('expand-brackets'); +const brackets = require('expand-brackets'); /** * Extglob compilers @@ -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); } @@ -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); } @@ -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' ? '(?!\\.)' : ''; @@ -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 '!': @@ -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] !== '?') { @@ -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 @@ -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); } } @@ -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); }); }; diff --git a/lib/extglob.js b/lib/extglob.js index 0e55079..fa21d6b 100644 --- a/lib/extglob.js +++ b/lib/extglob.js @@ -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 @@ -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; } diff --git a/lib/parsers.js b/lib/parsers.js index 97109e6..298a6a8 100644 --- a/lib/parsers.js +++ b/lib/parsers.js @@ -1,15 +1,15 @@ 'use strict'; -var brackets = require('expand-brackets'); -var utils = require('./utils'); +const brackets = require('expand-brackets'); +const utils = require('./utils'); /** * Characters to use in text regex (we want to "not" match * characters that are matched by other parsers) */ -var TEXT_REGEX = '([!@*?+]?\\(|\\)|[*?.+\\\\]|\\[:?(?=.*\\])|:?\\])+'; -var not = utils.createRegex(TEXT_REGEX); +const TEXT_REGEX = '([!@*?+]?\\(|\\)|[*?.+\\\\]|\\[:?(?=.*\\])|:?\\])+'; +const not = utils.createRegex(TEXT_REGEX); /** * Extglob parsers @@ -31,22 +31,22 @@ function parsers(extglob) { */ .set('paren.open', function() { - var pos = this.position(); - var m = this.match(/^([!@*?+])?\(/); + const pos = this.position(); + const m = this.match(/^([!@*?+])?\(/); if (!m) return; - var prev = this.prev(); - var prefix = m[1]; - var val = m[0]; + const prev = this.prev(); + const prefix = m[1]; + const val = m[0]; - var open = pos({ + const open = pos({ type: 'paren.open', - val: val + val }); - var node = pos({ + const node = pos({ type: 'paren', - prefix: prefix, + prefix, nodes: [] }); @@ -66,16 +66,16 @@ function parsers(extglob) { */ .set('paren.close', function() { - var parsed = this.parsed; - var pos = this.position(); - var m = this.match(/^\)/); + const parsed = this.parsed; + const pos = this.position(); + const m = this.match(/^\)/); if (!m) return; - var parent = this.pop('paren'); - var node = pos({ + const parent = this.pop('paren'); + const node = pos({ type: 'paren.close', rest: this.input, - parsed: parsed, + parsed, val: m[0] }); @@ -96,8 +96,8 @@ function parsers(extglob) { */ .set('escape', function() { - var pos = this.position(); - var m = this.match(/^\\(.)/); + const pos = this.position(); + const m = this.match(/^\\(.)/); if (!m) return; return pos({ @@ -112,15 +112,15 @@ function parsers(extglob) { */ .set('qmark', function() { - var parsed = this.parsed; - var pos = this.position(); - var m = this.match(/^\?+(?!\()/); + const parsed = this.parsed; + const pos = this.position(); + const m = this.match(/^\?+(?!\()/); if (!m) return; extglob.state.metachar = true; return pos({ type: 'qmark', rest: this.input, - parsed: parsed, + parsed, val: m[0] }); }) diff --git a/lib/utils.js b/lib/utils.js index 37a59fb..fc7c97a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,14 +1,14 @@ 'use strict'; -var regex = require('regex-not'); -var Cache = require('fragment-cache'); +const regex = require('regex-not'); +const Cache = require('fragment-cache'); /** * Utils */ -var utils = module.exports; -var cache = utils.cache = new Cache(); +const utils = module.exports; +const cache = utils.cache = new Cache(); /** * Cast `val` to an array @@ -27,13 +27,13 @@ utils.arrayify = function(val) { */ utils.memoize = function(type, pattern, options, fn) { - var key = utils.createKey(type + pattern, options); + const key = utils.createKey(type + pattern, options); if (cache.has(type, key)) { return cache.get(type, key); } - var val = fn(pattern, options); + const val = fn(pattern, options); if (options && options.cache === false) { return val; } @@ -49,11 +49,11 @@ utils.memoize = function(type, pattern, options, fn) { */ utils.createKey = function(pattern, options) { - var key = pattern; + let key = pattern; if (typeof options === 'undefined') { return key; } - for (var prop in options) { + for (const prop in options) { key += ';' + prop + '=' + String(options[prop]); } return key; @@ -64,6 +64,6 @@ utils.createKey = function(pattern, options) { */ utils.createRegex = function(str) { - var opts = {contains: true, strictClose: false}; + const opts = {contains: true, strictClose: false}; return regex(str, opts); };