build: update npm install command to use --legacy-peer-deps
This change modifies the build scripts to use --legacy-peer-deps flag when installing npm dependencies to resolve potential peer dependency conflicts during the build process. The change is applied to both bash (build.sh) and batch (build.bat) build scripts.
This commit is contained in:
+1628
-2079
File diff suppressed because it is too large
Load Diff
-247
@@ -1,247 +0,0 @@
|
||||
/**
|
||||
* @fileoverview Utility functions to locate the source text of each code unit in the value of a string literal or template token.
|
||||
* @author Francesco Trotta
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Represents a code unit produced by the evaluation of a JavaScript common token like a string
|
||||
* literal or template token.
|
||||
*/
|
||||
class CodeUnit {
|
||||
constructor(start, source) {
|
||||
this.start = start;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
get end() {
|
||||
return this.start + this.length;
|
||||
}
|
||||
|
||||
get length() {
|
||||
return this.source.length;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An object used to keep track of the position in a source text where the next characters will be read.
|
||||
*/
|
||||
class TextReader {
|
||||
constructor(source) {
|
||||
this.source = source;
|
||||
this.pos = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances the reading position of the specified number of characters.
|
||||
* @param {number} length Number of characters to advance.
|
||||
* @returns {void}
|
||||
*/
|
||||
advance(length) {
|
||||
this.pos += length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads characters from the source.
|
||||
* @param {number} [offset=0] The offset where reading starts, relative to the current position.
|
||||
* @param {number} [length=1] Number of characters to read.
|
||||
* @returns {string} A substring of source characters.
|
||||
*/
|
||||
read(offset = 0, length = 1) {
|
||||
const start = offset + this.pos;
|
||||
|
||||
return this.source.slice(start, start + length);
|
||||
}
|
||||
}
|
||||
|
||||
const SIMPLE_ESCAPE_SEQUENCES = {
|
||||
__proto__: null,
|
||||
b: "\b",
|
||||
f: "\f",
|
||||
n: "\n",
|
||||
r: "\r",
|
||||
t: "\t",
|
||||
v: "\v",
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a hex escape sequence.
|
||||
* @param {TextReader} reader The reader should be positioned on the first hexadecimal digit.
|
||||
* @param {number} length The number of hexadecimal digits.
|
||||
* @returns {string} A code unit.
|
||||
*/
|
||||
function readHexSequence(reader, length) {
|
||||
const str = reader.read(0, length);
|
||||
const charCode = parseInt(str, 16);
|
||||
|
||||
reader.advance(length);
|
||||
return String.fromCharCode(charCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Unicode escape sequence.
|
||||
* @param {TextReader} reader The reader should be positioned after the "u".
|
||||
* @returns {string} A code unit.
|
||||
*/
|
||||
function readUnicodeSequence(reader) {
|
||||
const regExp = /\{(?<hexDigits>[\dA-F]+)\}/iuy;
|
||||
|
||||
regExp.lastIndex = reader.pos;
|
||||
const match = regExp.exec(reader.source);
|
||||
|
||||
if (match) {
|
||||
const codePoint = parseInt(match.groups.hexDigits, 16);
|
||||
|
||||
reader.pos = regExp.lastIndex;
|
||||
return String.fromCodePoint(codePoint);
|
||||
}
|
||||
return readHexSequence(reader, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an octal escape sequence.
|
||||
* @param {TextReader} reader The reader should be positioned after the first octal digit.
|
||||
* @param {number} maxLength The maximum number of octal digits.
|
||||
* @returns {string} A code unit.
|
||||
*/
|
||||
function readOctalSequence(reader, maxLength) {
|
||||
const [octalStr] = reader.read(-1, maxLength).match(/^[0-7]+/u);
|
||||
|
||||
reader.advance(octalStr.length - 1);
|
||||
const octal = parseInt(octalStr, 8);
|
||||
|
||||
return String.fromCharCode(octal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an escape sequence or line continuation.
|
||||
* @param {TextReader} reader The reader should be positioned on the backslash.
|
||||
* @returns {string} A string of zero, one or two code units.
|
||||
*/
|
||||
function readEscapeSequenceOrLineContinuation(reader) {
|
||||
const char = reader.read(1);
|
||||
|
||||
reader.advance(2);
|
||||
const unitChar = SIMPLE_ESCAPE_SEQUENCES[char];
|
||||
|
||||
if (unitChar) {
|
||||
return unitChar;
|
||||
}
|
||||
switch (char) {
|
||||
case "x":
|
||||
return readHexSequence(reader, 2);
|
||||
case "u":
|
||||
return readUnicodeSequence(reader);
|
||||
case "\r":
|
||||
if (reader.read() === "\n") {
|
||||
reader.advance(1);
|
||||
}
|
||||
|
||||
// fallthrough
|
||||
case "\n":
|
||||
case "\u2028":
|
||||
case "\u2029":
|
||||
return "";
|
||||
case "0":
|
||||
case "1":
|
||||
case "2":
|
||||
case "3":
|
||||
return readOctalSequence(reader, 3);
|
||||
case "4":
|
||||
case "5":
|
||||
case "6":
|
||||
case "7":
|
||||
return readOctalSequence(reader, 2);
|
||||
default:
|
||||
return char;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an escape sequence or line continuation and generates the respective `CodeUnit` elements.
|
||||
* @param {TextReader} reader The reader should be positioned on the backslash.
|
||||
* @returns {Generator<CodeUnit>} Zero, one or two `CodeUnit` elements.
|
||||
*/
|
||||
function* mapEscapeSequenceOrLineContinuation(reader) {
|
||||
const start = reader.pos;
|
||||
const str = readEscapeSequenceOrLineContinuation(reader);
|
||||
const end = reader.pos;
|
||||
const source = reader.source.slice(start, end);
|
||||
|
||||
switch (str.length) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
yield new CodeUnit(start, source);
|
||||
break;
|
||||
default:
|
||||
yield new CodeUnit(start, source);
|
||||
yield new CodeUnit(start, source);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string literal.
|
||||
* @param {string} source The string literal to parse, including the delimiting quotes.
|
||||
* @returns {CodeUnit[]} A list of code units produced by the string literal.
|
||||
*/
|
||||
function parseStringLiteral(source) {
|
||||
const reader = new TextReader(source);
|
||||
const quote = reader.read();
|
||||
|
||||
reader.advance(1);
|
||||
const codeUnits = [];
|
||||
|
||||
for (;;) {
|
||||
const char = reader.read();
|
||||
|
||||
if (char === quote) {
|
||||
break;
|
||||
}
|
||||
if (char === "\\") {
|
||||
codeUnits.push(...mapEscapeSequenceOrLineContinuation(reader));
|
||||
} else {
|
||||
codeUnits.push(new CodeUnit(reader.pos, char));
|
||||
reader.advance(1);
|
||||
}
|
||||
}
|
||||
return codeUnits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a template token.
|
||||
* @param {string} source The template token to parse, including the delimiting sequences `` ` ``, `${` and `}`.
|
||||
* @returns {CodeUnit[]} A list of code units produced by the template token.
|
||||
*/
|
||||
function parseTemplateToken(source) {
|
||||
const reader = new TextReader(source);
|
||||
|
||||
reader.advance(1);
|
||||
const codeUnits = [];
|
||||
|
||||
for (;;) {
|
||||
const char = reader.read();
|
||||
|
||||
if (char === "`" || (char === "$" && reader.read(1) === "{")) {
|
||||
break;
|
||||
}
|
||||
if (char === "\\") {
|
||||
codeUnits.push(...mapEscapeSequenceOrLineContinuation(reader));
|
||||
} else {
|
||||
let unitSource;
|
||||
|
||||
if (char === "\r" && reader.read(1) === "\n") {
|
||||
unitSource = "\r\n";
|
||||
} else {
|
||||
unitSource = char;
|
||||
}
|
||||
codeUnits.push(new CodeUnit(reader.pos, unitSource));
|
||||
reader.advance(unitSource.length);
|
||||
}
|
||||
}
|
||||
return codeUnits;
|
||||
}
|
||||
|
||||
module.exports = { parseStringLiteral, parseTemplateToken };
|
||||
+80
-91
@@ -4,14 +4,6 @@
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Typedefs
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @import { SourceRange } from "@eslint/core";
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -28,98 +20,95 @@ const astUtils = require("./ast-utils");
|
||||
* replaced so that other fixes won't touch that region in the same pass.
|
||||
*/
|
||||
class FixTracker {
|
||||
/**
|
||||
* Create a new FixTracker.
|
||||
* @param {ruleFixer} fixer A ruleFixer instance.
|
||||
* @param {SourceCode} sourceCode A SourceCode object for the current code.
|
||||
*/
|
||||
constructor(fixer, sourceCode) {
|
||||
this.fixer = fixer;
|
||||
this.sourceCode = sourceCode;
|
||||
this.retainedRange = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given range as "retained", meaning that other fixes may not
|
||||
* may not modify this region in the same pass.
|
||||
* @param {SourceRange} range The range to retain.
|
||||
* @returns {FixTracker} The same RuleFixer, for chained calls.
|
||||
*/
|
||||
retainRange(range) {
|
||||
this.retainedRange = range;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Create a new FixTracker.
|
||||
* @param {ruleFixer} fixer A ruleFixer instance.
|
||||
* @param {SourceCode} sourceCode A SourceCode object for the current code.
|
||||
*/
|
||||
constructor(fixer, sourceCode) {
|
||||
this.fixer = fixer;
|
||||
this.sourceCode = sourceCode;
|
||||
this.retainedRange = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a node, find the function containing it (or the entire program) and
|
||||
* mark it as retained, meaning that other fixes may not modify it in this
|
||||
* pass. This is useful for avoiding conflicts in fixes that modify control
|
||||
* flow.
|
||||
* @param {ASTNode} node The node to use as a starting point.
|
||||
* @returns {FixTracker} The same RuleFixer, for chained calls.
|
||||
*/
|
||||
retainEnclosingFunction(node) {
|
||||
const functionNode = astUtils.getUpperFunction(node);
|
||||
/**
|
||||
* Mark the given range as "retained", meaning that other fixes may not
|
||||
* may not modify this region in the same pass.
|
||||
* @param {int[]} range The range to retain.
|
||||
* @returns {FixTracker} The same RuleFixer, for chained calls.
|
||||
*/
|
||||
retainRange(range) {
|
||||
this.retainedRange = range;
|
||||
return this;
|
||||
}
|
||||
|
||||
return this.retainRange(
|
||||
functionNode ? functionNode.range : this.sourceCode.ast.range,
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Given a node, find the function containing it (or the entire program) and
|
||||
* mark it as retained, meaning that other fixes may not modify it in this
|
||||
* pass. This is useful for avoiding conflicts in fixes that modify control
|
||||
* flow.
|
||||
* @param {ASTNode} node The node to use as a starting point.
|
||||
* @returns {FixTracker} The same RuleFixer, for chained calls.
|
||||
*/
|
||||
retainEnclosingFunction(node) {
|
||||
const functionNode = astUtils.getUpperFunction(node);
|
||||
|
||||
/**
|
||||
* Given a node or token, find the token before and afterward, and mark that
|
||||
* range as retained, meaning that other fixes may not modify it in this
|
||||
* pass. This is useful for avoiding conflicts in fixes that make a small
|
||||
* change to the code where the AST should not be changed.
|
||||
* @param {ASTNode|Token} nodeOrToken The node or token to use as a starting
|
||||
* point. The token to the left and right are use in the range.
|
||||
* @returns {FixTracker} The same RuleFixer, for chained calls.
|
||||
*/
|
||||
retainSurroundingTokens(nodeOrToken) {
|
||||
const tokenBefore =
|
||||
this.sourceCode.getTokenBefore(nodeOrToken) || nodeOrToken;
|
||||
const tokenAfter =
|
||||
this.sourceCode.getTokenAfter(nodeOrToken) || nodeOrToken;
|
||||
return this.retainRange(functionNode ? functionNode.range : this.sourceCode.ast.range);
|
||||
}
|
||||
|
||||
return this.retainRange([tokenBefore.range[0], tokenAfter.range[1]]);
|
||||
}
|
||||
/**
|
||||
* Given a node or token, find the token before and afterward, and mark that
|
||||
* range as retained, meaning that other fixes may not modify it in this
|
||||
* pass. This is useful for avoiding conflicts in fixes that make a small
|
||||
* change to the code where the AST should not be changed.
|
||||
* @param {ASTNode|Token} nodeOrToken The node or token to use as a starting
|
||||
* point. The token to the left and right are use in the range.
|
||||
* @returns {FixTracker} The same RuleFixer, for chained calls.
|
||||
*/
|
||||
retainSurroundingTokens(nodeOrToken) {
|
||||
const tokenBefore = this.sourceCode.getTokenBefore(nodeOrToken) || nodeOrToken;
|
||||
const tokenAfter = this.sourceCode.getTokenAfter(nodeOrToken) || nodeOrToken;
|
||||
|
||||
/**
|
||||
* Create a fix command that replaces the given range with the given text,
|
||||
* accounting for any retained ranges.
|
||||
* @param {SourceRange} range The range to remove in the fix.
|
||||
* @param {string} text The text to insert in place of the range.
|
||||
* @returns {Object} The fix command.
|
||||
*/
|
||||
replaceTextRange(range, text) {
|
||||
let actualRange;
|
||||
return this.retainRange([tokenBefore.range[0], tokenAfter.range[1]]);
|
||||
}
|
||||
|
||||
if (this.retainedRange) {
|
||||
actualRange = [
|
||||
Math.min(this.retainedRange[0], range[0]),
|
||||
Math.max(this.retainedRange[1], range[1]),
|
||||
];
|
||||
} else {
|
||||
actualRange = range;
|
||||
}
|
||||
/**
|
||||
* Create a fix command that replaces the given range with the given text,
|
||||
* accounting for any retained ranges.
|
||||
* @param {int[]} range The range to remove in the fix.
|
||||
* @param {string} text The text to insert in place of the range.
|
||||
* @returns {Object} The fix command.
|
||||
*/
|
||||
replaceTextRange(range, text) {
|
||||
let actualRange;
|
||||
|
||||
return this.fixer.replaceTextRange(
|
||||
actualRange,
|
||||
this.sourceCode.text.slice(actualRange[0], range[0]) +
|
||||
text +
|
||||
this.sourceCode.text.slice(range[1], actualRange[1]),
|
||||
);
|
||||
}
|
||||
if (this.retainedRange) {
|
||||
actualRange = [
|
||||
Math.min(this.retainedRange[0], range[0]),
|
||||
Math.max(this.retainedRange[1], range[1])
|
||||
];
|
||||
} else {
|
||||
actualRange = range;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fix command that removes the given node or token, accounting for
|
||||
* any retained ranges.
|
||||
* @param {ASTNode|Token} nodeOrToken The node or token to remove.
|
||||
* @returns {Object} The fix command.
|
||||
*/
|
||||
remove(nodeOrToken) {
|
||||
return this.replaceTextRange(nodeOrToken.range, "");
|
||||
}
|
||||
return this.fixer.replaceTextRange(
|
||||
actualRange,
|
||||
this.sourceCode.text.slice(actualRange[0], range[0]) +
|
||||
text +
|
||||
this.sourceCode.text.slice(range[1], actualRange[1])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fix command that removes the given node or token, accounting for
|
||||
* any retained ranges.
|
||||
* @param {ASTNode|Token} nodeOrToken The node or token to remove.
|
||||
* @returns {Object} The fix command.
|
||||
*/
|
||||
remove(nodeOrToken) {
|
||||
return this.replaceTextRange(nodeOrToken.range, "");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FixTracker;
|
||||
|
||||
+59
-59
@@ -5,63 +5,63 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = [
|
||||
"abstract",
|
||||
"boolean",
|
||||
"break",
|
||||
"byte",
|
||||
"case",
|
||||
"catch",
|
||||
"char",
|
||||
"class",
|
||||
"const",
|
||||
"continue",
|
||||
"debugger",
|
||||
"default",
|
||||
"delete",
|
||||
"do",
|
||||
"double",
|
||||
"else",
|
||||
"enum",
|
||||
"export",
|
||||
"extends",
|
||||
"false",
|
||||
"final",
|
||||
"finally",
|
||||
"float",
|
||||
"for",
|
||||
"function",
|
||||
"goto",
|
||||
"if",
|
||||
"implements",
|
||||
"import",
|
||||
"in",
|
||||
"instanceof",
|
||||
"int",
|
||||
"interface",
|
||||
"long",
|
||||
"native",
|
||||
"new",
|
||||
"null",
|
||||
"package",
|
||||
"private",
|
||||
"protected",
|
||||
"public",
|
||||
"return",
|
||||
"short",
|
||||
"static",
|
||||
"super",
|
||||
"switch",
|
||||
"synchronized",
|
||||
"this",
|
||||
"throw",
|
||||
"throws",
|
||||
"transient",
|
||||
"true",
|
||||
"try",
|
||||
"typeof",
|
||||
"var",
|
||||
"void",
|
||||
"volatile",
|
||||
"while",
|
||||
"with",
|
||||
"abstract",
|
||||
"boolean",
|
||||
"break",
|
||||
"byte",
|
||||
"case",
|
||||
"catch",
|
||||
"char",
|
||||
"class",
|
||||
"const",
|
||||
"continue",
|
||||
"debugger",
|
||||
"default",
|
||||
"delete",
|
||||
"do",
|
||||
"double",
|
||||
"else",
|
||||
"enum",
|
||||
"export",
|
||||
"extends",
|
||||
"false",
|
||||
"final",
|
||||
"finally",
|
||||
"float",
|
||||
"for",
|
||||
"function",
|
||||
"goto",
|
||||
"if",
|
||||
"implements",
|
||||
"import",
|
||||
"in",
|
||||
"instanceof",
|
||||
"int",
|
||||
"interface",
|
||||
"long",
|
||||
"native",
|
||||
"new",
|
||||
"null",
|
||||
"package",
|
||||
"private",
|
||||
"protected",
|
||||
"public",
|
||||
"return",
|
||||
"short",
|
||||
"static",
|
||||
"super",
|
||||
"switch",
|
||||
"synchronized",
|
||||
"this",
|
||||
"throw",
|
||||
"throws",
|
||||
"transient",
|
||||
"true",
|
||||
"try",
|
||||
"typeof",
|
||||
"var",
|
||||
"void",
|
||||
"volatile",
|
||||
"while",
|
||||
"with"
|
||||
];
|
||||
|
||||
+78
-81
@@ -6,7 +6,7 @@
|
||||
|
||||
const debug = require("debug")("eslint:rules");
|
||||
|
||||
/** @typedef {import("../../types").Rule.RuleModule} Rule */
|
||||
/** @typedef {import("./types").Rule} Rule */
|
||||
|
||||
/**
|
||||
* The `Map` object that loads each rule when it's accessed.
|
||||
@@ -19,100 +19,97 @@ const debug = require("debug")("eslint:rules");
|
||||
*
|
||||
* rules.get("semi"); // call `() => require("semi")` here.
|
||||
*
|
||||
* @extends {Map<string, Rule>}
|
||||
* @extends {Map<string, () => Rule>}
|
||||
*/
|
||||
class LazyLoadingRuleMap extends Map {
|
||||
/**
|
||||
* Initialize this map.
|
||||
* @param {Array<[string, function(): Rule]>} loaders The rule loaders.
|
||||
*/
|
||||
constructor(loaders) {
|
||||
let remaining = loaders.length;
|
||||
|
||||
super(
|
||||
debug.enabled
|
||||
? loaders.map(([ruleId, load]) => {
|
||||
let cache = null;
|
||||
/**
|
||||
* Initialize this map.
|
||||
* @param {Array<[string, function(): Rule]>} loaders The rule loaders.
|
||||
*/
|
||||
constructor(loaders) {
|
||||
let remaining = loaders.length;
|
||||
|
||||
return [
|
||||
ruleId,
|
||||
() => {
|
||||
if (!cache) {
|
||||
debug(
|
||||
"Loading rule %o (remaining=%d)",
|
||||
ruleId,
|
||||
--remaining,
|
||||
);
|
||||
cache = load();
|
||||
}
|
||||
return cache;
|
||||
},
|
||||
];
|
||||
})
|
||||
: loaders,
|
||||
);
|
||||
super(
|
||||
debug.enabled
|
||||
? loaders.map(([ruleId, load]) => {
|
||||
let cache = null;
|
||||
|
||||
// `super(...iterable)` uses `this.set()`, so disable it here.
|
||||
Object.defineProperty(LazyLoadingRuleMap.prototype, "set", {
|
||||
configurable: true,
|
||||
value: void 0,
|
||||
});
|
||||
}
|
||||
return [
|
||||
ruleId,
|
||||
() => {
|
||||
if (!cache) {
|
||||
debug("Loading rule %o (remaining=%d)", ruleId, --remaining);
|
||||
cache = load();
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
];
|
||||
})
|
||||
: loaders
|
||||
);
|
||||
|
||||
/**
|
||||
* Get a rule.
|
||||
* Each rule will be loaded on the first access.
|
||||
* @param {string} ruleId The rule ID to get.
|
||||
* @returns {Rule|undefined} The rule.
|
||||
*/
|
||||
get(ruleId) {
|
||||
const load = super.get(ruleId);
|
||||
// `super(...iterable)` uses `this.set()`, so disable it here.
|
||||
Object.defineProperty(LazyLoadingRuleMap.prototype, "set", {
|
||||
configurable: true,
|
||||
value: void 0
|
||||
});
|
||||
}
|
||||
|
||||
return load && load();
|
||||
}
|
||||
/**
|
||||
* Get a rule.
|
||||
* Each rule will be loaded on the first access.
|
||||
* @param {string} ruleId The rule ID to get.
|
||||
* @returns {Rule|undefined} The rule.
|
||||
*/
|
||||
get(ruleId) {
|
||||
const load = super.get(ruleId);
|
||||
|
||||
/**
|
||||
* Iterate rules.
|
||||
* @returns {IterableIterator<Rule>} Rules.
|
||||
*/
|
||||
*values() {
|
||||
for (const load of super.values()) {
|
||||
yield load();
|
||||
}
|
||||
}
|
||||
return load && load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate rules.
|
||||
* @returns {IterableIterator<[string, Rule]>} Rules.
|
||||
*/
|
||||
*entries() {
|
||||
for (const [ruleId, load] of super.entries()) {
|
||||
yield [ruleId, load()];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Iterate rules.
|
||||
* @returns {IterableIterator<Rule>} Rules.
|
||||
*/
|
||||
*values() {
|
||||
for (const load of super.values()) {
|
||||
yield load();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a function with each rule.
|
||||
* @param {Function} callbackFn The callback function.
|
||||
* @param {any} [thisArg] The object to pass to `this` of the callback function.
|
||||
* @returns {void}
|
||||
*/
|
||||
forEach(callbackFn, thisArg) {
|
||||
for (const [ruleId, load] of super.entries()) {
|
||||
callbackFn.call(thisArg, load(), ruleId, this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Iterate rules.
|
||||
* @returns {IterableIterator<[string, Rule]>} Rules.
|
||||
*/
|
||||
*entries() {
|
||||
for (const [ruleId, load] of super.entries()) {
|
||||
yield [ruleId, load()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a function with each rule.
|
||||
* @param {Function} callbackFn The callback function.
|
||||
* @param {any} [thisArg] The object to pass to `this` of the callback function.
|
||||
* @returns {void}
|
||||
*/
|
||||
forEach(callbackFn, thisArg) {
|
||||
for (const [ruleId, load] of super.entries()) {
|
||||
callbackFn.call(thisArg, load(), ruleId, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Forbid mutation.
|
||||
Object.defineProperties(LazyLoadingRuleMap.prototype, {
|
||||
clear: { configurable: true, value: void 0 },
|
||||
delete: { configurable: true, value: void 0 },
|
||||
[Symbol.iterator]: {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: LazyLoadingRuleMap.prototype.entries,
|
||||
},
|
||||
clear: { configurable: true, value: void 0 },
|
||||
delete: { configurable: true, value: void 0 },
|
||||
[Symbol.iterator]: {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: LazyLoadingRuleMap.prototype.entries
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = { LazyLoadingRuleMap };
|
||||
|
||||
+36
File diff suppressed because one or more lines are too long
+16
-32
@@ -8,51 +8,35 @@
|
||||
|
||||
const { RegExpValidator } = require("@eslint-community/regexpp");
|
||||
|
||||
const REGEXPP_LATEST_ECMA_VERSION = 2025;
|
||||
const REGEXPP_LATEST_ECMA_VERSION = 2024;
|
||||
|
||||
/**
|
||||
* Checks if the given regular expression pattern would be valid with the `u` flag.
|
||||
* @param {number} ecmaVersion ECMAScript version to parse in.
|
||||
* @param {string} pattern The regular expression pattern to verify.
|
||||
* @param {"u"|"v"} flag The type of Unicode flag
|
||||
* @returns {boolean} `true` if the pattern would be valid with the `u` flag.
|
||||
* `false` if the pattern would be invalid with the `u` flag or the configured
|
||||
* ecmaVersion doesn't support the `u` flag.
|
||||
*/
|
||||
function isValidWithUnicodeFlag(ecmaVersion, pattern, flag = "u") {
|
||||
if (flag === "u" && ecmaVersion <= 5) {
|
||||
// ecmaVersion <= 5 doesn't support the 'u' flag
|
||||
return false;
|
||||
}
|
||||
if (flag === "v" && ecmaVersion <= 2023) {
|
||||
return false;
|
||||
}
|
||||
function isValidWithUnicodeFlag(ecmaVersion, pattern) {
|
||||
if (ecmaVersion <= 5) { // ecmaVersion <= 5 doesn't support the 'u' flag
|
||||
return false;
|
||||
}
|
||||
|
||||
const validator = new RegExpValidator({
|
||||
ecmaVersion: Math.min(ecmaVersion, REGEXPP_LATEST_ECMA_VERSION),
|
||||
});
|
||||
const validator = new RegExpValidator({
|
||||
ecmaVersion: Math.min(ecmaVersion, REGEXPP_LATEST_ECMA_VERSION)
|
||||
});
|
||||
|
||||
try {
|
||||
validator.validatePattern(
|
||||
pattern,
|
||||
void 0,
|
||||
void 0,
|
||||
flag === "u"
|
||||
? {
|
||||
unicode: /* uFlag = */ true,
|
||||
}
|
||||
: {
|
||||
unicodeSets: true,
|
||||
},
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
validator.validatePattern(pattern, void 0, void 0, { unicode: /* uFlag = */ true });
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isValidWithUnicodeFlag,
|
||||
REGEXPP_LATEST_ECMA_VERSION,
|
||||
isValidWithUnicodeFlag,
|
||||
REGEXPP_LATEST_ECMA_VERSION
|
||||
};
|
||||
|
||||
+4
-9
@@ -3,14 +3,9 @@
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const isCombiningCharacter = require("./is-combining-character");
|
||||
const isEmojiModifier = require("./is-emoji-modifier");
|
||||
const isRegionalIndicatorSymbol = require("./is-regional-indicator-symbol");
|
||||
const isSurrogatePair = require("./is-surrogate-pair");
|
||||
|
||||
module.exports = {
|
||||
isCombiningCharacter,
|
||||
isEmojiModifier,
|
||||
isRegionalIndicatorSymbol,
|
||||
isSurrogatePair,
|
||||
isCombiningCharacter: require("./is-combining-character"),
|
||||
isEmojiModifier: require("./is-emoji-modifier"),
|
||||
isRegionalIndicatorSymbol: require("./is-regional-indicator-symbol"),
|
||||
isSurrogatePair: require("./is-surrogate-pair")
|
||||
};
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
* @returns {boolean} `true` if the character belongs to the category, any of `Mc`, `Me`, and `Mn`.
|
||||
*/
|
||||
module.exports = function isCombiningCharacter(codePoint) {
|
||||
return /^[\p{Mc}\p{Me}\p{Mn}]$/u.test(String.fromCodePoint(codePoint));
|
||||
return /^[\p{Mc}\p{Me}\p{Mn}]$/u.test(String.fromCodePoint(codePoint));
|
||||
};
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
* @returns {boolean} `true` if the character is an emoji modifier.
|
||||
*/
|
||||
module.exports = function isEmojiModifier(code) {
|
||||
return code >= 0x1f3fb && code <= 0x1f3ff;
|
||||
return code >= 0x1F3FB && code <= 0x1F3FF;
|
||||
};
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -9,5 +9,5 @@
|
||||
* @returns {boolean} `true` if the character is a regional indicator symbol.
|
||||
*/
|
||||
module.exports = function isRegionalIndicatorSymbol(code) {
|
||||
return code >= 0x1f1e6 && code <= 0x1f1ff;
|
||||
return code >= 0x1F1E6 && code <= 0x1F1FF;
|
||||
};
|
||||
|
||||
+1
-1
@@ -10,5 +10,5 @@
|
||||
* @returns {boolean} `true` if the character pair is a surrogate pair.
|
||||
*/
|
||||
module.exports = function isSurrogatePair(lead, tail) {
|
||||
return lead >= 0xd800 && lead < 0xdc00 && tail >= 0xdc00 && tail < 0xe000;
|
||||
return lead >= 0xD800 && lead < 0xDC00 && tail >= 0xDC00 && tail < 0xE000;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user