summaryrefslogtreecommitdiff
path: root/node_modules/braces/lib
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
commitefbc2ffe6a1ee5ec38a4396305561d6515d0943e (patch)
tree2b4c94f18f2c792dfda813050755d5c0273fae22 /node_modules/braces/lib
parent43acceb75957c880a5ba5a31aae221394a36d5f6 (diff)
node fixes, updates
Diffstat (limited to 'node_modules/braces/lib')
-rw-r--r--node_modules/braces/lib/compile.js25
-rw-r--r--node_modules/braces/lib/constants.js2
-rw-r--r--node_modules/braces/lib/expand.js18
-rw-r--r--node_modules/braces/lib/parse.js30
-rw-r--r--node_modules/braces/lib/stringify.js8
-rw-r--r--node_modules/braces/lib/utils.js16
6 files changed, 55 insertions, 44 deletions
diff --git a/node_modules/braces/lib/compile.js b/node_modules/braces/lib/compile.js
index 3e984a4b..dce69beb 100644
--- a/node_modules/braces/lib/compile.js
+++ b/node_modules/braces/lib/compile.js
@@ -4,30 +4,32 @@ const fill = require('fill-range');
const utils = require('./utils');
const compile = (ast, options = {}) => {
- let walk = (node, parent = {}) => {
- let invalidBlock = utils.isInvalidBrace(parent);
- let invalidNode = node.invalid === true && options.escapeInvalid === true;
- let invalid = invalidBlock === true || invalidNode === true;
- let prefix = options.escapeInvalid === true ? '\\' : '';
+ const walk = (node, parent = {}) => {
+ const invalidBlock = utils.isInvalidBrace(parent);
+ const invalidNode = node.invalid === true && options.escapeInvalid === true;
+ const invalid = invalidBlock === true || invalidNode === true;
+ const prefix = options.escapeInvalid === true ? '\\' : '';
let output = '';
if (node.isOpen === true) {
return prefix + node.value;
}
+
if (node.isClose === true) {
+ console.log('node.isClose', prefix, node.value);
return prefix + node.value;
}
if (node.type === 'open') {
- return invalid ? (prefix + node.value) : '(';
+ return invalid ? prefix + node.value : '(';
}
if (node.type === 'close') {
- return invalid ? (prefix + node.value) : ')';
+ return invalid ? prefix + node.value : ')';
}
if (node.type === 'comma') {
- return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
+ return node.prev.type === 'comma' ? '' : invalid ? node.value : '|';
}
if (node.value) {
@@ -35,8 +37,8 @@ const compile = (ast, options = {}) => {
}
if (node.nodes && node.ranges > 0) {
- let args = utils.reduce(node.nodes);
- let range = fill(...args, { ...options, wrap: false, toRegex: true });
+ const args = utils.reduce(node.nodes);
+ const range = fill(...args, { ...options, wrap: false, toRegex: true, strictZeros: true });
if (range.length !== 0) {
return args.length > 1 && range.length > 1 ? `(${range})` : range;
@@ -44,10 +46,11 @@ const compile = (ast, options = {}) => {
}
if (node.nodes) {
- for (let child of node.nodes) {
+ for (const child of node.nodes) {
output += walk(child, node);
}
}
+
return output;
};
diff --git a/node_modules/braces/lib/constants.js b/node_modules/braces/lib/constants.js
index a9379436..2bb3b884 100644
--- a/node_modules/braces/lib/constants.js
+++ b/node_modules/braces/lib/constants.js
@@ -1,7 +1,7 @@
'use strict';
module.exports = {
- MAX_LENGTH: 1024 * 64,
+ MAX_LENGTH: 10000,
// Digits
CHAR_0: '0', /* 0 */
diff --git a/node_modules/braces/lib/expand.js b/node_modules/braces/lib/expand.js
index 376c748a..35b2c41d 100644
--- a/node_modules/braces/lib/expand.js
+++ b/node_modules/braces/lib/expand.js
@@ -5,7 +5,7 @@ const stringify = require('./stringify');
const utils = require('./utils');
const append = (queue = '', stash = '', enclose = false) => {
- let result = [];
+ const result = [];
queue = [].concat(queue);
stash = [].concat(stash);
@@ -15,15 +15,15 @@ const append = (queue = '', stash = '', enclose = false) => {
return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
}
- for (let item of queue) {
+ for (const item of queue) {
if (Array.isArray(item)) {
- for (let value of item) {
+ for (const value of item) {
result.push(append(value, stash, enclose));
}
} else {
for (let ele of stash) {
if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
- result.push(Array.isArray(ele) ? append(item, ele, enclose) : (item + ele));
+ result.push(Array.isArray(ele) ? append(item, ele, enclose) : item + ele);
}
}
}
@@ -31,9 +31,9 @@ const append = (queue = '', stash = '', enclose = false) => {
};
const expand = (ast, options = {}) => {
- let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
+ const rangeLimit = options.rangeLimit === undefined ? 1000 : options.rangeLimit;
- let walk = (node, parent = {}) => {
+ const walk = (node, parent = {}) => {
node.queue = [];
let p = parent;
@@ -55,7 +55,7 @@ const expand = (ast, options = {}) => {
}
if (node.nodes && node.ranges > 0) {
- let args = utils.reduce(node.nodes);
+ const args = utils.reduce(node.nodes);
if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
@@ -71,7 +71,7 @@ const expand = (ast, options = {}) => {
return;
}
- let enclose = utils.encloseBrace(node);
+ const enclose = utils.encloseBrace(node);
let queue = node.queue;
let block = node;
@@ -81,7 +81,7 @@ const expand = (ast, options = {}) => {
}
for (let i = 0; i < node.nodes.length; i++) {
- let child = node.nodes[i];
+ const child = node.nodes[i];
if (child.type === 'comma' && node.type === 'brace') {
if (i === 1) queue.push('');
diff --git a/node_modules/braces/lib/parse.js b/node_modules/braces/lib/parse.js
index 145ea264..3a6988e6 100644
--- a/node_modules/braces/lib/parse.js
+++ b/node_modules/braces/lib/parse.js
@@ -33,22 +33,21 @@ const parse = (input, options = {}) => {
throw new TypeError('Expected a string');
}
- let opts = options || {};
- let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
+ const opts = options || {};
+ const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
if (input.length > max) {
throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
}
- let ast = { type: 'root', input, nodes: [] };
- let stack = [ast];
+ const ast = { type: 'root', input, nodes: [] };
+ const stack = [ast];
let block = ast;
let prev = ast;
let brackets = 0;
- let length = input.length;
+ const length = input.length;
let index = 0;
let depth = 0;
let value;
- let memo = {};
/**
* Helpers
@@ -111,7 +110,6 @@ const parse = (input, options = {}) => {
if (value === CHAR_LEFT_SQUARE_BRACKET) {
brackets++;
- let closed = true;
let next;
while (index < length && (next = advance())) {
@@ -167,7 +165,7 @@ const parse = (input, options = {}) => {
*/
if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
- let open = value;
+ const open = value;
let next;
if (options.keepQuotes !== true) {
@@ -199,8 +197,8 @@ const parse = (input, options = {}) => {
if (value === CHAR_LEFT_CURLY_BRACE) {
depth++;
- let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
- let brace = {
+ const dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
+ const brace = {
type: 'brace',
open: true,
close: false,
@@ -227,7 +225,7 @@ const parse = (input, options = {}) => {
continue;
}
- let type = 'close';
+ const type = 'close';
block = stack.pop();
block.close = true;
@@ -245,7 +243,7 @@ const parse = (input, options = {}) => {
if (value === CHAR_COMMA && depth > 0) {
if (block.ranges > 0) {
block.ranges = 0;
- let open = block.nodes.shift();
+ const open = block.nodes.shift();
block.nodes = [open, { type: 'text', value: stringify(block) }];
}
@@ -259,7 +257,7 @@ const parse = (input, options = {}) => {
*/
if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
- let siblings = block.nodes;
+ const siblings = block.nodes;
if (depth === 0 || siblings.length === 0) {
push({ type: 'text', value });
@@ -286,7 +284,7 @@ const parse = (input, options = {}) => {
if (prev.type === 'range') {
siblings.pop();
- let before = siblings[siblings.length - 1];
+ const before = siblings[siblings.length - 1];
before.value += prev.value + value;
prev = before;
block.ranges--;
@@ -319,8 +317,8 @@ const parse = (input, options = {}) => {
});
// get the location of the block on parent.nodes (block's siblings)
- let parent = stack[stack.length - 1];
- let index = parent.nodes.indexOf(block);
+ const parent = stack[stack.length - 1];
+ const index = parent.nodes.indexOf(block);
// replace the (invalid) block with it's nodes
parent.nodes.splice(index, 1, ...block.nodes);
}
diff --git a/node_modules/braces/lib/stringify.js b/node_modules/braces/lib/stringify.js
index 414b7bcc..8bcf872c 100644
--- a/node_modules/braces/lib/stringify.js
+++ b/node_modules/braces/lib/stringify.js
@@ -3,9 +3,9 @@
const utils = require('./utils');
module.exports = (ast, options = {}) => {
- let stringify = (node, parent = {}) => {
- let invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
- let invalidNode = node.invalid === true && options.escapeInvalid === true;
+ const stringify = (node, parent = {}) => {
+ const invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
+ const invalidNode = node.invalid === true && options.escapeInvalid === true;
let output = '';
if (node.value) {
@@ -20,7 +20,7 @@ module.exports = (ast, options = {}) => {
}
if (node.nodes) {
- for (let child of node.nodes) {
+ for (const child of node.nodes) {
output += stringify(child);
}
}
diff --git a/node_modules/braces/lib/utils.js b/node_modules/braces/lib/utils.js
index e3551a67..d19311fe 100644
--- a/node_modules/braces/lib/utils.js
+++ b/node_modules/braces/lib/utils.js
@@ -31,7 +31,7 @@ exports.exceedsLimit = (min, max, step = 1, limit) => {
*/
exports.escapeNode = (block, n = 0, type) => {
- let node = block.nodes[n];
+ const node = block.nodes[n];
if (!node) return;
if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
@@ -100,13 +100,23 @@ exports.reduce = nodes => nodes.reduce((acc, node) => {
exports.flatten = (...args) => {
const result = [];
+
const flat = arr => {
for (let i = 0; i < arr.length; i++) {
- let ele = arr[i];
- Array.isArray(ele) ? flat(ele, result) : ele !== void 0 && result.push(ele);
+ const ele = arr[i];
+
+ if (Array.isArray(ele)) {
+ flat(ele);
+ continue;
+ }
+
+ if (ele !== undefined) {
+ result.push(ele);
+ }
}
return result;
};
+
flat(args);
return result;
};