Upgrade Ava to v4
This commit is contained in:
parent
9a40cc5274
commit
ce89f1b611
1153 changed files with 27264 additions and 95308 deletions
138
node_modules/ignore/legacy.js
generated
vendored
138
node_modules/ignore/legacy.js
generated
vendored
|
|
@ -11,6 +11,9 @@ function makeArray(subject) {
|
|||
return Array.isArray(subject) ? subject : [subject];
|
||||
}
|
||||
|
||||
var EMPTY = '';
|
||||
var SPACE = ' ';
|
||||
var ESCAPE = '\\';
|
||||
var REGEX_TEST_BLANK_LINE = /^\s+$/;
|
||||
var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
||||
var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
||||
|
|
@ -32,15 +35,26 @@ var define = function define(object, key, value) {
|
|||
});
|
||||
};
|
||||
|
||||
var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression
|
||||
var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
|
||||
|
||||
var RETURN_FALSE = function RETURN_FALSE() {
|
||||
return false;
|
||||
}; // Sanitize the range of a regular expression
|
||||
// The cases are complicated, see test cases for details
|
||||
|
||||
|
||||
var sanitizeRange = function sanitizeRange(range) {
|
||||
return range.replace(REGEX_REGEXP_RANGE, function (match, from, to) {
|
||||
return from.charCodeAt(0) <= to.charCodeAt(0) ? match // Invalid range (out of order) which is ok for gitignore rules but
|
||||
// fatal for JavaScript regular expression, so eliminate it.
|
||||
: '';
|
||||
: EMPTY;
|
||||
});
|
||||
}; // See fixtures #59
|
||||
|
||||
|
||||
var cleanRangeBackSlash = function cleanRangeBackSlash(slashes) {
|
||||
var length = slashes.length;
|
||||
return slashes.slice(0, length - length % 2);
|
||||
}; // > If the pattern ends with a slash,
|
||||
// > it is removed for the purpose of the following description,
|
||||
// > but it would only find a match with a directory.
|
||||
|
|
@ -58,10 +72,10 @@ var REPLACERS = [// > Trailing spaces are ignored unless they are quoted with ba
|
|||
// (a ) -> (a)
|
||||
// (a \ ) -> (a )
|
||||
/\\?\s+$/, function (match) {
|
||||
return match.indexOf('\\') === 0 ? ' ' : '';
|
||||
return match.indexOf('\\') === 0 ? SPACE : EMPTY;
|
||||
}], // replace (\ ) with ' '
|
||||
[/\\\s/g, function () {
|
||||
return ' ';
|
||||
return SPACE;
|
||||
}], // Escape metacharacters
|
||||
// which is written down by users but means special for regular expressions.
|
||||
// > There are 12 characters with special meanings:
|
||||
|
|
@ -78,12 +92,8 @@ var REPLACERS = [// > Trailing spaces are ignored unless they are quoted with ba
|
|||
// > - and the opening square bracket [,
|
||||
// > - the opening curly brace {,
|
||||
// > These special characters are often called "metacharacters".
|
||||
[/[\\^$.|*+(){]/g, function (match) {
|
||||
[/[\\$.|*+(){^]/g, function (match) {
|
||||
return "\\".concat(match);
|
||||
}], [// > [abc] matches any character inside the brackets
|
||||
// > (in this case a, b, or c);
|
||||
/\[([^\]/]*)($|\])/g, function (match, p1, p2) {
|
||||
return p2 === ']' ? "[".concat(sanitizeRange(p1), "]") : "\\".concat(match);
|
||||
}], [// > a question mark (?) matches a single character
|
||||
/(?!\\)\?/g, function () {
|
||||
return '[^/]';
|
||||
|
|
@ -105,23 +115,6 @@ var REPLACERS = [// > Trailing spaces are ignored unless they are quoted with ba
|
|||
/^\^*\\\*\\\*\\\//, // '**/foo' <-> 'foo'
|
||||
function () {
|
||||
return '^(?:.*\\/)?';
|
||||
}], // ending
|
||||
[// 'js' will not match 'js.'
|
||||
// 'ab' will not match 'abc'
|
||||
/(?:[^*])$/, // WTF!
|
||||
// https://git-scm.com/docs/gitignore
|
||||
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
|
||||
// which re-fixes #24, #38
|
||||
// > If there is a separator at the end of the pattern then the pattern
|
||||
// > will only match directories, otherwise the pattern can match both
|
||||
// > files and directories.
|
||||
// 'js*' will not match 'a.js'
|
||||
// 'js/' will not match 'a.js'
|
||||
// 'js' will match 'a.js' and 'a.js/'
|
||||
function (match) {
|
||||
return /\/$/.test(match) // foo/ will not match 'foo'
|
||||
? "".concat(match, "$") // foo matches 'foo' and 'foo/'
|
||||
: "".concat(match, "(?=$|\\/$)");
|
||||
}], // starting
|
||||
[// there will be no leading '/'
|
||||
// (which has been replaced by section "leading slash")
|
||||
|
|
@ -166,10 +159,46 @@ function (_, index, str) {
|
|||
// '*.js' doesn't match 'abc'
|
||||
function (_, p1) {
|
||||
return "".concat(p1, "[^\\/]*");
|
||||
}], [// unescape, revert step 3 except for back slash
|
||||
// For example, if a user escape a '\\*',
|
||||
// after step 3, the result will be '\\\\\\*'
|
||||
/\\\\\\(?=[$.|*+(){^])/g, function () {
|
||||
return ESCAPE;
|
||||
}], [// '\\\\' -> '\\'
|
||||
/\\\\/g, function () {
|
||||
return ESCAPE;
|
||||
}], [// > The range notation, e.g. [a-zA-Z],
|
||||
// > can be used to match one of the characters in a range.
|
||||
// `\` is escaped by step 3
|
||||
/(\\)?\[([^\]/]*?)(\\*)($|\])/g, function (match, leadEscape, range, endEscape, close) {
|
||||
return leadEscape === ESCAPE // '\\[bar]' -> '\\\\[bar\\]'
|
||||
? "\\[".concat(range).concat(cleanRangeBackSlash(endEscape)).concat(close) : close === ']' ? endEscape.length % 2 === 0 // A normal case, and it is a range notation
|
||||
// '[bar]'
|
||||
// '[bar\\\\]'
|
||||
? "[".concat(sanitizeRange(range)).concat(endEscape, "]") // Invalid range notaton
|
||||
// '[bar\\]' -> '[bar\\\\]'
|
||||
: '[]' : '[]';
|
||||
}], // ending
|
||||
[// 'js' will not match 'js.'
|
||||
// 'ab' will not match 'abc'
|
||||
/(?:[^*])$/, // WTF!
|
||||
// https://git-scm.com/docs/gitignore
|
||||
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
|
||||
// which re-fixes #24, #38
|
||||
// > If there is a separator at the end of the pattern then the pattern
|
||||
// > will only match directories, otherwise the pattern can match both
|
||||
// > files and directories.
|
||||
// 'js*' will not match 'a.js'
|
||||
// 'js/' will not match 'a.js'
|
||||
// 'js' will match 'a.js' and 'a.js/'
|
||||
function (match) {
|
||||
return /\/$/.test(match) // foo/ will not match 'foo'
|
||||
? "".concat(match, "$") // foo matches 'foo' and 'foo/'
|
||||
: "".concat(match, "(?=$|\\/$)");
|
||||
}], // trailing wildcard
|
||||
[/(\^|\\\/)?\\\*$/, function (_, p1) {
|
||||
var prefix = p1 // '\^':
|
||||
// '/*' does not match ''
|
||||
// '/*' does not match EMPTY
|
||||
// '/*' does not match everything
|
||||
// '\\\/':
|
||||
// 'abc/*' does not match 'abc/'
|
||||
|
|
@ -177,27 +206,21 @@ function (_, p1) {
|
|||
// 'a*' matches 'aa'
|
||||
: '[^/]*';
|
||||
return "".concat(prefix, "(?=$|\\/$)");
|
||||
}], [// unescape
|
||||
/\\\\\\/g, function () {
|
||||
return '\\';
|
||||
}]]; // A simple cache, because an ignore rule only has only one certain meaning
|
||||
|
||||
var regexCache = Object.create(null); // @param {pattern}
|
||||
|
||||
var makeRegex = function makeRegex(pattern, negative, ignorecase) {
|
||||
var r = regexCache[pattern];
|
||||
var makeRegex = function makeRegex(pattern, ignoreCase) {
|
||||
var source = regexCache[pattern];
|
||||
|
||||
if (r) {
|
||||
return r;
|
||||
} // const replacers = negative
|
||||
// ? NEGATIVE_REPLACERS
|
||||
// : POSITIVE_REPLACERS
|
||||
if (!source) {
|
||||
source = REPLACERS.reduce(function (prev, current) {
|
||||
return prev.replace(current[0], current[1].bind(pattern));
|
||||
}, pattern);
|
||||
regexCache[pattern] = source;
|
||||
}
|
||||
|
||||
|
||||
var source = REPLACERS.reduce(function (prev, current) {
|
||||
return prev.replace(current[0], current[1].bind(pattern));
|
||||
}, pattern);
|
||||
return regexCache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source);
|
||||
return ignoreCase ? new RegExp(source, 'i') : new RegExp(source);
|
||||
};
|
||||
|
||||
var isString = function isString(subject) {
|
||||
|
|
@ -223,7 +246,7 @@ var IgnoreRule = function IgnoreRule(origin, pattern, negative, regex) {
|
|||
this.regex = regex;
|
||||
};
|
||||
|
||||
var createRule = function createRule(pattern, ignorecase) {
|
||||
var createRule = function createRule(pattern, ignoreCase) {
|
||||
var origin = pattern;
|
||||
var negative = false; // > An optional prefix "!" which negates the pattern;
|
||||
|
||||
|
|
@ -237,7 +260,7 @@ var createRule = function createRule(pattern, ignorecase) {
|
|||
.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that
|
||||
// > begin with a hash.
|
||||
.replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#');
|
||||
var regex = makeRegex(pattern, negative, ignorecase);
|
||||
var regex = makeRegex(pattern, ignoreCase);
|
||||
return new IgnoreRule(origin, pattern, negative, regex);
|
||||
};
|
||||
|
||||
|
|
@ -248,7 +271,7 @@ var throwError = function throwError(message, Ctor) {
|
|||
var checkPath = function checkPath(path, originalPath, doThrow) {
|
||||
if (!isString(path)) {
|
||||
return doThrow("path must be a string, but got `".concat(originalPath, "`"), TypeError);
|
||||
} // We don't know if we should ignore '', so throw
|
||||
} // We don't know if we should ignore EMPTY, so throw
|
||||
|
||||
|
||||
if (!path) {
|
||||
|
|
@ -274,19 +297,22 @@ checkPath.convert = function (p) {
|
|||
return p;
|
||||
};
|
||||
|
||||
var Ignore =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
var Ignore = /*#__PURE__*/function () {
|
||||
function Ignore() {
|
||||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
||||
_ref$ignorecase = _ref.ignorecase,
|
||||
ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase;
|
||||
ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase,
|
||||
_ref$ignoreCase = _ref.ignoreCase,
|
||||
ignoreCase = _ref$ignoreCase === void 0 ? ignorecase : _ref$ignoreCase,
|
||||
_ref$allowRelativePat = _ref.allowRelativePaths,
|
||||
allowRelativePaths = _ref$allowRelativePat === void 0 ? false : _ref$allowRelativePat;
|
||||
|
||||
_classCallCheck(this, Ignore);
|
||||
|
||||
this._rules = [];
|
||||
this._ignorecase = ignorecase;
|
||||
define(this, KEY_IGNORE, true);
|
||||
this._rules = [];
|
||||
this._ignoreCase = ignoreCase;
|
||||
this._allowRelativePaths = allowRelativePaths;
|
||||
|
||||
this._initCache();
|
||||
}
|
||||
|
|
@ -308,7 +334,7 @@ function () {
|
|||
}
|
||||
|
||||
if (checkPattern(pattern)) {
|
||||
var rule = createRule(pattern, this._ignorecase);
|
||||
var rule = createRule(pattern, this._ignoreCase);
|
||||
this._added = true;
|
||||
|
||||
this._rules.push(rule);
|
||||
|
|
@ -379,7 +405,7 @@ function () {
|
|||
value: function _test(originalPath, cache, checkUnignored, slices) {
|
||||
var path = originalPath // Supports nullable path
|
||||
&& checkPath.convert(originalPath);
|
||||
checkPath(path, originalPath, throwError);
|
||||
checkPath(path, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError);
|
||||
return this._t(path, cache, checkUnignored, slices);
|
||||
}
|
||||
}, {
|
||||
|
|
@ -442,12 +468,8 @@ var factory = function factory(options) {
|
|||
return new Ignore(options);
|
||||
};
|
||||
|
||||
var returnFalse = function returnFalse() {
|
||||
return false;
|
||||
};
|
||||
|
||||
var isPathValid = function isPathValid(path) {
|
||||
return checkPath(path && checkPath.convert(path), path, returnFalse);
|
||||
return checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
|
||||
};
|
||||
|
||||
factory.isPathValid = isPathValid; // Fixes typescript
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue