Skip to content

Commit

Permalink
[fix] revert all breaking syntax changes
Browse files Browse the repository at this point in the history
Fixes #153.

PR-URL: #154
Credit: @ljharb
Close: #154
Reviewed-by: @isaacs
  • Loading branch information
ljharb authored and isaacs committed Feb 12, 2022
1 parent 2ff0388 commit 20b4b56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
41 changes: 21 additions & 20 deletions minimatch.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module.exports = minimatch
minimatch.Minimatch = Minimatch

const path = (() => { try { return require('path') } catch (e) {}})() || {
var path = (function () { try { return require('path') } catch (e) {}}()) || {
sep: '/'
}
minimatch.sep = path.sep

const GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
const expand = require('brace-expansion')
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
var expand = require('brace-expansion')

const plTypes = {
var plTypes = {
'!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
'?': { open: '(?:', close: ')?' },
'+': { open: '(?:', close: ')+' },
Expand All @@ -19,22 +19,22 @@ const plTypes = {

// any single thing other than /
// don't need to escape / when using new RegExp()
const qmark = '[^/]'
var qmark = '[^/]'

// * => any number of characters
const star = qmark + '*?'
var star = qmark + '*?'

// ** when dots are allowed. Anything goes, except .. and .
// not (^ or / followed by one or two dots followed by $ or /),
// followed by anything, any number of times.
const twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'

// not a ^ or / followed by a dot,
// followed by anything, any number of times.
const twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'
var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'

// characters that need to be escaped in RegExp.
const reSpecials = charSet('().*{}+?[]^$\\!')
var reSpecials = charSet('().*{}+?[]^$\\!')

// "abc" -> { a:true, b:true, c:true }
function charSet (s) {
Expand All @@ -45,7 +45,7 @@ function charSet (s) {
}

// normalizes slashes.
const slashSplit = /\/+/
var slashSplit = /\/+/

minimatch.filter = filter
function filter (pattern, options) {
Expand All @@ -57,7 +57,7 @@ function filter (pattern, options) {

function ext (a, b) {
b = b || {}
const t = {}
var t = {}
Object.keys(a).forEach(function (k) {
t[k] = a[k]
})
Expand All @@ -72,16 +72,16 @@ minimatch.defaults = function (def) {
return minimatch
}

const orig = minimatch
var orig = minimatch

const m = function minimatch (p, pattern, options) {
var m = function minimatch (p, pattern, options) {
return orig(p, pattern, ext(def, options))
}

m.Minimatch = function Minimatch (pattern, options) {
return new orig.Minimatch(pattern, ext(def, options))
}
m.Minimatch.defaults = options => {
m.Minimatch.defaults = function defaults (options) {
return orig.defaults(ext(def, options)).Minimatch
}

Expand Down Expand Up @@ -175,7 +175,7 @@ function make () {
// step 2: expand braces
var set = this.globSet = this.braceExpand()

if (options.debug) this.debug = (...args) => console.error(...args)
if (options.debug) this.debug = function debug() { console.error.apply(console, arguments) }

this.debug(this.pattern, set)

Expand Down Expand Up @@ -267,8 +267,8 @@ function braceExpand (pattern, options) {
return expand(pattern)
}

const MAX_PATTERN_LENGTH = 1024 * 64
const assertValidPattern = pattern => {
var MAX_PATTERN_LENGTH = 1024 * 64
var assertValidPattern = function (pattern) {
if (typeof pattern !== 'string') {
throw new TypeError('invalid pattern')
}
Expand All @@ -290,7 +290,7 @@ const assertValidPattern = pattern => {
// of * is equivalent to a single *. Globstar behavior is enabled by
// default, and can be disabled by setting options.noglobstar.
Minimatch.prototype.parse = parse
const SUBPARSE = {}
var SUBPARSE = {}
function parse (pattern, isSub) {
assertValidPattern(pattern)

Expand Down Expand Up @@ -710,7 +710,7 @@ function makeRe () {

minimatch.match = function (list, pattern, options) {
options = options || {}
const mm = new Minimatch(pattern, options)
var mm = new Minimatch(pattern, options)
list = list.filter(function (f) {
return mm.match(f)
})
Expand All @@ -720,7 +720,8 @@ minimatch.match = function (list, pattern, options) {
return list
}

Minimatch.prototype.match = function match (f, partial = this.partial) {
Minimatch.prototype.match = function match (f, partial) {
if (typeof partial === 'undefined') partial = this.partial
this.debug('match', f, this.pattern)
// short-circuit in the case of busted things.
// comments, etc.
Expand Down
2 changes: 2 additions & 0 deletions test/partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ const mm = require('../')
t.equal(mm('/a/b', '/*/b/x/y/z', { partial: true }), true)
t.equal(mm('/a/b/c', '/*/b/x/y/z', { partial: true }), false)
t.equal(mm('/', 'x', { partial: true }), true)
const m = new mm.Minimatch('/*/b/x/y/z')
t.equal(m.match('/a/b', true), true)

0 comments on commit 20b4b56

Please sign in to comment.