format: prettify entire project

This commit is contained in:
Rim
2025-04-02 06:50:39 -04:00
parent 86f0782a98
commit 7ccc0be712
1711 changed files with 755867 additions and 235931 deletions

242
node_modules/picomatch/lib/parse.js generated vendored
View File

@ -12,7 +12,7 @@ const {
POSIX_REGEX_SOURCE,
REGEX_NON_SPECIAL_CHARS,
REGEX_SPECIAL_CHARS_BACKREF,
REPLACEMENTS
REPLACEMENTS,
} = constants;
/**
@ -31,7 +31,7 @@ const expandRange = (args, options) => {
/* eslint-disable-next-line no-new */
new RegExp(value);
} catch (ex) {
return args.map(v => utils.escapeRegex(v)).join('..');
return args.map((v) => utils.escapeRegex(v)).join('..');
}
return value;
@ -60,11 +60,16 @@ const parse = (input, options) => {
input = REPLACEMENTS[input] || input;
const opts = { ...options };
const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
const max =
typeof opts.maxLength === 'number' ?
Math.min(MAX_LENGTH, opts.maxLength)
: MAX_LENGTH;
let len = input.length;
if (len > max) {
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
throw new SyntaxError(
`Input length: ${len}, exceeds maximum allowed length: ${max}`
);
}
const bos = { type: 'bos', value: '', output: opts.prepend || '' };
@ -89,10 +94,10 @@ const parse = (input, options) => {
QMARK,
QMARK_NO_DOT,
STAR,
START_ANCHOR
START_ANCHOR,
} = PLATFORM_CHARS;
const globstar = opts => {
const globstar = (opts) => {
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
};
@ -124,7 +129,7 @@ const parse = (input, options) => {
parens: 0,
quotes: 0,
globstar: false,
tokens
tokens,
};
input = utils.removePrefix(input, state);
@ -141,15 +146,15 @@ const parse = (input, options) => {
*/
const eos = () => state.index === len - 1;
const peek = state.peek = (n = 1) => input[state.index + n];
const advance = state.advance = () => input[++state.index] || '';
const peek = (state.peek = (n = 1) => input[state.index + n]);
const advance = (state.advance = () => input[++state.index] || '');
const remaining = () => input.slice(state.index + 1);
const consume = (value = '', num = 0) => {
state.consumed += value;
state.index += num;
};
const append = token => {
const append = (token) => {
state.output += token.output != null ? token.output : token.value;
consume(token.value);
};
@ -172,12 +177,12 @@ const parse = (input, options) => {
return true;
};
const increment = type => {
const increment = (type) => {
state[type]++;
stack.push(type);
};
const decrement = type => {
const decrement = (type) => {
state[type]--;
stack.pop();
};
@ -190,12 +195,20 @@ const parse = (input, options) => {
* lookbehinds.
*/
const push = tok => {
const push = (tok) => {
if (prev.type === 'globstar') {
const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
const isExtglob = tok.extglob === true || (extglobs.length && (tok.type === 'pipe' || tok.type === 'paren'));
const isBrace =
state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
const isExtglob =
tok.extglob === true ||
(extglobs.length && (tok.type === 'pipe' || tok.type === 'paren'));
if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
if (
tok.type !== 'slash' &&
tok.type !== 'paren' &&
!isBrace &&
!isExtglob
) {
state.output = state.output.slice(0, -prev.output.length);
prev.type = 'star';
prev.value = '*';
@ -234,7 +247,7 @@ const parse = (input, options) => {
extglobs.push(token);
};
const extglobClose = token => {
const extglobClose = (token) => {
let output = token.close + (opts.capture ? ')' : '');
let rest;
@ -249,7 +262,11 @@ const parse = (input, options) => {
output = token.close = `)$))${extglobStar}`;
}
if (token.inner.includes('*') && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
if (
token.inner.includes('*') &&
(rest = remaining()) &&
/^\.[^\\/.]+$/.test(rest)
) {
// Any non-magical string (`.ts`) or even nested expression (`.{ts,tsx}`) can follow after the closing parenthesis.
// In this case, we need to parse the string and use it in the output of the original pattern.
// Suitable patterns: `/!(*.d).ts`, `/!(*.d).{ts,tsx}`, `**/!(*-dbg).@(js)`.
@ -276,41 +293,48 @@ const parse = (input, options) => {
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
let backslashes = false;
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
if (first === '\\') {
backslashes = true;
return m;
}
if (first === '?') {
if (esc) {
return esc + first + (rest ? QMARK.repeat(rest.length) : '');
let output = input.replace(
REGEX_SPECIAL_CHARS_BACKREF,
(m, esc, chars, first, rest, index) => {
if (first === '\\') {
backslashes = true;
return m;
}
if (index === 0) {
return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
}
return QMARK.repeat(chars.length);
}
if (first === '.') {
return DOT_LITERAL.repeat(chars.length);
}
if (first === '*') {
if (esc) {
return esc + first + (rest ? star : '');
if (first === '?') {
if (esc) {
return esc + first + (rest ? QMARK.repeat(rest.length) : '');
}
if (index === 0) {
return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
}
return QMARK.repeat(chars.length);
}
return star;
if (first === '.') {
return DOT_LITERAL.repeat(chars.length);
}
if (first === '*') {
if (esc) {
return esc + first + (rest ? star : '');
}
return star;
}
return esc ? m : `\\${m}`;
}
return esc ? m : `\\${m}`;
});
);
if (backslashes === true) {
if (opts.unescape === true) {
output = output.replace(/\\/g, '');
} else {
output = output.replace(/\\+/g, m => {
return m.length % 2 === 0 ? '\\\\' : (m ? '\\' : '');
output = output.replace(/\\+/g, (m) => {
return (
m.length % 2 === 0 ? '\\\\'
: m ? '\\'
: ''
);
});
}
}
@ -385,7 +409,10 @@ const parse = (input, options) => {
* until we reach the closing bracket.
*/
if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
if (
state.brackets > 0 &&
(value !== ']' || prev.value === '[' || prev.value === '[^')
) {
if (opts.posix !== false && value === ':') {
const inner = prev.value.slice(1);
if (inner.includes('[')) {
@ -410,7 +437,10 @@ const parse = (input, options) => {
}
}
if ((value === '[' && peek() !== ':') || (value === '-' && peek() === ']')) {
if (
(value === '[' && peek() !== ':') ||
(value === '-' && peek() === ']')
) {
value = `\\${value}`;
}
@ -497,7 +527,10 @@ const parse = (input, options) => {
}
if (value === ']') {
if (opts.nobracket === true || (prev && prev.type === 'bracket' && prev.value.length === 1)) {
if (
opts.nobracket === true ||
(prev && prev.type === 'bracket' && prev.value.length === 1)
) {
push({ type: 'text', value, output: `\\${value}` });
continue;
}
@ -514,7 +547,11 @@ const parse = (input, options) => {
decrement('brackets');
const prevValue = prev.value.slice(1);
if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
if (
prev.posix !== true &&
prevValue[0] === '^' &&
!prevValue.includes('/')
) {
value = `/${value}`;
}
@ -556,7 +593,7 @@ const parse = (input, options) => {
value,
output: '(',
outputIndex: state.output.length,
tokensIndex: state.tokens.length
tokensIndex: state.tokens.length,
};
braces.push(open);
@ -599,7 +636,7 @@ const parse = (input, options) => {
value = output = '\\}';
state.output = out;
for (const t of toks) {
state.output += (t.output || t.value);
state.output += t.output || t.value;
}
}
@ -675,7 +712,11 @@ const parse = (input, options) => {
continue;
}
if ((state.braces + state.parens) === 0 && prev.type !== 'bos' && prev.type !== 'slash') {
if (
state.braces + state.parens === 0 &&
prev.type !== 'bos' &&
prev.type !== 'slash'
) {
push({ type: 'text', value, output: DOT_LITERAL });
continue;
}
@ -690,7 +731,12 @@ const parse = (input, options) => {
if (value === '?') {
const isGroup = prev && prev.value === '(';
if (!isGroup && opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
if (
!isGroup &&
opts.noextglob !== true &&
peek() === '(' &&
peek(2) !== '?'
) {
extglobOpen('qmark', value);
continue;
}
@ -700,10 +746,15 @@ const parse = (input, options) => {
let output = value;
if (next === '<' && !utils.supportsLookbehinds()) {
throw new Error('Node.js v10 or higher is required for regex lookbehinds');
throw new Error(
'Node.js v10 or higher is required for regex lookbehinds'
);
}
if ((prev.value === '(' && !/[!=<:]/.test(next)) || (next === '<' && !/<([!=]|\w+>)/.test(remaining()))) {
if (
(prev.value === '(' && !/[!=<:]/.test(next)) ||
(next === '<' && !/<([!=]|\w+>)/.test(remaining()))
) {
output = `\\${value}`;
}
@ -753,7 +804,13 @@ const parse = (input, options) => {
continue;
}
if ((prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace')) || state.parens > 0) {
if (
(prev &&
(prev.type === 'bracket' ||
prev.type === 'paren' ||
prev.type === 'brace')) ||
state.parens > 0
) {
push({ type: 'plus', value });
continue;
}
@ -825,15 +882,18 @@ const parse = (input, options) => {
const prior = prev.prev;
const before = prior.prev;
const isStart = prior.type === 'slash' || prior.type === 'bos';
const afterStar = before && (before.type === 'star' || before.type === 'globstar');
const afterStar =
before && (before.type === 'star' || before.type === 'globstar');
if (opts.bash === true && (!isStart || (rest[0] && rest[0] !== '/'))) {
push({ type: 'star', value, output: '' });
continue;
}
const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
const isBrace =
state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
const isExtglob =
extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
push({ type: 'star', value, output: '' });
continue;
@ -859,8 +919,16 @@ const parse = (input, options) => {
continue;
}
if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
state.output = state.output.slice(0, -(prior.output + prev.output).length);
if (
prior.type === 'slash' &&
prior.prev.type !== 'bos' &&
!afterStar &&
eos()
) {
state.output = state.output.slice(
0,
-(prior.output + prev.output).length
);
prior.output = `(?:${prior.output}`;
prev.type = 'globstar';
@ -872,10 +940,17 @@ const parse = (input, options) => {
continue;
}
if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
if (
prior.type === 'slash' &&
prior.prev.type !== 'bos' &&
rest[0] === '/'
) {
const end = rest[1] !== void 0 ? '|$' : '';
state.output = state.output.slice(0, -(prior.output + prev.output).length);
state.output = state.output.slice(
0,
-(prior.output + prev.output).length
);
prior.output = `(?:${prior.output}`;
prev.type = 'globstar';
@ -928,21 +1003,27 @@ const parse = (input, options) => {
continue;
}
if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
if (
prev &&
(prev.type === 'bracket' || prev.type === 'paren') &&
opts.regex === true
) {
token.output = value;
push(token);
continue;
}
if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
if (
state.index === state.start ||
prev.type === 'slash' ||
prev.type === 'dot'
) {
if (prev.type === 'dot') {
state.output += NO_DOT_SLASH;
prev.output += NO_DOT_SLASH;
} else if (opts.dot === true) {
state.output += NO_DOTS_SLASH;
prev.output += NO_DOTS_SLASH;
} else {
state.output += nodot;
prev.output += nodot;
@ -958,24 +1039,30 @@ const parse = (input, options) => {
}
while (state.brackets > 0) {
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ']'));
if (opts.strictBrackets === true)
throw new SyntaxError(syntaxError('closing', ']'));
state.output = utils.escapeLast(state.output, '[');
decrement('brackets');
}
while (state.parens > 0) {
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ')'));
if (opts.strictBrackets === true)
throw new SyntaxError(syntaxError('closing', ')'));
state.output = utils.escapeLast(state.output, '(');
decrement('parens');
}
while (state.braces > 0) {
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', '}'));
if (opts.strictBrackets === true)
throw new SyntaxError(syntaxError('closing', '}'));
state.output = utils.escapeLast(state.output, '{');
decrement('braces');
}
if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
if (
opts.strictSlashes !== true &&
(prev.type === 'star' || prev.type === 'bracket')
) {
push({ type: 'maybe_slash', value: '', output: `${SLASH_LITERAL}?` });
}
@ -1003,10 +1090,15 @@ const parse = (input, options) => {
parse.fastpaths = (input, options) => {
const opts = { ...options };
const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
const max =
typeof opts.maxLength === 'number' ?
Math.min(MAX_LENGTH, opts.maxLength)
: MAX_LENGTH;
const len = input.length;
if (len > max) {
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
throw new SyntaxError(
`Input length: ${len}, exceeds maximum allowed length: ${max}`
);
}
input = REPLACEMENTS[input] || input;
@ -1022,7 +1114,7 @@ parse.fastpaths = (input, options) => {
NO_DOTS,
NO_DOTS_SLASH,
STAR,
START_ANCHOR
START_ANCHOR,
} = constants.globChars(win32);
const nodot = opts.dot ? NO_DOTS : NO_DOT;
@ -1035,12 +1127,12 @@ parse.fastpaths = (input, options) => {
star = `(${star})`;
}
const globstar = opts => {
const globstar = (opts) => {
if (opts.noglobstar === true) return star;
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
};
const create = str => {
const create = (str) => {
switch (str) {
case '*':
return `${nodot}${ONE_CHAR}${star}`;