first
This commit is contained in:
BIN
node_modules/@eslint-community/.DS_Store
generated
vendored
Normal file
BIN
node_modules/@eslint-community/.DS_Store
generated
vendored
Normal file
Binary file not shown.
21
node_modules/@eslint-community/eslint-utils/LICENSE
generated
vendored
Normal file
21
node_modules/@eslint-community/eslint-utils/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Toru Nagashima
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
37
node_modules/@eslint-community/eslint-utils/README.md
generated
vendored
Normal file
37
node_modules/@eslint-community/eslint-utils/README.md
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# @eslint-community/eslint-utils
|
||||
|
||||
[](https://www.npmjs.com/package/@eslint-community/eslint-utils)
|
||||
[](http://www.npmtrends.com/@eslint-community/eslint-utils)
|
||||
[](https://github.com/eslint-community/eslint-utils/actions)
|
||||
[](https://codecov.io/gh/eslint-community/eslint-utils)
|
||||
|
||||
## 🏁 Goal
|
||||
|
||||
This package provides utility functions and classes for make ESLint custom rules.
|
||||
|
||||
For examples:
|
||||
|
||||
- [`getStaticValue`](https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getstaticvalue) evaluates static value on AST.
|
||||
- [`ReferenceTracker`](https://eslint-community.github.io/eslint-utils/api/scope-utils.html#referencetracker-class) checks the members of modules/globals as handling assignments and destructuring.
|
||||
|
||||
## 📖 Usage
|
||||
|
||||
See [documentation](https://eslint-community.github.io/eslint-utils).
|
||||
|
||||
## 📰 Changelog
|
||||
|
||||
See [releases](https://github.com/eslint-community/eslint-utils/releases).
|
||||
|
||||
## ❤️ Contributing
|
||||
|
||||
Welcome contributing!
|
||||
|
||||
Please use GitHub's Issues/PRs.
|
||||
|
||||
### Development Tools
|
||||
|
||||
- `npm test` runs tests and measures coverage.
|
||||
- `npm run clean` removes the coverage result of `npm test` command.
|
||||
- `npm run coverage` shows the coverage result of the last `npm test` command.
|
||||
- `npm run lint` runs ESLint.
|
||||
- `npm run watch` runs tests on each file change.
|
||||
2068
node_modules/@eslint-community/eslint-utils/index.js
generated
vendored
Normal file
2068
node_modules/@eslint-community/eslint-utils/index.js
generated
vendored
Normal file
@@ -0,0 +1,2068 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var eslintVisitorKeys = require('eslint-visitor-keys');
|
||||
|
||||
/**
|
||||
* Get the innermost scope which contains a given location.
|
||||
* @param {Scope} initialScope The initial scope to search.
|
||||
* @param {Node} node The location to search.
|
||||
* @returns {Scope} The innermost scope.
|
||||
*/
|
||||
function getInnermostScope(initialScope, node) {
|
||||
const location = node.range[0];
|
||||
|
||||
let scope = initialScope;
|
||||
let found = false;
|
||||
do {
|
||||
found = false;
|
||||
for (const childScope of scope.childScopes) {
|
||||
const range = childScope.block.range;
|
||||
|
||||
if (range[0] <= location && location < range[1]) {
|
||||
scope = childScope;
|
||||
found = true;
|
||||
break
|
||||
}
|
||||
}
|
||||
} while (found)
|
||||
|
||||
return scope
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the variable of a given name.
|
||||
* @param {Scope} initialScope The scope to start finding.
|
||||
* @param {string|Node} nameOrNode The variable name to find. If this is a Node object then it should be an Identifier node.
|
||||
* @returns {Variable|null} The found variable or null.
|
||||
*/
|
||||
function findVariable(initialScope, nameOrNode) {
|
||||
let name = "";
|
||||
let scope = initialScope;
|
||||
|
||||
if (typeof nameOrNode === "string") {
|
||||
name = nameOrNode;
|
||||
} else {
|
||||
name = nameOrNode.name;
|
||||
scope = getInnermostScope(scope, nameOrNode);
|
||||
}
|
||||
|
||||
while (scope != null) {
|
||||
const variable = scope.set.get(name);
|
||||
if (variable != null) {
|
||||
return variable
|
||||
}
|
||||
scope = scope.upper;
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate the result of `this` calling.
|
||||
* @param {Token} token The token to check.
|
||||
* @returns {boolean} `true` if the result of `this(token)` is `false`.
|
||||
*/
|
||||
function negate0(token) {
|
||||
return !this(token) //eslint-disable-line no-invalid-this
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the negate function of the given function.
|
||||
* @param {function(Token):boolean} f - The function to negate.
|
||||
* @returns {function(Token):boolean} Negated function.
|
||||
*/
|
||||
function negate(f) {
|
||||
return negate0.bind(f)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a PunctuatorToken with the given value
|
||||
* @param {Token} token - The token to check.
|
||||
* @param {string} value - The value to check.
|
||||
* @returns {boolean} `true` if the token is a PunctuatorToken with the given value.
|
||||
*/
|
||||
function isPunctuatorTokenWithValue(token, value) {
|
||||
return token.type === "Punctuator" && token.value === value
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is an arrow token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is an arrow token.
|
||||
*/
|
||||
function isArrowToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "=>")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a comma token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a comma token.
|
||||
*/
|
||||
function isCommaToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, ",")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a semicolon token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a semicolon token.
|
||||
*/
|
||||
function isSemicolonToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, ";")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a colon token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a colon token.
|
||||
*/
|
||||
function isColonToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, ":")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is an opening parenthesis token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is an opening parenthesis token.
|
||||
*/
|
||||
function isOpeningParenToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "(")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a closing parenthesis token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a closing parenthesis token.
|
||||
*/
|
||||
function isClosingParenToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, ")")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is an opening square bracket token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is an opening square bracket token.
|
||||
*/
|
||||
function isOpeningBracketToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "[")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a closing square bracket token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a closing square bracket token.
|
||||
*/
|
||||
function isClosingBracketToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "]")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is an opening brace token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is an opening brace token.
|
||||
*/
|
||||
function isOpeningBraceToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "{")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a closing brace token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a closing brace token.
|
||||
*/
|
||||
function isClosingBraceToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "}")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a comment token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a comment token.
|
||||
*/
|
||||
function isCommentToken(token) {
|
||||
return ["Block", "Line", "Shebang"].includes(token.type)
|
||||
}
|
||||
|
||||
const isNotArrowToken = negate(isArrowToken);
|
||||
const isNotCommaToken = negate(isCommaToken);
|
||||
const isNotSemicolonToken = negate(isSemicolonToken);
|
||||
const isNotColonToken = negate(isColonToken);
|
||||
const isNotOpeningParenToken = negate(isOpeningParenToken);
|
||||
const isNotClosingParenToken = negate(isClosingParenToken);
|
||||
const isNotOpeningBracketToken = negate(isOpeningBracketToken);
|
||||
const isNotClosingBracketToken = negate(isClosingBracketToken);
|
||||
const isNotOpeningBraceToken = negate(isOpeningBraceToken);
|
||||
const isNotClosingBraceToken = negate(isClosingBraceToken);
|
||||
const isNotCommentToken = negate(isCommentToken);
|
||||
|
||||
/**
|
||||
* Get the `(` token of the given function node.
|
||||
* @param {Node} node - The function node to get.
|
||||
* @param {SourceCode} sourceCode - The source code object to get tokens.
|
||||
* @returns {Token} `(` token.
|
||||
*/
|
||||
function getOpeningParenOfParams(node, sourceCode) {
|
||||
return node.id
|
||||
? sourceCode.getTokenAfter(node.id, isOpeningParenToken)
|
||||
: sourceCode.getFirstToken(node, isOpeningParenToken)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the location of the given function node for reporting.
|
||||
* @param {Node} node - The function node to get.
|
||||
* @param {SourceCode} sourceCode - The source code object to get tokens.
|
||||
* @returns {string} The location of the function node for reporting.
|
||||
*/
|
||||
function getFunctionHeadLocation(node, sourceCode) {
|
||||
const parent = node.parent;
|
||||
let start = null;
|
||||
let end = null;
|
||||
|
||||
if (node.type === "ArrowFunctionExpression") {
|
||||
const arrowToken = sourceCode.getTokenBefore(node.body, isArrowToken);
|
||||
|
||||
start = arrowToken.loc.start;
|
||||
end = arrowToken.loc.end;
|
||||
} else if (
|
||||
parent.type === "Property" ||
|
||||
parent.type === "MethodDefinition" ||
|
||||
parent.type === "PropertyDefinition"
|
||||
) {
|
||||
start = parent.loc.start;
|
||||
end = getOpeningParenOfParams(node, sourceCode).loc.start;
|
||||
} else {
|
||||
start = node.loc.start;
|
||||
end = getOpeningParenOfParams(node, sourceCode).loc.start;
|
||||
}
|
||||
|
||||
return {
|
||||
start: { ...start },
|
||||
end: { ...end },
|
||||
}
|
||||
}
|
||||
|
||||
/* globals globalThis, global, self, window */
|
||||
|
||||
const globalObject =
|
||||
typeof globalThis !== "undefined"
|
||||
? globalThis
|
||||
: typeof self !== "undefined"
|
||||
? self
|
||||
: typeof window !== "undefined"
|
||||
? window
|
||||
: typeof global !== "undefined"
|
||||
? global
|
||||
: {};
|
||||
|
||||
const builtinNames = Object.freeze(
|
||||
new Set([
|
||||
"Array",
|
||||
"ArrayBuffer",
|
||||
"BigInt",
|
||||
"BigInt64Array",
|
||||
"BigUint64Array",
|
||||
"Boolean",
|
||||
"DataView",
|
||||
"Date",
|
||||
"decodeURI",
|
||||
"decodeURIComponent",
|
||||
"encodeURI",
|
||||
"encodeURIComponent",
|
||||
"escape",
|
||||
"Float32Array",
|
||||
"Float64Array",
|
||||
"Function",
|
||||
"Infinity",
|
||||
"Int16Array",
|
||||
"Int32Array",
|
||||
"Int8Array",
|
||||
"isFinite",
|
||||
"isNaN",
|
||||
"isPrototypeOf",
|
||||
"JSON",
|
||||
"Map",
|
||||
"Math",
|
||||
"NaN",
|
||||
"Number",
|
||||
"Object",
|
||||
"parseFloat",
|
||||
"parseInt",
|
||||
"Promise",
|
||||
"Proxy",
|
||||
"Reflect",
|
||||
"RegExp",
|
||||
"Set",
|
||||
"String",
|
||||
"Symbol",
|
||||
"Uint16Array",
|
||||
"Uint32Array",
|
||||
"Uint8Array",
|
||||
"Uint8ClampedArray",
|
||||
"undefined",
|
||||
"unescape",
|
||||
"WeakMap",
|
||||
"WeakSet",
|
||||
]),
|
||||
);
|
||||
const callAllowed = new Set(
|
||||
[
|
||||
Array.isArray,
|
||||
Array.of,
|
||||
Array.prototype.at,
|
||||
Array.prototype.concat,
|
||||
Array.prototype.entries,
|
||||
Array.prototype.every,
|
||||
Array.prototype.filter,
|
||||
Array.prototype.find,
|
||||
Array.prototype.findIndex,
|
||||
Array.prototype.flat,
|
||||
Array.prototype.includes,
|
||||
Array.prototype.indexOf,
|
||||
Array.prototype.join,
|
||||
Array.prototype.keys,
|
||||
Array.prototype.lastIndexOf,
|
||||
Array.prototype.slice,
|
||||
Array.prototype.some,
|
||||
Array.prototype.toString,
|
||||
Array.prototype.values,
|
||||
typeof BigInt === "function" ? BigInt : undefined,
|
||||
Boolean,
|
||||
Date,
|
||||
Date.parse,
|
||||
decodeURI,
|
||||
decodeURIComponent,
|
||||
encodeURI,
|
||||
encodeURIComponent,
|
||||
escape,
|
||||
isFinite,
|
||||
isNaN,
|
||||
isPrototypeOf,
|
||||
Map,
|
||||
Map.prototype.entries,
|
||||
Map.prototype.get,
|
||||
Map.prototype.has,
|
||||
Map.prototype.keys,
|
||||
Map.prototype.values,
|
||||
...Object.getOwnPropertyNames(Math)
|
||||
.filter((k) => k !== "random")
|
||||
.map((k) => Math[k])
|
||||
.filter((f) => typeof f === "function"),
|
||||
Number,
|
||||
Number.isFinite,
|
||||
Number.isNaN,
|
||||
Number.parseFloat,
|
||||
Number.parseInt,
|
||||
Number.prototype.toExponential,
|
||||
Number.prototype.toFixed,
|
||||
Number.prototype.toPrecision,
|
||||
Number.prototype.toString,
|
||||
Object,
|
||||
Object.entries,
|
||||
Object.is,
|
||||
Object.isExtensible,
|
||||
Object.isFrozen,
|
||||
Object.isSealed,
|
||||
Object.keys,
|
||||
Object.values,
|
||||
parseFloat,
|
||||
parseInt,
|
||||
RegExp,
|
||||
Set,
|
||||
Set.prototype.entries,
|
||||
Set.prototype.has,
|
||||
Set.prototype.keys,
|
||||
Set.prototype.values,
|
||||
String,
|
||||
String.fromCharCode,
|
||||
String.fromCodePoint,
|
||||
String.raw,
|
||||
String.prototype.at,
|
||||
String.prototype.charAt,
|
||||
String.prototype.charCodeAt,
|
||||
String.prototype.codePointAt,
|
||||
String.prototype.concat,
|
||||
String.prototype.endsWith,
|
||||
String.prototype.includes,
|
||||
String.prototype.indexOf,
|
||||
String.prototype.lastIndexOf,
|
||||
String.prototype.normalize,
|
||||
String.prototype.padEnd,
|
||||
String.prototype.padStart,
|
||||
String.prototype.slice,
|
||||
String.prototype.startsWith,
|
||||
String.prototype.substr,
|
||||
String.prototype.substring,
|
||||
String.prototype.toLowerCase,
|
||||
String.prototype.toString,
|
||||
String.prototype.toUpperCase,
|
||||
String.prototype.trim,
|
||||
String.prototype.trimEnd,
|
||||
String.prototype.trimLeft,
|
||||
String.prototype.trimRight,
|
||||
String.prototype.trimStart,
|
||||
Symbol.for,
|
||||
Symbol.keyFor,
|
||||
unescape,
|
||||
].filter((f) => typeof f === "function"),
|
||||
);
|
||||
const callPassThrough = new Set([
|
||||
Object.freeze,
|
||||
Object.preventExtensions,
|
||||
Object.seal,
|
||||
]);
|
||||
|
||||
/** @type {ReadonlyArray<readonly [Function, ReadonlySet<string>]>} */
|
||||
const getterAllowed = [
|
||||
[Map, new Set(["size"])],
|
||||
[
|
||||
RegExp,
|
||||
new Set([
|
||||
"dotAll",
|
||||
"flags",
|
||||
"global",
|
||||
"hasIndices",
|
||||
"ignoreCase",
|
||||
"multiline",
|
||||
"source",
|
||||
"sticky",
|
||||
"unicode",
|
||||
]),
|
||||
],
|
||||
[Set, new Set(["size"])],
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the property descriptor.
|
||||
* @param {object} object The object to get.
|
||||
* @param {string|number|symbol} name The property name to get.
|
||||
*/
|
||||
function getPropertyDescriptor(object, name) {
|
||||
let x = object;
|
||||
while ((typeof x === "object" || typeof x === "function") && x !== null) {
|
||||
const d = Object.getOwnPropertyDescriptor(x, name);
|
||||
if (d) {
|
||||
return d
|
||||
}
|
||||
x = Object.getPrototypeOf(x);
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a property is getter or not.
|
||||
* @param {object} object The object to check.
|
||||
* @param {string|number|symbol} name The property name to check.
|
||||
*/
|
||||
function isGetter(object, name) {
|
||||
const d = getPropertyDescriptor(object, name);
|
||||
return d != null && d.get != null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element values of a given node list.
|
||||
* @param {Node[]} nodeList The node list to get values.
|
||||
* @param {Scope|undefined} initialScope The initial scope to find variables.
|
||||
* @returns {any[]|null} The value list if all nodes are constant. Otherwise, null.
|
||||
*/
|
||||
function getElementValues(nodeList, initialScope) {
|
||||
const valueList = [];
|
||||
|
||||
for (let i = 0; i < nodeList.length; ++i) {
|
||||
const elementNode = nodeList[i];
|
||||
|
||||
if (elementNode == null) {
|
||||
valueList.length = i + 1;
|
||||
} else if (elementNode.type === "SpreadElement") {
|
||||
const argument = getStaticValueR(elementNode.argument, initialScope);
|
||||
if (argument == null) {
|
||||
return null
|
||||
}
|
||||
valueList.push(...argument.value);
|
||||
} else {
|
||||
const element = getStaticValueR(elementNode, initialScope);
|
||||
if (element == null) {
|
||||
return null
|
||||
}
|
||||
valueList.push(element.value);
|
||||
}
|
||||
}
|
||||
|
||||
return valueList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given variable is never written to after initialization.
|
||||
* @param {import("eslint").Scope.Variable} variable
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isEffectivelyConst(variable) {
|
||||
const refs = variable.references;
|
||||
|
||||
const inits = refs.filter((r) => r.init).length;
|
||||
const reads = refs.filter((r) => r.isReadOnly()).length;
|
||||
if (inits === 1 && reads + inits === refs.length) {
|
||||
// there is only one init and all other references only read
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const operations = Object.freeze({
|
||||
ArrayExpression(node, initialScope) {
|
||||
const elements = getElementValues(node.elements, initialScope);
|
||||
return elements != null ? { value: elements } : null
|
||||
},
|
||||
|
||||
AssignmentExpression(node, initialScope) {
|
||||
if (node.operator === "=") {
|
||||
return getStaticValueR(node.right, initialScope)
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
//eslint-disable-next-line complexity
|
||||
BinaryExpression(node, initialScope) {
|
||||
if (node.operator === "in" || node.operator === "instanceof") {
|
||||
// Not supported.
|
||||
return null
|
||||
}
|
||||
|
||||
const left = getStaticValueR(node.left, initialScope);
|
||||
const right = getStaticValueR(node.right, initialScope);
|
||||
if (left != null && right != null) {
|
||||
switch (node.operator) {
|
||||
case "==":
|
||||
return { value: left.value == right.value } //eslint-disable-line eqeqeq
|
||||
case "!=":
|
||||
return { value: left.value != right.value } //eslint-disable-line eqeqeq
|
||||
case "===":
|
||||
return { value: left.value === right.value }
|
||||
case "!==":
|
||||
return { value: left.value !== right.value }
|
||||
case "<":
|
||||
return { value: left.value < right.value }
|
||||
case "<=":
|
||||
return { value: left.value <= right.value }
|
||||
case ">":
|
||||
return { value: left.value > right.value }
|
||||
case ">=":
|
||||
return { value: left.value >= right.value }
|
||||
case "<<":
|
||||
return { value: left.value << right.value }
|
||||
case ">>":
|
||||
return { value: left.value >> right.value }
|
||||
case ">>>":
|
||||
return { value: left.value >>> right.value }
|
||||
case "+":
|
||||
return { value: left.value + right.value }
|
||||
case "-":
|
||||
return { value: left.value - right.value }
|
||||
case "*":
|
||||
return { value: left.value * right.value }
|
||||
case "/":
|
||||
return { value: left.value / right.value }
|
||||
case "%":
|
||||
return { value: left.value % right.value }
|
||||
case "**":
|
||||
return { value: left.value ** right.value }
|
||||
case "|":
|
||||
return { value: left.value | right.value }
|
||||
case "^":
|
||||
return { value: left.value ^ right.value }
|
||||
case "&":
|
||||
return { value: left.value & right.value }
|
||||
|
||||
// no default
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
CallExpression(node, initialScope) {
|
||||
const calleeNode = node.callee;
|
||||
const args = getElementValues(node.arguments, initialScope);
|
||||
|
||||
if (args != null) {
|
||||
if (calleeNode.type === "MemberExpression") {
|
||||
if (calleeNode.property.type === "PrivateIdentifier") {
|
||||
return null
|
||||
}
|
||||
const object = getStaticValueR(calleeNode.object, initialScope);
|
||||
if (object != null) {
|
||||
if (
|
||||
object.value == null &&
|
||||
(object.optional || node.optional)
|
||||
) {
|
||||
return { value: undefined, optional: true }
|
||||
}
|
||||
const property = getStaticPropertyNameValue(
|
||||
calleeNode,
|
||||
initialScope,
|
||||
);
|
||||
|
||||
if (property != null) {
|
||||
const receiver = object.value;
|
||||
const methodName = property.value;
|
||||
if (callAllowed.has(receiver[methodName])) {
|
||||
return { value: receiver[methodName](...args) }
|
||||
}
|
||||
if (callPassThrough.has(receiver[methodName])) {
|
||||
return { value: args[0] }
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const callee = getStaticValueR(calleeNode, initialScope);
|
||||
if (callee != null) {
|
||||
if (callee.value == null && node.optional) {
|
||||
return { value: undefined, optional: true }
|
||||
}
|
||||
const func = callee.value;
|
||||
if (callAllowed.has(func)) {
|
||||
return { value: func(...args) }
|
||||
}
|
||||
if (callPassThrough.has(func)) {
|
||||
return { value: args[0] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
ConditionalExpression(node, initialScope) {
|
||||
const test = getStaticValueR(node.test, initialScope);
|
||||
if (test != null) {
|
||||
return test.value
|
||||
? getStaticValueR(node.consequent, initialScope)
|
||||
: getStaticValueR(node.alternate, initialScope)
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
ExpressionStatement(node, initialScope) {
|
||||
return getStaticValueR(node.expression, initialScope)
|
||||
},
|
||||
|
||||
Identifier(node, initialScope) {
|
||||
if (initialScope != null) {
|
||||
const variable = findVariable(initialScope, node);
|
||||
|
||||
// Built-in globals.
|
||||
if (
|
||||
variable != null &&
|
||||
variable.defs.length === 0 &&
|
||||
builtinNames.has(variable.name) &&
|
||||
variable.name in globalObject
|
||||
) {
|
||||
return { value: globalObject[variable.name] }
|
||||
}
|
||||
|
||||
// Constants.
|
||||
if (variable != null && variable.defs.length === 1) {
|
||||
const def = variable.defs[0];
|
||||
if (
|
||||
def.parent &&
|
||||
def.type === "Variable" &&
|
||||
(def.parent.kind === "const" ||
|
||||
isEffectivelyConst(variable)) &&
|
||||
// TODO(mysticatea): don't support destructuring here.
|
||||
def.node.id.type === "Identifier"
|
||||
) {
|
||||
return getStaticValueR(def.node.init, initialScope)
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
Literal(node) {
|
||||
//istanbul ignore if : this is implementation-specific behavior.
|
||||
if ((node.regex != null || node.bigint != null) && node.value == null) {
|
||||
// It was a RegExp/BigInt literal, but Node.js didn't support it.
|
||||
return null
|
||||
}
|
||||
return { value: node.value }
|
||||
},
|
||||
|
||||
LogicalExpression(node, initialScope) {
|
||||
const left = getStaticValueR(node.left, initialScope);
|
||||
if (left != null) {
|
||||
if (
|
||||
(node.operator === "||" && Boolean(left.value) === true) ||
|
||||
(node.operator === "&&" && Boolean(left.value) === false) ||
|
||||
(node.operator === "??" && left.value != null)
|
||||
) {
|
||||
return left
|
||||
}
|
||||
|
||||
const right = getStaticValueR(node.right, initialScope);
|
||||
if (right != null) {
|
||||
return right
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
MemberExpression(node, initialScope) {
|
||||
if (node.property.type === "PrivateIdentifier") {
|
||||
return null
|
||||
}
|
||||
const object = getStaticValueR(node.object, initialScope);
|
||||
if (object != null) {
|
||||
if (object.value == null && (object.optional || node.optional)) {
|
||||
return { value: undefined, optional: true }
|
||||
}
|
||||
const property = getStaticPropertyNameValue(node, initialScope);
|
||||
|
||||
if (property != null) {
|
||||
if (!isGetter(object.value, property.value)) {
|
||||
return { value: object.value[property.value] }
|
||||
}
|
||||
|
||||
for (const [classFn, allowed] of getterAllowed) {
|
||||
if (
|
||||
object.value instanceof classFn &&
|
||||
allowed.has(property.value)
|
||||
) {
|
||||
return { value: object.value[property.value] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
ChainExpression(node, initialScope) {
|
||||
const expression = getStaticValueR(node.expression, initialScope);
|
||||
if (expression != null) {
|
||||
return { value: expression.value }
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
NewExpression(node, initialScope) {
|
||||
const callee = getStaticValueR(node.callee, initialScope);
|
||||
const args = getElementValues(node.arguments, initialScope);
|
||||
|
||||
if (callee != null && args != null) {
|
||||
const Func = callee.value;
|
||||
if (callAllowed.has(Func)) {
|
||||
return { value: new Func(...args) }
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
ObjectExpression(node, initialScope) {
|
||||
const object = {};
|
||||
|
||||
for (const propertyNode of node.properties) {
|
||||
if (propertyNode.type === "Property") {
|
||||
if (propertyNode.kind !== "init") {
|
||||
return null
|
||||
}
|
||||
const key = getStaticPropertyNameValue(
|
||||
propertyNode,
|
||||
initialScope,
|
||||
);
|
||||
const value = getStaticValueR(propertyNode.value, initialScope);
|
||||
if (key == null || value == null) {
|
||||
return null
|
||||
}
|
||||
object[key.value] = value.value;
|
||||
} else if (
|
||||
propertyNode.type === "SpreadElement" ||
|
||||
propertyNode.type === "ExperimentalSpreadProperty"
|
||||
) {
|
||||
const argument = getStaticValueR(
|
||||
propertyNode.argument,
|
||||
initialScope,
|
||||
);
|
||||
if (argument == null) {
|
||||
return null
|
||||
}
|
||||
Object.assign(object, argument.value);
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
return { value: object }
|
||||
},
|
||||
|
||||
SequenceExpression(node, initialScope) {
|
||||
const last = node.expressions[node.expressions.length - 1];
|
||||
return getStaticValueR(last, initialScope)
|
||||
},
|
||||
|
||||
TaggedTemplateExpression(node, initialScope) {
|
||||
const tag = getStaticValueR(node.tag, initialScope);
|
||||
const expressions = getElementValues(
|
||||
node.quasi.expressions,
|
||||
initialScope,
|
||||
);
|
||||
|
||||
if (tag != null && expressions != null) {
|
||||
const func = tag.value;
|
||||
const strings = node.quasi.quasis.map((q) => q.value.cooked);
|
||||
strings.raw = node.quasi.quasis.map((q) => q.value.raw);
|
||||
|
||||
if (func === String.raw) {
|
||||
return { value: func(strings, ...expressions) }
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
TemplateLiteral(node, initialScope) {
|
||||
const expressions = getElementValues(node.expressions, initialScope);
|
||||
if (expressions != null) {
|
||||
let value = node.quasis[0].value.cooked;
|
||||
for (let i = 0; i < expressions.length; ++i) {
|
||||
value += expressions[i];
|
||||
value += node.quasis[i + 1].value.cooked;
|
||||
}
|
||||
return { value }
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
UnaryExpression(node, initialScope) {
|
||||
if (node.operator === "delete") {
|
||||
// Not supported.
|
||||
return null
|
||||
}
|
||||
if (node.operator === "void") {
|
||||
return { value: undefined }
|
||||
}
|
||||
|
||||
const arg = getStaticValueR(node.argument, initialScope);
|
||||
if (arg != null) {
|
||||
switch (node.operator) {
|
||||
case "-":
|
||||
return { value: -arg.value }
|
||||
case "+":
|
||||
return { value: +arg.value } //eslint-disable-line no-implicit-coercion
|
||||
case "!":
|
||||
return { value: !arg.value }
|
||||
case "~":
|
||||
return { value: ~arg.value }
|
||||
case "typeof":
|
||||
return { value: typeof arg.value }
|
||||
|
||||
// no default
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the value of a given node if it's a static value.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {Scope|undefined} initialScope The scope to start finding variable.
|
||||
* @returns {{value:any}|{value:undefined,optional?:true}|null} The static value of the node, or `null`.
|
||||
*/
|
||||
function getStaticValueR(node, initialScope) {
|
||||
if (node != null && Object.hasOwnProperty.call(operations, node.type)) {
|
||||
return operations[node.type](node, initialScope)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the static value of property name from a MemberExpression node or a Property node.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {Scope} [initialScope] The scope to start finding variable. Optional. If the node is a computed property node and this scope was given, this checks the computed property name by the `getStringIfConstant` function with the scope, and returns the value of it.
|
||||
* @returns {{value:any}|{value:undefined,optional?:true}|null} The static value of the property name of the node, or `null`.
|
||||
*/
|
||||
function getStaticPropertyNameValue(node, initialScope) {
|
||||
const nameNode = node.type === "Property" ? node.key : node.property;
|
||||
|
||||
if (node.computed) {
|
||||
return getStaticValueR(nameNode, initialScope)
|
||||
}
|
||||
|
||||
if (nameNode.type === "Identifier") {
|
||||
return { value: nameNode.name }
|
||||
}
|
||||
|
||||
if (nameNode.type === "Literal") {
|
||||
if (nameNode.bigint) {
|
||||
return { value: nameNode.bigint }
|
||||
}
|
||||
return { value: String(nameNode.value) }
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a given node if it's a static value.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {Scope} [initialScope] The scope to start finding variable. Optional. If this scope was given, this tries to resolve identifier references which are in the given node as much as possible.
|
||||
* @returns {{value:any}|{value:undefined,optional?:true}|null} The static value of the node, or `null`.
|
||||
*/
|
||||
function getStaticValue(node, initialScope = null) {
|
||||
try {
|
||||
return getStaticValueR(node, initialScope)
|
||||
} catch (_error) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a given node if it's a literal or a template literal.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {Scope} [initialScope] The scope to start finding variable. Optional. If the node is an Identifier node and this scope was given, this checks the variable of the identifier, and returns the value of it if the variable is a constant.
|
||||
* @returns {string|null} The value of the node, or `null`.
|
||||
*/
|
||||
function getStringIfConstant(node, initialScope = null) {
|
||||
// Handle the literals that the platform doesn't support natively.
|
||||
if (node && node.type === "Literal" && node.value === null) {
|
||||
if (node.regex) {
|
||||
return `/${node.regex.pattern}/${node.regex.flags}`
|
||||
}
|
||||
if (node.bigint) {
|
||||
return node.bigint
|
||||
}
|
||||
}
|
||||
|
||||
const evaluated = getStaticValue(node, initialScope);
|
||||
return evaluated && String(evaluated.value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property name from a MemberExpression node or a Property node.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {Scope} [initialScope] The scope to start finding variable. Optional. If the node is a computed property node and this scope was given, this checks the computed property name by the `getStringIfConstant` function with the scope, and returns the value of it.
|
||||
* @returns {string|null} The property name of the node.
|
||||
*/
|
||||
function getPropertyName(node, initialScope) {
|
||||
switch (node.type) {
|
||||
case "MemberExpression":
|
||||
if (node.computed) {
|
||||
return getStringIfConstant(node.property, initialScope)
|
||||
}
|
||||
if (node.property.type === "PrivateIdentifier") {
|
||||
return null
|
||||
}
|
||||
return node.property.name
|
||||
|
||||
case "Property":
|
||||
case "MethodDefinition":
|
||||
case "PropertyDefinition":
|
||||
if (node.computed) {
|
||||
return getStringIfConstant(node.key, initialScope)
|
||||
}
|
||||
if (node.key.type === "Literal") {
|
||||
return String(node.key.value)
|
||||
}
|
||||
if (node.key.type === "PrivateIdentifier") {
|
||||
return null
|
||||
}
|
||||
return node.key.name
|
||||
|
||||
// no default
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name and kind of the given function node.
|
||||
* @param {ASTNode} node - The function node to get.
|
||||
* @param {SourceCode} [sourceCode] The source code object to get the code of computed property keys.
|
||||
* @returns {string} The name and kind of the function node.
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
function getFunctionNameWithKind(node, sourceCode) {
|
||||
const parent = node.parent;
|
||||
const tokens = [];
|
||||
const isObjectMethod = parent.type === "Property" && parent.value === node;
|
||||
const isClassMethod =
|
||||
parent.type === "MethodDefinition" && parent.value === node;
|
||||
const isClassFieldMethod =
|
||||
parent.type === "PropertyDefinition" && parent.value === node;
|
||||
|
||||
// Modifiers.
|
||||
if (isClassMethod || isClassFieldMethod) {
|
||||
if (parent.static) {
|
||||
tokens.push("static");
|
||||
}
|
||||
if (parent.key.type === "PrivateIdentifier") {
|
||||
tokens.push("private");
|
||||
}
|
||||
}
|
||||
if (node.async) {
|
||||
tokens.push("async");
|
||||
}
|
||||
if (node.generator) {
|
||||
tokens.push("generator");
|
||||
}
|
||||
|
||||
// Kinds.
|
||||
if (isObjectMethod || isClassMethod) {
|
||||
if (parent.kind === "constructor") {
|
||||
return "constructor"
|
||||
}
|
||||
if (parent.kind === "get") {
|
||||
tokens.push("getter");
|
||||
} else if (parent.kind === "set") {
|
||||
tokens.push("setter");
|
||||
} else {
|
||||
tokens.push("method");
|
||||
}
|
||||
} else if (isClassFieldMethod) {
|
||||
tokens.push("method");
|
||||
} else {
|
||||
if (node.type === "ArrowFunctionExpression") {
|
||||
tokens.push("arrow");
|
||||
}
|
||||
tokens.push("function");
|
||||
}
|
||||
|
||||
// Names.
|
||||
if (isObjectMethod || isClassMethod || isClassFieldMethod) {
|
||||
if (parent.key.type === "PrivateIdentifier") {
|
||||
tokens.push(`#${parent.key.name}`);
|
||||
} else {
|
||||
const name = getPropertyName(parent);
|
||||
if (name) {
|
||||
tokens.push(`'${name}'`);
|
||||
} else if (sourceCode) {
|
||||
const keyText = sourceCode.getText(parent.key);
|
||||
if (!keyText.includes("\n")) {
|
||||
tokens.push(`[${keyText}]`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (node.id) {
|
||||
tokens.push(`'${node.id.name}'`);
|
||||
} else if (
|
||||
parent.type === "VariableDeclarator" &&
|
||||
parent.id &&
|
||||
parent.id.type === "Identifier"
|
||||
) {
|
||||
tokens.push(`'${parent.id.name}'`);
|
||||
} else if (
|
||||
(parent.type === "AssignmentExpression" ||
|
||||
parent.type === "AssignmentPattern") &&
|
||||
parent.left &&
|
||||
parent.left.type === "Identifier"
|
||||
) {
|
||||
tokens.push(`'${parent.left.name}'`);
|
||||
} else if (
|
||||
parent.type === "ExportDefaultDeclaration" &&
|
||||
parent.declaration === node
|
||||
) {
|
||||
tokens.push("'default'");
|
||||
}
|
||||
|
||||
return tokens.join(" ")
|
||||
}
|
||||
|
||||
const typeConversionBinaryOps = Object.freeze(
|
||||
new Set([
|
||||
"==",
|
||||
"!=",
|
||||
"<",
|
||||
"<=",
|
||||
">",
|
||||
">=",
|
||||
"<<",
|
||||
">>",
|
||||
">>>",
|
||||
"+",
|
||||
"-",
|
||||
"*",
|
||||
"/",
|
||||
"%",
|
||||
"|",
|
||||
"^",
|
||||
"&",
|
||||
"in",
|
||||
]),
|
||||
);
|
||||
const typeConversionUnaryOps = Object.freeze(new Set(["-", "+", "!", "~"]));
|
||||
|
||||
/**
|
||||
* Check whether the given value is an ASTNode or not.
|
||||
* @param {any} x The value to check.
|
||||
* @returns {boolean} `true` if the value is an ASTNode.
|
||||
*/
|
||||
function isNode(x) {
|
||||
return x !== null && typeof x === "object" && typeof x.type === "string"
|
||||
}
|
||||
|
||||
const visitor = Object.freeze(
|
||||
Object.assign(Object.create(null), {
|
||||
$visit(node, options, visitorKeys) {
|
||||
const { type } = node;
|
||||
|
||||
if (typeof this[type] === "function") {
|
||||
return this[type](node, options, visitorKeys)
|
||||
}
|
||||
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
|
||||
$visitChildren(node, options, visitorKeys) {
|
||||
const { type } = node;
|
||||
|
||||
for (const key of visitorKeys[type] || eslintVisitorKeys.getKeys(node)) {
|
||||
const value = node[key];
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
for (const element of value) {
|
||||
if (
|
||||
isNode(element) &&
|
||||
this.$visit(element, options, visitorKeys)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
isNode(value) &&
|
||||
this.$visit(value, options, visitorKeys)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
|
||||
ArrowFunctionExpression() {
|
||||
return false
|
||||
},
|
||||
AssignmentExpression() {
|
||||
return true
|
||||
},
|
||||
AwaitExpression() {
|
||||
return true
|
||||
},
|
||||
BinaryExpression(node, options, visitorKeys) {
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
typeConversionBinaryOps.has(node.operator) &&
|
||||
(node.left.type !== "Literal" || node.right.type !== "Literal")
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
CallExpression() {
|
||||
return true
|
||||
},
|
||||
FunctionExpression() {
|
||||
return false
|
||||
},
|
||||
ImportExpression() {
|
||||
return true
|
||||
},
|
||||
MemberExpression(node, options, visitorKeys) {
|
||||
if (options.considerGetters) {
|
||||
return true
|
||||
}
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
node.computed &&
|
||||
node.property.type !== "Literal"
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
MethodDefinition(node, options, visitorKeys) {
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
node.computed &&
|
||||
node.key.type !== "Literal"
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
NewExpression() {
|
||||
return true
|
||||
},
|
||||
Property(node, options, visitorKeys) {
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
node.computed &&
|
||||
node.key.type !== "Literal"
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
PropertyDefinition(node, options, visitorKeys) {
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
node.computed &&
|
||||
node.key.type !== "Literal"
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
UnaryExpression(node, options, visitorKeys) {
|
||||
if (node.operator === "delete") {
|
||||
return true
|
||||
}
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
typeConversionUnaryOps.has(node.operator) &&
|
||||
node.argument.type !== "Literal"
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
UpdateExpression() {
|
||||
return true
|
||||
},
|
||||
YieldExpression() {
|
||||
return true
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* Check whether a given node has any side effect or not.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {SourceCode} sourceCode The source code object.
|
||||
* @param {object} [options] The option object.
|
||||
* @param {boolean} [options.considerGetters=false] If `true` then it considers member accesses as the node which has side effects.
|
||||
* @param {boolean} [options.considerImplicitTypeConversion=false] If `true` then it considers implicit type conversion as the node which has side effects.
|
||||
* @param {object} [options.visitorKeys=KEYS] The keys to traverse nodes. Use `context.getSourceCode().visitorKeys`.
|
||||
* @returns {boolean} `true` if the node has a certain side effect.
|
||||
*/
|
||||
function hasSideEffect(
|
||||
node,
|
||||
sourceCode,
|
||||
{ considerGetters = false, considerImplicitTypeConversion = false } = {},
|
||||
) {
|
||||
return visitor.$visit(
|
||||
node,
|
||||
{ considerGetters, considerImplicitTypeConversion },
|
||||
sourceCode.visitorKeys || eslintVisitorKeys.KEYS,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the left parenthesis of the parent node syntax if it exists.
|
||||
* E.g., `if (a) {}` then the `(`.
|
||||
* @param {Node} node The AST node to check.
|
||||
* @param {SourceCode} sourceCode The source code object to get tokens.
|
||||
* @returns {Token|null} The left parenthesis of the parent node syntax
|
||||
*/
|
||||
function getParentSyntaxParen(node, sourceCode) {
|
||||
const parent = node.parent;
|
||||
|
||||
switch (parent.type) {
|
||||
case "CallExpression":
|
||||
case "NewExpression":
|
||||
if (parent.arguments.length === 1 && parent.arguments[0] === node) {
|
||||
return sourceCode.getTokenAfter(
|
||||
parent.callee,
|
||||
isOpeningParenToken,
|
||||
)
|
||||
}
|
||||
return null
|
||||
|
||||
case "DoWhileStatement":
|
||||
if (parent.test === node) {
|
||||
return sourceCode.getTokenAfter(
|
||||
parent.body,
|
||||
isOpeningParenToken,
|
||||
)
|
||||
}
|
||||
return null
|
||||
|
||||
case "IfStatement":
|
||||
case "WhileStatement":
|
||||
if (parent.test === node) {
|
||||
return sourceCode.getFirstToken(parent, 1)
|
||||
}
|
||||
return null
|
||||
|
||||
case "ImportExpression":
|
||||
if (parent.source === node) {
|
||||
return sourceCode.getFirstToken(parent, 1)
|
||||
}
|
||||
return null
|
||||
|
||||
case "SwitchStatement":
|
||||
if (parent.discriminant === node) {
|
||||
return sourceCode.getFirstToken(parent, 1)
|
||||
}
|
||||
return null
|
||||
|
||||
case "WithStatement":
|
||||
if (parent.object === node) {
|
||||
return sourceCode.getFirstToken(parent, 1)
|
||||
}
|
||||
return null
|
||||
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given node is parenthesized or not.
|
||||
* @param {number} times The number of parantheses.
|
||||
* @param {Node} node The AST node to check.
|
||||
* @param {SourceCode} sourceCode The source code object to get tokens.
|
||||
* @returns {boolean} `true` if the node is parenthesized the given times.
|
||||
*/
|
||||
/**
|
||||
* Check whether a given node is parenthesized or not.
|
||||
* @param {Node} node The AST node to check.
|
||||
* @param {SourceCode} sourceCode The source code object to get tokens.
|
||||
* @returns {boolean} `true` if the node is parenthesized.
|
||||
*/
|
||||
function isParenthesized(
|
||||
timesOrNode,
|
||||
nodeOrSourceCode,
|
||||
optionalSourceCode,
|
||||
) {
|
||||
let times, node, sourceCode, maybeLeftParen, maybeRightParen;
|
||||
if (typeof timesOrNode === "number") {
|
||||
times = timesOrNode | 0;
|
||||
node = nodeOrSourceCode;
|
||||
sourceCode = optionalSourceCode;
|
||||
if (!(times >= 1)) {
|
||||
throw new TypeError("'times' should be a positive integer.")
|
||||
}
|
||||
} else {
|
||||
times = 1;
|
||||
node = timesOrNode;
|
||||
sourceCode = nodeOrSourceCode;
|
||||
}
|
||||
|
||||
if (
|
||||
node == null ||
|
||||
// `Program` can't be parenthesized
|
||||
node.parent == null ||
|
||||
// `CatchClause.param` can't be parenthesized, example `try {} catch (error) {}`
|
||||
(node.parent.type === "CatchClause" && node.parent.param === node)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
maybeLeftParen = maybeRightParen = node;
|
||||
do {
|
||||
maybeLeftParen = sourceCode.getTokenBefore(maybeLeftParen);
|
||||
maybeRightParen = sourceCode.getTokenAfter(maybeRightParen);
|
||||
} while (
|
||||
maybeLeftParen != null &&
|
||||
maybeRightParen != null &&
|
||||
isOpeningParenToken(maybeLeftParen) &&
|
||||
isClosingParenToken(maybeRightParen) &&
|
||||
// Avoid false positive such as `if (a) {}`
|
||||
maybeLeftParen !== getParentSyntaxParen(node, sourceCode) &&
|
||||
--times > 0
|
||||
)
|
||||
|
||||
return times === 0
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
* See LICENSE file in root directory for full license.
|
||||
*/
|
||||
|
||||
const placeholder = /\$(?:[$&`']|[1-9][0-9]?)/gu;
|
||||
|
||||
/** @type {WeakMap<PatternMatcher, {pattern:RegExp,escaped:boolean}>} */
|
||||
const internal = new WeakMap();
|
||||
|
||||
/**
|
||||
* Check whether a given character is escaped or not.
|
||||
* @param {string} str The string to check.
|
||||
* @param {number} index The location of the character to check.
|
||||
* @returns {boolean} `true` if the character is escaped.
|
||||
*/
|
||||
function isEscaped(str, index) {
|
||||
let escaped = false;
|
||||
for (let i = index - 1; i >= 0 && str.charCodeAt(i) === 0x5c; --i) {
|
||||
escaped = !escaped;
|
||||
}
|
||||
return escaped
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a given string by a given matcher.
|
||||
* @param {PatternMatcher} matcher The pattern matcher.
|
||||
* @param {string} str The string to be replaced.
|
||||
* @param {string} replacement The new substring to replace each matched part.
|
||||
* @returns {string} The replaced string.
|
||||
*/
|
||||
function replaceS(matcher, str, replacement) {
|
||||
const chunks = [];
|
||||
let index = 0;
|
||||
|
||||
/** @type {RegExpExecArray} */
|
||||
let match = null;
|
||||
|
||||
/**
|
||||
* @param {string} key The placeholder.
|
||||
* @returns {string} The replaced string.
|
||||
*/
|
||||
function replacer(key) {
|
||||
switch (key) {
|
||||
case "$$":
|
||||
return "$"
|
||||
case "$&":
|
||||
return match[0]
|
||||
case "$`":
|
||||
return str.slice(0, match.index)
|
||||
case "$'":
|
||||
return str.slice(match.index + match[0].length)
|
||||
default: {
|
||||
const i = key.slice(1);
|
||||
if (i in match) {
|
||||
return match[i]
|
||||
}
|
||||
return key
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (match of matcher.execAll(str)) {
|
||||
chunks.push(str.slice(index, match.index));
|
||||
chunks.push(replacement.replace(placeholder, replacer));
|
||||
index = match.index + match[0].length;
|
||||
}
|
||||
chunks.push(str.slice(index));
|
||||
|
||||
return chunks.join("")
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a given string by a given matcher.
|
||||
* @param {PatternMatcher} matcher The pattern matcher.
|
||||
* @param {string} str The string to be replaced.
|
||||
* @param {(...strs[])=>string} replace The function to replace each matched part.
|
||||
* @returns {string} The replaced string.
|
||||
*/
|
||||
function replaceF(matcher, str, replace) {
|
||||
const chunks = [];
|
||||
let index = 0;
|
||||
|
||||
for (const match of matcher.execAll(str)) {
|
||||
chunks.push(str.slice(index, match.index));
|
||||
chunks.push(String(replace(...match, match.index, match.input)));
|
||||
index = match.index + match[0].length;
|
||||
}
|
||||
chunks.push(str.slice(index));
|
||||
|
||||
return chunks.join("")
|
||||
}
|
||||
|
||||
/**
|
||||
* The class to find patterns as considering escape sequences.
|
||||
*/
|
||||
class PatternMatcher {
|
||||
/**
|
||||
* Initialize this matcher.
|
||||
* @param {RegExp} pattern The pattern to match.
|
||||
* @param {{escaped:boolean}} options The options.
|
||||
*/
|
||||
constructor(pattern, { escaped = false } = {}) {
|
||||
if (!(pattern instanceof RegExp)) {
|
||||
throw new TypeError("'pattern' should be a RegExp instance.")
|
||||
}
|
||||
if (!pattern.flags.includes("g")) {
|
||||
throw new Error("'pattern' should contains 'g' flag.")
|
||||
}
|
||||
|
||||
internal.set(this, {
|
||||
pattern: new RegExp(pattern.source, pattern.flags),
|
||||
escaped: Boolean(escaped),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the pattern in a given string.
|
||||
* @param {string} str The string to find.
|
||||
* @returns {IterableIterator<RegExpExecArray>} The iterator which iterate the matched information.
|
||||
*/
|
||||
*execAll(str) {
|
||||
const { pattern, escaped } = internal.get(this);
|
||||
let match = null;
|
||||
let lastIndex = 0;
|
||||
|
||||
pattern.lastIndex = 0;
|
||||
while ((match = pattern.exec(str)) != null) {
|
||||
if (escaped || !isEscaped(str, match.index)) {
|
||||
lastIndex = pattern.lastIndex;
|
||||
yield match;
|
||||
pattern.lastIndex = lastIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the pattern is found in a given string.
|
||||
* @param {string} str The string to check.
|
||||
* @returns {boolean} `true` if the pattern was found in the string.
|
||||
*/
|
||||
test(str) {
|
||||
const it = this.execAll(str);
|
||||
const ret = it.next();
|
||||
return !ret.done
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a given string.
|
||||
* @param {string} str The string to be replaced.
|
||||
* @param {(string|((...strs:string[])=>string))} replacer The string or function to replace. This is the same as the 2nd argument of `String.prototype.replace`.
|
||||
* @returns {string} The replaced string.
|
||||
*/
|
||||
[Symbol.replace](str, replacer) {
|
||||
return typeof replacer === "function"
|
||||
? replaceF(this, String(str), replacer)
|
||||
: replaceS(this, String(str), String(replacer))
|
||||
}
|
||||
}
|
||||
|
||||
const IMPORT_TYPE = /^(?:Import|Export(?:All|Default|Named))Declaration$/u;
|
||||
const has = Function.call.bind(Object.hasOwnProperty);
|
||||
|
||||
const READ = Symbol("read");
|
||||
const CALL = Symbol("call");
|
||||
const CONSTRUCT = Symbol("construct");
|
||||
const ESM = Symbol("esm");
|
||||
|
||||
const requireCall = { require: { [CALL]: true } };
|
||||
|
||||
/**
|
||||
* Check whether a given variable is modified or not.
|
||||
* @param {Variable} variable The variable to check.
|
||||
* @returns {boolean} `true` if the variable is modified.
|
||||
*/
|
||||
function isModifiedGlobal(variable) {
|
||||
return (
|
||||
variable == null ||
|
||||
variable.defs.length !== 0 ||
|
||||
variable.references.some((r) => r.isWrite())
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the value of a given node is passed through to the parent syntax as-is.
|
||||
* For example, `a` and `b` in (`a || b` and `c ? a : b`) are passed through.
|
||||
* @param {Node} node A node to check.
|
||||
* @returns {boolean} `true` if the node is passed through.
|
||||
*/
|
||||
function isPassThrough(node) {
|
||||
const parent = node.parent;
|
||||
|
||||
switch (parent && parent.type) {
|
||||
case "ConditionalExpression":
|
||||
return parent.consequent === node || parent.alternate === node
|
||||
case "LogicalExpression":
|
||||
return true
|
||||
case "SequenceExpression":
|
||||
return parent.expressions[parent.expressions.length - 1] === node
|
||||
case "ChainExpression":
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The reference tracker.
|
||||
*/
|
||||
class ReferenceTracker {
|
||||
/**
|
||||
* Initialize this tracker.
|
||||
* @param {Scope} globalScope The global scope.
|
||||
* @param {object} [options] The options.
|
||||
* @param {"legacy"|"strict"} [options.mode="strict"] The mode to determine the ImportDeclaration's behavior for CJS modules.
|
||||
* @param {string[]} [options.globalObjectNames=["global","globalThis","self","window"]] The variable names for Global Object.
|
||||
*/
|
||||
constructor(
|
||||
globalScope,
|
||||
{
|
||||
mode = "strict",
|
||||
globalObjectNames = ["global", "globalThis", "self", "window"],
|
||||
} = {},
|
||||
) {
|
||||
this.variableStack = [];
|
||||
this.globalScope = globalScope;
|
||||
this.mode = mode;
|
||||
this.globalObjectNames = globalObjectNames.slice(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references of global variables.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*iterateGlobalReferences(traceMap) {
|
||||
for (const key of Object.keys(traceMap)) {
|
||||
const nextTraceMap = traceMap[key];
|
||||
const path = [key];
|
||||
const variable = this.globalScope.set.get(key);
|
||||
|
||||
if (isModifiedGlobal(variable)) {
|
||||
continue
|
||||
}
|
||||
|
||||
yield* this._iterateVariableReferences(
|
||||
variable,
|
||||
path,
|
||||
nextTraceMap,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
for (const key of this.globalObjectNames) {
|
||||
const path = [];
|
||||
const variable = this.globalScope.set.get(key);
|
||||
|
||||
if (isModifiedGlobal(variable)) {
|
||||
continue
|
||||
}
|
||||
|
||||
yield* this._iterateVariableReferences(
|
||||
variable,
|
||||
path,
|
||||
traceMap,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references of CommonJS modules.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*iterateCjsReferences(traceMap) {
|
||||
for (const { node } of this.iterateGlobalReferences(requireCall)) {
|
||||
const key = getStringIfConstant(node.arguments[0]);
|
||||
if (key == null || !has(traceMap, key)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const nextTraceMap = traceMap[key];
|
||||
const path = [key];
|
||||
|
||||
if (nextTraceMap[READ]) {
|
||||
yield {
|
||||
node,
|
||||
path,
|
||||
type: READ,
|
||||
info: nextTraceMap[READ],
|
||||
};
|
||||
}
|
||||
yield* this._iteratePropertyReferences(node, path, nextTraceMap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references of ES modules.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*iterateEsmReferences(traceMap) {
|
||||
const programNode = this.globalScope.block;
|
||||
|
||||
for (const node of programNode.body) {
|
||||
if (!IMPORT_TYPE.test(node.type) || node.source == null) {
|
||||
continue
|
||||
}
|
||||
const moduleId = node.source.value;
|
||||
|
||||
if (!has(traceMap, moduleId)) {
|
||||
continue
|
||||
}
|
||||
const nextTraceMap = traceMap[moduleId];
|
||||
const path = [moduleId];
|
||||
|
||||
if (nextTraceMap[READ]) {
|
||||
yield { node, path, type: READ, info: nextTraceMap[READ] };
|
||||
}
|
||||
|
||||
if (node.type === "ExportAllDeclaration") {
|
||||
for (const key of Object.keys(nextTraceMap)) {
|
||||
const exportTraceMap = nextTraceMap[key];
|
||||
if (exportTraceMap[READ]) {
|
||||
yield {
|
||||
node,
|
||||
path: path.concat(key),
|
||||
type: READ,
|
||||
info: exportTraceMap[READ],
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const specifier of node.specifiers) {
|
||||
const esm = has(nextTraceMap, ESM);
|
||||
const it = this._iterateImportReferences(
|
||||
specifier,
|
||||
path,
|
||||
esm
|
||||
? nextTraceMap
|
||||
: this.mode === "legacy"
|
||||
? { default: nextTraceMap, ...nextTraceMap }
|
||||
: { default: nextTraceMap },
|
||||
);
|
||||
|
||||
if (esm) {
|
||||
yield* it;
|
||||
} else {
|
||||
for (const report of it) {
|
||||
report.path = report.path.filter(exceptDefault);
|
||||
if (
|
||||
report.path.length >= 2 ||
|
||||
report.type !== READ
|
||||
) {
|
||||
yield report;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references for a given variable.
|
||||
* @param {Variable} variable The variable to iterate that references.
|
||||
* @param {string[]} path The current path.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @param {boolean} shouldReport = The flag to report those references.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*_iterateVariableReferences(variable, path, traceMap, shouldReport) {
|
||||
if (this.variableStack.includes(variable)) {
|
||||
return
|
||||
}
|
||||
this.variableStack.push(variable);
|
||||
try {
|
||||
for (const reference of variable.references) {
|
||||
if (!reference.isRead()) {
|
||||
continue
|
||||
}
|
||||
const node = reference.identifier;
|
||||
|
||||
if (shouldReport && traceMap[READ]) {
|
||||
yield { node, path, type: READ, info: traceMap[READ] };
|
||||
}
|
||||
yield* this._iteratePropertyReferences(node, path, traceMap);
|
||||
}
|
||||
} finally {
|
||||
this.variableStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references for a given AST node.
|
||||
* @param rootNode The AST node to iterate references.
|
||||
* @param {string[]} path The current path.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
//eslint-disable-next-line complexity
|
||||
*_iteratePropertyReferences(rootNode, path, traceMap) {
|
||||
let node = rootNode;
|
||||
while (isPassThrough(node)) {
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
const parent = node.parent;
|
||||
if (parent.type === "MemberExpression") {
|
||||
if (parent.object === node) {
|
||||
const key = getPropertyName(parent);
|
||||
if (key == null || !has(traceMap, key)) {
|
||||
return
|
||||
}
|
||||
|
||||
path = path.concat(key); //eslint-disable-line no-param-reassign
|
||||
const nextTraceMap = traceMap[key];
|
||||
if (nextTraceMap[READ]) {
|
||||
yield {
|
||||
node: parent,
|
||||
path,
|
||||
type: READ,
|
||||
info: nextTraceMap[READ],
|
||||
};
|
||||
}
|
||||
yield* this._iteratePropertyReferences(
|
||||
parent,
|
||||
path,
|
||||
nextTraceMap,
|
||||
);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (parent.type === "CallExpression") {
|
||||
if (parent.callee === node && traceMap[CALL]) {
|
||||
yield { node: parent, path, type: CALL, info: traceMap[CALL] };
|
||||
}
|
||||
return
|
||||
}
|
||||
if (parent.type === "NewExpression") {
|
||||
if (parent.callee === node && traceMap[CONSTRUCT]) {
|
||||
yield {
|
||||
node: parent,
|
||||
path,
|
||||
type: CONSTRUCT,
|
||||
info: traceMap[CONSTRUCT],
|
||||
};
|
||||
}
|
||||
return
|
||||
}
|
||||
if (parent.type === "AssignmentExpression") {
|
||||
if (parent.right === node) {
|
||||
yield* this._iterateLhsReferences(parent.left, path, traceMap);
|
||||
yield* this._iteratePropertyReferences(parent, path, traceMap);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (parent.type === "AssignmentPattern") {
|
||||
if (parent.right === node) {
|
||||
yield* this._iterateLhsReferences(parent.left, path, traceMap);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (parent.type === "VariableDeclarator") {
|
||||
if (parent.init === node) {
|
||||
yield* this._iterateLhsReferences(parent.id, path, traceMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references for a given Pattern node.
|
||||
* @param {Node} patternNode The Pattern node to iterate references.
|
||||
* @param {string[]} path The current path.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*_iterateLhsReferences(patternNode, path, traceMap) {
|
||||
if (patternNode.type === "Identifier") {
|
||||
const variable = findVariable(this.globalScope, patternNode);
|
||||
if (variable != null) {
|
||||
yield* this._iterateVariableReferences(
|
||||
variable,
|
||||
path,
|
||||
traceMap,
|
||||
false,
|
||||
);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (patternNode.type === "ObjectPattern") {
|
||||
for (const property of patternNode.properties) {
|
||||
const key = getPropertyName(property);
|
||||
|
||||
if (key == null || !has(traceMap, key)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const nextPath = path.concat(key);
|
||||
const nextTraceMap = traceMap[key];
|
||||
if (nextTraceMap[READ]) {
|
||||
yield {
|
||||
node: property,
|
||||
path: nextPath,
|
||||
type: READ,
|
||||
info: nextTraceMap[READ],
|
||||
};
|
||||
}
|
||||
yield* this._iterateLhsReferences(
|
||||
property.value,
|
||||
nextPath,
|
||||
nextTraceMap,
|
||||
);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (patternNode.type === "AssignmentPattern") {
|
||||
yield* this._iterateLhsReferences(patternNode.left, path, traceMap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references for a given ModuleSpecifier node.
|
||||
* @param {Node} specifierNode The ModuleSpecifier node to iterate references.
|
||||
* @param {string[]} path The current path.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*_iterateImportReferences(specifierNode, path, traceMap) {
|
||||
const type = specifierNode.type;
|
||||
|
||||
if (type === "ImportSpecifier" || type === "ImportDefaultSpecifier") {
|
||||
const key =
|
||||
type === "ImportDefaultSpecifier"
|
||||
? "default"
|
||||
: specifierNode.imported.name;
|
||||
if (!has(traceMap, key)) {
|
||||
return
|
||||
}
|
||||
|
||||
path = path.concat(key); //eslint-disable-line no-param-reassign
|
||||
const nextTraceMap = traceMap[key];
|
||||
if (nextTraceMap[READ]) {
|
||||
yield {
|
||||
node: specifierNode,
|
||||
path,
|
||||
type: READ,
|
||||
info: nextTraceMap[READ],
|
||||
};
|
||||
}
|
||||
yield* this._iterateVariableReferences(
|
||||
findVariable(this.globalScope, specifierNode.local),
|
||||
path,
|
||||
nextTraceMap,
|
||||
false,
|
||||
);
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (type === "ImportNamespaceSpecifier") {
|
||||
yield* this._iterateVariableReferences(
|
||||
findVariable(this.globalScope, specifierNode.local),
|
||||
path,
|
||||
traceMap,
|
||||
false,
|
||||
);
|
||||
return
|
||||
}
|
||||
|
||||
if (type === "ExportSpecifier") {
|
||||
const key = specifierNode.local.name;
|
||||
if (!has(traceMap, key)) {
|
||||
return
|
||||
}
|
||||
|
||||
path = path.concat(key); //eslint-disable-line no-param-reassign
|
||||
const nextTraceMap = traceMap[key];
|
||||
if (nextTraceMap[READ]) {
|
||||
yield {
|
||||
node: specifierNode,
|
||||
path,
|
||||
type: READ,
|
||||
info: nextTraceMap[READ],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReferenceTracker.READ = READ;
|
||||
ReferenceTracker.CALL = CALL;
|
||||
ReferenceTracker.CONSTRUCT = CONSTRUCT;
|
||||
ReferenceTracker.ESM = ESM;
|
||||
|
||||
/**
|
||||
* This is a predicate function for Array#filter.
|
||||
* @param {string} name A name part.
|
||||
* @param {number} index The index of the name.
|
||||
* @returns {boolean} `false` if it's default.
|
||||
*/
|
||||
function exceptDefault(name, index) {
|
||||
return !(index === 1 && name === "default")
|
||||
}
|
||||
|
||||
var index = {
|
||||
CALL,
|
||||
CONSTRUCT,
|
||||
ESM,
|
||||
findVariable,
|
||||
getFunctionHeadLocation,
|
||||
getFunctionNameWithKind,
|
||||
getInnermostScope,
|
||||
getPropertyName,
|
||||
getStaticValue,
|
||||
getStringIfConstant,
|
||||
hasSideEffect,
|
||||
isArrowToken,
|
||||
isClosingBraceToken,
|
||||
isClosingBracketToken,
|
||||
isClosingParenToken,
|
||||
isColonToken,
|
||||
isCommaToken,
|
||||
isCommentToken,
|
||||
isNotArrowToken,
|
||||
isNotClosingBraceToken,
|
||||
isNotClosingBracketToken,
|
||||
isNotClosingParenToken,
|
||||
isNotColonToken,
|
||||
isNotCommaToken,
|
||||
isNotCommentToken,
|
||||
isNotOpeningBraceToken,
|
||||
isNotOpeningBracketToken,
|
||||
isNotOpeningParenToken,
|
||||
isNotSemicolonToken,
|
||||
isOpeningBraceToken,
|
||||
isOpeningBracketToken,
|
||||
isOpeningParenToken,
|
||||
isParenthesized,
|
||||
isSemicolonToken,
|
||||
PatternMatcher,
|
||||
READ,
|
||||
ReferenceTracker,
|
||||
};
|
||||
|
||||
exports.CALL = CALL;
|
||||
exports.CONSTRUCT = CONSTRUCT;
|
||||
exports.ESM = ESM;
|
||||
exports.PatternMatcher = PatternMatcher;
|
||||
exports.READ = READ;
|
||||
exports.ReferenceTracker = ReferenceTracker;
|
||||
exports["default"] = index;
|
||||
exports.findVariable = findVariable;
|
||||
exports.getFunctionHeadLocation = getFunctionHeadLocation;
|
||||
exports.getFunctionNameWithKind = getFunctionNameWithKind;
|
||||
exports.getInnermostScope = getInnermostScope;
|
||||
exports.getPropertyName = getPropertyName;
|
||||
exports.getStaticValue = getStaticValue;
|
||||
exports.getStringIfConstant = getStringIfConstant;
|
||||
exports.hasSideEffect = hasSideEffect;
|
||||
exports.isArrowToken = isArrowToken;
|
||||
exports.isClosingBraceToken = isClosingBraceToken;
|
||||
exports.isClosingBracketToken = isClosingBracketToken;
|
||||
exports.isClosingParenToken = isClosingParenToken;
|
||||
exports.isColonToken = isColonToken;
|
||||
exports.isCommaToken = isCommaToken;
|
||||
exports.isCommentToken = isCommentToken;
|
||||
exports.isNotArrowToken = isNotArrowToken;
|
||||
exports.isNotClosingBraceToken = isNotClosingBraceToken;
|
||||
exports.isNotClosingBracketToken = isNotClosingBracketToken;
|
||||
exports.isNotClosingParenToken = isNotClosingParenToken;
|
||||
exports.isNotColonToken = isNotColonToken;
|
||||
exports.isNotCommaToken = isNotCommaToken;
|
||||
exports.isNotCommentToken = isNotCommentToken;
|
||||
exports.isNotOpeningBraceToken = isNotOpeningBraceToken;
|
||||
exports.isNotOpeningBracketToken = isNotOpeningBracketToken;
|
||||
exports.isNotOpeningParenToken = isNotOpeningParenToken;
|
||||
exports.isNotSemicolonToken = isNotSemicolonToken;
|
||||
exports.isOpeningBraceToken = isOpeningBraceToken;
|
||||
exports.isOpeningBracketToken = isOpeningBracketToken;
|
||||
exports.isOpeningParenToken = isOpeningParenToken;
|
||||
exports.isParenthesized = isParenthesized;
|
||||
exports.isSemicolonToken = isSemicolonToken;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@eslint-community/eslint-utils/index.js.map
generated
vendored
Normal file
1
node_modules/@eslint-community/eslint-utils/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2027
node_modules/@eslint-community/eslint-utils/index.mjs
generated
vendored
Normal file
2027
node_modules/@eslint-community/eslint-utils/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,2027 @@
|
||||
import { getKeys, KEYS } from 'eslint-visitor-keys';
|
||||
|
||||
/**
|
||||
* Get the innermost scope which contains a given location.
|
||||
* @param {Scope} initialScope The initial scope to search.
|
||||
* @param {Node} node The location to search.
|
||||
* @returns {Scope} The innermost scope.
|
||||
*/
|
||||
function getInnermostScope(initialScope, node) {
|
||||
const location = node.range[0];
|
||||
|
||||
let scope = initialScope;
|
||||
let found = false;
|
||||
do {
|
||||
found = false;
|
||||
for (const childScope of scope.childScopes) {
|
||||
const range = childScope.block.range;
|
||||
|
||||
if (range[0] <= location && location < range[1]) {
|
||||
scope = childScope;
|
||||
found = true;
|
||||
break
|
||||
}
|
||||
}
|
||||
} while (found)
|
||||
|
||||
return scope
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the variable of a given name.
|
||||
* @param {Scope} initialScope The scope to start finding.
|
||||
* @param {string|Node} nameOrNode The variable name to find. If this is a Node object then it should be an Identifier node.
|
||||
* @returns {Variable|null} The found variable or null.
|
||||
*/
|
||||
function findVariable(initialScope, nameOrNode) {
|
||||
let name = "";
|
||||
let scope = initialScope;
|
||||
|
||||
if (typeof nameOrNode === "string") {
|
||||
name = nameOrNode;
|
||||
} else {
|
||||
name = nameOrNode.name;
|
||||
scope = getInnermostScope(scope, nameOrNode);
|
||||
}
|
||||
|
||||
while (scope != null) {
|
||||
const variable = scope.set.get(name);
|
||||
if (variable != null) {
|
||||
return variable
|
||||
}
|
||||
scope = scope.upper;
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate the result of `this` calling.
|
||||
* @param {Token} token The token to check.
|
||||
* @returns {boolean} `true` if the result of `this(token)` is `false`.
|
||||
*/
|
||||
function negate0(token) {
|
||||
return !this(token) //eslint-disable-line no-invalid-this
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the negate function of the given function.
|
||||
* @param {function(Token):boolean} f - The function to negate.
|
||||
* @returns {function(Token):boolean} Negated function.
|
||||
*/
|
||||
function negate(f) {
|
||||
return negate0.bind(f)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a PunctuatorToken with the given value
|
||||
* @param {Token} token - The token to check.
|
||||
* @param {string} value - The value to check.
|
||||
* @returns {boolean} `true` if the token is a PunctuatorToken with the given value.
|
||||
*/
|
||||
function isPunctuatorTokenWithValue(token, value) {
|
||||
return token.type === "Punctuator" && token.value === value
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is an arrow token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is an arrow token.
|
||||
*/
|
||||
function isArrowToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "=>")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a comma token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a comma token.
|
||||
*/
|
||||
function isCommaToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, ",")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a semicolon token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a semicolon token.
|
||||
*/
|
||||
function isSemicolonToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, ";")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a colon token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a colon token.
|
||||
*/
|
||||
function isColonToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, ":")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is an opening parenthesis token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is an opening parenthesis token.
|
||||
*/
|
||||
function isOpeningParenToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "(")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a closing parenthesis token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a closing parenthesis token.
|
||||
*/
|
||||
function isClosingParenToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, ")")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is an opening square bracket token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is an opening square bracket token.
|
||||
*/
|
||||
function isOpeningBracketToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "[")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a closing square bracket token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a closing square bracket token.
|
||||
*/
|
||||
function isClosingBracketToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "]")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is an opening brace token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is an opening brace token.
|
||||
*/
|
||||
function isOpeningBraceToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "{")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a closing brace token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a closing brace token.
|
||||
*/
|
||||
function isClosingBraceToken(token) {
|
||||
return isPunctuatorTokenWithValue(token, "}")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given token is a comment token or not.
|
||||
* @param {Token} token - The token to check.
|
||||
* @returns {boolean} `true` if the token is a comment token.
|
||||
*/
|
||||
function isCommentToken(token) {
|
||||
return ["Block", "Line", "Shebang"].includes(token.type)
|
||||
}
|
||||
|
||||
const isNotArrowToken = negate(isArrowToken);
|
||||
const isNotCommaToken = negate(isCommaToken);
|
||||
const isNotSemicolonToken = negate(isSemicolonToken);
|
||||
const isNotColonToken = negate(isColonToken);
|
||||
const isNotOpeningParenToken = negate(isOpeningParenToken);
|
||||
const isNotClosingParenToken = negate(isClosingParenToken);
|
||||
const isNotOpeningBracketToken = negate(isOpeningBracketToken);
|
||||
const isNotClosingBracketToken = negate(isClosingBracketToken);
|
||||
const isNotOpeningBraceToken = negate(isOpeningBraceToken);
|
||||
const isNotClosingBraceToken = negate(isClosingBraceToken);
|
||||
const isNotCommentToken = negate(isCommentToken);
|
||||
|
||||
/**
|
||||
* Get the `(` token of the given function node.
|
||||
* @param {Node} node - The function node to get.
|
||||
* @param {SourceCode} sourceCode - The source code object to get tokens.
|
||||
* @returns {Token} `(` token.
|
||||
*/
|
||||
function getOpeningParenOfParams(node, sourceCode) {
|
||||
return node.id
|
||||
? sourceCode.getTokenAfter(node.id, isOpeningParenToken)
|
||||
: sourceCode.getFirstToken(node, isOpeningParenToken)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the location of the given function node for reporting.
|
||||
* @param {Node} node - The function node to get.
|
||||
* @param {SourceCode} sourceCode - The source code object to get tokens.
|
||||
* @returns {string} The location of the function node for reporting.
|
||||
*/
|
||||
function getFunctionHeadLocation(node, sourceCode) {
|
||||
const parent = node.parent;
|
||||
let start = null;
|
||||
let end = null;
|
||||
|
||||
if (node.type === "ArrowFunctionExpression") {
|
||||
const arrowToken = sourceCode.getTokenBefore(node.body, isArrowToken);
|
||||
|
||||
start = arrowToken.loc.start;
|
||||
end = arrowToken.loc.end;
|
||||
} else if (
|
||||
parent.type === "Property" ||
|
||||
parent.type === "MethodDefinition" ||
|
||||
parent.type === "PropertyDefinition"
|
||||
) {
|
||||
start = parent.loc.start;
|
||||
end = getOpeningParenOfParams(node, sourceCode).loc.start;
|
||||
} else {
|
||||
start = node.loc.start;
|
||||
end = getOpeningParenOfParams(node, sourceCode).loc.start;
|
||||
}
|
||||
|
||||
return {
|
||||
start: { ...start },
|
||||
end: { ...end },
|
||||
}
|
||||
}
|
||||
|
||||
/* globals globalThis, global, self, window */
|
||||
|
||||
const globalObject =
|
||||
typeof globalThis !== "undefined"
|
||||
? globalThis
|
||||
: typeof self !== "undefined"
|
||||
? self
|
||||
: typeof window !== "undefined"
|
||||
? window
|
||||
: typeof global !== "undefined"
|
||||
? global
|
||||
: {};
|
||||
|
||||
const builtinNames = Object.freeze(
|
||||
new Set([
|
||||
"Array",
|
||||
"ArrayBuffer",
|
||||
"BigInt",
|
||||
"BigInt64Array",
|
||||
"BigUint64Array",
|
||||
"Boolean",
|
||||
"DataView",
|
||||
"Date",
|
||||
"decodeURI",
|
||||
"decodeURIComponent",
|
||||
"encodeURI",
|
||||
"encodeURIComponent",
|
||||
"escape",
|
||||
"Float32Array",
|
||||
"Float64Array",
|
||||
"Function",
|
||||
"Infinity",
|
||||
"Int16Array",
|
||||
"Int32Array",
|
||||
"Int8Array",
|
||||
"isFinite",
|
||||
"isNaN",
|
||||
"isPrototypeOf",
|
||||
"JSON",
|
||||
"Map",
|
||||
"Math",
|
||||
"NaN",
|
||||
"Number",
|
||||
"Object",
|
||||
"parseFloat",
|
||||
"parseInt",
|
||||
"Promise",
|
||||
"Proxy",
|
||||
"Reflect",
|
||||
"RegExp",
|
||||
"Set",
|
||||
"String",
|
||||
"Symbol",
|
||||
"Uint16Array",
|
||||
"Uint32Array",
|
||||
"Uint8Array",
|
||||
"Uint8ClampedArray",
|
||||
"undefined",
|
||||
"unescape",
|
||||
"WeakMap",
|
||||
"WeakSet",
|
||||
]),
|
||||
);
|
||||
const callAllowed = new Set(
|
||||
[
|
||||
Array.isArray,
|
||||
Array.of,
|
||||
Array.prototype.at,
|
||||
Array.prototype.concat,
|
||||
Array.prototype.entries,
|
||||
Array.prototype.every,
|
||||
Array.prototype.filter,
|
||||
Array.prototype.find,
|
||||
Array.prototype.findIndex,
|
||||
Array.prototype.flat,
|
||||
Array.prototype.includes,
|
||||
Array.prototype.indexOf,
|
||||
Array.prototype.join,
|
||||
Array.prototype.keys,
|
||||
Array.prototype.lastIndexOf,
|
||||
Array.prototype.slice,
|
||||
Array.prototype.some,
|
||||
Array.prototype.toString,
|
||||
Array.prototype.values,
|
||||
typeof BigInt === "function" ? BigInt : undefined,
|
||||
Boolean,
|
||||
Date,
|
||||
Date.parse,
|
||||
decodeURI,
|
||||
decodeURIComponent,
|
||||
encodeURI,
|
||||
encodeURIComponent,
|
||||
escape,
|
||||
isFinite,
|
||||
isNaN,
|
||||
isPrototypeOf,
|
||||
Map,
|
||||
Map.prototype.entries,
|
||||
Map.prototype.get,
|
||||
Map.prototype.has,
|
||||
Map.prototype.keys,
|
||||
Map.prototype.values,
|
||||
...Object.getOwnPropertyNames(Math)
|
||||
.filter((k) => k !== "random")
|
||||
.map((k) => Math[k])
|
||||
.filter((f) => typeof f === "function"),
|
||||
Number,
|
||||
Number.isFinite,
|
||||
Number.isNaN,
|
||||
Number.parseFloat,
|
||||
Number.parseInt,
|
||||
Number.prototype.toExponential,
|
||||
Number.prototype.toFixed,
|
||||
Number.prototype.toPrecision,
|
||||
Number.prototype.toString,
|
||||
Object,
|
||||
Object.entries,
|
||||
Object.is,
|
||||
Object.isExtensible,
|
||||
Object.isFrozen,
|
||||
Object.isSealed,
|
||||
Object.keys,
|
||||
Object.values,
|
||||
parseFloat,
|
||||
parseInt,
|
||||
RegExp,
|
||||
Set,
|
||||
Set.prototype.entries,
|
||||
Set.prototype.has,
|
||||
Set.prototype.keys,
|
||||
Set.prototype.values,
|
||||
String,
|
||||
String.fromCharCode,
|
||||
String.fromCodePoint,
|
||||
String.raw,
|
||||
String.prototype.at,
|
||||
String.prototype.charAt,
|
||||
String.prototype.charCodeAt,
|
||||
String.prototype.codePointAt,
|
||||
String.prototype.concat,
|
||||
String.prototype.endsWith,
|
||||
String.prototype.includes,
|
||||
String.prototype.indexOf,
|
||||
String.prototype.lastIndexOf,
|
||||
String.prototype.normalize,
|
||||
String.prototype.padEnd,
|
||||
String.prototype.padStart,
|
||||
String.prototype.slice,
|
||||
String.prototype.startsWith,
|
||||
String.prototype.substr,
|
||||
String.prototype.substring,
|
||||
String.prototype.toLowerCase,
|
||||
String.prototype.toString,
|
||||
String.prototype.toUpperCase,
|
||||
String.prototype.trim,
|
||||
String.prototype.trimEnd,
|
||||
String.prototype.trimLeft,
|
||||
String.prototype.trimRight,
|
||||
String.prototype.trimStart,
|
||||
Symbol.for,
|
||||
Symbol.keyFor,
|
||||
unescape,
|
||||
].filter((f) => typeof f === "function"),
|
||||
);
|
||||
const callPassThrough = new Set([
|
||||
Object.freeze,
|
||||
Object.preventExtensions,
|
||||
Object.seal,
|
||||
]);
|
||||
|
||||
/** @type {ReadonlyArray<readonly [Function, ReadonlySet<string>]>} */
|
||||
const getterAllowed = [
|
||||
[Map, new Set(["size"])],
|
||||
[
|
||||
RegExp,
|
||||
new Set([
|
||||
"dotAll",
|
||||
"flags",
|
||||
"global",
|
||||
"hasIndices",
|
||||
"ignoreCase",
|
||||
"multiline",
|
||||
"source",
|
||||
"sticky",
|
||||
"unicode",
|
||||
]),
|
||||
],
|
||||
[Set, new Set(["size"])],
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the property descriptor.
|
||||
* @param {object} object The object to get.
|
||||
* @param {string|number|symbol} name The property name to get.
|
||||
*/
|
||||
function getPropertyDescriptor(object, name) {
|
||||
let x = object;
|
||||
while ((typeof x === "object" || typeof x === "function") && x !== null) {
|
||||
const d = Object.getOwnPropertyDescriptor(x, name);
|
||||
if (d) {
|
||||
return d
|
||||
}
|
||||
x = Object.getPrototypeOf(x);
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a property is getter or not.
|
||||
* @param {object} object The object to check.
|
||||
* @param {string|number|symbol} name The property name to check.
|
||||
*/
|
||||
function isGetter(object, name) {
|
||||
const d = getPropertyDescriptor(object, name);
|
||||
return d != null && d.get != null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element values of a given node list.
|
||||
* @param {Node[]} nodeList The node list to get values.
|
||||
* @param {Scope|undefined} initialScope The initial scope to find variables.
|
||||
* @returns {any[]|null} The value list if all nodes are constant. Otherwise, null.
|
||||
*/
|
||||
function getElementValues(nodeList, initialScope) {
|
||||
const valueList = [];
|
||||
|
||||
for (let i = 0; i < nodeList.length; ++i) {
|
||||
const elementNode = nodeList[i];
|
||||
|
||||
if (elementNode == null) {
|
||||
valueList.length = i + 1;
|
||||
} else if (elementNode.type === "SpreadElement") {
|
||||
const argument = getStaticValueR(elementNode.argument, initialScope);
|
||||
if (argument == null) {
|
||||
return null
|
||||
}
|
||||
valueList.push(...argument.value);
|
||||
} else {
|
||||
const element = getStaticValueR(elementNode, initialScope);
|
||||
if (element == null) {
|
||||
return null
|
||||
}
|
||||
valueList.push(element.value);
|
||||
}
|
||||
}
|
||||
|
||||
return valueList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given variable is never written to after initialization.
|
||||
* @param {import("eslint").Scope.Variable} variable
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isEffectivelyConst(variable) {
|
||||
const refs = variable.references;
|
||||
|
||||
const inits = refs.filter((r) => r.init).length;
|
||||
const reads = refs.filter((r) => r.isReadOnly()).length;
|
||||
if (inits === 1 && reads + inits === refs.length) {
|
||||
// there is only one init and all other references only read
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const operations = Object.freeze({
|
||||
ArrayExpression(node, initialScope) {
|
||||
const elements = getElementValues(node.elements, initialScope);
|
||||
return elements != null ? { value: elements } : null
|
||||
},
|
||||
|
||||
AssignmentExpression(node, initialScope) {
|
||||
if (node.operator === "=") {
|
||||
return getStaticValueR(node.right, initialScope)
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
//eslint-disable-next-line complexity
|
||||
BinaryExpression(node, initialScope) {
|
||||
if (node.operator === "in" || node.operator === "instanceof") {
|
||||
// Not supported.
|
||||
return null
|
||||
}
|
||||
|
||||
const left = getStaticValueR(node.left, initialScope);
|
||||
const right = getStaticValueR(node.right, initialScope);
|
||||
if (left != null && right != null) {
|
||||
switch (node.operator) {
|
||||
case "==":
|
||||
return { value: left.value == right.value } //eslint-disable-line eqeqeq
|
||||
case "!=":
|
||||
return { value: left.value != right.value } //eslint-disable-line eqeqeq
|
||||
case "===":
|
||||
return { value: left.value === right.value }
|
||||
case "!==":
|
||||
return { value: left.value !== right.value }
|
||||
case "<":
|
||||
return { value: left.value < right.value }
|
||||
case "<=":
|
||||
return { value: left.value <= right.value }
|
||||
case ">":
|
||||
return { value: left.value > right.value }
|
||||
case ">=":
|
||||
return { value: left.value >= right.value }
|
||||
case "<<":
|
||||
return { value: left.value << right.value }
|
||||
case ">>":
|
||||
return { value: left.value >> right.value }
|
||||
case ">>>":
|
||||
return { value: left.value >>> right.value }
|
||||
case "+":
|
||||
return { value: left.value + right.value }
|
||||
case "-":
|
||||
return { value: left.value - right.value }
|
||||
case "*":
|
||||
return { value: left.value * right.value }
|
||||
case "/":
|
||||
return { value: left.value / right.value }
|
||||
case "%":
|
||||
return { value: left.value % right.value }
|
||||
case "**":
|
||||
return { value: left.value ** right.value }
|
||||
case "|":
|
||||
return { value: left.value | right.value }
|
||||
case "^":
|
||||
return { value: left.value ^ right.value }
|
||||
case "&":
|
||||
return { value: left.value & right.value }
|
||||
|
||||
// no default
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
CallExpression(node, initialScope) {
|
||||
const calleeNode = node.callee;
|
||||
const args = getElementValues(node.arguments, initialScope);
|
||||
|
||||
if (args != null) {
|
||||
if (calleeNode.type === "MemberExpression") {
|
||||
if (calleeNode.property.type === "PrivateIdentifier") {
|
||||
return null
|
||||
}
|
||||
const object = getStaticValueR(calleeNode.object, initialScope);
|
||||
if (object != null) {
|
||||
if (
|
||||
object.value == null &&
|
||||
(object.optional || node.optional)
|
||||
) {
|
||||
return { value: undefined, optional: true }
|
||||
}
|
||||
const property = getStaticPropertyNameValue(
|
||||
calleeNode,
|
||||
initialScope,
|
||||
);
|
||||
|
||||
if (property != null) {
|
||||
const receiver = object.value;
|
||||
const methodName = property.value;
|
||||
if (callAllowed.has(receiver[methodName])) {
|
||||
return { value: receiver[methodName](...args) }
|
||||
}
|
||||
if (callPassThrough.has(receiver[methodName])) {
|
||||
return { value: args[0] }
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const callee = getStaticValueR(calleeNode, initialScope);
|
||||
if (callee != null) {
|
||||
if (callee.value == null && node.optional) {
|
||||
return { value: undefined, optional: true }
|
||||
}
|
||||
const func = callee.value;
|
||||
if (callAllowed.has(func)) {
|
||||
return { value: func(...args) }
|
||||
}
|
||||
if (callPassThrough.has(func)) {
|
||||
return { value: args[0] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
ConditionalExpression(node, initialScope) {
|
||||
const test = getStaticValueR(node.test, initialScope);
|
||||
if (test != null) {
|
||||
return test.value
|
||||
? getStaticValueR(node.consequent, initialScope)
|
||||
: getStaticValueR(node.alternate, initialScope)
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
ExpressionStatement(node, initialScope) {
|
||||
return getStaticValueR(node.expression, initialScope)
|
||||
},
|
||||
|
||||
Identifier(node, initialScope) {
|
||||
if (initialScope != null) {
|
||||
const variable = findVariable(initialScope, node);
|
||||
|
||||
// Built-in globals.
|
||||
if (
|
||||
variable != null &&
|
||||
variable.defs.length === 0 &&
|
||||
builtinNames.has(variable.name) &&
|
||||
variable.name in globalObject
|
||||
) {
|
||||
return { value: globalObject[variable.name] }
|
||||
}
|
||||
|
||||
// Constants.
|
||||
if (variable != null && variable.defs.length === 1) {
|
||||
const def = variable.defs[0];
|
||||
if (
|
||||
def.parent &&
|
||||
def.type === "Variable" &&
|
||||
(def.parent.kind === "const" ||
|
||||
isEffectivelyConst(variable)) &&
|
||||
// TODO(mysticatea): don't support destructuring here.
|
||||
def.node.id.type === "Identifier"
|
||||
) {
|
||||
return getStaticValueR(def.node.init, initialScope)
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
Literal(node) {
|
||||
//istanbul ignore if : this is implementation-specific behavior.
|
||||
if ((node.regex != null || node.bigint != null) && node.value == null) {
|
||||
// It was a RegExp/BigInt literal, but Node.js didn't support it.
|
||||
return null
|
||||
}
|
||||
return { value: node.value }
|
||||
},
|
||||
|
||||
LogicalExpression(node, initialScope) {
|
||||
const left = getStaticValueR(node.left, initialScope);
|
||||
if (left != null) {
|
||||
if (
|
||||
(node.operator === "||" && Boolean(left.value) === true) ||
|
||||
(node.operator === "&&" && Boolean(left.value) === false) ||
|
||||
(node.operator === "??" && left.value != null)
|
||||
) {
|
||||
return left
|
||||
}
|
||||
|
||||
const right = getStaticValueR(node.right, initialScope);
|
||||
if (right != null) {
|
||||
return right
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
MemberExpression(node, initialScope) {
|
||||
if (node.property.type === "PrivateIdentifier") {
|
||||
return null
|
||||
}
|
||||
const object = getStaticValueR(node.object, initialScope);
|
||||
if (object != null) {
|
||||
if (object.value == null && (object.optional || node.optional)) {
|
||||
return { value: undefined, optional: true }
|
||||
}
|
||||
const property = getStaticPropertyNameValue(node, initialScope);
|
||||
|
||||
if (property != null) {
|
||||
if (!isGetter(object.value, property.value)) {
|
||||
return { value: object.value[property.value] }
|
||||
}
|
||||
|
||||
for (const [classFn, allowed] of getterAllowed) {
|
||||
if (
|
||||
object.value instanceof classFn &&
|
||||
allowed.has(property.value)
|
||||
) {
|
||||
return { value: object.value[property.value] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
ChainExpression(node, initialScope) {
|
||||
const expression = getStaticValueR(node.expression, initialScope);
|
||||
if (expression != null) {
|
||||
return { value: expression.value }
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
NewExpression(node, initialScope) {
|
||||
const callee = getStaticValueR(node.callee, initialScope);
|
||||
const args = getElementValues(node.arguments, initialScope);
|
||||
|
||||
if (callee != null && args != null) {
|
||||
const Func = callee.value;
|
||||
if (callAllowed.has(Func)) {
|
||||
return { value: new Func(...args) }
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
ObjectExpression(node, initialScope) {
|
||||
const object = {};
|
||||
|
||||
for (const propertyNode of node.properties) {
|
||||
if (propertyNode.type === "Property") {
|
||||
if (propertyNode.kind !== "init") {
|
||||
return null
|
||||
}
|
||||
const key = getStaticPropertyNameValue(
|
||||
propertyNode,
|
||||
initialScope,
|
||||
);
|
||||
const value = getStaticValueR(propertyNode.value, initialScope);
|
||||
if (key == null || value == null) {
|
||||
return null
|
||||
}
|
||||
object[key.value] = value.value;
|
||||
} else if (
|
||||
propertyNode.type === "SpreadElement" ||
|
||||
propertyNode.type === "ExperimentalSpreadProperty"
|
||||
) {
|
||||
const argument = getStaticValueR(
|
||||
propertyNode.argument,
|
||||
initialScope,
|
||||
);
|
||||
if (argument == null) {
|
||||
return null
|
||||
}
|
||||
Object.assign(object, argument.value);
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
return { value: object }
|
||||
},
|
||||
|
||||
SequenceExpression(node, initialScope) {
|
||||
const last = node.expressions[node.expressions.length - 1];
|
||||
return getStaticValueR(last, initialScope)
|
||||
},
|
||||
|
||||
TaggedTemplateExpression(node, initialScope) {
|
||||
const tag = getStaticValueR(node.tag, initialScope);
|
||||
const expressions = getElementValues(
|
||||
node.quasi.expressions,
|
||||
initialScope,
|
||||
);
|
||||
|
||||
if (tag != null && expressions != null) {
|
||||
const func = tag.value;
|
||||
const strings = node.quasi.quasis.map((q) => q.value.cooked);
|
||||
strings.raw = node.quasi.quasis.map((q) => q.value.raw);
|
||||
|
||||
if (func === String.raw) {
|
||||
return { value: func(strings, ...expressions) }
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
TemplateLiteral(node, initialScope) {
|
||||
const expressions = getElementValues(node.expressions, initialScope);
|
||||
if (expressions != null) {
|
||||
let value = node.quasis[0].value.cooked;
|
||||
for (let i = 0; i < expressions.length; ++i) {
|
||||
value += expressions[i];
|
||||
value += node.quasis[i + 1].value.cooked;
|
||||
}
|
||||
return { value }
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
UnaryExpression(node, initialScope) {
|
||||
if (node.operator === "delete") {
|
||||
// Not supported.
|
||||
return null
|
||||
}
|
||||
if (node.operator === "void") {
|
||||
return { value: undefined }
|
||||
}
|
||||
|
||||
const arg = getStaticValueR(node.argument, initialScope);
|
||||
if (arg != null) {
|
||||
switch (node.operator) {
|
||||
case "-":
|
||||
return { value: -arg.value }
|
||||
case "+":
|
||||
return { value: +arg.value } //eslint-disable-line no-implicit-coercion
|
||||
case "!":
|
||||
return { value: !arg.value }
|
||||
case "~":
|
||||
return { value: ~arg.value }
|
||||
case "typeof":
|
||||
return { value: typeof arg.value }
|
||||
|
||||
// no default
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the value of a given node if it's a static value.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {Scope|undefined} initialScope The scope to start finding variable.
|
||||
* @returns {{value:any}|{value:undefined,optional?:true}|null} The static value of the node, or `null`.
|
||||
*/
|
||||
function getStaticValueR(node, initialScope) {
|
||||
if (node != null && Object.hasOwnProperty.call(operations, node.type)) {
|
||||
return operations[node.type](node, initialScope)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the static value of property name from a MemberExpression node or a Property node.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {Scope} [initialScope] The scope to start finding variable. Optional. If the node is a computed property node and this scope was given, this checks the computed property name by the `getStringIfConstant` function with the scope, and returns the value of it.
|
||||
* @returns {{value:any}|{value:undefined,optional?:true}|null} The static value of the property name of the node, or `null`.
|
||||
*/
|
||||
function getStaticPropertyNameValue(node, initialScope) {
|
||||
const nameNode = node.type === "Property" ? node.key : node.property;
|
||||
|
||||
if (node.computed) {
|
||||
return getStaticValueR(nameNode, initialScope)
|
||||
}
|
||||
|
||||
if (nameNode.type === "Identifier") {
|
||||
return { value: nameNode.name }
|
||||
}
|
||||
|
||||
if (nameNode.type === "Literal") {
|
||||
if (nameNode.bigint) {
|
||||
return { value: nameNode.bigint }
|
||||
}
|
||||
return { value: String(nameNode.value) }
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a given node if it's a static value.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {Scope} [initialScope] The scope to start finding variable. Optional. If this scope was given, this tries to resolve identifier references which are in the given node as much as possible.
|
||||
* @returns {{value:any}|{value:undefined,optional?:true}|null} The static value of the node, or `null`.
|
||||
*/
|
||||
function getStaticValue(node, initialScope = null) {
|
||||
try {
|
||||
return getStaticValueR(node, initialScope)
|
||||
} catch (_error) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a given node if it's a literal or a template literal.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {Scope} [initialScope] The scope to start finding variable. Optional. If the node is an Identifier node and this scope was given, this checks the variable of the identifier, and returns the value of it if the variable is a constant.
|
||||
* @returns {string|null} The value of the node, or `null`.
|
||||
*/
|
||||
function getStringIfConstant(node, initialScope = null) {
|
||||
// Handle the literals that the platform doesn't support natively.
|
||||
if (node && node.type === "Literal" && node.value === null) {
|
||||
if (node.regex) {
|
||||
return `/${node.regex.pattern}/${node.regex.flags}`
|
||||
}
|
||||
if (node.bigint) {
|
||||
return node.bigint
|
||||
}
|
||||
}
|
||||
|
||||
const evaluated = getStaticValue(node, initialScope);
|
||||
return evaluated && String(evaluated.value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property name from a MemberExpression node or a Property node.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {Scope} [initialScope] The scope to start finding variable. Optional. If the node is a computed property node and this scope was given, this checks the computed property name by the `getStringIfConstant` function with the scope, and returns the value of it.
|
||||
* @returns {string|null} The property name of the node.
|
||||
*/
|
||||
function getPropertyName(node, initialScope) {
|
||||
switch (node.type) {
|
||||
case "MemberExpression":
|
||||
if (node.computed) {
|
||||
return getStringIfConstant(node.property, initialScope)
|
||||
}
|
||||
if (node.property.type === "PrivateIdentifier") {
|
||||
return null
|
||||
}
|
||||
return node.property.name
|
||||
|
||||
case "Property":
|
||||
case "MethodDefinition":
|
||||
case "PropertyDefinition":
|
||||
if (node.computed) {
|
||||
return getStringIfConstant(node.key, initialScope)
|
||||
}
|
||||
if (node.key.type === "Literal") {
|
||||
return String(node.key.value)
|
||||
}
|
||||
if (node.key.type === "PrivateIdentifier") {
|
||||
return null
|
||||
}
|
||||
return node.key.name
|
||||
|
||||
// no default
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name and kind of the given function node.
|
||||
* @param {ASTNode} node - The function node to get.
|
||||
* @param {SourceCode} [sourceCode] The source code object to get the code of computed property keys.
|
||||
* @returns {string} The name and kind of the function node.
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
function getFunctionNameWithKind(node, sourceCode) {
|
||||
const parent = node.parent;
|
||||
const tokens = [];
|
||||
const isObjectMethod = parent.type === "Property" && parent.value === node;
|
||||
const isClassMethod =
|
||||
parent.type === "MethodDefinition" && parent.value === node;
|
||||
const isClassFieldMethod =
|
||||
parent.type === "PropertyDefinition" && parent.value === node;
|
||||
|
||||
// Modifiers.
|
||||
if (isClassMethod || isClassFieldMethod) {
|
||||
if (parent.static) {
|
||||
tokens.push("static");
|
||||
}
|
||||
if (parent.key.type === "PrivateIdentifier") {
|
||||
tokens.push("private");
|
||||
}
|
||||
}
|
||||
if (node.async) {
|
||||
tokens.push("async");
|
||||
}
|
||||
if (node.generator) {
|
||||
tokens.push("generator");
|
||||
}
|
||||
|
||||
// Kinds.
|
||||
if (isObjectMethod || isClassMethod) {
|
||||
if (parent.kind === "constructor") {
|
||||
return "constructor"
|
||||
}
|
||||
if (parent.kind === "get") {
|
||||
tokens.push("getter");
|
||||
} else if (parent.kind === "set") {
|
||||
tokens.push("setter");
|
||||
} else {
|
||||
tokens.push("method");
|
||||
}
|
||||
} else if (isClassFieldMethod) {
|
||||
tokens.push("method");
|
||||
} else {
|
||||
if (node.type === "ArrowFunctionExpression") {
|
||||
tokens.push("arrow");
|
||||
}
|
||||
tokens.push("function");
|
||||
}
|
||||
|
||||
// Names.
|
||||
if (isObjectMethod || isClassMethod || isClassFieldMethod) {
|
||||
if (parent.key.type === "PrivateIdentifier") {
|
||||
tokens.push(`#${parent.key.name}`);
|
||||
} else {
|
||||
const name = getPropertyName(parent);
|
||||
if (name) {
|
||||
tokens.push(`'${name}'`);
|
||||
} else if (sourceCode) {
|
||||
const keyText = sourceCode.getText(parent.key);
|
||||
if (!keyText.includes("\n")) {
|
||||
tokens.push(`[${keyText}]`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (node.id) {
|
||||
tokens.push(`'${node.id.name}'`);
|
||||
} else if (
|
||||
parent.type === "VariableDeclarator" &&
|
||||
parent.id &&
|
||||
parent.id.type === "Identifier"
|
||||
) {
|
||||
tokens.push(`'${parent.id.name}'`);
|
||||
} else if (
|
||||
(parent.type === "AssignmentExpression" ||
|
||||
parent.type === "AssignmentPattern") &&
|
||||
parent.left &&
|
||||
parent.left.type === "Identifier"
|
||||
) {
|
||||
tokens.push(`'${parent.left.name}'`);
|
||||
} else if (
|
||||
parent.type === "ExportDefaultDeclaration" &&
|
||||
parent.declaration === node
|
||||
) {
|
||||
tokens.push("'default'");
|
||||
}
|
||||
|
||||
return tokens.join(" ")
|
||||
}
|
||||
|
||||
const typeConversionBinaryOps = Object.freeze(
|
||||
new Set([
|
||||
"==",
|
||||
"!=",
|
||||
"<",
|
||||
"<=",
|
||||
">",
|
||||
">=",
|
||||
"<<",
|
||||
">>",
|
||||
">>>",
|
||||
"+",
|
||||
"-",
|
||||
"*",
|
||||
"/",
|
||||
"%",
|
||||
"|",
|
||||
"^",
|
||||
"&",
|
||||
"in",
|
||||
]),
|
||||
);
|
||||
const typeConversionUnaryOps = Object.freeze(new Set(["-", "+", "!", "~"]));
|
||||
|
||||
/**
|
||||
* Check whether the given value is an ASTNode or not.
|
||||
* @param {any} x The value to check.
|
||||
* @returns {boolean} `true` if the value is an ASTNode.
|
||||
*/
|
||||
function isNode(x) {
|
||||
return x !== null && typeof x === "object" && typeof x.type === "string"
|
||||
}
|
||||
|
||||
const visitor = Object.freeze(
|
||||
Object.assign(Object.create(null), {
|
||||
$visit(node, options, visitorKeys) {
|
||||
const { type } = node;
|
||||
|
||||
if (typeof this[type] === "function") {
|
||||
return this[type](node, options, visitorKeys)
|
||||
}
|
||||
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
|
||||
$visitChildren(node, options, visitorKeys) {
|
||||
const { type } = node;
|
||||
|
||||
for (const key of visitorKeys[type] || getKeys(node)) {
|
||||
const value = node[key];
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
for (const element of value) {
|
||||
if (
|
||||
isNode(element) &&
|
||||
this.$visit(element, options, visitorKeys)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
isNode(value) &&
|
||||
this.$visit(value, options, visitorKeys)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
|
||||
ArrowFunctionExpression() {
|
||||
return false
|
||||
},
|
||||
AssignmentExpression() {
|
||||
return true
|
||||
},
|
||||
AwaitExpression() {
|
||||
return true
|
||||
},
|
||||
BinaryExpression(node, options, visitorKeys) {
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
typeConversionBinaryOps.has(node.operator) &&
|
||||
(node.left.type !== "Literal" || node.right.type !== "Literal")
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
CallExpression() {
|
||||
return true
|
||||
},
|
||||
FunctionExpression() {
|
||||
return false
|
||||
},
|
||||
ImportExpression() {
|
||||
return true
|
||||
},
|
||||
MemberExpression(node, options, visitorKeys) {
|
||||
if (options.considerGetters) {
|
||||
return true
|
||||
}
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
node.computed &&
|
||||
node.property.type !== "Literal"
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
MethodDefinition(node, options, visitorKeys) {
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
node.computed &&
|
||||
node.key.type !== "Literal"
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
NewExpression() {
|
||||
return true
|
||||
},
|
||||
Property(node, options, visitorKeys) {
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
node.computed &&
|
||||
node.key.type !== "Literal"
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
PropertyDefinition(node, options, visitorKeys) {
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
node.computed &&
|
||||
node.key.type !== "Literal"
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
UnaryExpression(node, options, visitorKeys) {
|
||||
if (node.operator === "delete") {
|
||||
return true
|
||||
}
|
||||
if (
|
||||
options.considerImplicitTypeConversion &&
|
||||
typeConversionUnaryOps.has(node.operator) &&
|
||||
node.argument.type !== "Literal"
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return this.$visitChildren(node, options, visitorKeys)
|
||||
},
|
||||
UpdateExpression() {
|
||||
return true
|
||||
},
|
||||
YieldExpression() {
|
||||
return true
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* Check whether a given node has any side effect or not.
|
||||
* @param {Node} node The node to get.
|
||||
* @param {SourceCode} sourceCode The source code object.
|
||||
* @param {object} [options] The option object.
|
||||
* @param {boolean} [options.considerGetters=false] If `true` then it considers member accesses as the node which has side effects.
|
||||
* @param {boolean} [options.considerImplicitTypeConversion=false] If `true` then it considers implicit type conversion as the node which has side effects.
|
||||
* @param {object} [options.visitorKeys=KEYS] The keys to traverse nodes. Use `context.getSourceCode().visitorKeys`.
|
||||
* @returns {boolean} `true` if the node has a certain side effect.
|
||||
*/
|
||||
function hasSideEffect(
|
||||
node,
|
||||
sourceCode,
|
||||
{ considerGetters = false, considerImplicitTypeConversion = false } = {},
|
||||
) {
|
||||
return visitor.$visit(
|
||||
node,
|
||||
{ considerGetters, considerImplicitTypeConversion },
|
||||
sourceCode.visitorKeys || KEYS,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the left parenthesis of the parent node syntax if it exists.
|
||||
* E.g., `if (a) {}` then the `(`.
|
||||
* @param {Node} node The AST node to check.
|
||||
* @param {SourceCode} sourceCode The source code object to get tokens.
|
||||
* @returns {Token|null} The left parenthesis of the parent node syntax
|
||||
*/
|
||||
function getParentSyntaxParen(node, sourceCode) {
|
||||
const parent = node.parent;
|
||||
|
||||
switch (parent.type) {
|
||||
case "CallExpression":
|
||||
case "NewExpression":
|
||||
if (parent.arguments.length === 1 && parent.arguments[0] === node) {
|
||||
return sourceCode.getTokenAfter(
|
||||
parent.callee,
|
||||
isOpeningParenToken,
|
||||
)
|
||||
}
|
||||
return null
|
||||
|
||||
case "DoWhileStatement":
|
||||
if (parent.test === node) {
|
||||
return sourceCode.getTokenAfter(
|
||||
parent.body,
|
||||
isOpeningParenToken,
|
||||
)
|
||||
}
|
||||
return null
|
||||
|
||||
case "IfStatement":
|
||||
case "WhileStatement":
|
||||
if (parent.test === node) {
|
||||
return sourceCode.getFirstToken(parent, 1)
|
||||
}
|
||||
return null
|
||||
|
||||
case "ImportExpression":
|
||||
if (parent.source === node) {
|
||||
return sourceCode.getFirstToken(parent, 1)
|
||||
}
|
||||
return null
|
||||
|
||||
case "SwitchStatement":
|
||||
if (parent.discriminant === node) {
|
||||
return sourceCode.getFirstToken(parent, 1)
|
||||
}
|
||||
return null
|
||||
|
||||
case "WithStatement":
|
||||
if (parent.object === node) {
|
||||
return sourceCode.getFirstToken(parent, 1)
|
||||
}
|
||||
return null
|
||||
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given node is parenthesized or not.
|
||||
* @param {number} times The number of parantheses.
|
||||
* @param {Node} node The AST node to check.
|
||||
* @param {SourceCode} sourceCode The source code object to get tokens.
|
||||
* @returns {boolean} `true` if the node is parenthesized the given times.
|
||||
*/
|
||||
/**
|
||||
* Check whether a given node is parenthesized or not.
|
||||
* @param {Node} node The AST node to check.
|
||||
* @param {SourceCode} sourceCode The source code object to get tokens.
|
||||
* @returns {boolean} `true` if the node is parenthesized.
|
||||
*/
|
||||
function isParenthesized(
|
||||
timesOrNode,
|
||||
nodeOrSourceCode,
|
||||
optionalSourceCode,
|
||||
) {
|
||||
let times, node, sourceCode, maybeLeftParen, maybeRightParen;
|
||||
if (typeof timesOrNode === "number") {
|
||||
times = timesOrNode | 0;
|
||||
node = nodeOrSourceCode;
|
||||
sourceCode = optionalSourceCode;
|
||||
if (!(times >= 1)) {
|
||||
throw new TypeError("'times' should be a positive integer.")
|
||||
}
|
||||
} else {
|
||||
times = 1;
|
||||
node = timesOrNode;
|
||||
sourceCode = nodeOrSourceCode;
|
||||
}
|
||||
|
||||
if (
|
||||
node == null ||
|
||||
// `Program` can't be parenthesized
|
||||
node.parent == null ||
|
||||
// `CatchClause.param` can't be parenthesized, example `try {} catch (error) {}`
|
||||
(node.parent.type === "CatchClause" && node.parent.param === node)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
maybeLeftParen = maybeRightParen = node;
|
||||
do {
|
||||
maybeLeftParen = sourceCode.getTokenBefore(maybeLeftParen);
|
||||
maybeRightParen = sourceCode.getTokenAfter(maybeRightParen);
|
||||
} while (
|
||||
maybeLeftParen != null &&
|
||||
maybeRightParen != null &&
|
||||
isOpeningParenToken(maybeLeftParen) &&
|
||||
isClosingParenToken(maybeRightParen) &&
|
||||
// Avoid false positive such as `if (a) {}`
|
||||
maybeLeftParen !== getParentSyntaxParen(node, sourceCode) &&
|
||||
--times > 0
|
||||
)
|
||||
|
||||
return times === 0
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
* See LICENSE file in root directory for full license.
|
||||
*/
|
||||
|
||||
const placeholder = /\$(?:[$&`']|[1-9][0-9]?)/gu;
|
||||
|
||||
/** @type {WeakMap<PatternMatcher, {pattern:RegExp,escaped:boolean}>} */
|
||||
const internal = new WeakMap();
|
||||
|
||||
/**
|
||||
* Check whether a given character is escaped or not.
|
||||
* @param {string} str The string to check.
|
||||
* @param {number} index The location of the character to check.
|
||||
* @returns {boolean} `true` if the character is escaped.
|
||||
*/
|
||||
function isEscaped(str, index) {
|
||||
let escaped = false;
|
||||
for (let i = index - 1; i >= 0 && str.charCodeAt(i) === 0x5c; --i) {
|
||||
escaped = !escaped;
|
||||
}
|
||||
return escaped
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a given string by a given matcher.
|
||||
* @param {PatternMatcher} matcher The pattern matcher.
|
||||
* @param {string} str The string to be replaced.
|
||||
* @param {string} replacement The new substring to replace each matched part.
|
||||
* @returns {string} The replaced string.
|
||||
*/
|
||||
function replaceS(matcher, str, replacement) {
|
||||
const chunks = [];
|
||||
let index = 0;
|
||||
|
||||
/** @type {RegExpExecArray} */
|
||||
let match = null;
|
||||
|
||||
/**
|
||||
* @param {string} key The placeholder.
|
||||
* @returns {string} The replaced string.
|
||||
*/
|
||||
function replacer(key) {
|
||||
switch (key) {
|
||||
case "$$":
|
||||
return "$"
|
||||
case "$&":
|
||||
return match[0]
|
||||
case "$`":
|
||||
return str.slice(0, match.index)
|
||||
case "$'":
|
||||
return str.slice(match.index + match[0].length)
|
||||
default: {
|
||||
const i = key.slice(1);
|
||||
if (i in match) {
|
||||
return match[i]
|
||||
}
|
||||
return key
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (match of matcher.execAll(str)) {
|
||||
chunks.push(str.slice(index, match.index));
|
||||
chunks.push(replacement.replace(placeholder, replacer));
|
||||
index = match.index + match[0].length;
|
||||
}
|
||||
chunks.push(str.slice(index));
|
||||
|
||||
return chunks.join("")
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a given string by a given matcher.
|
||||
* @param {PatternMatcher} matcher The pattern matcher.
|
||||
* @param {string} str The string to be replaced.
|
||||
* @param {(...strs[])=>string} replace The function to replace each matched part.
|
||||
* @returns {string} The replaced string.
|
||||
*/
|
||||
function replaceF(matcher, str, replace) {
|
||||
const chunks = [];
|
||||
let index = 0;
|
||||
|
||||
for (const match of matcher.execAll(str)) {
|
||||
chunks.push(str.slice(index, match.index));
|
||||
chunks.push(String(replace(...match, match.index, match.input)));
|
||||
index = match.index + match[0].length;
|
||||
}
|
||||
chunks.push(str.slice(index));
|
||||
|
||||
return chunks.join("")
|
||||
}
|
||||
|
||||
/**
|
||||
* The class to find patterns as considering escape sequences.
|
||||
*/
|
||||
class PatternMatcher {
|
||||
/**
|
||||
* Initialize this matcher.
|
||||
* @param {RegExp} pattern The pattern to match.
|
||||
* @param {{escaped:boolean}} options The options.
|
||||
*/
|
||||
constructor(pattern, { escaped = false } = {}) {
|
||||
if (!(pattern instanceof RegExp)) {
|
||||
throw new TypeError("'pattern' should be a RegExp instance.")
|
||||
}
|
||||
if (!pattern.flags.includes("g")) {
|
||||
throw new Error("'pattern' should contains 'g' flag.")
|
||||
}
|
||||
|
||||
internal.set(this, {
|
||||
pattern: new RegExp(pattern.source, pattern.flags),
|
||||
escaped: Boolean(escaped),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the pattern in a given string.
|
||||
* @param {string} str The string to find.
|
||||
* @returns {IterableIterator<RegExpExecArray>} The iterator which iterate the matched information.
|
||||
*/
|
||||
*execAll(str) {
|
||||
const { pattern, escaped } = internal.get(this);
|
||||
let match = null;
|
||||
let lastIndex = 0;
|
||||
|
||||
pattern.lastIndex = 0;
|
||||
while ((match = pattern.exec(str)) != null) {
|
||||
if (escaped || !isEscaped(str, match.index)) {
|
||||
lastIndex = pattern.lastIndex;
|
||||
yield match;
|
||||
pattern.lastIndex = lastIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the pattern is found in a given string.
|
||||
* @param {string} str The string to check.
|
||||
* @returns {boolean} `true` if the pattern was found in the string.
|
||||
*/
|
||||
test(str) {
|
||||
const it = this.execAll(str);
|
||||
const ret = it.next();
|
||||
return !ret.done
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a given string.
|
||||
* @param {string} str The string to be replaced.
|
||||
* @param {(string|((...strs:string[])=>string))} replacer The string or function to replace. This is the same as the 2nd argument of `String.prototype.replace`.
|
||||
* @returns {string} The replaced string.
|
||||
*/
|
||||
[Symbol.replace](str, replacer) {
|
||||
return typeof replacer === "function"
|
||||
? replaceF(this, String(str), replacer)
|
||||
: replaceS(this, String(str), String(replacer))
|
||||
}
|
||||
}
|
||||
|
||||
const IMPORT_TYPE = /^(?:Import|Export(?:All|Default|Named))Declaration$/u;
|
||||
const has = Function.call.bind(Object.hasOwnProperty);
|
||||
|
||||
const READ = Symbol("read");
|
||||
const CALL = Symbol("call");
|
||||
const CONSTRUCT = Symbol("construct");
|
||||
const ESM = Symbol("esm");
|
||||
|
||||
const requireCall = { require: { [CALL]: true } };
|
||||
|
||||
/**
|
||||
* Check whether a given variable is modified or not.
|
||||
* @param {Variable} variable The variable to check.
|
||||
* @returns {boolean} `true` if the variable is modified.
|
||||
*/
|
||||
function isModifiedGlobal(variable) {
|
||||
return (
|
||||
variable == null ||
|
||||
variable.defs.length !== 0 ||
|
||||
variable.references.some((r) => r.isWrite())
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the value of a given node is passed through to the parent syntax as-is.
|
||||
* For example, `a` and `b` in (`a || b` and `c ? a : b`) are passed through.
|
||||
* @param {Node} node A node to check.
|
||||
* @returns {boolean} `true` if the node is passed through.
|
||||
*/
|
||||
function isPassThrough(node) {
|
||||
const parent = node.parent;
|
||||
|
||||
switch (parent && parent.type) {
|
||||
case "ConditionalExpression":
|
||||
return parent.consequent === node || parent.alternate === node
|
||||
case "LogicalExpression":
|
||||
return true
|
||||
case "SequenceExpression":
|
||||
return parent.expressions[parent.expressions.length - 1] === node
|
||||
case "ChainExpression":
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The reference tracker.
|
||||
*/
|
||||
class ReferenceTracker {
|
||||
/**
|
||||
* Initialize this tracker.
|
||||
* @param {Scope} globalScope The global scope.
|
||||
* @param {object} [options] The options.
|
||||
* @param {"legacy"|"strict"} [options.mode="strict"] The mode to determine the ImportDeclaration's behavior for CJS modules.
|
||||
* @param {string[]} [options.globalObjectNames=["global","globalThis","self","window"]] The variable names for Global Object.
|
||||
*/
|
||||
constructor(
|
||||
globalScope,
|
||||
{
|
||||
mode = "strict",
|
||||
globalObjectNames = ["global", "globalThis", "self", "window"],
|
||||
} = {},
|
||||
) {
|
||||
this.variableStack = [];
|
||||
this.globalScope = globalScope;
|
||||
this.mode = mode;
|
||||
this.globalObjectNames = globalObjectNames.slice(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references of global variables.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*iterateGlobalReferences(traceMap) {
|
||||
for (const key of Object.keys(traceMap)) {
|
||||
const nextTraceMap = traceMap[key];
|
||||
const path = [key];
|
||||
const variable = this.globalScope.set.get(key);
|
||||
|
||||
if (isModifiedGlobal(variable)) {
|
||||
continue
|
||||
}
|
||||
|
||||
yield* this._iterateVariableReferences(
|
||||
variable,
|
||||
path,
|
||||
nextTraceMap,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
for (const key of this.globalObjectNames) {
|
||||
const path = [];
|
||||
const variable = this.globalScope.set.get(key);
|
||||
|
||||
if (isModifiedGlobal(variable)) {
|
||||
continue
|
||||
}
|
||||
|
||||
yield* this._iterateVariableReferences(
|
||||
variable,
|
||||
path,
|
||||
traceMap,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references of CommonJS modules.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*iterateCjsReferences(traceMap) {
|
||||
for (const { node } of this.iterateGlobalReferences(requireCall)) {
|
||||
const key = getStringIfConstant(node.arguments[0]);
|
||||
if (key == null || !has(traceMap, key)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const nextTraceMap = traceMap[key];
|
||||
const path = [key];
|
||||
|
||||
if (nextTraceMap[READ]) {
|
||||
yield {
|
||||
node,
|
||||
path,
|
||||
type: READ,
|
||||
info: nextTraceMap[READ],
|
||||
};
|
||||
}
|
||||
yield* this._iteratePropertyReferences(node, path, nextTraceMap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references of ES modules.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*iterateEsmReferences(traceMap) {
|
||||
const programNode = this.globalScope.block;
|
||||
|
||||
for (const node of programNode.body) {
|
||||
if (!IMPORT_TYPE.test(node.type) || node.source == null) {
|
||||
continue
|
||||
}
|
||||
const moduleId = node.source.value;
|
||||
|
||||
if (!has(traceMap, moduleId)) {
|
||||
continue
|
||||
}
|
||||
const nextTraceMap = traceMap[moduleId];
|
||||
const path = [moduleId];
|
||||
|
||||
if (nextTraceMap[READ]) {
|
||||
yield { node, path, type: READ, info: nextTraceMap[READ] };
|
||||
}
|
||||
|
||||
if (node.type === "ExportAllDeclaration") {
|
||||
for (const key of Object.keys(nextTraceMap)) {
|
||||
const exportTraceMap = nextTraceMap[key];
|
||||
if (exportTraceMap[READ]) {
|
||||
yield {
|
||||
node,
|
||||
path: path.concat(key),
|
||||
type: READ,
|
||||
info: exportTraceMap[READ],
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const specifier of node.specifiers) {
|
||||
const esm = has(nextTraceMap, ESM);
|
||||
const it = this._iterateImportReferences(
|
||||
specifier,
|
||||
path,
|
||||
esm
|
||||
? nextTraceMap
|
||||
: this.mode === "legacy"
|
||||
? { default: nextTraceMap, ...nextTraceMap }
|
||||
: { default: nextTraceMap },
|
||||
);
|
||||
|
||||
if (esm) {
|
||||
yield* it;
|
||||
} else {
|
||||
for (const report of it) {
|
||||
report.path = report.path.filter(exceptDefault);
|
||||
if (
|
||||
report.path.length >= 2 ||
|
||||
report.type !== READ
|
||||
) {
|
||||
yield report;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references for a given variable.
|
||||
* @param {Variable} variable The variable to iterate that references.
|
||||
* @param {string[]} path The current path.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @param {boolean} shouldReport = The flag to report those references.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*_iterateVariableReferences(variable, path, traceMap, shouldReport) {
|
||||
if (this.variableStack.includes(variable)) {
|
||||
return
|
||||
}
|
||||
this.variableStack.push(variable);
|
||||
try {
|
||||
for (const reference of variable.references) {
|
||||
if (!reference.isRead()) {
|
||||
continue
|
||||
}
|
||||
const node = reference.identifier;
|
||||
|
||||
if (shouldReport && traceMap[READ]) {
|
||||
yield { node, path, type: READ, info: traceMap[READ] };
|
||||
}
|
||||
yield* this._iteratePropertyReferences(node, path, traceMap);
|
||||
}
|
||||
} finally {
|
||||
this.variableStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references for a given AST node.
|
||||
* @param rootNode The AST node to iterate references.
|
||||
* @param {string[]} path The current path.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
//eslint-disable-next-line complexity
|
||||
*_iteratePropertyReferences(rootNode, path, traceMap) {
|
||||
let node = rootNode;
|
||||
while (isPassThrough(node)) {
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
const parent = node.parent;
|
||||
if (parent.type === "MemberExpression") {
|
||||
if (parent.object === node) {
|
||||
const key = getPropertyName(parent);
|
||||
if (key == null || !has(traceMap, key)) {
|
||||
return
|
||||
}
|
||||
|
||||
path = path.concat(key); //eslint-disable-line no-param-reassign
|
||||
const nextTraceMap = traceMap[key];
|
||||
if (nextTraceMap[READ]) {
|
||||
yield {
|
||||
node: parent,
|
||||
path,
|
||||
type: READ,
|
||||
info: nextTraceMap[READ],
|
||||
};
|
||||
}
|
||||
yield* this._iteratePropertyReferences(
|
||||
parent,
|
||||
path,
|
||||
nextTraceMap,
|
||||
);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (parent.type === "CallExpression") {
|
||||
if (parent.callee === node && traceMap[CALL]) {
|
||||
yield { node: parent, path, type: CALL, info: traceMap[CALL] };
|
||||
}
|
||||
return
|
||||
}
|
||||
if (parent.type === "NewExpression") {
|
||||
if (parent.callee === node && traceMap[CONSTRUCT]) {
|
||||
yield {
|
||||
node: parent,
|
||||
path,
|
||||
type: CONSTRUCT,
|
||||
info: traceMap[CONSTRUCT],
|
||||
};
|
||||
}
|
||||
return
|
||||
}
|
||||
if (parent.type === "AssignmentExpression") {
|
||||
if (parent.right === node) {
|
||||
yield* this._iterateLhsReferences(parent.left, path, traceMap);
|
||||
yield* this._iteratePropertyReferences(parent, path, traceMap);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (parent.type === "AssignmentPattern") {
|
||||
if (parent.right === node) {
|
||||
yield* this._iterateLhsReferences(parent.left, path, traceMap);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (parent.type === "VariableDeclarator") {
|
||||
if (parent.init === node) {
|
||||
yield* this._iterateLhsReferences(parent.id, path, traceMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references for a given Pattern node.
|
||||
* @param {Node} patternNode The Pattern node to iterate references.
|
||||
* @param {string[]} path The current path.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*_iterateLhsReferences(patternNode, path, traceMap) {
|
||||
if (patternNode.type === "Identifier") {
|
||||
const variable = findVariable(this.globalScope, patternNode);
|
||||
if (variable != null) {
|
||||
yield* this._iterateVariableReferences(
|
||||
variable,
|
||||
path,
|
||||
traceMap,
|
||||
false,
|
||||
);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (patternNode.type === "ObjectPattern") {
|
||||
for (const property of patternNode.properties) {
|
||||
const key = getPropertyName(property);
|
||||
|
||||
if (key == null || !has(traceMap, key)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const nextPath = path.concat(key);
|
||||
const nextTraceMap = traceMap[key];
|
||||
if (nextTraceMap[READ]) {
|
||||
yield {
|
||||
node: property,
|
||||
path: nextPath,
|
||||
type: READ,
|
||||
info: nextTraceMap[READ],
|
||||
};
|
||||
}
|
||||
yield* this._iterateLhsReferences(
|
||||
property.value,
|
||||
nextPath,
|
||||
nextTraceMap,
|
||||
);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (patternNode.type === "AssignmentPattern") {
|
||||
yield* this._iterateLhsReferences(patternNode.left, path, traceMap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate the references for a given ModuleSpecifier node.
|
||||
* @param {Node} specifierNode The ModuleSpecifier node to iterate references.
|
||||
* @param {string[]} path The current path.
|
||||
* @param {object} traceMap The trace map.
|
||||
* @returns {IterableIterator<{node:Node,path:string[],type:symbol,info:any}>} The iterator to iterate references.
|
||||
*/
|
||||
*_iterateImportReferences(specifierNode, path, traceMap) {
|
||||
const type = specifierNode.type;
|
||||
|
||||
if (type === "ImportSpecifier" || type === "ImportDefaultSpecifier") {
|
||||
const key =
|
||||
type === "ImportDefaultSpecifier"
|
||||
? "default"
|
||||
: specifierNode.imported.name;
|
||||
if (!has(traceMap, key)) {
|
||||
return
|
||||
}
|
||||
|
||||
path = path.concat(key); //eslint-disable-line no-param-reassign
|
||||
const nextTraceMap = traceMap[key];
|
||||
if (nextTraceMap[READ]) {
|
||||
yield {
|
||||
node: specifierNode,
|
||||
path,
|
||||
type: READ,
|
||||
info: nextTraceMap[READ],
|
||||
};
|
||||
}
|
||||
yield* this._iterateVariableReferences(
|
||||
findVariable(this.globalScope, specifierNode.local),
|
||||
path,
|
||||
nextTraceMap,
|
||||
false,
|
||||
);
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (type === "ImportNamespaceSpecifier") {
|
||||
yield* this._iterateVariableReferences(
|
||||
findVariable(this.globalScope, specifierNode.local),
|
||||
path,
|
||||
traceMap,
|
||||
false,
|
||||
);
|
||||
return
|
||||
}
|
||||
|
||||
if (type === "ExportSpecifier") {
|
||||
const key = specifierNode.local.name;
|
||||
if (!has(traceMap, key)) {
|
||||
return
|
||||
}
|
||||
|
||||
path = path.concat(key); //eslint-disable-line no-param-reassign
|
||||
const nextTraceMap = traceMap[key];
|
||||
if (nextTraceMap[READ]) {
|
||||
yield {
|
||||
node: specifierNode,
|
||||
path,
|
||||
type: READ,
|
||||
info: nextTraceMap[READ],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReferenceTracker.READ = READ;
|
||||
ReferenceTracker.CALL = CALL;
|
||||
ReferenceTracker.CONSTRUCT = CONSTRUCT;
|
||||
ReferenceTracker.ESM = ESM;
|
||||
|
||||
/**
|
||||
* This is a predicate function for Array#filter.
|
||||
* @param {string} name A name part.
|
||||
* @param {number} index The index of the name.
|
||||
* @returns {boolean} `false` if it's default.
|
||||
*/
|
||||
function exceptDefault(name, index) {
|
||||
return !(index === 1 && name === "default")
|
||||
}
|
||||
|
||||
var index = {
|
||||
CALL,
|
||||
CONSTRUCT,
|
||||
ESM,
|
||||
findVariable,
|
||||
getFunctionHeadLocation,
|
||||
getFunctionNameWithKind,
|
||||
getInnermostScope,
|
||||
getPropertyName,
|
||||
getStaticValue,
|
||||
getStringIfConstant,
|
||||
hasSideEffect,
|
||||
isArrowToken,
|
||||
isClosingBraceToken,
|
||||
isClosingBracketToken,
|
||||
isClosingParenToken,
|
||||
isColonToken,
|
||||
isCommaToken,
|
||||
isCommentToken,
|
||||
isNotArrowToken,
|
||||
isNotClosingBraceToken,
|
||||
isNotClosingBracketToken,
|
||||
isNotClosingParenToken,
|
||||
isNotColonToken,
|
||||
isNotCommaToken,
|
||||
isNotCommentToken,
|
||||
isNotOpeningBraceToken,
|
||||
isNotOpeningBracketToken,
|
||||
isNotOpeningParenToken,
|
||||
isNotSemicolonToken,
|
||||
isOpeningBraceToken,
|
||||
isOpeningBracketToken,
|
||||
isOpeningParenToken,
|
||||
isParenthesized,
|
||||
isSemicolonToken,
|
||||
PatternMatcher,
|
||||
READ,
|
||||
ReferenceTracker,
|
||||
};
|
||||
|
||||
export { CALL, CONSTRUCT, ESM, PatternMatcher, READ, ReferenceTracker, index as default, findVariable, getFunctionHeadLocation, getFunctionNameWithKind, getInnermostScope, getPropertyName, getStaticValue, getStringIfConstant, hasSideEffect, isArrowToken, isClosingBraceToken, isClosingBracketToken, isClosingParenToken, isColonToken, isCommaToken, isCommentToken, isNotArrowToken, isNotClosingBraceToken, isNotClosingBracketToken, isNotClosingParenToken, isNotColonToken, isNotCommaToken, isNotCommentToken, isNotOpeningBraceToken, isNotOpeningBracketToken, isNotOpeningParenToken, isNotSemicolonToken, isOpeningBraceToken, isOpeningBracketToken, isOpeningParenToken, isParenthesized, isSemicolonToken };
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
1
node_modules/@eslint-community/eslint-utils/index.mjs.map
generated
vendored
Normal file
1
node_modules/@eslint-community/eslint-utils/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
73
node_modules/@eslint-community/eslint-utils/package.json
generated
vendored
Normal file
73
node_modules/@eslint-community/eslint-utils/package.json
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"name": "@eslint-community/eslint-utils",
|
||||
"version": "4.4.0",
|
||||
"description": "Utilities for ESLint plugins.",
|
||||
"keywords": [
|
||||
"eslint"
|
||||
],
|
||||
"homepage": "https://github.com/eslint-community/eslint-utils#readme",
|
||||
"bugs": {
|
||||
"url": "https://github.com/eslint-community/eslint-utils/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/eslint-community/eslint-utils"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "Toru Nagashima",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./index.mjs",
|
||||
"require": "./index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "index",
|
||||
"module": "index.mjs",
|
||||
"files": [
|
||||
"index.*"
|
||||
],
|
||||
"scripts": {
|
||||
"prebuild": "npm run -s clean",
|
||||
"build": "rollup -c",
|
||||
"clean": "rimraf .nyc_output coverage index.*",
|
||||
"coverage": "opener ./coverage/lcov-report/index.html",
|
||||
"docs:build": "vitepress build docs",
|
||||
"docs:watch": "vitepress dev docs",
|
||||
"format": "npm run -s format:prettier -- --write",
|
||||
"format:prettier": "prettier .",
|
||||
"format:check": "npm run -s format:prettier -- --check",
|
||||
"lint": "eslint .",
|
||||
"test": "c8 mocha --reporter dot \"test/*.mjs\"",
|
||||
"preversion": "npm test && npm run -s build",
|
||||
"postversion": "git push && git push --tags",
|
||||
"prewatch": "npm run -s clean",
|
||||
"watch": "warun \"{src,test}/**/*.mjs\" -- npm run -s test:mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"eslint-visitor-keys": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint-community/eslint-plugin-mysticatea": "^15.2.0",
|
||||
"c8": "^7.12.0",
|
||||
"dot-prop": "^6.0.1",
|
||||
"eslint": "^8.28.0",
|
||||
"mocha": "^9.2.2",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"opener": "^1.5.2",
|
||||
"prettier": "2.8.4",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "^2.79.1",
|
||||
"rollup-plugin-sourcemaps": "^0.6.3",
|
||||
"semver": "^7.3.8",
|
||||
"vitepress": "^1.0.0-alpha.40",
|
||||
"warun": "^1.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^6.0.0 || ^7.0.0 || >=8.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
}
|
||||
}
|
||||
21
node_modules/@eslint-community/regexpp/LICENSE
generated
vendored
Normal file
21
node_modules/@eslint-community/regexpp/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Toru Nagashima
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
177
node_modules/@eslint-community/regexpp/README.md
generated
vendored
Normal file
177
node_modules/@eslint-community/regexpp/README.md
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
# @eslint-community/regexpp
|
||||
|
||||
[](https://www.npmjs.com/package/@eslint-community/regexpp)
|
||||
[](http://www.npmtrends.com/@eslint-community/regexpp)
|
||||
[](https://github.com/eslint-community/regexpp/actions)
|
||||
[](https://codecov.io/gh/eslint-community/regexpp)
|
||||
|
||||
A regular expression parser for ECMAScript.
|
||||
|
||||
## 💿 Installation
|
||||
|
||||
```bash
|
||||
$ npm install @eslint-community/regexpp
|
||||
```
|
||||
|
||||
- require Node@^12.0.0 || ^14.0.0 || >=16.0.0.
|
||||
|
||||
## 📖 Usage
|
||||
|
||||
```ts
|
||||
import {
|
||||
AST,
|
||||
RegExpParser,
|
||||
RegExpValidator,
|
||||
RegExpVisitor,
|
||||
parseRegExpLiteral,
|
||||
validateRegExpLiteral,
|
||||
visitRegExpAST
|
||||
} from "@eslint-community/regexpp"
|
||||
```
|
||||
|
||||
### parseRegExpLiteral(source, options?)
|
||||
|
||||
Parse a given regular expression literal then make AST object.
|
||||
|
||||
This is equivalent to `new RegExpParser(options).parseLiteral(source)`.
|
||||
|
||||
- **Parameters:**
|
||||
- `source` (`string | RegExp`) The source code to parse.
|
||||
- `options?` ([`RegExpParser.Options`]) The options to parse.
|
||||
- **Return:**
|
||||
- The AST of the regular expression.
|
||||
|
||||
### validateRegExpLiteral(source, options?)
|
||||
|
||||
Validate a given regular expression literal.
|
||||
|
||||
This is equivalent to `new RegExpValidator(options).validateLiteral(source)`.
|
||||
|
||||
- **Parameters:**
|
||||
- `source` (`string`) The source code to validate.
|
||||
- `options?` ([`RegExpValidator.Options`]) The options to validate.
|
||||
|
||||
### visitRegExpAST(ast, handlers)
|
||||
|
||||
Visit each node of a given AST.
|
||||
|
||||
This is equivalent to `new RegExpVisitor(handlers).visit(ast)`.
|
||||
|
||||
- **Parameters:**
|
||||
- `ast` ([`AST.Node`]) The AST to visit.
|
||||
- `handlers` ([`RegExpVisitor.Handlers`]) The callbacks.
|
||||
|
||||
### RegExpParser
|
||||
|
||||
#### new RegExpParser(options?)
|
||||
|
||||
- **Parameters:**
|
||||
- `options?` ([`RegExpParser.Options`]) The options to parse.
|
||||
|
||||
#### parser.parseLiteral(source, start?, end?)
|
||||
|
||||
Parse a regular expression literal.
|
||||
|
||||
- **Parameters:**
|
||||
- `source` (`string`) The source code to parse. E.g. `"/abc/g"`.
|
||||
- `start?` (`number`) The start index in the source code. Default is `0`.
|
||||
- `end?` (`number`) The end index in the source code. Default is `source.length`.
|
||||
- **Return:**
|
||||
- The AST of the regular expression.
|
||||
|
||||
#### parser.parsePattern(source, start?, end?, flags?)
|
||||
|
||||
Parse a regular expression pattern.
|
||||
|
||||
- **Parameters:**
|
||||
- `source` (`string`) The source code to parse. E.g. `"abc"`.
|
||||
- `start?` (`number`) The start index in the source code. Default is `0`.
|
||||
- `end?` (`number`) The end index in the source code. Default is `source.length`.
|
||||
- `flags?` (`{ unicode?: boolean, unicodeSets?: boolean }`) The flags to enable Unicode mode, and Unicode Set mode.
|
||||
- **Return:**
|
||||
- The AST of the regular expression pattern.
|
||||
|
||||
#### parser.parseFlags(source, start?, end?)
|
||||
|
||||
Parse a regular expression flags.
|
||||
|
||||
- **Parameters:**
|
||||
- `source` (`string`) The source code to parse. E.g. `"gim"`.
|
||||
- `start?` (`number`) The start index in the source code. Default is `0`.
|
||||
- `end?` (`number`) The end index in the source code. Default is `source.length`.
|
||||
- **Return:**
|
||||
- The AST of the regular expression flags.
|
||||
|
||||
### RegExpValidator
|
||||
|
||||
#### new RegExpValidator(options)
|
||||
|
||||
- **Parameters:**
|
||||
- `options` ([`RegExpValidator.Options`]) The options to validate.
|
||||
|
||||
#### validator.validateLiteral(source, start, end)
|
||||
|
||||
Validate a regular expression literal.
|
||||
|
||||
- **Parameters:**
|
||||
- `source` (`string`) The source code to validate.
|
||||
- `start?` (`number`) The start index in the source code. Default is `0`.
|
||||
- `end?` (`number`) The end index in the source code. Default is `source.length`.
|
||||
|
||||
#### validator.validatePattern(source, start, end, flags)
|
||||
|
||||
Validate a regular expression pattern.
|
||||
|
||||
- **Parameters:**
|
||||
- `source` (`string`) The source code to validate.
|
||||
- `start?` (`number`) The start index in the source code. Default is `0`.
|
||||
- `end?` (`number`) The end index in the source code. Default is `source.length`.
|
||||
- `flags?` (`{ unicode?: boolean, unicodeSets?: boolean }`) The flags to enable Unicode mode, and Unicode Set mode.
|
||||
|
||||
#### validator.validateFlags(source, start, end)
|
||||
|
||||
Validate a regular expression flags.
|
||||
|
||||
- **Parameters:**
|
||||
- `source` (`string`) The source code to validate.
|
||||
- `start?` (`number`) The start index in the source code. Default is `0`.
|
||||
- `end?` (`number`) The end index in the source code. Default is `source.length`.
|
||||
|
||||
### RegExpVisitor
|
||||
|
||||
#### new RegExpVisitor(handlers)
|
||||
|
||||
- **Parameters:**
|
||||
- `handlers` ([`RegExpVisitor.Handlers`]) The callbacks.
|
||||
|
||||
#### visitor.visit(ast)
|
||||
|
||||
Validate a regular expression literal.
|
||||
|
||||
- **Parameters:**
|
||||
- `ast` ([`AST.Node`]) The AST to visit.
|
||||
|
||||
## 📰 Changelog
|
||||
|
||||
- [GitHub Releases](https://github.com/eslint-community/regexpp/releases)
|
||||
|
||||
## 🍻 Contributing
|
||||
|
||||
Welcome contributing!
|
||||
|
||||
Please use GitHub's Issues/PRs.
|
||||
|
||||
### Development Tools
|
||||
|
||||
- `npm test` runs tests and measures coverage.
|
||||
- `npm run build` compiles TypeScript source code to `index.js`, `index.js.map`, and `index.d.ts`.
|
||||
- `npm run clean` removes the temporary files which are created by `npm test` and `npm run build`.
|
||||
- `npm run lint` runs ESLint.
|
||||
- `npm run update:test` updates test fixtures.
|
||||
- `npm run update:ids` updates `src/unicode/ids.ts`.
|
||||
- `npm run watch` runs tests with `--watch` option.
|
||||
|
||||
[`AST.Node`]: src/ast.ts#L4
|
||||
[`RegExpParser.Options`]: src/parser.ts#L743
|
||||
[`RegExpValidator.Options`]: src/validator.ts#L220
|
||||
[`RegExpVisitor.Handlers`]: src/visitor.ts#L291
|
||||
1065
node_modules/@eslint-community/regexpp/index.d.ts
generated
vendored
Normal file
1065
node_modules/@eslint-community/regexpp/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,1065 @@
|
||||
// Generated by dts-bundle v0.7.3
|
||||
|
||||
declare module "@eslint-community/regexpp" {
|
||||
import * as AST from "@eslint-community/regexpp/ast";
|
||||
import { RegExpParser } from "@eslint-community/regexpp/parser";
|
||||
import { RegExpValidator } from "@eslint-community/regexpp/validator";
|
||||
import { RegExpVisitor } from "@eslint-community/regexpp/visitor";
|
||||
export { RegExpSyntaxError } from "@eslint-community/regexpp/regexp-syntax-error";
|
||||
export { AST, RegExpParser, RegExpValidator };
|
||||
/**
|
||||
* Parse a given regular expression literal then make AST object.
|
||||
* @param source The source code to parse.
|
||||
* @param options The options to parse.
|
||||
* @returns The AST of the regular expression.
|
||||
*/
|
||||
export function parseRegExpLiteral(
|
||||
source: RegExp | string,
|
||||
options?: RegExpParser.Options
|
||||
): AST.RegExpLiteral;
|
||||
/**
|
||||
* Validate a given regular expression literal.
|
||||
* @param source The source code to validate.
|
||||
* @param options The options to validate.
|
||||
*/
|
||||
export function validateRegExpLiteral(
|
||||
source: string,
|
||||
options?: RegExpValidator.Options
|
||||
): void;
|
||||
export function visitRegExpAST(
|
||||
node: AST.Node,
|
||||
handlers: RegExpVisitor.Handlers
|
||||
): void;
|
||||
}
|
||||
|
||||
declare module "@eslint-community/regexpp/ast" {
|
||||
/**
|
||||
* The type which includes all nodes.
|
||||
*/
|
||||
export type Node = BranchNode | LeafNode;
|
||||
/**
|
||||
* The type which includes all branch nodes.
|
||||
*/
|
||||
export type BranchNode =
|
||||
| Alternative
|
||||
| CapturingGroup
|
||||
| CharacterClass
|
||||
| CharacterClassRange
|
||||
| ClassIntersection
|
||||
| ClassStringDisjunction
|
||||
| ClassSubtraction
|
||||
| ExpressionCharacterClass
|
||||
| Group
|
||||
| LookaroundAssertion
|
||||
| Pattern
|
||||
| Quantifier
|
||||
| RegExpLiteral
|
||||
| StringAlternative;
|
||||
/**
|
||||
* The type which includes all leaf nodes.
|
||||
*/
|
||||
export type LeafNode =
|
||||
| Backreference
|
||||
| BoundaryAssertion
|
||||
| Character
|
||||
| CharacterSet
|
||||
| Flags;
|
||||
/**
|
||||
* The type which includes all atom nodes.
|
||||
*/
|
||||
export type Element = Assertion | QuantifiableElement | Quantifier;
|
||||
/**
|
||||
* The type which includes all atom nodes that Quantifier node can have as children.
|
||||
*/
|
||||
export type QuantifiableElement =
|
||||
| Backreference
|
||||
| CapturingGroup
|
||||
| Character
|
||||
| CharacterClass
|
||||
| CharacterSet
|
||||
| ExpressionCharacterClass
|
||||
| Group
|
||||
| LookaheadAssertion;
|
||||
/**
|
||||
* The type which includes all character class atom nodes.
|
||||
*/
|
||||
export type CharacterClassElement =
|
||||
| ClassRangesCharacterClassElement
|
||||
| UnicodeSetsCharacterClassElement;
|
||||
export type ClassRangesCharacterClassElement =
|
||||
| Character
|
||||
| CharacterClassRange
|
||||
| CharacterUnicodePropertyCharacterSet
|
||||
| EscapeCharacterSet;
|
||||
export type UnicodeSetsCharacterClassElement =
|
||||
| Character
|
||||
| CharacterClassRange
|
||||
| ClassStringDisjunction
|
||||
| EscapeCharacterSet
|
||||
| ExpressionCharacterClass
|
||||
| UnicodePropertyCharacterSet
|
||||
| UnicodeSetsCharacterClass;
|
||||
/**
|
||||
* The type which defines common properties for all node types.
|
||||
*/
|
||||
export interface NodeBase {
|
||||
/** The node type. */
|
||||
type: Node["type"];
|
||||
/** The parent node. */
|
||||
parent: Node["parent"];
|
||||
/** The 0-based index that this node starts. */
|
||||
start: number;
|
||||
/** The 0-based index that this node ends. */
|
||||
end: number;
|
||||
/** The raw text of this node. */
|
||||
raw: string;
|
||||
}
|
||||
/**
|
||||
* The root node.
|
||||
*/
|
||||
export interface RegExpLiteral extends NodeBase {
|
||||
type: "RegExpLiteral";
|
||||
parent: null;
|
||||
pattern: Pattern;
|
||||
flags: Flags;
|
||||
}
|
||||
/**
|
||||
* The pattern.
|
||||
*/
|
||||
export interface Pattern extends NodeBase {
|
||||
type: "Pattern";
|
||||
parent: RegExpLiteral | null;
|
||||
alternatives: Alternative[];
|
||||
}
|
||||
/**
|
||||
* The alternative.
|
||||
* E.g. `a|b`
|
||||
*/
|
||||
export interface Alternative extends NodeBase {
|
||||
type: "Alternative";
|
||||
parent: CapturingGroup | Group | LookaroundAssertion | Pattern;
|
||||
elements: Element[];
|
||||
}
|
||||
/**
|
||||
* The uncapturing group.
|
||||
* E.g. `(?:ab)`
|
||||
*/
|
||||
export interface Group extends NodeBase {
|
||||
type: "Group";
|
||||
parent: Alternative | Quantifier;
|
||||
alternatives: Alternative[];
|
||||
}
|
||||
/**
|
||||
* The capturing group.
|
||||
* E.g. `(ab)`, `(?<name>ab)`
|
||||
*/
|
||||
export interface CapturingGroup extends NodeBase {
|
||||
type: "CapturingGroup";
|
||||
parent: Alternative | Quantifier;
|
||||
name: string | null;
|
||||
alternatives: Alternative[];
|
||||
references: Backreference[];
|
||||
}
|
||||
/**
|
||||
* The lookaround assertion.
|
||||
*/
|
||||
export type LookaroundAssertion = LookaheadAssertion | LookbehindAssertion;
|
||||
/**
|
||||
* The lookahead assertion.
|
||||
* E.g. `(?=ab)`, `(?!ab)`
|
||||
*/
|
||||
export interface LookaheadAssertion extends NodeBase {
|
||||
type: "Assertion";
|
||||
parent: Alternative | Quantifier;
|
||||
kind: "lookahead";
|
||||
negate: boolean;
|
||||
alternatives: Alternative[];
|
||||
}
|
||||
/**
|
||||
* The lookbehind assertion.
|
||||
* E.g. `(?<=ab)`, `(?<!ab)`
|
||||
*/
|
||||
export interface LookbehindAssertion extends NodeBase {
|
||||
type: "Assertion";
|
||||
parent: Alternative;
|
||||
kind: "lookbehind";
|
||||
negate: boolean;
|
||||
alternatives: Alternative[];
|
||||
}
|
||||
/**
|
||||
* The quantifier.
|
||||
* E.g. `a?`, `a*`, `a+`, `a{1,2}`, `a??`, `a*?`, `a+?`, `a{1,2}?`
|
||||
*/
|
||||
export interface Quantifier extends NodeBase {
|
||||
type: "Quantifier";
|
||||
parent: Alternative;
|
||||
min: number;
|
||||
max: number;
|
||||
greedy: boolean;
|
||||
element: QuantifiableElement;
|
||||
}
|
||||
/**
|
||||
* The character class.
|
||||
* E.g. `[ab]`, `[^ab]`
|
||||
*/
|
||||
export type CharacterClass =
|
||||
| ClassRangesCharacterClass
|
||||
| UnicodeSetsCharacterClass;
|
||||
interface BaseCharacterClass extends NodeBase {
|
||||
type: "CharacterClass";
|
||||
parent:
|
||||
| Alternative
|
||||
| ClassIntersection
|
||||
| ClassSubtraction
|
||||
| Quantifier
|
||||
| UnicodeSetsCharacterClass;
|
||||
unicodeSets: boolean;
|
||||
negate: boolean;
|
||||
elements: CharacterClassElement[];
|
||||
}
|
||||
/**
|
||||
* The character class used in legacy (neither `u` nor `v` flag) and Unicode mode (`u` flag).
|
||||
*
|
||||
* This character class is guaranteed to **not** contain strings.
|
||||
*
|
||||
* In Unicode sets mode (`v` flag), {@link UnicodeSetsCharacterClass} is used.
|
||||
*/
|
||||
export interface ClassRangesCharacterClass extends BaseCharacterClass {
|
||||
parent: Alternative | Quantifier;
|
||||
unicodeSets: false;
|
||||
elements: ClassRangesCharacterClassElement[];
|
||||
}
|
||||
/**
|
||||
* The character class used in Unicode sets mode (`v` flag).
|
||||
*
|
||||
* This character class may contain strings.
|
||||
*/
|
||||
export interface UnicodeSetsCharacterClass extends BaseCharacterClass {
|
||||
parent:
|
||||
| Alternative
|
||||
| ClassIntersection
|
||||
| ClassSubtraction
|
||||
| Quantifier
|
||||
| UnicodeSetsCharacterClass;
|
||||
unicodeSets: true;
|
||||
elements: UnicodeSetsCharacterClassElement[];
|
||||
}
|
||||
/**
|
||||
* The character class.
|
||||
* E.g. `[a-b]`
|
||||
*/
|
||||
export interface CharacterClassRange extends NodeBase {
|
||||
type: "CharacterClassRange";
|
||||
parent: CharacterClass;
|
||||
min: Character;
|
||||
max: Character;
|
||||
}
|
||||
/**
|
||||
* The assertion.
|
||||
*/
|
||||
export type Assertion = BoundaryAssertion | LookaroundAssertion;
|
||||
/**
|
||||
* The boundary assertion.
|
||||
*/
|
||||
export type BoundaryAssertion = EdgeAssertion | WordBoundaryAssertion;
|
||||
/**
|
||||
* The edge boundary assertion.
|
||||
* E.g. `^`, `$`
|
||||
*/
|
||||
export interface EdgeAssertion extends NodeBase {
|
||||
type: "Assertion";
|
||||
parent: Alternative | Quantifier;
|
||||
kind: "end" | "start";
|
||||
}
|
||||
/**
|
||||
* The word bondary assertion.
|
||||
* E.g. `\b`, `\B`
|
||||
*/
|
||||
export interface WordBoundaryAssertion extends NodeBase {
|
||||
type: "Assertion";
|
||||
parent: Alternative | Quantifier;
|
||||
kind: "word";
|
||||
negate: boolean;
|
||||
}
|
||||
/**
|
||||
* The character set.
|
||||
*/
|
||||
export type CharacterSet =
|
||||
| AnyCharacterSet
|
||||
| EscapeCharacterSet
|
||||
| UnicodePropertyCharacterSet;
|
||||
/**
|
||||
* The dot.
|
||||
* E.g. `.`
|
||||
*/
|
||||
export interface AnyCharacterSet extends NodeBase {
|
||||
type: "CharacterSet";
|
||||
parent: Alternative | Quantifier;
|
||||
kind: "any";
|
||||
}
|
||||
/**
|
||||
* The character class escape.
|
||||
* E.g. `\d`, `\s`, `\w`, `\D`, `\S`, `\W`
|
||||
*/
|
||||
export interface EscapeCharacterSet extends NodeBase {
|
||||
type: "CharacterSet";
|
||||
parent:
|
||||
| Alternative
|
||||
| CharacterClass
|
||||
| ClassIntersection
|
||||
| ClassSubtraction
|
||||
| Quantifier;
|
||||
kind: "digit" | "space" | "word";
|
||||
negate: boolean;
|
||||
}
|
||||
/**
|
||||
* The unicode property escape.
|
||||
* E.g. `\p{ASCII}`, `\P{ASCII}`, `\p{Script=Hiragana}`
|
||||
*/
|
||||
export type UnicodePropertyCharacterSet =
|
||||
| CharacterUnicodePropertyCharacterSet
|
||||
| StringsUnicodePropertyCharacterSet;
|
||||
interface BaseUnicodePropertyCharacterSet extends NodeBase {
|
||||
type: "CharacterSet";
|
||||
parent:
|
||||
| Alternative
|
||||
| CharacterClass
|
||||
| ClassIntersection
|
||||
| ClassSubtraction
|
||||
| Quantifier;
|
||||
kind: "property";
|
||||
strings: boolean;
|
||||
key: string;
|
||||
value: string | null;
|
||||
negate: boolean;
|
||||
}
|
||||
export interface CharacterUnicodePropertyCharacterSet
|
||||
extends BaseUnicodePropertyCharacterSet {
|
||||
strings: false;
|
||||
value: string | null;
|
||||
negate: boolean;
|
||||
}
|
||||
/** StringsUnicodePropertyCharacterSet is Unicode property escape with property of strings. */
|
||||
export interface StringsUnicodePropertyCharacterSet
|
||||
extends BaseUnicodePropertyCharacterSet {
|
||||
parent:
|
||||
| Alternative
|
||||
| ClassIntersection
|
||||
| ClassSubtraction
|
||||
| Quantifier
|
||||
| UnicodeSetsCharacterClass;
|
||||
strings: true;
|
||||
value: null;
|
||||
negate: false;
|
||||
}
|
||||
/**
|
||||
* The expression character class.
|
||||
* E.g. `[a--b]`, `[a&&b]`,`[^a--b]`, `[^a&&b]`
|
||||
*/
|
||||
export interface ExpressionCharacterClass extends NodeBase {
|
||||
type: "ExpressionCharacterClass";
|
||||
parent:
|
||||
| Alternative
|
||||
| ClassIntersection
|
||||
| ClassSubtraction
|
||||
| Quantifier
|
||||
| UnicodeSetsCharacterClass;
|
||||
negate: boolean;
|
||||
expression: ClassIntersection | ClassSubtraction;
|
||||
}
|
||||
export type ClassSetOperand =
|
||||
| Character
|
||||
| ClassStringDisjunction
|
||||
| EscapeCharacterSet
|
||||
| ExpressionCharacterClass
|
||||
| UnicodePropertyCharacterSet
|
||||
| UnicodeSetsCharacterClass;
|
||||
/**
|
||||
* The character class intersection.
|
||||
* E.g. `a&&b`
|
||||
*/
|
||||
export interface ClassIntersection extends NodeBase {
|
||||
type: "ClassIntersection";
|
||||
parent: ClassIntersection | ExpressionCharacterClass;
|
||||
left: ClassIntersection | ClassSetOperand;
|
||||
right: ClassSetOperand;
|
||||
}
|
||||
/**
|
||||
* The character class subtraction.
|
||||
* E.g. `a--b`
|
||||
*/
|
||||
export interface ClassSubtraction extends NodeBase {
|
||||
type: "ClassSubtraction";
|
||||
parent: ClassSubtraction | ExpressionCharacterClass;
|
||||
left: ClassSetOperand | ClassSubtraction;
|
||||
right: ClassSetOperand;
|
||||
}
|
||||
/**
|
||||
* The character class string disjunction.
|
||||
* E.g. `\q{a|b}`
|
||||
*/
|
||||
export interface ClassStringDisjunction extends NodeBase {
|
||||
type: "ClassStringDisjunction";
|
||||
parent: ClassIntersection | ClassSubtraction | UnicodeSetsCharacterClass;
|
||||
alternatives: StringAlternative[];
|
||||
}
|
||||
/** StringAlternative is only used for `\q{alt}`({@link ClassStringDisjunction}). */
|
||||
export interface StringAlternative extends NodeBase {
|
||||
type: "StringAlternative";
|
||||
parent: ClassStringDisjunction;
|
||||
elements: Character[];
|
||||
}
|
||||
/**
|
||||
* The character.
|
||||
* This includes escape sequences which mean a character.
|
||||
* E.g. `a`, `あ`, `✿`, `\x65`, `\u0065`, `\u{65}`, `\/`
|
||||
*/
|
||||
export interface Character extends NodeBase {
|
||||
type: "Character";
|
||||
parent:
|
||||
| Alternative
|
||||
| CharacterClass
|
||||
| CharacterClassRange
|
||||
| ClassIntersection
|
||||
| ClassSubtraction
|
||||
| Quantifier
|
||||
| StringAlternative;
|
||||
value: number;
|
||||
}
|
||||
/**
|
||||
* The backreference.
|
||||
* E.g. `\1`, `\k<name>`
|
||||
*/
|
||||
export interface Backreference extends NodeBase {
|
||||
type: "Backreference";
|
||||
parent: Alternative | Quantifier;
|
||||
ref: number | string;
|
||||
resolved: CapturingGroup;
|
||||
}
|
||||
/**
|
||||
* The flags.
|
||||
*/
|
||||
export interface Flags extends NodeBase {
|
||||
type: "Flags";
|
||||
parent: RegExpLiteral | null;
|
||||
dotAll: boolean;
|
||||
global: boolean;
|
||||
hasIndices: boolean;
|
||||
ignoreCase: boolean;
|
||||
multiline: boolean;
|
||||
sticky: boolean;
|
||||
unicode: boolean;
|
||||
unicodeSets: boolean;
|
||||
}
|
||||
export {};
|
||||
}
|
||||
|
||||
declare module "@eslint-community/regexpp/parser" {
|
||||
import type {
|
||||
Flags,
|
||||
RegExpLiteral,
|
||||
Pattern,
|
||||
} from "@eslint-community/regexpp/ast";
|
||||
import type { EcmaVersion } from "@eslint-community/regexpp/ecma-versions";
|
||||
export namespace RegExpParser {
|
||||
/**
|
||||
* The options for RegExpParser construction.
|
||||
*/
|
||||
interface Options {
|
||||
/**
|
||||
* The flag to disable Annex B syntax. Default is `false`.
|
||||
*/
|
||||
strict?: boolean;
|
||||
/**
|
||||
* ECMAScript version. Default is `2024`.
|
||||
* - `2015` added `u` and `y` flags.
|
||||
* - `2018` added `s` flag, Named Capturing Group, Lookbehind Assertion,
|
||||
* and Unicode Property Escape.
|
||||
* - `2019`, `2020`, and `2021` added more valid Unicode Property Escapes.
|
||||
* - `2022` added `d` flag.
|
||||
* - `2023` added more valid Unicode Property Escapes.
|
||||
* - `2024` added `v` flag.
|
||||
*/
|
||||
ecmaVersion?: EcmaVersion;
|
||||
}
|
||||
}
|
||||
export class RegExpParser {
|
||||
/**
|
||||
* Initialize this parser.
|
||||
* @param options The options of parser.
|
||||
*/
|
||||
constructor(options?: RegExpParser.Options);
|
||||
/**
|
||||
* Parse a regular expression literal. E.g. "/abc/g"
|
||||
* @param source The source code to parse.
|
||||
* @param start The start index in the source code.
|
||||
* @param end The end index in the source code.
|
||||
* @returns The AST of the given regular expression.
|
||||
*/
|
||||
parseLiteral(source: string, start?: number, end?: number): RegExpLiteral;
|
||||
/**
|
||||
* Parse a regular expression flags. E.g. "gim"
|
||||
* @param source The source code to parse.
|
||||
* @param start The start index in the source code.
|
||||
* @param end The end index in the source code.
|
||||
* @returns The AST of the given flags.
|
||||
*/
|
||||
parseFlags(source: string, start?: number, end?: number): Flags;
|
||||
/**
|
||||
* Parse a regular expression pattern. E.g. "abc"
|
||||
* @param source The source code to parse.
|
||||
* @param start The start index in the source code.
|
||||
* @param end The end index in the source code.
|
||||
* @param flags The flags.
|
||||
* @returns The AST of the given pattern.
|
||||
*/
|
||||
parsePattern(
|
||||
source: string,
|
||||
start?: number,
|
||||
end?: number,
|
||||
flags?: {
|
||||
unicode?: boolean;
|
||||
unicodeSets?: boolean;
|
||||
}
|
||||
): Pattern;
|
||||
/**
|
||||
* @deprecated Backward compatibility
|
||||
* Use object `flags` instead of boolean `uFlag`.
|
||||
*
|
||||
* @param source The source code to parse.
|
||||
* @param start The start index in the source code.
|
||||
* @param end The end index in the source code.
|
||||
* @param uFlag The flag to set unicode mode.
|
||||
* @returns The AST of the given pattern.
|
||||
*/
|
||||
parsePattern(
|
||||
source: string,
|
||||
start?: number,
|
||||
end?: number,
|
||||
uFlag?: boolean
|
||||
): Pattern;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "@eslint-community/regexpp/validator" {
|
||||
import type { EcmaVersion } from "@eslint-community/regexpp/ecma-versions";
|
||||
export type RegExpValidatorSourceContext = {
|
||||
readonly source: string;
|
||||
readonly start: number;
|
||||
readonly end: number;
|
||||
readonly kind: "flags" | "literal" | "pattern";
|
||||
};
|
||||
export namespace RegExpValidator {
|
||||
/**
|
||||
* The options for RegExpValidator construction.
|
||||
*/
|
||||
interface Options {
|
||||
/**
|
||||
* The flag to disable Annex B syntax. Default is `false`.
|
||||
*/
|
||||
strict?: boolean;
|
||||
/**
|
||||
* ECMAScript version. Default is `2024`.
|
||||
* - `2015` added `u` and `y` flags.
|
||||
* - `2018` added `s` flag, Named Capturing Group, Lookbehind Assertion,
|
||||
* and Unicode Property Escape.
|
||||
* - `2019`, `2020`, and `2021` added more valid Unicode Property Escapes.
|
||||
* - `2022` added `d` flag.
|
||||
* - `2023` added more valid Unicode Property Escapes.
|
||||
* - `2024` added `v` flag.
|
||||
*/
|
||||
ecmaVersion?: EcmaVersion;
|
||||
/**
|
||||
* A function that is called when the validator entered a RegExp literal.
|
||||
* @param start The 0-based index of the first character.
|
||||
*/
|
||||
onLiteralEnter?: (start: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator left a RegExp literal.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
*/
|
||||
onLiteralLeave?: (start: number, end: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator found flags.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param flags.global `g` flag.
|
||||
* @param flags.ignoreCase `i` flag.
|
||||
* @param flags.multiline `m` flag.
|
||||
* @param flags.unicode `u` flag.
|
||||
* @param flags.sticky `y` flag.
|
||||
* @param flags.dotAll `s` flag.
|
||||
* @param flags.hasIndices `d` flag.
|
||||
* @param flags.unicodeSets `v` flag.
|
||||
*/
|
||||
onRegExpFlags?: (
|
||||
start: number,
|
||||
end: number,
|
||||
flags: {
|
||||
global: boolean;
|
||||
ignoreCase: boolean;
|
||||
multiline: boolean;
|
||||
unicode: boolean;
|
||||
sticky: boolean;
|
||||
dotAll: boolean;
|
||||
hasIndices: boolean;
|
||||
unicodeSets: boolean;
|
||||
}
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator found flags.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param global `g` flag.
|
||||
* @param ignoreCase `i` flag.
|
||||
* @param multiline `m` flag.
|
||||
* @param unicode `u` flag.
|
||||
* @param sticky `y` flag.
|
||||
* @param dotAll `s` flag.
|
||||
* @param hasIndices `d` flag.
|
||||
*
|
||||
* @deprecated Use `onRegExpFlags` instead.
|
||||
*/
|
||||
onFlags?: (
|
||||
start: number,
|
||||
end: number,
|
||||
global: boolean,
|
||||
ignoreCase: boolean,
|
||||
multiline: boolean,
|
||||
unicode: boolean,
|
||||
sticky: boolean,
|
||||
dotAll: boolean,
|
||||
hasIndices: boolean
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator entered a pattern.
|
||||
* @param start The 0-based index of the first character.
|
||||
*/
|
||||
onPatternEnter?: (start: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator left a pattern.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
*/
|
||||
onPatternLeave?: (start: number, end: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator entered a disjunction.
|
||||
* @param start The 0-based index of the first character.
|
||||
*/
|
||||
onDisjunctionEnter?: (start: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator left a disjunction.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
*/
|
||||
onDisjunctionLeave?: (start: number, end: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator entered an alternative.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param index The 0-based index of alternatives in a disjunction.
|
||||
*/
|
||||
onAlternativeEnter?: (start: number, index: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator left an alternative.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param index The 0-based index of alternatives in a disjunction.
|
||||
*/
|
||||
onAlternativeLeave?: (start: number, end: number, index: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator entered an uncapturing group.
|
||||
* @param start The 0-based index of the first character.
|
||||
*/
|
||||
onGroupEnter?: (start: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator left an uncapturing group.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
*/
|
||||
onGroupLeave?: (start: number, end: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator entered a capturing group.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param name The group name.
|
||||
*/
|
||||
onCapturingGroupEnter?: (start: number, name: string | null) => void;
|
||||
/**
|
||||
* A function that is called when the validator left a capturing group.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param name The group name.
|
||||
*/
|
||||
onCapturingGroupLeave?: (
|
||||
start: number,
|
||||
end: number,
|
||||
name: string | null
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator found a quantifier.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param min The minimum number of repeating.
|
||||
* @param max The maximum number of repeating.
|
||||
* @param greedy The flag to choose the longest matching.
|
||||
*/
|
||||
onQuantifier?: (
|
||||
start: number,
|
||||
end: number,
|
||||
min: number,
|
||||
max: number,
|
||||
greedy: boolean
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator entered a lookahead/lookbehind assertion.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param kind The kind of the assertion.
|
||||
* @param negate The flag which represents that the assertion is negative.
|
||||
*/
|
||||
onLookaroundAssertionEnter?: (
|
||||
start: number,
|
||||
kind: "lookahead" | "lookbehind",
|
||||
negate: boolean
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator left a lookahead/lookbehind assertion.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param kind The kind of the assertion.
|
||||
* @param negate The flag which represents that the assertion is negative.
|
||||
*/
|
||||
onLookaroundAssertionLeave?: (
|
||||
start: number,
|
||||
end: number,
|
||||
kind: "lookahead" | "lookbehind",
|
||||
negate: boolean
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator found an edge boundary assertion.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param kind The kind of the assertion.
|
||||
*/
|
||||
onEdgeAssertion?: (
|
||||
start: number,
|
||||
end: number,
|
||||
kind: "end" | "start"
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator found a word boundary assertion.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param kind The kind of the assertion.
|
||||
* @param negate The flag which represents that the assertion is negative.
|
||||
*/
|
||||
onWordBoundaryAssertion?: (
|
||||
start: number,
|
||||
end: number,
|
||||
kind: "word",
|
||||
negate: boolean
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator found a dot.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param kind The kind of the character set.
|
||||
*/
|
||||
onAnyCharacterSet?: (start: number, end: number, kind: "any") => void;
|
||||
/**
|
||||
* A function that is called when the validator found a character set escape.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param kind The kind of the character set.
|
||||
* @param negate The flag which represents that the character set is negative.
|
||||
*/
|
||||
onEscapeCharacterSet?: (
|
||||
start: number,
|
||||
end: number,
|
||||
kind: "digit" | "space" | "word",
|
||||
negate: boolean
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator found a Unicode proerty escape.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param kind The kind of the character set.
|
||||
* @param key The property name.
|
||||
* @param value The property value.
|
||||
* @param negate The flag which represents that the character set is negative.
|
||||
* @param strings If true, the given property is property of strings.
|
||||
*/
|
||||
onUnicodePropertyCharacterSet?: (
|
||||
start: number,
|
||||
end: number,
|
||||
kind: "property",
|
||||
key: string,
|
||||
value: string | null,
|
||||
negate: boolean,
|
||||
strings: boolean
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator found a character.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param value The code point of the character.
|
||||
*/
|
||||
onCharacter?: (start: number, end: number, value: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator found a backreference.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param ref The key of the referred capturing group.
|
||||
*/
|
||||
onBackreference?: (
|
||||
start: number,
|
||||
end: number,
|
||||
ref: number | string
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator entered a character class.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param negate The flag which represents that the character class is negative.
|
||||
* @param unicodeSets `true` if unicodeSets mode.
|
||||
*/
|
||||
onCharacterClassEnter?: (
|
||||
start: number,
|
||||
negate: boolean,
|
||||
unicodeSets: boolean
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator left a character class.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param negate The flag which represents that the character class is negative.
|
||||
*/
|
||||
onCharacterClassLeave?: (
|
||||
start: number,
|
||||
end: number,
|
||||
negate: boolean
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator found a character class range.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param min The minimum code point of the range.
|
||||
* @param max The maximum code point of the range.
|
||||
*/
|
||||
onCharacterClassRange?: (
|
||||
start: number,
|
||||
end: number,
|
||||
min: number,
|
||||
max: number
|
||||
) => void;
|
||||
/**
|
||||
* A function that is called when the validator found a class intersection.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
*/
|
||||
onClassIntersection?: (start: number, end: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator found a class subtraction.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
*/
|
||||
onClassSubtraction?: (start: number, end: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator entered a class string disjunction.
|
||||
* @param start The 0-based index of the first character.
|
||||
*/
|
||||
onClassStringDisjunctionEnter?: (start: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator left a class string disjunction.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
*/
|
||||
onClassStringDisjunctionLeave?: (start: number, end: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator entered a string alternative.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param index The 0-based index of alternatives in a disjunction.
|
||||
*/
|
||||
onStringAlternativeEnter?: (start: number, index: number) => void;
|
||||
/**
|
||||
* A function that is called when the validator left a string alternative.
|
||||
* @param start The 0-based index of the first character.
|
||||
* @param end The next 0-based index of the last character.
|
||||
* @param index The 0-based index of alternatives in a disjunction.
|
||||
*/
|
||||
onStringAlternativeLeave?: (
|
||||
start: number,
|
||||
end: number,
|
||||
index: number
|
||||
) => void;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The regular expression validator.
|
||||
*/
|
||||
export class RegExpValidator {
|
||||
/**
|
||||
* Initialize this validator.
|
||||
* @param options The options of validator.
|
||||
*/
|
||||
constructor(options?: RegExpValidator.Options);
|
||||
/**
|
||||
* Validate a regular expression literal. E.g. "/abc/g"
|
||||
* @param source The source code to validate.
|
||||
* @param start The start index in the source code.
|
||||
* @param end The end index in the source code.
|
||||
*/
|
||||
validateLiteral(source: string, start?: number, end?: number): void;
|
||||
/**
|
||||
* Validate a regular expression flags. E.g. "gim"
|
||||
* @param source The source code to validate.
|
||||
* @param start The start index in the source code.
|
||||
* @param end The end index in the source code.
|
||||
*/
|
||||
validateFlags(source: string, start?: number, end?: number): void;
|
||||
/**
|
||||
* Validate a regular expression pattern. E.g. "abc"
|
||||
* @param source The source code to validate.
|
||||
* @param start The start index in the source code.
|
||||
* @param end The end index in the source code.
|
||||
* @param flags The flags.
|
||||
*/
|
||||
validatePattern(
|
||||
source: string,
|
||||
start?: number,
|
||||
end?: number,
|
||||
flags?: {
|
||||
unicode?: boolean;
|
||||
unicodeSets?: boolean;
|
||||
}
|
||||
): void;
|
||||
/**
|
||||
* @deprecated Backward compatibility
|
||||
* Use object `flags` instead of boolean `uFlag`.
|
||||
* @param source The source code to validate.
|
||||
* @param start The start index in the source code.
|
||||
* @param end The end index in the source code.
|
||||
* @param uFlag The flag to set unicode mode.
|
||||
*/
|
||||
validatePattern(
|
||||
source: string,
|
||||
start?: number,
|
||||
end?: number,
|
||||
uFlag?: boolean
|
||||
): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "@eslint-community/regexpp/visitor" {
|
||||
import type {
|
||||
Alternative,
|
||||
Assertion,
|
||||
Backreference,
|
||||
CapturingGroup,
|
||||
Character,
|
||||
CharacterClass,
|
||||
CharacterClassRange,
|
||||
CharacterSet,
|
||||
ClassIntersection,
|
||||
ClassStringDisjunction,
|
||||
ClassSubtraction,
|
||||
ExpressionCharacterClass,
|
||||
Flags,
|
||||
Group,
|
||||
Node,
|
||||
Pattern,
|
||||
Quantifier,
|
||||
RegExpLiteral,
|
||||
StringAlternative,
|
||||
} from "@eslint-community/regexpp/ast";
|
||||
/**
|
||||
* The visitor to walk on AST.
|
||||
*/
|
||||
export class RegExpVisitor {
|
||||
/**
|
||||
* Initialize this visitor.
|
||||
* @param handlers Callbacks for each node.
|
||||
*/
|
||||
constructor(handlers: RegExpVisitor.Handlers);
|
||||
/**
|
||||
* Visit a given node and descendant nodes.
|
||||
* @param node The root node to visit tree.
|
||||
*/
|
||||
visit(node: Node): void;
|
||||
}
|
||||
export namespace RegExpVisitor {
|
||||
interface Handlers {
|
||||
onAlternativeEnter?: (node: Alternative) => void;
|
||||
onAlternativeLeave?: (node: Alternative) => void;
|
||||
onAssertionEnter?: (node: Assertion) => void;
|
||||
onAssertionLeave?: (node: Assertion) => void;
|
||||
onBackreferenceEnter?: (node: Backreference) => void;
|
||||
onBackreferenceLeave?: (node: Backreference) => void;
|
||||
onCapturingGroupEnter?: (node: CapturingGroup) => void;
|
||||
onCapturingGroupLeave?: (node: CapturingGroup) => void;
|
||||
onCharacterEnter?: (node: Character) => void;
|
||||
onCharacterLeave?: (node: Character) => void;
|
||||
onCharacterClassEnter?: (node: CharacterClass) => void;
|
||||
onCharacterClassLeave?: (node: CharacterClass) => void;
|
||||
onCharacterClassRangeEnter?: (node: CharacterClassRange) => void;
|
||||
onCharacterClassRangeLeave?: (node: CharacterClassRange) => void;
|
||||
onCharacterSetEnter?: (node: CharacterSet) => void;
|
||||
onCharacterSetLeave?: (node: CharacterSet) => void;
|
||||
onClassIntersectionEnter?: (node: ClassIntersection) => void;
|
||||
onClassIntersectionLeave?: (node: ClassIntersection) => void;
|
||||
onClassStringDisjunctionEnter?: (node: ClassStringDisjunction) => void;
|
||||
onClassStringDisjunctionLeave?: (node: ClassStringDisjunction) => void;
|
||||
onClassSubtractionEnter?: (node: ClassSubtraction) => void;
|
||||
onClassSubtractionLeave?: (node: ClassSubtraction) => void;
|
||||
onExpressionCharacterClassEnter?: (
|
||||
node: ExpressionCharacterClass
|
||||
) => void;
|
||||
onExpressionCharacterClassLeave?: (
|
||||
node: ExpressionCharacterClass
|
||||
) => void;
|
||||
onFlagsEnter?: (node: Flags) => void;
|
||||
onFlagsLeave?: (node: Flags) => void;
|
||||
onGroupEnter?: (node: Group) => void;
|
||||
onGroupLeave?: (node: Group) => void;
|
||||
onPatternEnter?: (node: Pattern) => void;
|
||||
onPatternLeave?: (node: Pattern) => void;
|
||||
onQuantifierEnter?: (node: Quantifier) => void;
|
||||
onQuantifierLeave?: (node: Quantifier) => void;
|
||||
onRegExpLiteralEnter?: (node: RegExpLiteral) => void;
|
||||
onRegExpLiteralLeave?: (node: RegExpLiteral) => void;
|
||||
onStringAlternativeEnter?: (node: StringAlternative) => void;
|
||||
onStringAlternativeLeave?: (node: StringAlternative) => void;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare module "@eslint-community/regexpp/regexp-syntax-error" {
|
||||
import type { RegExpValidatorSourceContext } from "@eslint-community/regexpp/validator";
|
||||
export class RegExpSyntaxError extends SyntaxError {
|
||||
index: number;
|
||||
constructor(message: string, index: number);
|
||||
}
|
||||
export function newRegExpSyntaxError(
|
||||
srcCtx: RegExpValidatorSourceContext,
|
||||
flags: {
|
||||
unicode: boolean;
|
||||
unicodeSets: boolean;
|
||||
},
|
||||
index: number,
|
||||
message: string
|
||||
): RegExpSyntaxError;
|
||||
}
|
||||
|
||||
declare module "@eslint-community/regexpp/ecma-versions" {
|
||||
export type EcmaVersion =
|
||||
| 5
|
||||
| 2015
|
||||
| 2016
|
||||
| 2017
|
||||
| 2018
|
||||
| 2019
|
||||
| 2020
|
||||
| 2021
|
||||
| 2022
|
||||
| 2023
|
||||
| 2024;
|
||||
export const latestEcmaVersion = 2024;
|
||||
}
|
||||
2747
node_modules/@eslint-community/regexpp/index.js
generated
vendored
Normal file
2747
node_modules/@eslint-community/regexpp/index.js
generated
vendored
Normal file
@@ -0,0 +1,2747 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var ast = /*#__PURE__*/Object.freeze({
|
||||
__proto__: null
|
||||
});
|
||||
|
||||
const latestEcmaVersion = 2024;
|
||||
|
||||
let largeIdStartRanges = undefined;
|
||||
let largeIdContinueRanges = undefined;
|
||||
function isIdStart(cp) {
|
||||
if (cp < 0x41)
|
||||
return false;
|
||||
if (cp < 0x5b)
|
||||
return true;
|
||||
if (cp < 0x61)
|
||||
return false;
|
||||
if (cp < 0x7b)
|
||||
return true;
|
||||
return isLargeIdStart(cp);
|
||||
}
|
||||
function isIdContinue(cp) {
|
||||
if (cp < 0x30)
|
||||
return false;
|
||||
if (cp < 0x3a)
|
||||
return true;
|
||||
if (cp < 0x41)
|
||||
return false;
|
||||
if (cp < 0x5b)
|
||||
return true;
|
||||
if (cp === 0x5f)
|
||||
return true;
|
||||
if (cp < 0x61)
|
||||
return false;
|
||||
if (cp < 0x7b)
|
||||
return true;
|
||||
return isLargeIdStart(cp) || isLargeIdContinue(cp);
|
||||
}
|
||||
function isLargeIdStart(cp) {
|
||||
return isInRange(cp, largeIdStartRanges !== null && largeIdStartRanges !== void 0 ? largeIdStartRanges : (largeIdStartRanges = initLargeIdStartRanges()));
|
||||
}
|
||||
function isLargeIdContinue(cp) {
|
||||
return isInRange(cp, largeIdContinueRanges !== null && largeIdContinueRanges !== void 0 ? largeIdContinueRanges : (largeIdContinueRanges = initLargeIdContinueRanges()));
|
||||
}
|
||||
function initLargeIdStartRanges() {
|
||||
return restoreRanges("4q 0 b 0 5 0 6 m 2 u 2 cp 5 b f 4 8 0 2 0 3m 4 2 1 3 3 2 0 7 0 2 2 2 0 2 j 2 2a 2 3u 9 4l 2 11 3 0 7 14 20 q 5 3 1a 16 10 1 2 2q 2 0 g 1 8 1 b 2 3 0 h 0 2 t u 2g c 0 p w a 1 5 0 6 l 5 0 a 0 4 0 o o 8 a 6 n 2 5 i 15 1n 1h 4 0 j 0 8 9 g f 5 7 3 1 3 l 2 6 2 0 4 3 4 0 h 0 e 1 2 2 f 1 b 0 9 5 5 1 3 l 2 6 2 1 2 1 2 1 w 3 2 0 k 2 h 8 2 2 2 l 2 6 2 1 2 4 4 0 j 0 g 1 o 0 c 7 3 1 3 l 2 6 2 1 2 4 4 0 v 1 2 2 g 0 i 0 2 5 4 2 2 3 4 1 2 0 2 1 4 1 4 2 4 b n 0 1h 7 2 2 2 m 2 f 4 0 r 2 3 0 3 1 v 0 5 7 2 2 2 m 2 9 2 4 4 0 w 1 2 1 g 1 i 8 2 2 2 14 3 0 h 0 6 2 9 2 p 5 6 h 4 n 2 8 2 0 3 6 1n 1b 2 1 d 6 1n 1 2 0 2 4 2 n 2 0 2 9 2 1 a 0 3 4 2 0 m 3 x 0 1s 7 2 z s 4 38 16 l 0 h 5 5 3 4 0 4 1 8 2 5 c d 0 i 11 2 0 6 0 3 16 2 98 2 3 3 6 2 0 2 3 3 14 2 3 3 w 2 3 3 6 2 0 2 3 3 e 2 1k 2 3 3 1u 12 f h 2d 3 5 4 h7 3 g 2 p 6 22 4 a 8 h e i f h f c 2 2 g 1f 10 0 5 0 1w 2g 8 14 2 0 6 1x b u 1e t 3 4 c 17 5 p 1j m a 1g 2b 0 2m 1a i 7 1j t e 1 b 17 r z 16 2 b z 3 8 8 16 3 2 16 3 2 5 2 1 4 0 6 5b 1t 7p 3 5 3 11 3 5 3 7 2 0 2 0 2 0 2 u 3 1g 2 6 2 0 4 2 2 6 4 3 3 5 5 c 6 2 2 6 39 0 e 0 h c 2u 0 5 0 3 9 2 0 3 5 7 0 2 0 2 0 2 f 3 3 6 4 5 0 i 14 22g 6c 7 3 4 1 d 11 2 0 6 0 3 1j 8 0 h m a 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 fb 2 q 8 8 4 3 4 5 2d 5 4 2 2h 2 3 6 16 2 2l i v 1d f e9 533 1t h3g 1w 19 3 7g 4 f b 1 l 1a h u 3 27 14 8 3 2u 3 1r 6 1 2 0 2 4 p f 2 2 2 3 2 m u 1f f 1d 1r 5 4 0 2 1 c r b m q s 8 1a t 0 h 4 2 9 b 4 2 14 o 2 2 7 l m 4 0 4 1d 2 0 4 1 3 4 3 0 2 0 p 2 3 a 8 2 d 5 3 5 3 5 a 6 2 6 2 16 2 d 7 36 u 8mb d m 5 1c 6it a5 3 2x 13 6 d 4 6 0 2 9 2 c 2 4 2 0 2 1 2 1 2 2z y a2 j 1r 3 1h 15 b 39 4 2 3q 11 p 7 p c 2g 4 5 3 5 3 5 3 2 10 b 2 p 2 i 2 1 2 e 3 d z 3e 1y 1g 7g s 4 1c 1c v e t 6 11 b t 3 z 5 7 2 4 17 4d j z 5 z 5 13 9 1f d a 2 e 2 6 2 1 2 a 2 e 2 6 2 1 1w 8m a l b 7 p 5 2 15 2 8 1y 5 3 0 2 17 2 1 4 0 3 m b m a u 1u i 2 1 b l b p 1z 1j 7 1 1t 0 g 3 2 2 2 s 17 s 4 s 10 7 2 r s 1h b l b i e h 33 20 1k 1e e 1e e z 9p 15 7 1 27 s b 0 9 l 17 h 1b k s m d 1g 1m 1 3 0 e 18 x o r z u 0 3 0 9 y 4 0 d 1b f 3 m 0 2 0 10 h 2 o k 1 1s 6 2 0 2 3 2 e 2 9 8 1a 13 7 3 1 3 l 2 6 2 1 2 4 4 0 j 0 d 4 4f 1g j 3 l 2 v 1b l 1 2 0 55 1a 16 3 11 1b l 0 1o 16 e 0 20 q 12 6 56 17 39 1r w 7 3 0 3 7 2 1 2 n g 0 2 0 2n 7 3 12 h 0 2 0 t 0 b 13 8 0 m 0 c 19 k 0 j 20 7c 8 2 10 i 0 1e t 35 6 2 1 2 11 m 0 q 5 2 1 2 v f 0 94 i g 0 2 c 2 x 3h 0 28 pl 2v 32 i 5f 219 2o g tr i 5 33u g6 6nu fs 8 u i 26 i t j 1b h 3 w k 6 i j5 1r 3l 22 6 0 1v c 1t 1 2 0 t 4qf 9 yd 17 8 6w8 3 2 6 2 1 2 82 g 0 u 2 3 0 f 3 9 az 1s5 2y 6 c 4 8 8 9 4mf 2c 2 1y 2 1 3 0 3 1 3 3 2 b 2 0 2 6 2 1s 2 3 3 7 2 6 2 r 2 3 2 4 2 0 4 6 2 9f 3 o 2 o 2 u 2 o 2 u 2 o 2 u 2 o 2 u 2 o 2 7 1f9 u 7 5 7a 1p 43 18 b 6 h 0 8y t j 17 dh r l1 6 2 3 2 1 2 e 2 5g 1o 1v 8 0 xh 3 2 q 2 1 2 0 3 0 2 9 2 3 2 0 2 0 7 0 5 0 2 0 2 0 2 2 2 1 2 0 3 0 2 0 2 0 2 0 2 0 2 1 2 0 3 3 2 6 2 3 2 3 2 0 2 9 2 g 6 2 2 4 2 g 3et wyn x 37d 7 65 3 4g1 f 5rk g h9 1wj f1 15v 3t6 6 38f");
|
||||
}
|
||||
function initLargeIdContinueRanges() {
|
||||
return restoreRanges("53 0 g9 33 o 0 70 4 7e 18 2 0 2 1 2 1 2 0 21 a 1d u 7 0 2u 6 3 5 3 1 2 3 3 9 o 0 v q 2k a g 9 y 8 a 0 p 3 2 8 2 2 2 4 18 2 1p 7 17 n 2 w 1j 2 2 h 2 6 b 1 3 9 i 2 1l 0 2 6 3 1 3 2 a 0 b 1 3 9 f 0 3 2 1l 0 2 4 5 1 3 2 4 0 l b 4 0 c 2 1l 0 2 7 2 2 2 2 l 1 3 9 b 5 2 2 1l 0 2 6 3 1 3 2 8 2 b 1 3 9 j 0 1o 4 4 2 2 3 a 0 f 9 h 4 1k 0 2 6 2 2 2 3 8 1 c 1 3 9 i 2 1l 0 2 6 2 2 2 3 8 1 c 1 3 9 4 0 d 3 1k 1 2 6 2 2 2 3 a 0 b 1 3 9 i 2 1z 0 5 5 2 0 2 7 7 9 3 1 1q 0 3 6 d 7 2 9 2g 0 3 8 c 6 2 9 1r 1 7 9 c 0 2 0 2 0 5 1 1e j 2 1 6 a 2 z a 0 2t j 2 9 d 3 5 2 2 2 3 6 4 3 e b 2 e jk 2 a 8 pt 3 t 2 u 1 v 1 1t v a 0 3 9 y 2 2 a 40 0 3b b 5 b b 9 3l a 1p 4 1m 9 2 s 3 a 7 9 n d 2 f 1e 4 1c g c 9 i 8 d 2 v c 3 9 19 d 1d j 9 9 7 9 3b 2 2 k 5 0 7 0 3 2 5j 1r el 1 1e 1 k 0 3g c 5 0 4 b 2db 2 3y 0 2p v ff 5 2y 1 2p 0 n51 9 1y 0 5 9 x 1 29 1 7l 0 4 0 5 0 o 4 5 0 2c 1 1f h b 9 7 h e a t 7 q c 19 3 1c d g 9 c 0 b 9 1c d d 0 9 1 3 9 y 2 1f 0 2 2 3 1 6 1 2 0 16 4 6 1 6l 7 2 1 3 9 fmt 0 ki f h f 4 1 p 2 5d 9 12 0 12 0 ig 0 6b 0 46 4 86 9 120 2 2 1 6 3 15 2 5 0 4m 1 fy 3 9 9 aa 1 29 2 1z a 1e 3 3f 2 1i e w a 3 1 b 3 1a a 8 0 1a 9 7 2 11 d 2 9 6 1 19 0 d 2 1d d 9 3 2 b 2b b 7 0 3 0 4e b 6 9 7 3 1k 1 2 6 3 1 3 2 a 0 b 1 3 6 4 4 5d h a 9 5 0 2a j d 9 5y 6 3 8 s 1 2b g g 9 2a c 9 9 2c e 5 9 6r e 4m 9 1z 5 2 1 3 3 2 0 2 1 d 9 3c 6 3 6 4 0 t 9 15 6 2 3 9 0 a a 1b f ba 7 2 7 h 9 1l l 2 d 3f 5 4 0 2 1 2 6 2 0 9 9 1d 4 2 1 2 4 9 9 96 3 a 1 2 0 1d 6 4 4 e 9 44n 0 7 e aob 9 2f 9 13 4 1o 6 q 9 s6 0 2 1i 8 3 2a 0 c 1 f58 1 3mq 19 3 m f3 4 4 5 9 7 3 6 v 3 45 2 13e 1d e9 1i 5 1d 9 0 f 0 n 4 2 e 11t 6 2 g 3 6 2 1 2 4 2t 0 4h 6 a 9 9x 0 1q d dv d rb 6 32 6 6 9 3o7 9 gvt3 6n");
|
||||
}
|
||||
function isInRange(cp, ranges) {
|
||||
let l = 0, r = (ranges.length / 2) | 0, i = 0, min = 0, max = 0;
|
||||
while (l < r) {
|
||||
i = ((l + r) / 2) | 0;
|
||||
min = ranges[2 * i];
|
||||
max = ranges[2 * i + 1];
|
||||
if (cp < min) {
|
||||
r = i;
|
||||
}
|
||||
else if (cp > max) {
|
||||
l = i + 1;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function restoreRanges(data) {
|
||||
let last = 0;
|
||||
return data.split(" ").map((s) => (last += parseInt(s, 36) | 0));
|
||||
}
|
||||
|
||||
class DataSet {
|
||||
constructor(raw2018, raw2019, raw2020, raw2021, raw2022, raw2023, raw2024) {
|
||||
this._raw2018 = raw2018;
|
||||
this._raw2019 = raw2019;
|
||||
this._raw2020 = raw2020;
|
||||
this._raw2021 = raw2021;
|
||||
this._raw2022 = raw2022;
|
||||
this._raw2023 = raw2023;
|
||||
this._raw2024 = raw2024;
|
||||
}
|
||||
get es2018() {
|
||||
var _a;
|
||||
return ((_a = this._set2018) !== null && _a !== void 0 ? _a : (this._set2018 = new Set(this._raw2018.split(" "))));
|
||||
}
|
||||
get es2019() {
|
||||
var _a;
|
||||
return ((_a = this._set2019) !== null && _a !== void 0 ? _a : (this._set2019 = new Set(this._raw2019.split(" "))));
|
||||
}
|
||||
get es2020() {
|
||||
var _a;
|
||||
return ((_a = this._set2020) !== null && _a !== void 0 ? _a : (this._set2020 = new Set(this._raw2020.split(" "))));
|
||||
}
|
||||
get es2021() {
|
||||
var _a;
|
||||
return ((_a = this._set2021) !== null && _a !== void 0 ? _a : (this._set2021 = new Set(this._raw2021.split(" "))));
|
||||
}
|
||||
get es2022() {
|
||||
var _a;
|
||||
return ((_a = this._set2022) !== null && _a !== void 0 ? _a : (this._set2022 = new Set(this._raw2022.split(" "))));
|
||||
}
|
||||
get es2023() {
|
||||
var _a;
|
||||
return ((_a = this._set2023) !== null && _a !== void 0 ? _a : (this._set2023 = new Set(this._raw2023.split(" "))));
|
||||
}
|
||||
get es2024() {
|
||||
var _a;
|
||||
return ((_a = this._set2024) !== null && _a !== void 0 ? _a : (this._set2024 = new Set(this._raw2024.split(" "))));
|
||||
}
|
||||
}
|
||||
const gcNameSet = new Set(["General_Category", "gc"]);
|
||||
const scNameSet = new Set(["Script", "Script_Extensions", "sc", "scx"]);
|
||||
const gcValueSets = new DataSet("C Cased_Letter Cc Cf Close_Punctuation Cn Co Combining_Mark Connector_Punctuation Control Cs Currency_Symbol Dash_Punctuation Decimal_Number Enclosing_Mark Final_Punctuation Format Initial_Punctuation L LC Letter Letter_Number Line_Separator Ll Lm Lo Lowercase_Letter Lt Lu M Mark Math_Symbol Mc Me Mn Modifier_Letter Modifier_Symbol N Nd Nl No Nonspacing_Mark Number Open_Punctuation Other Other_Letter Other_Number Other_Punctuation Other_Symbol P Paragraph_Separator Pc Pd Pe Pf Pi Po Private_Use Ps Punctuation S Sc Separator Sk Sm So Space_Separator Spacing_Mark Surrogate Symbol Titlecase_Letter Unassigned Uppercase_Letter Z Zl Zp Zs cntrl digit punct", "", "", "", "", "", "");
|
||||
const scValueSets = new DataSet("Adlam Adlm Aghb Ahom Anatolian_Hieroglyphs Arab Arabic Armenian Armi Armn Avestan Avst Bali Balinese Bamu Bamum Bass Bassa_Vah Batak Batk Beng Bengali Bhaiksuki Bhks Bopo Bopomofo Brah Brahmi Brai Braille Bugi Buginese Buhd Buhid Cakm Canadian_Aboriginal Cans Cari Carian Caucasian_Albanian Chakma Cham Cher Cherokee Common Copt Coptic Cprt Cuneiform Cypriot Cyrillic Cyrl Deseret Deva Devanagari Dsrt Dupl Duployan Egyp Egyptian_Hieroglyphs Elba Elbasan Ethi Ethiopic Geor Georgian Glag Glagolitic Gonm Goth Gothic Gran Grantha Greek Grek Gujarati Gujr Gurmukhi Guru Han Hang Hangul Hani Hano Hanunoo Hatr Hatran Hebr Hebrew Hira Hiragana Hluw Hmng Hung Imperial_Aramaic Inherited Inscriptional_Pahlavi Inscriptional_Parthian Ital Java Javanese Kaithi Kali Kana Kannada Katakana Kayah_Li Khar Kharoshthi Khmer Khmr Khoj Khojki Khudawadi Knda Kthi Lana Lao Laoo Latin Latn Lepc Lepcha Limb Limbu Lina Linb Linear_A Linear_B Lisu Lyci Lycian Lydi Lydian Mahajani Mahj Malayalam Mand Mandaic Mani Manichaean Marc Marchen Masaram_Gondi Meetei_Mayek Mend Mende_Kikakui Merc Mero Meroitic_Cursive Meroitic_Hieroglyphs Miao Mlym Modi Mong Mongolian Mro Mroo Mtei Mult Multani Myanmar Mymr Nabataean Narb Nbat New_Tai_Lue Newa Nko Nkoo Nshu Nushu Ogam Ogham Ol_Chiki Olck Old_Hungarian Old_Italic Old_North_Arabian Old_Permic Old_Persian Old_South_Arabian Old_Turkic Oriya Orkh Orya Osage Osge Osma Osmanya Pahawh_Hmong Palm Palmyrene Pau_Cin_Hau Pauc Perm Phag Phags_Pa Phli Phlp Phnx Phoenician Plrd Prti Psalter_Pahlavi Qaac Qaai Rejang Rjng Runic Runr Samaritan Samr Sarb Saur Saurashtra Sgnw Sharada Shavian Shaw Shrd Sidd Siddham SignWriting Sind Sinh Sinhala Sora Sora_Sompeng Soyo Soyombo Sund Sundanese Sylo Syloti_Nagri Syrc Syriac Tagalog Tagb Tagbanwa Tai_Le Tai_Tham Tai_Viet Takr Takri Tale Talu Tamil Taml Tang Tangut Tavt Telu Telugu Tfng Tglg Thaa Thaana Thai Tibetan Tibt Tifinagh Tirh Tirhuta Ugar Ugaritic Vai Vaii Wara Warang_Citi Xpeo Xsux Yi Yiii Zanabazar_Square Zanb Zinh Zyyy", "Dogr Dogra Gong Gunjala_Gondi Hanifi_Rohingya Maka Makasar Medefaidrin Medf Old_Sogdian Rohg Sogd Sogdian Sogo", "Elym Elymaic Hmnp Nand Nandinagari Nyiakeng_Puachue_Hmong Wancho Wcho", "Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi", "Cpmn Cypro_Minoan Old_Uyghur Ougr Tangsa Tnsa Toto Vith Vithkuqi", "Hrkt Katakana_Or_Hiragana Kawi Nag_Mundari Nagm Unknown Zzzz", "");
|
||||
const binPropertySets = new DataSet("AHex ASCII ASCII_Hex_Digit Alpha Alphabetic Any Assigned Bidi_C Bidi_Control Bidi_M Bidi_Mirrored CI CWCF CWCM CWKCF CWL CWT CWU Case_Ignorable Cased Changes_When_Casefolded Changes_When_Casemapped Changes_When_Lowercased Changes_When_NFKC_Casefolded Changes_When_Titlecased Changes_When_Uppercased DI Dash Default_Ignorable_Code_Point Dep Deprecated Dia Diacritic Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Ext Extender Gr_Base Gr_Ext Grapheme_Base Grapheme_Extend Hex Hex_Digit IDC IDS IDSB IDST IDS_Binary_Operator IDS_Trinary_Operator ID_Continue ID_Start Ideo Ideographic Join_C Join_Control LOE Logical_Order_Exception Lower Lowercase Math NChar Noncharacter_Code_Point Pat_Syn Pat_WS Pattern_Syntax Pattern_White_Space QMark Quotation_Mark RI Radical Regional_Indicator SD STerm Sentence_Terminal Soft_Dotted Term Terminal_Punctuation UIdeo Unified_Ideograph Upper Uppercase VS Variation_Selector White_Space XIDC XIDS XID_Continue XID_Start space", "Extended_Pictographic", "", "EBase EComp EMod EPres ExtPict", "", "", "");
|
||||
const binPropertyOfStringsSets = new DataSet("", "", "", "", "", "", "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji RGI_Emoji_Flag_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence");
|
||||
function isValidUnicodeProperty(version, name, value) {
|
||||
if (gcNameSet.has(name)) {
|
||||
return version >= 2018 && gcValueSets.es2018.has(value);
|
||||
}
|
||||
if (scNameSet.has(name)) {
|
||||
return ((version >= 2018 && scValueSets.es2018.has(value)) ||
|
||||
(version >= 2019 && scValueSets.es2019.has(value)) ||
|
||||
(version >= 2020 && scValueSets.es2020.has(value)) ||
|
||||
(version >= 2021 && scValueSets.es2021.has(value)) ||
|
||||
(version >= 2022 && scValueSets.es2022.has(value)) ||
|
||||
(version >= 2023 && scValueSets.es2023.has(value)));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isValidLoneUnicodeProperty(version, value) {
|
||||
return ((version >= 2018 && binPropertySets.es2018.has(value)) ||
|
||||
(version >= 2019 && binPropertySets.es2019.has(value)) ||
|
||||
(version >= 2021 && binPropertySets.es2021.has(value)));
|
||||
}
|
||||
function isValidLoneUnicodePropertyOfString(version, value) {
|
||||
return version >= 2024 && binPropertyOfStringsSets.es2024.has(value);
|
||||
}
|
||||
|
||||
const BACKSPACE = 0x08;
|
||||
const CHARACTER_TABULATION = 0x09;
|
||||
const LINE_FEED = 0x0a;
|
||||
const LINE_TABULATION = 0x0b;
|
||||
const FORM_FEED = 0x0c;
|
||||
const CARRIAGE_RETURN = 0x0d;
|
||||
const EXCLAMATION_MARK = 0x21;
|
||||
const NUMBER_SIGN = 0x23;
|
||||
const DOLLAR_SIGN = 0x24;
|
||||
const PERCENT_SIGN = 0x25;
|
||||
const AMPERSAND = 0x26;
|
||||
const LEFT_PARENTHESIS = 0x28;
|
||||
const RIGHT_PARENTHESIS = 0x29;
|
||||
const ASTERISK = 0x2a;
|
||||
const PLUS_SIGN = 0x2b;
|
||||
const COMMA = 0x2c;
|
||||
const HYPHEN_MINUS = 0x2d;
|
||||
const FULL_STOP = 0x2e;
|
||||
const SOLIDUS = 0x2f;
|
||||
const DIGIT_ZERO = 0x30;
|
||||
const DIGIT_ONE = 0x31;
|
||||
const DIGIT_SEVEN = 0x37;
|
||||
const DIGIT_NINE = 0x39;
|
||||
const COLON = 0x3a;
|
||||
const SEMICOLON = 0x3b;
|
||||
const LESS_THAN_SIGN = 0x3c;
|
||||
const EQUALS_SIGN = 0x3d;
|
||||
const GREATER_THAN_SIGN = 0x3e;
|
||||
const QUESTION_MARK = 0x3f;
|
||||
const COMMERCIAL_AT = 0x40;
|
||||
const LATIN_CAPITAL_LETTER_A = 0x41;
|
||||
const LATIN_CAPITAL_LETTER_B = 0x42;
|
||||
const LATIN_CAPITAL_LETTER_D = 0x44;
|
||||
const LATIN_CAPITAL_LETTER_F = 0x46;
|
||||
const LATIN_CAPITAL_LETTER_P = 0x50;
|
||||
const LATIN_CAPITAL_LETTER_S = 0x53;
|
||||
const LATIN_CAPITAL_LETTER_W = 0x57;
|
||||
const LATIN_CAPITAL_LETTER_Z = 0x5a;
|
||||
const LOW_LINE = 0x5f;
|
||||
const LATIN_SMALL_LETTER_A = 0x61;
|
||||
const LATIN_SMALL_LETTER_B = 0x62;
|
||||
const LATIN_SMALL_LETTER_C = 0x63;
|
||||
const LATIN_SMALL_LETTER_D = 0x64;
|
||||
const LATIN_SMALL_LETTER_F = 0x66;
|
||||
const LATIN_SMALL_LETTER_G = 0x67;
|
||||
const LATIN_SMALL_LETTER_I = 0x69;
|
||||
const LATIN_SMALL_LETTER_K = 0x6b;
|
||||
const LATIN_SMALL_LETTER_M = 0x6d;
|
||||
const LATIN_SMALL_LETTER_N = 0x6e;
|
||||
const LATIN_SMALL_LETTER_P = 0x70;
|
||||
const LATIN_SMALL_LETTER_Q = 0x71;
|
||||
const LATIN_SMALL_LETTER_R = 0x72;
|
||||
const LATIN_SMALL_LETTER_S = 0x73;
|
||||
const LATIN_SMALL_LETTER_T = 0x74;
|
||||
const LATIN_SMALL_LETTER_U = 0x75;
|
||||
const LATIN_SMALL_LETTER_V = 0x76;
|
||||
const LATIN_SMALL_LETTER_W = 0x77;
|
||||
const LATIN_SMALL_LETTER_X = 0x78;
|
||||
const LATIN_SMALL_LETTER_Y = 0x79;
|
||||
const LATIN_SMALL_LETTER_Z = 0x7a;
|
||||
const LEFT_SQUARE_BRACKET = 0x5b;
|
||||
const REVERSE_SOLIDUS = 0x5c;
|
||||
const RIGHT_SQUARE_BRACKET = 0x5d;
|
||||
const CIRCUMFLEX_ACCENT = 0x5e;
|
||||
const GRAVE_ACCENT = 0x60;
|
||||
const LEFT_CURLY_BRACKET = 0x7b;
|
||||
const VERTICAL_LINE = 0x7c;
|
||||
const RIGHT_CURLY_BRACKET = 0x7d;
|
||||
const TILDE = 0x7e;
|
||||
const ZERO_WIDTH_NON_JOINER = 0x200c;
|
||||
const ZERO_WIDTH_JOINER = 0x200d;
|
||||
const LINE_SEPARATOR = 0x2028;
|
||||
const PARAGRAPH_SEPARATOR = 0x2029;
|
||||
const MIN_CODE_POINT = 0x00;
|
||||
const MAX_CODE_POINT = 0x10ffff;
|
||||
function isLatinLetter(code) {
|
||||
return ((code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_Z) ||
|
||||
(code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_Z));
|
||||
}
|
||||
function isDecimalDigit(code) {
|
||||
return code >= DIGIT_ZERO && code <= DIGIT_NINE;
|
||||
}
|
||||
function isOctalDigit(code) {
|
||||
return code >= DIGIT_ZERO && code <= DIGIT_SEVEN;
|
||||
}
|
||||
function isHexDigit(code) {
|
||||
return ((code >= DIGIT_ZERO && code <= DIGIT_NINE) ||
|
||||
(code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) ||
|
||||
(code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F));
|
||||
}
|
||||
function isLineTerminator(code) {
|
||||
return (code === LINE_FEED ||
|
||||
code === CARRIAGE_RETURN ||
|
||||
code === LINE_SEPARATOR ||
|
||||
code === PARAGRAPH_SEPARATOR);
|
||||
}
|
||||
function isValidUnicode(code) {
|
||||
return code >= MIN_CODE_POINT && code <= MAX_CODE_POINT;
|
||||
}
|
||||
function digitToInt(code) {
|
||||
if (code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F) {
|
||||
return code - LATIN_SMALL_LETTER_A + 10;
|
||||
}
|
||||
if (code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) {
|
||||
return code - LATIN_CAPITAL_LETTER_A + 10;
|
||||
}
|
||||
return code - DIGIT_ZERO;
|
||||
}
|
||||
function isLeadSurrogate(code) {
|
||||
return code >= 0xd800 && code <= 0xdbff;
|
||||
}
|
||||
function isTrailSurrogate(code) {
|
||||
return code >= 0xdc00 && code <= 0xdfff;
|
||||
}
|
||||
function combineSurrogatePair(lead, trail) {
|
||||
return (lead - 0xd800) * 0x400 + (trail - 0xdc00) + 0x10000;
|
||||
}
|
||||
|
||||
const legacyImpl = {
|
||||
at(s, end, i) {
|
||||
return i < end ? s.charCodeAt(i) : -1;
|
||||
},
|
||||
width(c) {
|
||||
return 1;
|
||||
},
|
||||
};
|
||||
const unicodeImpl = {
|
||||
at(s, end, i) {
|
||||
return i < end ? s.codePointAt(i) : -1;
|
||||
},
|
||||
width(c) {
|
||||
return c > 0xffff ? 2 : 1;
|
||||
},
|
||||
};
|
||||
class Reader {
|
||||
constructor() {
|
||||
this._impl = legacyImpl;
|
||||
this._s = "";
|
||||
this._i = 0;
|
||||
this._end = 0;
|
||||
this._cp1 = -1;
|
||||
this._w1 = 1;
|
||||
this._cp2 = -1;
|
||||
this._w2 = 1;
|
||||
this._cp3 = -1;
|
||||
this._w3 = 1;
|
||||
this._cp4 = -1;
|
||||
}
|
||||
get source() {
|
||||
return this._s;
|
||||
}
|
||||
get index() {
|
||||
return this._i;
|
||||
}
|
||||
get currentCodePoint() {
|
||||
return this._cp1;
|
||||
}
|
||||
get nextCodePoint() {
|
||||
return this._cp2;
|
||||
}
|
||||
get nextCodePoint2() {
|
||||
return this._cp3;
|
||||
}
|
||||
get nextCodePoint3() {
|
||||
return this._cp4;
|
||||
}
|
||||
reset(source, start, end, uFlag) {
|
||||
this._impl = uFlag ? unicodeImpl : legacyImpl;
|
||||
this._s = source;
|
||||
this._end = end;
|
||||
this.rewind(start);
|
||||
}
|
||||
rewind(index) {
|
||||
const impl = this._impl;
|
||||
this._i = index;
|
||||
this._cp1 = impl.at(this._s, this._end, index);
|
||||
this._w1 = impl.width(this._cp1);
|
||||
this._cp2 = impl.at(this._s, this._end, index + this._w1);
|
||||
this._w2 = impl.width(this._cp2);
|
||||
this._cp3 = impl.at(this._s, this._end, index + this._w1 + this._w2);
|
||||
this._w3 = impl.width(this._cp3);
|
||||
this._cp4 = impl.at(this._s, this._end, index + this._w1 + this._w2 + this._w3);
|
||||
}
|
||||
advance() {
|
||||
if (this._cp1 !== -1) {
|
||||
const impl = this._impl;
|
||||
this._i += this._w1;
|
||||
this._cp1 = this._cp2;
|
||||
this._w1 = this._w2;
|
||||
this._cp2 = this._cp3;
|
||||
this._w2 = impl.width(this._cp2);
|
||||
this._cp3 = this._cp4;
|
||||
this._w3 = impl.width(this._cp3);
|
||||
this._cp4 = impl.at(this._s, this._end, this._i + this._w1 + this._w2 + this._w3);
|
||||
}
|
||||
}
|
||||
eat(cp) {
|
||||
if (this._cp1 === cp) {
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eat2(cp1, cp2) {
|
||||
if (this._cp1 === cp1 && this._cp2 === cp2) {
|
||||
this.advance();
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eat3(cp1, cp2, cp3) {
|
||||
if (this._cp1 === cp1 && this._cp2 === cp2 && this._cp3 === cp3) {
|
||||
this.advance();
|
||||
this.advance();
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class RegExpSyntaxError extends SyntaxError {
|
||||
constructor(message, index) {
|
||||
super(message);
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
function newRegExpSyntaxError(srcCtx, flags, index, message) {
|
||||
let source = "";
|
||||
if (srcCtx.kind === "literal") {
|
||||
const literal = srcCtx.source.slice(srcCtx.start, srcCtx.end);
|
||||
if (literal) {
|
||||
source = `: ${literal}`;
|
||||
}
|
||||
}
|
||||
else if (srcCtx.kind === "pattern") {
|
||||
const pattern = srcCtx.source.slice(srcCtx.start, srcCtx.end);
|
||||
const flagsText = `${flags.unicode ? "u" : ""}${flags.unicodeSets ? "v" : ""}`;
|
||||
source = `: /${pattern}/${flagsText}`;
|
||||
}
|
||||
return new RegExpSyntaxError(`Invalid regular expression${source}: ${message}`, index);
|
||||
}
|
||||
|
||||
const SYNTAX_CHARACTER = new Set([
|
||||
CIRCUMFLEX_ACCENT,
|
||||
DOLLAR_SIGN,
|
||||
REVERSE_SOLIDUS,
|
||||
FULL_STOP,
|
||||
ASTERISK,
|
||||
PLUS_SIGN,
|
||||
QUESTION_MARK,
|
||||
LEFT_PARENTHESIS,
|
||||
RIGHT_PARENTHESIS,
|
||||
LEFT_SQUARE_BRACKET,
|
||||
RIGHT_SQUARE_BRACKET,
|
||||
LEFT_CURLY_BRACKET,
|
||||
RIGHT_CURLY_BRACKET,
|
||||
VERTICAL_LINE,
|
||||
]);
|
||||
const CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR_CHARACTER = new Set([
|
||||
AMPERSAND,
|
||||
EXCLAMATION_MARK,
|
||||
NUMBER_SIGN,
|
||||
DOLLAR_SIGN,
|
||||
PERCENT_SIGN,
|
||||
ASTERISK,
|
||||
PLUS_SIGN,
|
||||
COMMA,
|
||||
FULL_STOP,
|
||||
COLON,
|
||||
SEMICOLON,
|
||||
LESS_THAN_SIGN,
|
||||
EQUALS_SIGN,
|
||||
GREATER_THAN_SIGN,
|
||||
QUESTION_MARK,
|
||||
COMMERCIAL_AT,
|
||||
CIRCUMFLEX_ACCENT,
|
||||
GRAVE_ACCENT,
|
||||
TILDE,
|
||||
]);
|
||||
const CLASS_SET_SYNTAX_CHARACTER = new Set([
|
||||
LEFT_PARENTHESIS,
|
||||
RIGHT_PARENTHESIS,
|
||||
LEFT_SQUARE_BRACKET,
|
||||
RIGHT_SQUARE_BRACKET,
|
||||
LEFT_CURLY_BRACKET,
|
||||
RIGHT_CURLY_BRACKET,
|
||||
SOLIDUS,
|
||||
HYPHEN_MINUS,
|
||||
REVERSE_SOLIDUS,
|
||||
VERTICAL_LINE,
|
||||
]);
|
||||
const CLASS_SET_RESERVED_PUNCTUATOR = new Set([
|
||||
AMPERSAND,
|
||||
HYPHEN_MINUS,
|
||||
EXCLAMATION_MARK,
|
||||
NUMBER_SIGN,
|
||||
PERCENT_SIGN,
|
||||
COMMA,
|
||||
COLON,
|
||||
SEMICOLON,
|
||||
LESS_THAN_SIGN,
|
||||
EQUALS_SIGN,
|
||||
GREATER_THAN_SIGN,
|
||||
COMMERCIAL_AT,
|
||||
GRAVE_ACCENT,
|
||||
TILDE,
|
||||
]);
|
||||
function isSyntaxCharacter(cp) {
|
||||
return SYNTAX_CHARACTER.has(cp);
|
||||
}
|
||||
function isClassSetReservedDoublePunctuatorCharacter(cp) {
|
||||
return CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR_CHARACTER.has(cp);
|
||||
}
|
||||
function isClassSetSyntaxCharacter(cp) {
|
||||
return CLASS_SET_SYNTAX_CHARACTER.has(cp);
|
||||
}
|
||||
function isClassSetReservedPunctuator(cp) {
|
||||
return CLASS_SET_RESERVED_PUNCTUATOR.has(cp);
|
||||
}
|
||||
function isIdentifierStartChar(cp) {
|
||||
return isIdStart(cp) || cp === DOLLAR_SIGN || cp === LOW_LINE;
|
||||
}
|
||||
function isIdentifierPartChar(cp) {
|
||||
return (isIdContinue(cp) ||
|
||||
cp === DOLLAR_SIGN ||
|
||||
cp === ZERO_WIDTH_NON_JOINER ||
|
||||
cp === ZERO_WIDTH_JOINER);
|
||||
}
|
||||
function isUnicodePropertyNameCharacter(cp) {
|
||||
return isLatinLetter(cp) || cp === LOW_LINE;
|
||||
}
|
||||
function isUnicodePropertyValueCharacter(cp) {
|
||||
return isUnicodePropertyNameCharacter(cp) || isDecimalDigit(cp);
|
||||
}
|
||||
class RegExpValidator {
|
||||
constructor(options) {
|
||||
this._reader = new Reader();
|
||||
this._unicodeMode = false;
|
||||
this._unicodeSetsMode = false;
|
||||
this._nFlag = false;
|
||||
this._lastIntValue = 0;
|
||||
this._lastRange = {
|
||||
min: 0,
|
||||
max: Number.POSITIVE_INFINITY,
|
||||
};
|
||||
this._lastStrValue = "";
|
||||
this._lastAssertionIsQuantifiable = false;
|
||||
this._numCapturingParens = 0;
|
||||
this._groupNames = new Set();
|
||||
this._backreferenceNames = new Set();
|
||||
this._srcCtx = null;
|
||||
this._options = options !== null && options !== void 0 ? options : {};
|
||||
}
|
||||
validateLiteral(source, start = 0, end = source.length) {
|
||||
this._srcCtx = { source, start, end, kind: "literal" };
|
||||
this._unicodeSetsMode = this._unicodeMode = this._nFlag = false;
|
||||
this.reset(source, start, end);
|
||||
this.onLiteralEnter(start);
|
||||
if (this.eat(SOLIDUS) && this.eatRegExpBody() && this.eat(SOLIDUS)) {
|
||||
const flagStart = this.index;
|
||||
const unicode = source.includes("u", flagStart);
|
||||
const unicodeSets = source.includes("v", flagStart);
|
||||
this.validateFlagsInternal(source, flagStart, end);
|
||||
this.validatePatternInternal(source, start + 1, flagStart - 1, {
|
||||
unicode,
|
||||
unicodeSets,
|
||||
});
|
||||
}
|
||||
else if (start >= end) {
|
||||
this.raise("Empty");
|
||||
}
|
||||
else {
|
||||
const c = String.fromCodePoint(this.currentCodePoint);
|
||||
this.raise(`Unexpected character '${c}'`);
|
||||
}
|
||||
this.onLiteralLeave(start, end);
|
||||
}
|
||||
validateFlags(source, start = 0, end = source.length) {
|
||||
this._srcCtx = { source, start, end, kind: "flags" };
|
||||
this.validateFlagsInternal(source, start, end);
|
||||
}
|
||||
validatePattern(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
|
||||
this._srcCtx = { source, start, end, kind: "pattern" };
|
||||
this.validatePatternInternal(source, start, end, uFlagOrFlags);
|
||||
}
|
||||
validatePatternInternal(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
|
||||
const mode = this._parseFlagsOptionToMode(uFlagOrFlags, end);
|
||||
this._unicodeMode = mode.unicodeMode;
|
||||
this._nFlag = mode.nFlag;
|
||||
this._unicodeSetsMode = mode.unicodeSetsMode;
|
||||
this.reset(source, start, end);
|
||||
this.consumePattern();
|
||||
if (!this._nFlag &&
|
||||
this.ecmaVersion >= 2018 &&
|
||||
this._groupNames.size > 0) {
|
||||
this._nFlag = true;
|
||||
this.rewind(start);
|
||||
this.consumePattern();
|
||||
}
|
||||
}
|
||||
validateFlagsInternal(source, start, end) {
|
||||
const existingFlags = new Set();
|
||||
let global = false;
|
||||
let ignoreCase = false;
|
||||
let multiline = false;
|
||||
let sticky = false;
|
||||
let unicode = false;
|
||||
let dotAll = false;
|
||||
let hasIndices = false;
|
||||
let unicodeSets = false;
|
||||
for (let i = start; i < end; ++i) {
|
||||
const flag = source.charCodeAt(i);
|
||||
if (existingFlags.has(flag)) {
|
||||
this.raise(`Duplicated flag '${source[i]}'`, { index: start });
|
||||
}
|
||||
existingFlags.add(flag);
|
||||
if (flag === LATIN_SMALL_LETTER_G) {
|
||||
global = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_I) {
|
||||
ignoreCase = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_M) {
|
||||
multiline = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_U &&
|
||||
this.ecmaVersion >= 2015) {
|
||||
unicode = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_Y &&
|
||||
this.ecmaVersion >= 2015) {
|
||||
sticky = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_S &&
|
||||
this.ecmaVersion >= 2018) {
|
||||
dotAll = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_D &&
|
||||
this.ecmaVersion >= 2022) {
|
||||
hasIndices = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_V &&
|
||||
this.ecmaVersion >= 2024) {
|
||||
unicodeSets = true;
|
||||
}
|
||||
else {
|
||||
this.raise(`Invalid flag '${source[i]}'`, { index: start });
|
||||
}
|
||||
}
|
||||
this.onRegExpFlags(start, end, {
|
||||
global,
|
||||
ignoreCase,
|
||||
multiline,
|
||||
unicode,
|
||||
sticky,
|
||||
dotAll,
|
||||
hasIndices,
|
||||
unicodeSets,
|
||||
});
|
||||
}
|
||||
_parseFlagsOptionToMode(uFlagOrFlags, sourceEnd) {
|
||||
let unicode = false;
|
||||
let unicodeSets = false;
|
||||
if (uFlagOrFlags && this.ecmaVersion >= 2015) {
|
||||
if (typeof uFlagOrFlags === "object") {
|
||||
unicode = Boolean(uFlagOrFlags.unicode);
|
||||
if (this.ecmaVersion >= 2024) {
|
||||
unicodeSets = Boolean(uFlagOrFlags.unicodeSets);
|
||||
}
|
||||
}
|
||||
else {
|
||||
unicode = uFlagOrFlags;
|
||||
}
|
||||
}
|
||||
if (unicode && unicodeSets) {
|
||||
this.raise("Invalid regular expression flags", {
|
||||
index: sourceEnd + 1,
|
||||
unicode,
|
||||
unicodeSets,
|
||||
});
|
||||
}
|
||||
const unicodeMode = unicode || unicodeSets;
|
||||
const nFlag = (unicode && this.ecmaVersion >= 2018) ||
|
||||
unicodeSets ||
|
||||
Boolean(this._options.strict && this.ecmaVersion >= 2023);
|
||||
const unicodeSetsMode = unicodeSets;
|
||||
return { unicodeMode, nFlag, unicodeSetsMode };
|
||||
}
|
||||
get strict() {
|
||||
return Boolean(this._options.strict) || this._unicodeMode;
|
||||
}
|
||||
get ecmaVersion() {
|
||||
var _a;
|
||||
return (_a = this._options.ecmaVersion) !== null && _a !== void 0 ? _a : latestEcmaVersion;
|
||||
}
|
||||
onLiteralEnter(start) {
|
||||
if (this._options.onLiteralEnter) {
|
||||
this._options.onLiteralEnter(start);
|
||||
}
|
||||
}
|
||||
onLiteralLeave(start, end) {
|
||||
if (this._options.onLiteralLeave) {
|
||||
this._options.onLiteralLeave(start, end);
|
||||
}
|
||||
}
|
||||
onRegExpFlags(start, end, flags) {
|
||||
if (this._options.onRegExpFlags) {
|
||||
this._options.onRegExpFlags(start, end, flags);
|
||||
}
|
||||
if (this._options.onFlags) {
|
||||
this._options.onFlags(start, end, flags.global, flags.ignoreCase, flags.multiline, flags.unicode, flags.sticky, flags.dotAll, flags.hasIndices);
|
||||
}
|
||||
}
|
||||
onPatternEnter(start) {
|
||||
if (this._options.onPatternEnter) {
|
||||
this._options.onPatternEnter(start);
|
||||
}
|
||||
}
|
||||
onPatternLeave(start, end) {
|
||||
if (this._options.onPatternLeave) {
|
||||
this._options.onPatternLeave(start, end);
|
||||
}
|
||||
}
|
||||
onDisjunctionEnter(start) {
|
||||
if (this._options.onDisjunctionEnter) {
|
||||
this._options.onDisjunctionEnter(start);
|
||||
}
|
||||
}
|
||||
onDisjunctionLeave(start, end) {
|
||||
if (this._options.onDisjunctionLeave) {
|
||||
this._options.onDisjunctionLeave(start, end);
|
||||
}
|
||||
}
|
||||
onAlternativeEnter(start, index) {
|
||||
if (this._options.onAlternativeEnter) {
|
||||
this._options.onAlternativeEnter(start, index);
|
||||
}
|
||||
}
|
||||
onAlternativeLeave(start, end, index) {
|
||||
if (this._options.onAlternativeLeave) {
|
||||
this._options.onAlternativeLeave(start, end, index);
|
||||
}
|
||||
}
|
||||
onGroupEnter(start) {
|
||||
if (this._options.onGroupEnter) {
|
||||
this._options.onGroupEnter(start);
|
||||
}
|
||||
}
|
||||
onGroupLeave(start, end) {
|
||||
if (this._options.onGroupLeave) {
|
||||
this._options.onGroupLeave(start, end);
|
||||
}
|
||||
}
|
||||
onCapturingGroupEnter(start, name) {
|
||||
if (this._options.onCapturingGroupEnter) {
|
||||
this._options.onCapturingGroupEnter(start, name);
|
||||
}
|
||||
}
|
||||
onCapturingGroupLeave(start, end, name) {
|
||||
if (this._options.onCapturingGroupLeave) {
|
||||
this._options.onCapturingGroupLeave(start, end, name);
|
||||
}
|
||||
}
|
||||
onQuantifier(start, end, min, max, greedy) {
|
||||
if (this._options.onQuantifier) {
|
||||
this._options.onQuantifier(start, end, min, max, greedy);
|
||||
}
|
||||
}
|
||||
onLookaroundAssertionEnter(start, kind, negate) {
|
||||
if (this._options.onLookaroundAssertionEnter) {
|
||||
this._options.onLookaroundAssertionEnter(start, kind, negate);
|
||||
}
|
||||
}
|
||||
onLookaroundAssertionLeave(start, end, kind, negate) {
|
||||
if (this._options.onLookaroundAssertionLeave) {
|
||||
this._options.onLookaroundAssertionLeave(start, end, kind, negate);
|
||||
}
|
||||
}
|
||||
onEdgeAssertion(start, end, kind) {
|
||||
if (this._options.onEdgeAssertion) {
|
||||
this._options.onEdgeAssertion(start, end, kind);
|
||||
}
|
||||
}
|
||||
onWordBoundaryAssertion(start, end, kind, negate) {
|
||||
if (this._options.onWordBoundaryAssertion) {
|
||||
this._options.onWordBoundaryAssertion(start, end, kind, negate);
|
||||
}
|
||||
}
|
||||
onAnyCharacterSet(start, end, kind) {
|
||||
if (this._options.onAnyCharacterSet) {
|
||||
this._options.onAnyCharacterSet(start, end, kind);
|
||||
}
|
||||
}
|
||||
onEscapeCharacterSet(start, end, kind, negate) {
|
||||
if (this._options.onEscapeCharacterSet) {
|
||||
this._options.onEscapeCharacterSet(start, end, kind, negate);
|
||||
}
|
||||
}
|
||||
onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings) {
|
||||
if (this._options.onUnicodePropertyCharacterSet) {
|
||||
this._options.onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings);
|
||||
}
|
||||
}
|
||||
onCharacter(start, end, value) {
|
||||
if (this._options.onCharacter) {
|
||||
this._options.onCharacter(start, end, value);
|
||||
}
|
||||
}
|
||||
onBackreference(start, end, ref) {
|
||||
if (this._options.onBackreference) {
|
||||
this._options.onBackreference(start, end, ref);
|
||||
}
|
||||
}
|
||||
onCharacterClassEnter(start, negate, unicodeSets) {
|
||||
if (this._options.onCharacterClassEnter) {
|
||||
this._options.onCharacterClassEnter(start, negate, unicodeSets);
|
||||
}
|
||||
}
|
||||
onCharacterClassLeave(start, end, negate) {
|
||||
if (this._options.onCharacterClassLeave) {
|
||||
this._options.onCharacterClassLeave(start, end, negate);
|
||||
}
|
||||
}
|
||||
onCharacterClassRange(start, end, min, max) {
|
||||
if (this._options.onCharacterClassRange) {
|
||||
this._options.onCharacterClassRange(start, end, min, max);
|
||||
}
|
||||
}
|
||||
onClassIntersection(start, end) {
|
||||
if (this._options.onClassIntersection) {
|
||||
this._options.onClassIntersection(start, end);
|
||||
}
|
||||
}
|
||||
onClassSubtraction(start, end) {
|
||||
if (this._options.onClassSubtraction) {
|
||||
this._options.onClassSubtraction(start, end);
|
||||
}
|
||||
}
|
||||
onClassStringDisjunctionEnter(start) {
|
||||
if (this._options.onClassStringDisjunctionEnter) {
|
||||
this._options.onClassStringDisjunctionEnter(start);
|
||||
}
|
||||
}
|
||||
onClassStringDisjunctionLeave(start, end) {
|
||||
if (this._options.onClassStringDisjunctionLeave) {
|
||||
this._options.onClassStringDisjunctionLeave(start, end);
|
||||
}
|
||||
}
|
||||
onStringAlternativeEnter(start, index) {
|
||||
if (this._options.onStringAlternativeEnter) {
|
||||
this._options.onStringAlternativeEnter(start, index);
|
||||
}
|
||||
}
|
||||
onStringAlternativeLeave(start, end, index) {
|
||||
if (this._options.onStringAlternativeLeave) {
|
||||
this._options.onStringAlternativeLeave(start, end, index);
|
||||
}
|
||||
}
|
||||
get index() {
|
||||
return this._reader.index;
|
||||
}
|
||||
get currentCodePoint() {
|
||||
return this._reader.currentCodePoint;
|
||||
}
|
||||
get nextCodePoint() {
|
||||
return this._reader.nextCodePoint;
|
||||
}
|
||||
get nextCodePoint2() {
|
||||
return this._reader.nextCodePoint2;
|
||||
}
|
||||
get nextCodePoint3() {
|
||||
return this._reader.nextCodePoint3;
|
||||
}
|
||||
reset(source, start, end) {
|
||||
this._reader.reset(source, start, end, this._unicodeMode);
|
||||
}
|
||||
rewind(index) {
|
||||
this._reader.rewind(index);
|
||||
}
|
||||
advance() {
|
||||
this._reader.advance();
|
||||
}
|
||||
eat(cp) {
|
||||
return this._reader.eat(cp);
|
||||
}
|
||||
eat2(cp1, cp2) {
|
||||
return this._reader.eat2(cp1, cp2);
|
||||
}
|
||||
eat3(cp1, cp2, cp3) {
|
||||
return this._reader.eat3(cp1, cp2, cp3);
|
||||
}
|
||||
raise(message, context) {
|
||||
var _a, _b, _c;
|
||||
throw newRegExpSyntaxError(this._srcCtx, {
|
||||
unicode: (_a = context === null || context === void 0 ? void 0 : context.unicode) !== null && _a !== void 0 ? _a : (this._unicodeMode && !this._unicodeSetsMode),
|
||||
unicodeSets: (_b = context === null || context === void 0 ? void 0 : context.unicodeSets) !== null && _b !== void 0 ? _b : this._unicodeSetsMode,
|
||||
}, (_c = context === null || context === void 0 ? void 0 : context.index) !== null && _c !== void 0 ? _c : this.index, message);
|
||||
}
|
||||
eatRegExpBody() {
|
||||
const start = this.index;
|
||||
let inClass = false;
|
||||
let escaped = false;
|
||||
for (;;) {
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp === -1 || isLineTerminator(cp)) {
|
||||
const kind = inClass ? "character class" : "regular expression";
|
||||
this.raise(`Unterminated ${kind}`);
|
||||
}
|
||||
if (escaped) {
|
||||
escaped = false;
|
||||
}
|
||||
else if (cp === REVERSE_SOLIDUS) {
|
||||
escaped = true;
|
||||
}
|
||||
else if (cp === LEFT_SQUARE_BRACKET) {
|
||||
inClass = true;
|
||||
}
|
||||
else if (cp === RIGHT_SQUARE_BRACKET) {
|
||||
inClass = false;
|
||||
}
|
||||
else if ((cp === SOLIDUS && !inClass) ||
|
||||
(cp === ASTERISK && this.index === start)) {
|
||||
break;
|
||||
}
|
||||
this.advance();
|
||||
}
|
||||
return this.index !== start;
|
||||
}
|
||||
consumePattern() {
|
||||
const start = this.index;
|
||||
this._numCapturingParens = this.countCapturingParens();
|
||||
this._groupNames.clear();
|
||||
this._backreferenceNames.clear();
|
||||
this.onPatternEnter(start);
|
||||
this.consumeDisjunction();
|
||||
const cp = this.currentCodePoint;
|
||||
if (this.currentCodePoint !== -1) {
|
||||
if (cp === RIGHT_PARENTHESIS) {
|
||||
this.raise("Unmatched ')'");
|
||||
}
|
||||
if (cp === REVERSE_SOLIDUS) {
|
||||
this.raise("\\ at end of pattern");
|
||||
}
|
||||
if (cp === RIGHT_SQUARE_BRACKET || cp === RIGHT_CURLY_BRACKET) {
|
||||
this.raise("Lone quantifier brackets");
|
||||
}
|
||||
const c = String.fromCodePoint(cp);
|
||||
this.raise(`Unexpected character '${c}'`);
|
||||
}
|
||||
for (const name of this._backreferenceNames) {
|
||||
if (!this._groupNames.has(name)) {
|
||||
this.raise("Invalid named capture referenced");
|
||||
}
|
||||
}
|
||||
this.onPatternLeave(start, this.index);
|
||||
}
|
||||
countCapturingParens() {
|
||||
const start = this.index;
|
||||
let inClass = false;
|
||||
let escaped = false;
|
||||
let count = 0;
|
||||
let cp = 0;
|
||||
while ((cp = this.currentCodePoint) !== -1) {
|
||||
if (escaped) {
|
||||
escaped = false;
|
||||
}
|
||||
else if (cp === REVERSE_SOLIDUS) {
|
||||
escaped = true;
|
||||
}
|
||||
else if (cp === LEFT_SQUARE_BRACKET) {
|
||||
inClass = true;
|
||||
}
|
||||
else if (cp === RIGHT_SQUARE_BRACKET) {
|
||||
inClass = false;
|
||||
}
|
||||
else if (cp === LEFT_PARENTHESIS &&
|
||||
!inClass &&
|
||||
(this.nextCodePoint !== QUESTION_MARK ||
|
||||
(this.nextCodePoint2 === LESS_THAN_SIGN &&
|
||||
this.nextCodePoint3 !== EQUALS_SIGN &&
|
||||
this.nextCodePoint3 !== EXCLAMATION_MARK))) {
|
||||
count += 1;
|
||||
}
|
||||
this.advance();
|
||||
}
|
||||
this.rewind(start);
|
||||
return count;
|
||||
}
|
||||
consumeDisjunction() {
|
||||
const start = this.index;
|
||||
let i = 0;
|
||||
this.onDisjunctionEnter(start);
|
||||
do {
|
||||
this.consumeAlternative(i++);
|
||||
} while (this.eat(VERTICAL_LINE));
|
||||
if (this.consumeQuantifier(true)) {
|
||||
this.raise("Nothing to repeat");
|
||||
}
|
||||
if (this.eat(LEFT_CURLY_BRACKET)) {
|
||||
this.raise("Lone quantifier brackets");
|
||||
}
|
||||
this.onDisjunctionLeave(start, this.index);
|
||||
}
|
||||
consumeAlternative(i) {
|
||||
const start = this.index;
|
||||
this.onAlternativeEnter(start, i);
|
||||
while (this.currentCodePoint !== -1 && this.consumeTerm()) {
|
||||
}
|
||||
this.onAlternativeLeave(start, this.index, i);
|
||||
}
|
||||
consumeTerm() {
|
||||
if (this._unicodeMode || this.strict) {
|
||||
return (this.consumeAssertion() ||
|
||||
(this.consumeAtom() && this.consumeOptionalQuantifier()));
|
||||
}
|
||||
return ((this.consumeAssertion() &&
|
||||
(!this._lastAssertionIsQuantifiable ||
|
||||
this.consumeOptionalQuantifier())) ||
|
||||
(this.consumeExtendedAtom() && this.consumeOptionalQuantifier()));
|
||||
}
|
||||
consumeOptionalQuantifier() {
|
||||
this.consumeQuantifier();
|
||||
return true;
|
||||
}
|
||||
consumeAssertion() {
|
||||
const start = this.index;
|
||||
this._lastAssertionIsQuantifiable = false;
|
||||
if (this.eat(CIRCUMFLEX_ACCENT)) {
|
||||
this.onEdgeAssertion(start, this.index, "start");
|
||||
return true;
|
||||
}
|
||||
if (this.eat(DOLLAR_SIGN)) {
|
||||
this.onEdgeAssertion(start, this.index, "end");
|
||||
return true;
|
||||
}
|
||||
if (this.eat2(REVERSE_SOLIDUS, LATIN_CAPITAL_LETTER_B)) {
|
||||
this.onWordBoundaryAssertion(start, this.index, "word", true);
|
||||
return true;
|
||||
}
|
||||
if (this.eat2(REVERSE_SOLIDUS, LATIN_SMALL_LETTER_B)) {
|
||||
this.onWordBoundaryAssertion(start, this.index, "word", false);
|
||||
return true;
|
||||
}
|
||||
if (this.eat2(LEFT_PARENTHESIS, QUESTION_MARK)) {
|
||||
const lookbehind = this.ecmaVersion >= 2018 && this.eat(LESS_THAN_SIGN);
|
||||
let negate = false;
|
||||
if (this.eat(EQUALS_SIGN) ||
|
||||
(negate = this.eat(EXCLAMATION_MARK))) {
|
||||
const kind = lookbehind ? "lookbehind" : "lookahead";
|
||||
this.onLookaroundAssertionEnter(start, kind, negate);
|
||||
this.consumeDisjunction();
|
||||
if (!this.eat(RIGHT_PARENTHESIS)) {
|
||||
this.raise("Unterminated group");
|
||||
}
|
||||
this._lastAssertionIsQuantifiable = !lookbehind && !this.strict;
|
||||
this.onLookaroundAssertionLeave(start, this.index, kind, negate);
|
||||
return true;
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeQuantifier(noConsume = false) {
|
||||
const start = this.index;
|
||||
let min = 0;
|
||||
let max = 0;
|
||||
let greedy = false;
|
||||
if (this.eat(ASTERISK)) {
|
||||
min = 0;
|
||||
max = Number.POSITIVE_INFINITY;
|
||||
}
|
||||
else if (this.eat(PLUS_SIGN)) {
|
||||
min = 1;
|
||||
max = Number.POSITIVE_INFINITY;
|
||||
}
|
||||
else if (this.eat(QUESTION_MARK)) {
|
||||
min = 0;
|
||||
max = 1;
|
||||
}
|
||||
else if (this.eatBracedQuantifier(noConsume)) {
|
||||
({ min, max } = this._lastRange);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
greedy = !this.eat(QUESTION_MARK);
|
||||
if (!noConsume) {
|
||||
this.onQuantifier(start, this.index, min, max, greedy);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
eatBracedQuantifier(noError) {
|
||||
const start = this.index;
|
||||
if (this.eat(LEFT_CURLY_BRACKET)) {
|
||||
if (this.eatDecimalDigits()) {
|
||||
const min = this._lastIntValue;
|
||||
let max = min;
|
||||
if (this.eat(COMMA)) {
|
||||
max = this.eatDecimalDigits()
|
||||
? this._lastIntValue
|
||||
: Number.POSITIVE_INFINITY;
|
||||
}
|
||||
if (this.eat(RIGHT_CURLY_BRACKET)) {
|
||||
if (!noError && max < min) {
|
||||
this.raise("numbers out of order in {} quantifier");
|
||||
}
|
||||
this._lastRange = { min, max };
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!noError && (this._unicodeMode || this.strict)) {
|
||||
this.raise("Incomplete quantifier");
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeAtom() {
|
||||
return (this.consumePatternCharacter() ||
|
||||
this.consumeDot() ||
|
||||
this.consumeReverseSolidusAtomEscape() ||
|
||||
Boolean(this.consumeCharacterClass()) ||
|
||||
this.consumeUncapturingGroup() ||
|
||||
this.consumeCapturingGroup());
|
||||
}
|
||||
consumeDot() {
|
||||
if (this.eat(FULL_STOP)) {
|
||||
this.onAnyCharacterSet(this.index - 1, this.index, "any");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeReverseSolidusAtomEscape() {
|
||||
const start = this.index;
|
||||
if (this.eat(REVERSE_SOLIDUS)) {
|
||||
if (this.consumeAtomEscape()) {
|
||||
return true;
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeUncapturingGroup() {
|
||||
const start = this.index;
|
||||
if (this.eat3(LEFT_PARENTHESIS, QUESTION_MARK, COLON)) {
|
||||
this.onGroupEnter(start);
|
||||
this.consumeDisjunction();
|
||||
if (!this.eat(RIGHT_PARENTHESIS)) {
|
||||
this.raise("Unterminated group");
|
||||
}
|
||||
this.onGroupLeave(start, this.index);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeCapturingGroup() {
|
||||
const start = this.index;
|
||||
if (this.eat(LEFT_PARENTHESIS)) {
|
||||
let name = null;
|
||||
if (this.ecmaVersion >= 2018) {
|
||||
if (this.consumeGroupSpecifier()) {
|
||||
name = this._lastStrValue;
|
||||
}
|
||||
}
|
||||
else if (this.currentCodePoint === QUESTION_MARK) {
|
||||
this.raise("Invalid group");
|
||||
}
|
||||
this.onCapturingGroupEnter(start, name);
|
||||
this.consumeDisjunction();
|
||||
if (!this.eat(RIGHT_PARENTHESIS)) {
|
||||
this.raise("Unterminated group");
|
||||
}
|
||||
this.onCapturingGroupLeave(start, this.index, name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeExtendedAtom() {
|
||||
return (this.consumeDot() ||
|
||||
this.consumeReverseSolidusAtomEscape() ||
|
||||
this.consumeReverseSolidusFollowedByC() ||
|
||||
Boolean(this.consumeCharacterClass()) ||
|
||||
this.consumeUncapturingGroup() ||
|
||||
this.consumeCapturingGroup() ||
|
||||
this.consumeInvalidBracedQuantifier() ||
|
||||
this.consumeExtendedPatternCharacter());
|
||||
}
|
||||
consumeReverseSolidusFollowedByC() {
|
||||
const start = this.index;
|
||||
if (this.currentCodePoint === REVERSE_SOLIDUS &&
|
||||
this.nextCodePoint === LATIN_SMALL_LETTER_C) {
|
||||
this._lastIntValue = this.currentCodePoint;
|
||||
this.advance();
|
||||
this.onCharacter(start, this.index, REVERSE_SOLIDUS);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeInvalidBracedQuantifier() {
|
||||
if (this.eatBracedQuantifier(true)) {
|
||||
this.raise("Nothing to repeat");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumePatternCharacter() {
|
||||
const start = this.index;
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp !== -1 && !isSyntaxCharacter(cp)) {
|
||||
this.advance();
|
||||
this.onCharacter(start, this.index, cp);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeExtendedPatternCharacter() {
|
||||
const start = this.index;
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp !== -1 &&
|
||||
cp !== CIRCUMFLEX_ACCENT &&
|
||||
cp !== DOLLAR_SIGN &&
|
||||
cp !== REVERSE_SOLIDUS &&
|
||||
cp !== FULL_STOP &&
|
||||
cp !== ASTERISK &&
|
||||
cp !== PLUS_SIGN &&
|
||||
cp !== QUESTION_MARK &&
|
||||
cp !== LEFT_PARENTHESIS &&
|
||||
cp !== RIGHT_PARENTHESIS &&
|
||||
cp !== LEFT_SQUARE_BRACKET &&
|
||||
cp !== VERTICAL_LINE) {
|
||||
this.advance();
|
||||
this.onCharacter(start, this.index, cp);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeGroupSpecifier() {
|
||||
if (this.eat(QUESTION_MARK)) {
|
||||
if (this.eatGroupName()) {
|
||||
if (!this._groupNames.has(this._lastStrValue)) {
|
||||
this._groupNames.add(this._lastStrValue);
|
||||
return true;
|
||||
}
|
||||
this.raise("Duplicate capture group name");
|
||||
}
|
||||
this.raise("Invalid group");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeAtomEscape() {
|
||||
if (this.consumeBackreference() ||
|
||||
this.consumeCharacterClassEscape() ||
|
||||
this.consumeCharacterEscape() ||
|
||||
(this._nFlag && this.consumeKGroupName())) {
|
||||
return true;
|
||||
}
|
||||
if (this.strict || this._unicodeMode) {
|
||||
this.raise("Invalid escape");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeBackreference() {
|
||||
const start = this.index;
|
||||
if (this.eatDecimalEscape()) {
|
||||
const n = this._lastIntValue;
|
||||
if (n <= this._numCapturingParens) {
|
||||
this.onBackreference(start - 1, this.index, n);
|
||||
return true;
|
||||
}
|
||||
if (this.strict || this._unicodeMode) {
|
||||
this.raise("Invalid escape");
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeCharacterClassEscape() {
|
||||
var _a;
|
||||
const start = this.index;
|
||||
if (this.eat(LATIN_SMALL_LETTER_D)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "digit", false);
|
||||
return {};
|
||||
}
|
||||
if (this.eat(LATIN_CAPITAL_LETTER_D)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "digit", true);
|
||||
return {};
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_S)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "space", false);
|
||||
return {};
|
||||
}
|
||||
if (this.eat(LATIN_CAPITAL_LETTER_S)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "space", true);
|
||||
return {};
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_W)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "word", false);
|
||||
return {};
|
||||
}
|
||||
if (this.eat(LATIN_CAPITAL_LETTER_W)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "word", true);
|
||||
return {};
|
||||
}
|
||||
let negate = false;
|
||||
if (this._unicodeMode &&
|
||||
this.ecmaVersion >= 2018 &&
|
||||
(this.eat(LATIN_SMALL_LETTER_P) ||
|
||||
(negate = this.eat(LATIN_CAPITAL_LETTER_P)))) {
|
||||
this._lastIntValue = -1;
|
||||
let result = null;
|
||||
if (this.eat(LEFT_CURLY_BRACKET) &&
|
||||
(result = this.eatUnicodePropertyValueExpression()) &&
|
||||
this.eat(RIGHT_CURLY_BRACKET)) {
|
||||
if (negate && result.strings) {
|
||||
this.raise("Invalid property name");
|
||||
}
|
||||
this.onUnicodePropertyCharacterSet(start - 1, this.index, "property", result.key, result.value, negate, (_a = result.strings) !== null && _a !== void 0 ? _a : false);
|
||||
return { mayContainStrings: result.strings };
|
||||
}
|
||||
this.raise("Invalid property name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
consumeCharacterEscape() {
|
||||
const start = this.index;
|
||||
if (this.eatControlEscape() ||
|
||||
this.eatCControlLetter() ||
|
||||
this.eatZero() ||
|
||||
this.eatHexEscapeSequence() ||
|
||||
this.eatRegExpUnicodeEscapeSequence() ||
|
||||
(!this.strict &&
|
||||
!this._unicodeMode &&
|
||||
this.eatLegacyOctalEscapeSequence()) ||
|
||||
this.eatIdentityEscape()) {
|
||||
this.onCharacter(start - 1, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeKGroupName() {
|
||||
const start = this.index;
|
||||
if (this.eat(LATIN_SMALL_LETTER_K)) {
|
||||
if (this.eatGroupName()) {
|
||||
const groupName = this._lastStrValue;
|
||||
this._backreferenceNames.add(groupName);
|
||||
this.onBackreference(start - 1, this.index, groupName);
|
||||
return true;
|
||||
}
|
||||
this.raise("Invalid named reference");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeCharacterClass() {
|
||||
const start = this.index;
|
||||
if (this.eat(LEFT_SQUARE_BRACKET)) {
|
||||
const negate = this.eat(CIRCUMFLEX_ACCENT);
|
||||
this.onCharacterClassEnter(start, negate, this._unicodeSetsMode);
|
||||
const result = this.consumeClassContents();
|
||||
if (!this.eat(RIGHT_SQUARE_BRACKET)) {
|
||||
if (this.currentCodePoint === -1) {
|
||||
this.raise("Unterminated character class");
|
||||
}
|
||||
this.raise("Invalid character in character class");
|
||||
}
|
||||
if (negate && result.mayContainStrings) {
|
||||
this.raise("Negated character class may contain strings");
|
||||
}
|
||||
this.onCharacterClassLeave(start, this.index, negate);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
consumeClassContents() {
|
||||
if (this._unicodeSetsMode) {
|
||||
if (this.currentCodePoint === RIGHT_SQUARE_BRACKET) {
|
||||
return {};
|
||||
}
|
||||
const result = this.consumeClassSetExpression();
|
||||
return result;
|
||||
}
|
||||
const strict = this.strict || this._unicodeMode;
|
||||
for (;;) {
|
||||
const rangeStart = this.index;
|
||||
if (!this.consumeClassAtom()) {
|
||||
break;
|
||||
}
|
||||
const min = this._lastIntValue;
|
||||
if (!this.eat(HYPHEN_MINUS)) {
|
||||
continue;
|
||||
}
|
||||
this.onCharacter(this.index - 1, this.index, HYPHEN_MINUS);
|
||||
if (!this.consumeClassAtom()) {
|
||||
break;
|
||||
}
|
||||
const max = this._lastIntValue;
|
||||
if (min === -1 || max === -1) {
|
||||
if (strict) {
|
||||
this.raise("Invalid character class");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (min > max) {
|
||||
this.raise("Range out of order in character class");
|
||||
}
|
||||
this.onCharacterClassRange(rangeStart, this.index, min, max);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
consumeClassAtom() {
|
||||
const start = this.index;
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp !== -1 &&
|
||||
cp !== REVERSE_SOLIDUS &&
|
||||
cp !== RIGHT_SQUARE_BRACKET) {
|
||||
this.advance();
|
||||
this._lastIntValue = cp;
|
||||
this.onCharacter(start, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
if (this.eat(REVERSE_SOLIDUS)) {
|
||||
if (this.consumeClassEscape()) {
|
||||
return true;
|
||||
}
|
||||
if (!this.strict &&
|
||||
this.currentCodePoint === LATIN_SMALL_LETTER_C) {
|
||||
this._lastIntValue = REVERSE_SOLIDUS;
|
||||
this.onCharacter(start, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
if (this.strict || this._unicodeMode) {
|
||||
this.raise("Invalid escape");
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeClassEscape() {
|
||||
const start = this.index;
|
||||
if (this.eat(LATIN_SMALL_LETTER_B)) {
|
||||
this._lastIntValue = BACKSPACE;
|
||||
this.onCharacter(start - 1, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
if (this._unicodeMode && this.eat(HYPHEN_MINUS)) {
|
||||
this._lastIntValue = HYPHEN_MINUS;
|
||||
this.onCharacter(start - 1, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
let cp = 0;
|
||||
if (!this.strict &&
|
||||
!this._unicodeMode &&
|
||||
this.currentCodePoint === LATIN_SMALL_LETTER_C &&
|
||||
(isDecimalDigit((cp = this.nextCodePoint)) || cp === LOW_LINE)) {
|
||||
this.advance();
|
||||
this.advance();
|
||||
this._lastIntValue = cp % 0x20;
|
||||
this.onCharacter(start - 1, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
return (Boolean(this.consumeCharacterClassEscape()) ||
|
||||
this.consumeCharacterEscape());
|
||||
}
|
||||
consumeClassSetExpression() {
|
||||
const start = this.index;
|
||||
let mayContainStrings = false;
|
||||
let result = null;
|
||||
if (this.consumeClassSetCharacter()) {
|
||||
if (this.consumeClassSetRangeFromOperator(start)) {
|
||||
this.consumeClassUnionRight({});
|
||||
return {};
|
||||
}
|
||||
mayContainStrings = false;
|
||||
}
|
||||
else if ((result = this.consumeClassSetOperand())) {
|
||||
mayContainStrings = result.mayContainStrings;
|
||||
}
|
||||
else {
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp === REVERSE_SOLIDUS) {
|
||||
this.advance();
|
||||
this.raise("Invalid escape");
|
||||
}
|
||||
if (cp === this.nextCodePoint &&
|
||||
isClassSetReservedDoublePunctuatorCharacter(cp)) {
|
||||
this.raise("Invalid set operation in character class");
|
||||
}
|
||||
this.raise("Invalid character in character class");
|
||||
}
|
||||
if (this.eat2(AMPERSAND, AMPERSAND)) {
|
||||
while (this.currentCodePoint !== AMPERSAND &&
|
||||
(result = this.consumeClassSetOperand())) {
|
||||
this.onClassIntersection(start, this.index);
|
||||
if (!result.mayContainStrings) {
|
||||
mayContainStrings = false;
|
||||
}
|
||||
if (this.eat2(AMPERSAND, AMPERSAND)) {
|
||||
continue;
|
||||
}
|
||||
return { mayContainStrings };
|
||||
}
|
||||
this.raise("Invalid character in character class");
|
||||
}
|
||||
if (this.eat2(HYPHEN_MINUS, HYPHEN_MINUS)) {
|
||||
while (this.consumeClassSetOperand()) {
|
||||
this.onClassSubtraction(start, this.index);
|
||||
if (this.eat2(HYPHEN_MINUS, HYPHEN_MINUS)) {
|
||||
continue;
|
||||
}
|
||||
return { mayContainStrings };
|
||||
}
|
||||
this.raise("Invalid character in character class");
|
||||
}
|
||||
return this.consumeClassUnionRight({ mayContainStrings });
|
||||
}
|
||||
consumeClassUnionRight(leftResult) {
|
||||
let mayContainStrings = leftResult.mayContainStrings;
|
||||
for (;;) {
|
||||
const start = this.index;
|
||||
if (this.consumeClassSetCharacter()) {
|
||||
this.consumeClassSetRangeFromOperator(start);
|
||||
continue;
|
||||
}
|
||||
const result = this.consumeClassSetOperand();
|
||||
if (result) {
|
||||
if (result.mayContainStrings) {
|
||||
mayContainStrings = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return { mayContainStrings };
|
||||
}
|
||||
consumeClassSetRangeFromOperator(start) {
|
||||
const currentStart = this.index;
|
||||
const min = this._lastIntValue;
|
||||
if (this.eat(HYPHEN_MINUS)) {
|
||||
if (this.consumeClassSetCharacter()) {
|
||||
const max = this._lastIntValue;
|
||||
if (min === -1 || max === -1) {
|
||||
this.raise("Invalid character class");
|
||||
}
|
||||
if (min > max) {
|
||||
this.raise("Range out of order in character class");
|
||||
}
|
||||
this.onCharacterClassRange(start, this.index, min, max);
|
||||
return true;
|
||||
}
|
||||
this.rewind(currentStart);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeClassSetOperand() {
|
||||
let result = null;
|
||||
if ((result = this.consumeNestedClass())) {
|
||||
return result;
|
||||
}
|
||||
if ((result = this.consumeClassStringDisjunction())) {
|
||||
return result;
|
||||
}
|
||||
if (this.consumeClassSetCharacter()) {
|
||||
return {};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
consumeNestedClass() {
|
||||
const start = this.index;
|
||||
if (this.eat(LEFT_SQUARE_BRACKET)) {
|
||||
const negate = this.eat(CIRCUMFLEX_ACCENT);
|
||||
this.onCharacterClassEnter(start, negate, true);
|
||||
const result = this.consumeClassContents();
|
||||
if (!this.eat(RIGHT_SQUARE_BRACKET)) {
|
||||
this.raise("Unterminated character class");
|
||||
}
|
||||
if (negate && result.mayContainStrings) {
|
||||
this.raise("Negated character class may contain strings");
|
||||
}
|
||||
this.onCharacterClassLeave(start, this.index, negate);
|
||||
return result;
|
||||
}
|
||||
if (this.eat(REVERSE_SOLIDUS)) {
|
||||
const result = this.consumeCharacterClassEscape();
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
consumeClassStringDisjunction() {
|
||||
const start = this.index;
|
||||
if (this.eat3(REVERSE_SOLIDUS, LATIN_SMALL_LETTER_Q, LEFT_CURLY_BRACKET)) {
|
||||
this.onClassStringDisjunctionEnter(start);
|
||||
let i = 0;
|
||||
let mayContainStrings = false;
|
||||
do {
|
||||
if (this.consumeClassString(i++).mayContainStrings) {
|
||||
mayContainStrings = true;
|
||||
}
|
||||
} while (this.eat(VERTICAL_LINE));
|
||||
if (this.eat(RIGHT_CURLY_BRACKET)) {
|
||||
this.onClassStringDisjunctionLeave(start, this.index);
|
||||
return { mayContainStrings };
|
||||
}
|
||||
this.raise("Unterminated class string disjunction");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
consumeClassString(i) {
|
||||
const start = this.index;
|
||||
let count = 0;
|
||||
this.onStringAlternativeEnter(start, i);
|
||||
while (this.currentCodePoint !== -1 &&
|
||||
this.consumeClassSetCharacter()) {
|
||||
count++;
|
||||
}
|
||||
this.onStringAlternativeLeave(start, this.index, i);
|
||||
return { mayContainStrings: count !== 1 };
|
||||
}
|
||||
consumeClassSetCharacter() {
|
||||
const start = this.index;
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp !== this.nextCodePoint ||
|
||||
!isClassSetReservedDoublePunctuatorCharacter(cp)) {
|
||||
if (cp !== -1 && !isClassSetSyntaxCharacter(cp)) {
|
||||
this._lastIntValue = cp;
|
||||
this.advance();
|
||||
this.onCharacter(start, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (this.eat(REVERSE_SOLIDUS)) {
|
||||
if (this.consumeCharacterEscape()) {
|
||||
return true;
|
||||
}
|
||||
if (isClassSetReservedPunctuator(this.currentCodePoint)) {
|
||||
this._lastIntValue = this.currentCodePoint;
|
||||
this.advance();
|
||||
this.onCharacter(start, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_B)) {
|
||||
this._lastIntValue = BACKSPACE;
|
||||
this.onCharacter(start, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatGroupName() {
|
||||
if (this.eat(LESS_THAN_SIGN)) {
|
||||
if (this.eatRegExpIdentifierName() && this.eat(GREATER_THAN_SIGN)) {
|
||||
return true;
|
||||
}
|
||||
this.raise("Invalid capture group name");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpIdentifierName() {
|
||||
if (this.eatRegExpIdentifierStart()) {
|
||||
this._lastStrValue = String.fromCodePoint(this._lastIntValue);
|
||||
while (this.eatRegExpIdentifierPart()) {
|
||||
this._lastStrValue += String.fromCodePoint(this._lastIntValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpIdentifierStart() {
|
||||
const start = this.index;
|
||||
const forceUFlag = !this._unicodeMode && this.ecmaVersion >= 2020;
|
||||
let cp = this.currentCodePoint;
|
||||
this.advance();
|
||||
if (cp === REVERSE_SOLIDUS &&
|
||||
this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
|
||||
cp = this._lastIntValue;
|
||||
}
|
||||
else if (forceUFlag &&
|
||||
isLeadSurrogate(cp) &&
|
||||
isTrailSurrogate(this.currentCodePoint)) {
|
||||
cp = combineSurrogatePair(cp, this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
if (isIdentifierStartChar(cp)) {
|
||||
this._lastIntValue = cp;
|
||||
return true;
|
||||
}
|
||||
if (this.index !== start) {
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpIdentifierPart() {
|
||||
const start = this.index;
|
||||
const forceUFlag = !this._unicodeMode && this.ecmaVersion >= 2020;
|
||||
let cp = this.currentCodePoint;
|
||||
this.advance();
|
||||
if (cp === REVERSE_SOLIDUS &&
|
||||
this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
|
||||
cp = this._lastIntValue;
|
||||
}
|
||||
else if (forceUFlag &&
|
||||
isLeadSurrogate(cp) &&
|
||||
isTrailSurrogate(this.currentCodePoint)) {
|
||||
cp = combineSurrogatePair(cp, this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
if (isIdentifierPartChar(cp)) {
|
||||
this._lastIntValue = cp;
|
||||
return true;
|
||||
}
|
||||
if (this.index !== start) {
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatCControlLetter() {
|
||||
const start = this.index;
|
||||
if (this.eat(LATIN_SMALL_LETTER_C)) {
|
||||
if (this.eatControlLetter()) {
|
||||
return true;
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatZero() {
|
||||
if (this.currentCodePoint === DIGIT_ZERO &&
|
||||
!isDecimalDigit(this.nextCodePoint)) {
|
||||
this._lastIntValue = 0;
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatControlEscape() {
|
||||
if (this.eat(LATIN_SMALL_LETTER_F)) {
|
||||
this._lastIntValue = FORM_FEED;
|
||||
return true;
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_N)) {
|
||||
this._lastIntValue = LINE_FEED;
|
||||
return true;
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_R)) {
|
||||
this._lastIntValue = CARRIAGE_RETURN;
|
||||
return true;
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_T)) {
|
||||
this._lastIntValue = CHARACTER_TABULATION;
|
||||
return true;
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_V)) {
|
||||
this._lastIntValue = LINE_TABULATION;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatControlLetter() {
|
||||
const cp = this.currentCodePoint;
|
||||
if (isLatinLetter(cp)) {
|
||||
this.advance();
|
||||
this._lastIntValue = cp % 0x20;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpUnicodeEscapeSequence(forceUFlag = false) {
|
||||
const start = this.index;
|
||||
const uFlag = forceUFlag || this._unicodeMode;
|
||||
if (this.eat(LATIN_SMALL_LETTER_U)) {
|
||||
if ((uFlag && this.eatRegExpUnicodeSurrogatePairEscape()) ||
|
||||
this.eatFixedHexDigits(4) ||
|
||||
(uFlag && this.eatRegExpUnicodeCodePointEscape())) {
|
||||
return true;
|
||||
}
|
||||
if (this.strict || uFlag) {
|
||||
this.raise("Invalid unicode escape");
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpUnicodeSurrogatePairEscape() {
|
||||
const start = this.index;
|
||||
if (this.eatFixedHexDigits(4)) {
|
||||
const lead = this._lastIntValue;
|
||||
if (isLeadSurrogate(lead) &&
|
||||
this.eat(REVERSE_SOLIDUS) &&
|
||||
this.eat(LATIN_SMALL_LETTER_U) &&
|
||||
this.eatFixedHexDigits(4)) {
|
||||
const trail = this._lastIntValue;
|
||||
if (isTrailSurrogate(trail)) {
|
||||
this._lastIntValue = combineSurrogatePair(lead, trail);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpUnicodeCodePointEscape() {
|
||||
const start = this.index;
|
||||
if (this.eat(LEFT_CURLY_BRACKET) &&
|
||||
this.eatHexDigits() &&
|
||||
this.eat(RIGHT_CURLY_BRACKET) &&
|
||||
isValidUnicode(this._lastIntValue)) {
|
||||
return true;
|
||||
}
|
||||
this.rewind(start);
|
||||
return false;
|
||||
}
|
||||
eatIdentityEscape() {
|
||||
const cp = this.currentCodePoint;
|
||||
if (this.isValidIdentityEscape(cp)) {
|
||||
this._lastIntValue = cp;
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
isValidIdentityEscape(cp) {
|
||||
if (cp === -1) {
|
||||
return false;
|
||||
}
|
||||
if (this._unicodeMode) {
|
||||
return isSyntaxCharacter(cp) || cp === SOLIDUS;
|
||||
}
|
||||
if (this.strict) {
|
||||
return !isIdContinue(cp);
|
||||
}
|
||||
if (this._nFlag) {
|
||||
return !(cp === LATIN_SMALL_LETTER_C || cp === LATIN_SMALL_LETTER_K);
|
||||
}
|
||||
return cp !== LATIN_SMALL_LETTER_C;
|
||||
}
|
||||
eatDecimalEscape() {
|
||||
this._lastIntValue = 0;
|
||||
let cp = this.currentCodePoint;
|
||||
if (cp >= DIGIT_ONE && cp <= DIGIT_NINE) {
|
||||
do {
|
||||
this._lastIntValue = 10 * this._lastIntValue + (cp - DIGIT_ZERO);
|
||||
this.advance();
|
||||
} while ((cp = this.currentCodePoint) >= DIGIT_ZERO &&
|
||||
cp <= DIGIT_NINE);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatUnicodePropertyValueExpression() {
|
||||
const start = this.index;
|
||||
if (this.eatUnicodePropertyName() && this.eat(EQUALS_SIGN)) {
|
||||
const key = this._lastStrValue;
|
||||
if (this.eatUnicodePropertyValue()) {
|
||||
const value = this._lastStrValue;
|
||||
if (isValidUnicodeProperty(this.ecmaVersion, key, value)) {
|
||||
return {
|
||||
key,
|
||||
value: value || null,
|
||||
};
|
||||
}
|
||||
this.raise("Invalid property name");
|
||||
}
|
||||
}
|
||||
this.rewind(start);
|
||||
if (this.eatLoneUnicodePropertyNameOrValue()) {
|
||||
const nameOrValue = this._lastStrValue;
|
||||
if (isValidUnicodeProperty(this.ecmaVersion, "General_Category", nameOrValue)) {
|
||||
return {
|
||||
key: "General_Category",
|
||||
value: nameOrValue || null,
|
||||
};
|
||||
}
|
||||
if (isValidLoneUnicodeProperty(this.ecmaVersion, nameOrValue)) {
|
||||
return {
|
||||
key: nameOrValue,
|
||||
value: null,
|
||||
};
|
||||
}
|
||||
if (this._unicodeSetsMode &&
|
||||
isValidLoneUnicodePropertyOfString(this.ecmaVersion, nameOrValue)) {
|
||||
return {
|
||||
key: nameOrValue,
|
||||
value: null,
|
||||
strings: true,
|
||||
};
|
||||
}
|
||||
this.raise("Invalid property name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
eatUnicodePropertyName() {
|
||||
this._lastStrValue = "";
|
||||
while (isUnicodePropertyNameCharacter(this.currentCodePoint)) {
|
||||
this._lastStrValue += String.fromCodePoint(this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
return this._lastStrValue !== "";
|
||||
}
|
||||
eatUnicodePropertyValue() {
|
||||
this._lastStrValue = "";
|
||||
while (isUnicodePropertyValueCharacter(this.currentCodePoint)) {
|
||||
this._lastStrValue += String.fromCodePoint(this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
return this._lastStrValue !== "";
|
||||
}
|
||||
eatLoneUnicodePropertyNameOrValue() {
|
||||
return this.eatUnicodePropertyValue();
|
||||
}
|
||||
eatHexEscapeSequence() {
|
||||
const start = this.index;
|
||||
if (this.eat(LATIN_SMALL_LETTER_X)) {
|
||||
if (this.eatFixedHexDigits(2)) {
|
||||
return true;
|
||||
}
|
||||
if (this._unicodeMode || this.strict) {
|
||||
this.raise("Invalid escape");
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatDecimalDigits() {
|
||||
const start = this.index;
|
||||
this._lastIntValue = 0;
|
||||
while (isDecimalDigit(this.currentCodePoint)) {
|
||||
this._lastIntValue =
|
||||
10 * this._lastIntValue + digitToInt(this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
return this.index !== start;
|
||||
}
|
||||
eatHexDigits() {
|
||||
const start = this.index;
|
||||
this._lastIntValue = 0;
|
||||
while (isHexDigit(this.currentCodePoint)) {
|
||||
this._lastIntValue =
|
||||
16 * this._lastIntValue + digitToInt(this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
return this.index !== start;
|
||||
}
|
||||
eatLegacyOctalEscapeSequence() {
|
||||
if (this.eatOctalDigit()) {
|
||||
const n1 = this._lastIntValue;
|
||||
if (this.eatOctalDigit()) {
|
||||
const n2 = this._lastIntValue;
|
||||
if (n1 <= 3 && this.eatOctalDigit()) {
|
||||
this._lastIntValue = n1 * 64 + n2 * 8 + this._lastIntValue;
|
||||
}
|
||||
else {
|
||||
this._lastIntValue = n1 * 8 + n2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._lastIntValue = n1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatOctalDigit() {
|
||||
const cp = this.currentCodePoint;
|
||||
if (isOctalDigit(cp)) {
|
||||
this.advance();
|
||||
this._lastIntValue = cp - DIGIT_ZERO;
|
||||
return true;
|
||||
}
|
||||
this._lastIntValue = 0;
|
||||
return false;
|
||||
}
|
||||
eatFixedHexDigits(length) {
|
||||
const start = this.index;
|
||||
this._lastIntValue = 0;
|
||||
for (let i = 0; i < length; ++i) {
|
||||
const cp = this.currentCodePoint;
|
||||
if (!isHexDigit(cp)) {
|
||||
this.rewind(start);
|
||||
return false;
|
||||
}
|
||||
this._lastIntValue = 16 * this._lastIntValue + digitToInt(cp);
|
||||
this.advance();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const DUMMY_PATTERN = {};
|
||||
const DUMMY_FLAGS = {};
|
||||
const DUMMY_CAPTURING_GROUP = {};
|
||||
function isClassSetOperand(node) {
|
||||
return (node.type === "Character" ||
|
||||
node.type === "CharacterSet" ||
|
||||
node.type === "CharacterClass" ||
|
||||
node.type === "ExpressionCharacterClass" ||
|
||||
node.type === "ClassStringDisjunction");
|
||||
}
|
||||
class RegExpParserState {
|
||||
constructor(options) {
|
||||
var _a;
|
||||
this._node = DUMMY_PATTERN;
|
||||
this._expressionBufferMap = new Map();
|
||||
this._flags = DUMMY_FLAGS;
|
||||
this._backreferences = [];
|
||||
this._capturingGroups = [];
|
||||
this.source = "";
|
||||
this.strict = Boolean(options === null || options === void 0 ? void 0 : options.strict);
|
||||
this.ecmaVersion = (_a = options === null || options === void 0 ? void 0 : options.ecmaVersion) !== null && _a !== void 0 ? _a : latestEcmaVersion;
|
||||
}
|
||||
get pattern() {
|
||||
if (this._node.type !== "Pattern") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
return this._node;
|
||||
}
|
||||
get flags() {
|
||||
if (this._flags.type !== "Flags") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
return this._flags;
|
||||
}
|
||||
onRegExpFlags(start, end, { global, ignoreCase, multiline, unicode, sticky, dotAll, hasIndices, unicodeSets, }) {
|
||||
this._flags = {
|
||||
type: "Flags",
|
||||
parent: null,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
global,
|
||||
ignoreCase,
|
||||
multiline,
|
||||
unicode,
|
||||
sticky,
|
||||
dotAll,
|
||||
hasIndices,
|
||||
unicodeSets,
|
||||
};
|
||||
}
|
||||
onPatternEnter(start) {
|
||||
this._node = {
|
||||
type: "Pattern",
|
||||
parent: null,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
alternatives: [],
|
||||
};
|
||||
this._backreferences.length = 0;
|
||||
this._capturingGroups.length = 0;
|
||||
}
|
||||
onPatternLeave(start, end) {
|
||||
this._node.end = end;
|
||||
this._node.raw = this.source.slice(start, end);
|
||||
for (const reference of this._backreferences) {
|
||||
const ref = reference.ref;
|
||||
const group = typeof ref === "number"
|
||||
? this._capturingGroups[ref - 1]
|
||||
: this._capturingGroups.find((g) => g.name === ref);
|
||||
reference.resolved = group;
|
||||
group.references.push(reference);
|
||||
}
|
||||
}
|
||||
onAlternativeEnter(start) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Assertion" &&
|
||||
parent.type !== "CapturingGroup" &&
|
||||
parent.type !== "Group" &&
|
||||
parent.type !== "Pattern") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._node = {
|
||||
type: "Alternative",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
elements: [],
|
||||
};
|
||||
parent.alternatives.push(this._node);
|
||||
}
|
||||
onAlternativeLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
onGroupEnter(start) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._node = {
|
||||
type: "Group",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
alternatives: [],
|
||||
};
|
||||
parent.elements.push(this._node);
|
||||
}
|
||||
onGroupLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "Group" || node.parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
onCapturingGroupEnter(start, name) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._node = {
|
||||
type: "CapturingGroup",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
name,
|
||||
alternatives: [],
|
||||
references: [],
|
||||
};
|
||||
parent.elements.push(this._node);
|
||||
this._capturingGroups.push(this._node);
|
||||
}
|
||||
onCapturingGroupLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "CapturingGroup" ||
|
||||
node.parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
onQuantifier(start, end, min, max, greedy) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const element = parent.elements.pop();
|
||||
if (element == null ||
|
||||
element.type === "Quantifier" ||
|
||||
(element.type === "Assertion" && element.kind !== "lookahead")) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = {
|
||||
type: "Quantifier",
|
||||
parent,
|
||||
start: element.start,
|
||||
end,
|
||||
raw: this.source.slice(element.start, end),
|
||||
min,
|
||||
max,
|
||||
greedy,
|
||||
element,
|
||||
};
|
||||
parent.elements.push(node);
|
||||
element.parent = node;
|
||||
}
|
||||
onLookaroundAssertionEnter(start, kind, negate) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = (this._node = {
|
||||
type: "Assertion",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
kind,
|
||||
negate,
|
||||
alternatives: [],
|
||||
});
|
||||
parent.elements.push(node);
|
||||
}
|
||||
onLookaroundAssertionLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "Assertion" || node.parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
onEdgeAssertion(start, end, kind) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push({
|
||||
type: "Assertion",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
kind,
|
||||
});
|
||||
}
|
||||
onWordBoundaryAssertion(start, end, kind, negate) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push({
|
||||
type: "Assertion",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
kind,
|
||||
negate,
|
||||
});
|
||||
}
|
||||
onAnyCharacterSet(start, end, kind) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push({
|
||||
type: "CharacterSet",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
kind,
|
||||
});
|
||||
}
|
||||
onEscapeCharacterSet(start, end, kind, negate) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push({
|
||||
type: "CharacterSet",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
kind,
|
||||
negate,
|
||||
});
|
||||
}
|
||||
onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const base = {
|
||||
type: "CharacterSet",
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
kind,
|
||||
key,
|
||||
};
|
||||
if (strings) {
|
||||
if ((parent.type === "CharacterClass" && !parent.unicodeSets) ||
|
||||
negate ||
|
||||
value !== null) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push(Object.assign(Object.assign({}, base), { parent, strings, value, negate }));
|
||||
}
|
||||
else {
|
||||
parent.elements.push(Object.assign(Object.assign({}, base), { parent, strings, value, negate }));
|
||||
}
|
||||
}
|
||||
onCharacter(start, end, value) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative" &&
|
||||
parent.type !== "CharacterClass" &&
|
||||
parent.type !== "StringAlternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push({
|
||||
type: "Character",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
value,
|
||||
});
|
||||
}
|
||||
onBackreference(start, end, ref) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = {
|
||||
type: "Backreference",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
ref,
|
||||
resolved: DUMMY_CAPTURING_GROUP,
|
||||
};
|
||||
parent.elements.push(node);
|
||||
this._backreferences.push(node);
|
||||
}
|
||||
onCharacterClassEnter(start, negate, unicodeSets) {
|
||||
const parent = this._node;
|
||||
const base = {
|
||||
type: "CharacterClass",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
unicodeSets,
|
||||
negate,
|
||||
elements: [],
|
||||
};
|
||||
if (parent.type === "Alternative") {
|
||||
const node = Object.assign(Object.assign({}, base), { parent });
|
||||
this._node = node;
|
||||
parent.elements.push(node);
|
||||
}
|
||||
else if (parent.type === "CharacterClass" &&
|
||||
parent.unicodeSets &&
|
||||
unicodeSets) {
|
||||
const node = Object.assign(Object.assign({}, base), { parent,
|
||||
unicodeSets });
|
||||
this._node = node;
|
||||
parent.elements.push(node);
|
||||
}
|
||||
else {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
}
|
||||
onCharacterClassLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "CharacterClass" ||
|
||||
(node.parent.type !== "Alternative" &&
|
||||
node.parent.type !== "CharacterClass")) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const parent = node.parent;
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = parent;
|
||||
const expression = this._expressionBufferMap.get(node);
|
||||
if (!expression) {
|
||||
return;
|
||||
}
|
||||
if (node.elements.length > 0) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._expressionBufferMap.delete(node);
|
||||
const newNode = {
|
||||
type: "ExpressionCharacterClass",
|
||||
parent,
|
||||
start: node.start,
|
||||
end: node.end,
|
||||
raw: node.raw,
|
||||
negate: node.negate,
|
||||
expression,
|
||||
};
|
||||
expression.parent = newNode;
|
||||
if (node !== parent.elements.pop()) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push(newNode);
|
||||
}
|
||||
onCharacterClassRange(start, end) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "CharacterClass") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const elements = parent.elements;
|
||||
const max = elements.pop();
|
||||
if (!max || max.type !== "Character") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
if (!parent.unicodeSets) {
|
||||
const hyphen = elements.pop();
|
||||
if (!hyphen ||
|
||||
hyphen.type !== "Character" ||
|
||||
hyphen.value !== HYPHEN_MINUS) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
}
|
||||
const min = elements.pop();
|
||||
if (!min || min.type !== "Character") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = {
|
||||
type: "CharacterClassRange",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
min,
|
||||
max,
|
||||
};
|
||||
min.parent = node;
|
||||
max.parent = node;
|
||||
elements.push(node);
|
||||
}
|
||||
onClassIntersection(start, end) {
|
||||
var _a;
|
||||
const parent = this._node;
|
||||
if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const right = parent.elements.pop();
|
||||
const left = (_a = this._expressionBufferMap.get(parent)) !== null && _a !== void 0 ? _a : parent.elements.pop();
|
||||
if (!left ||
|
||||
!right ||
|
||||
left.type === "ClassSubtraction" ||
|
||||
(left.type !== "ClassIntersection" && !isClassSetOperand(left)) ||
|
||||
!isClassSetOperand(right)) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = {
|
||||
type: "ClassIntersection",
|
||||
parent: parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
left,
|
||||
right,
|
||||
};
|
||||
left.parent = node;
|
||||
right.parent = node;
|
||||
this._expressionBufferMap.set(parent, node);
|
||||
}
|
||||
onClassSubtraction(start, end) {
|
||||
var _a;
|
||||
const parent = this._node;
|
||||
if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const right = parent.elements.pop();
|
||||
const left = (_a = this._expressionBufferMap.get(parent)) !== null && _a !== void 0 ? _a : parent.elements.pop();
|
||||
if (!left ||
|
||||
!right ||
|
||||
left.type === "ClassIntersection" ||
|
||||
(left.type !== "ClassSubtraction" && !isClassSetOperand(left)) ||
|
||||
!isClassSetOperand(right)) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = {
|
||||
type: "ClassSubtraction",
|
||||
parent: parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
left,
|
||||
right,
|
||||
};
|
||||
left.parent = node;
|
||||
right.parent = node;
|
||||
this._expressionBufferMap.set(parent, node);
|
||||
}
|
||||
onClassStringDisjunctionEnter(start) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._node = {
|
||||
type: "ClassStringDisjunction",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
alternatives: [],
|
||||
};
|
||||
parent.elements.push(this._node);
|
||||
}
|
||||
onClassStringDisjunctionLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "ClassStringDisjunction" ||
|
||||
node.parent.type !== "CharacterClass") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
onStringAlternativeEnter(start) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "ClassStringDisjunction") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._node = {
|
||||
type: "StringAlternative",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
elements: [],
|
||||
};
|
||||
parent.alternatives.push(this._node);
|
||||
}
|
||||
onStringAlternativeLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "StringAlternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
}
|
||||
class RegExpParser {
|
||||
constructor(options) {
|
||||
this._state = new RegExpParserState(options);
|
||||
this._validator = new RegExpValidator(this._state);
|
||||
}
|
||||
parseLiteral(source, start = 0, end = source.length) {
|
||||
this._state.source = source;
|
||||
this._validator.validateLiteral(source, start, end);
|
||||
const pattern = this._state.pattern;
|
||||
const flags = this._state.flags;
|
||||
const literal = {
|
||||
type: "RegExpLiteral",
|
||||
parent: null,
|
||||
start,
|
||||
end,
|
||||
raw: source,
|
||||
pattern,
|
||||
flags,
|
||||
};
|
||||
pattern.parent = literal;
|
||||
flags.parent = literal;
|
||||
return literal;
|
||||
}
|
||||
parseFlags(source, start = 0, end = source.length) {
|
||||
this._state.source = source;
|
||||
this._validator.validateFlags(source, start, end);
|
||||
return this._state.flags;
|
||||
}
|
||||
parsePattern(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
|
||||
this._state.source = source;
|
||||
this._validator.validatePattern(source, start, end, uFlagOrFlags);
|
||||
return this._state.pattern;
|
||||
}
|
||||
}
|
||||
|
||||
class RegExpVisitor {
|
||||
constructor(handlers) {
|
||||
this._handlers = handlers;
|
||||
}
|
||||
visit(node) {
|
||||
switch (node.type) {
|
||||
case "Alternative":
|
||||
this.visitAlternative(node);
|
||||
break;
|
||||
case "Assertion":
|
||||
this.visitAssertion(node);
|
||||
break;
|
||||
case "Backreference":
|
||||
this.visitBackreference(node);
|
||||
break;
|
||||
case "CapturingGroup":
|
||||
this.visitCapturingGroup(node);
|
||||
break;
|
||||
case "Character":
|
||||
this.visitCharacter(node);
|
||||
break;
|
||||
case "CharacterClass":
|
||||
this.visitCharacterClass(node);
|
||||
break;
|
||||
case "CharacterClassRange":
|
||||
this.visitCharacterClassRange(node);
|
||||
break;
|
||||
case "CharacterSet":
|
||||
this.visitCharacterSet(node);
|
||||
break;
|
||||
case "ClassIntersection":
|
||||
this.visitClassIntersection(node);
|
||||
break;
|
||||
case "ClassStringDisjunction":
|
||||
this.visitClassStringDisjunction(node);
|
||||
break;
|
||||
case "ClassSubtraction":
|
||||
this.visitClassSubtraction(node);
|
||||
break;
|
||||
case "ExpressionCharacterClass":
|
||||
this.visitExpressionCharacterClass(node);
|
||||
break;
|
||||
case "Flags":
|
||||
this.visitFlags(node);
|
||||
break;
|
||||
case "Group":
|
||||
this.visitGroup(node);
|
||||
break;
|
||||
case "Pattern":
|
||||
this.visitPattern(node);
|
||||
break;
|
||||
case "Quantifier":
|
||||
this.visitQuantifier(node);
|
||||
break;
|
||||
case "RegExpLiteral":
|
||||
this.visitRegExpLiteral(node);
|
||||
break;
|
||||
case "StringAlternative":
|
||||
this.visitStringAlternative(node);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown type: ${node.type}`);
|
||||
}
|
||||
}
|
||||
visitAlternative(node) {
|
||||
if (this._handlers.onAlternativeEnter) {
|
||||
this._handlers.onAlternativeEnter(node);
|
||||
}
|
||||
node.elements.forEach(this.visit, this);
|
||||
if (this._handlers.onAlternativeLeave) {
|
||||
this._handlers.onAlternativeLeave(node);
|
||||
}
|
||||
}
|
||||
visitAssertion(node) {
|
||||
if (this._handlers.onAssertionEnter) {
|
||||
this._handlers.onAssertionEnter(node);
|
||||
}
|
||||
if (node.kind === "lookahead" || node.kind === "lookbehind") {
|
||||
node.alternatives.forEach(this.visit, this);
|
||||
}
|
||||
if (this._handlers.onAssertionLeave) {
|
||||
this._handlers.onAssertionLeave(node);
|
||||
}
|
||||
}
|
||||
visitBackreference(node) {
|
||||
if (this._handlers.onBackreferenceEnter) {
|
||||
this._handlers.onBackreferenceEnter(node);
|
||||
}
|
||||
if (this._handlers.onBackreferenceLeave) {
|
||||
this._handlers.onBackreferenceLeave(node);
|
||||
}
|
||||
}
|
||||
visitCapturingGroup(node) {
|
||||
if (this._handlers.onCapturingGroupEnter) {
|
||||
this._handlers.onCapturingGroupEnter(node);
|
||||
}
|
||||
node.alternatives.forEach(this.visit, this);
|
||||
if (this._handlers.onCapturingGroupLeave) {
|
||||
this._handlers.onCapturingGroupLeave(node);
|
||||
}
|
||||
}
|
||||
visitCharacter(node) {
|
||||
if (this._handlers.onCharacterEnter) {
|
||||
this._handlers.onCharacterEnter(node);
|
||||
}
|
||||
if (this._handlers.onCharacterLeave) {
|
||||
this._handlers.onCharacterLeave(node);
|
||||
}
|
||||
}
|
||||
visitCharacterClass(node) {
|
||||
if (this._handlers.onCharacterClassEnter) {
|
||||
this._handlers.onCharacterClassEnter(node);
|
||||
}
|
||||
node.elements.forEach(this.visit, this);
|
||||
if (this._handlers.onCharacterClassLeave) {
|
||||
this._handlers.onCharacterClassLeave(node);
|
||||
}
|
||||
}
|
||||
visitCharacterClassRange(node) {
|
||||
if (this._handlers.onCharacterClassRangeEnter) {
|
||||
this._handlers.onCharacterClassRangeEnter(node);
|
||||
}
|
||||
this.visitCharacter(node.min);
|
||||
this.visitCharacter(node.max);
|
||||
if (this._handlers.onCharacterClassRangeLeave) {
|
||||
this._handlers.onCharacterClassRangeLeave(node);
|
||||
}
|
||||
}
|
||||
visitCharacterSet(node) {
|
||||
if (this._handlers.onCharacterSetEnter) {
|
||||
this._handlers.onCharacterSetEnter(node);
|
||||
}
|
||||
if (this._handlers.onCharacterSetLeave) {
|
||||
this._handlers.onCharacterSetLeave(node);
|
||||
}
|
||||
}
|
||||
visitClassIntersection(node) {
|
||||
if (this._handlers.onClassIntersectionEnter) {
|
||||
this._handlers.onClassIntersectionEnter(node);
|
||||
}
|
||||
this.visit(node.left);
|
||||
this.visit(node.right);
|
||||
if (this._handlers.onClassIntersectionLeave) {
|
||||
this._handlers.onClassIntersectionLeave(node);
|
||||
}
|
||||
}
|
||||
visitClassStringDisjunction(node) {
|
||||
if (this._handlers.onClassStringDisjunctionEnter) {
|
||||
this._handlers.onClassStringDisjunctionEnter(node);
|
||||
}
|
||||
node.alternatives.forEach(this.visit, this);
|
||||
if (this._handlers.onClassStringDisjunctionLeave) {
|
||||
this._handlers.onClassStringDisjunctionLeave(node);
|
||||
}
|
||||
}
|
||||
visitClassSubtraction(node) {
|
||||
if (this._handlers.onClassSubtractionEnter) {
|
||||
this._handlers.onClassSubtractionEnter(node);
|
||||
}
|
||||
this.visit(node.left);
|
||||
this.visit(node.right);
|
||||
if (this._handlers.onClassSubtractionLeave) {
|
||||
this._handlers.onClassSubtractionLeave(node);
|
||||
}
|
||||
}
|
||||
visitExpressionCharacterClass(node) {
|
||||
if (this._handlers.onExpressionCharacterClassEnter) {
|
||||
this._handlers.onExpressionCharacterClassEnter(node);
|
||||
}
|
||||
this.visit(node.expression);
|
||||
if (this._handlers.onExpressionCharacterClassLeave) {
|
||||
this._handlers.onExpressionCharacterClassLeave(node);
|
||||
}
|
||||
}
|
||||
visitFlags(node) {
|
||||
if (this._handlers.onFlagsEnter) {
|
||||
this._handlers.onFlagsEnter(node);
|
||||
}
|
||||
if (this._handlers.onFlagsLeave) {
|
||||
this._handlers.onFlagsLeave(node);
|
||||
}
|
||||
}
|
||||
visitGroup(node) {
|
||||
if (this._handlers.onGroupEnter) {
|
||||
this._handlers.onGroupEnter(node);
|
||||
}
|
||||
node.alternatives.forEach(this.visit, this);
|
||||
if (this._handlers.onGroupLeave) {
|
||||
this._handlers.onGroupLeave(node);
|
||||
}
|
||||
}
|
||||
visitPattern(node) {
|
||||
if (this._handlers.onPatternEnter) {
|
||||
this._handlers.onPatternEnter(node);
|
||||
}
|
||||
node.alternatives.forEach(this.visit, this);
|
||||
if (this._handlers.onPatternLeave) {
|
||||
this._handlers.onPatternLeave(node);
|
||||
}
|
||||
}
|
||||
visitQuantifier(node) {
|
||||
if (this._handlers.onQuantifierEnter) {
|
||||
this._handlers.onQuantifierEnter(node);
|
||||
}
|
||||
this.visit(node.element);
|
||||
if (this._handlers.onQuantifierLeave) {
|
||||
this._handlers.onQuantifierLeave(node);
|
||||
}
|
||||
}
|
||||
visitRegExpLiteral(node) {
|
||||
if (this._handlers.onRegExpLiteralEnter) {
|
||||
this._handlers.onRegExpLiteralEnter(node);
|
||||
}
|
||||
this.visitPattern(node.pattern);
|
||||
this.visitFlags(node.flags);
|
||||
if (this._handlers.onRegExpLiteralLeave) {
|
||||
this._handlers.onRegExpLiteralLeave(node);
|
||||
}
|
||||
}
|
||||
visitStringAlternative(node) {
|
||||
if (this._handlers.onStringAlternativeEnter) {
|
||||
this._handlers.onStringAlternativeEnter(node);
|
||||
}
|
||||
node.elements.forEach(this.visit, this);
|
||||
if (this._handlers.onStringAlternativeLeave) {
|
||||
this._handlers.onStringAlternativeLeave(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parseRegExpLiteral(source, options) {
|
||||
return new RegExpParser(options).parseLiteral(String(source));
|
||||
}
|
||||
function validateRegExpLiteral(source, options) {
|
||||
new RegExpValidator(options).validateLiteral(source);
|
||||
}
|
||||
function visitRegExpAST(node, handlers) {
|
||||
new RegExpVisitor(handlers).visit(node);
|
||||
}
|
||||
|
||||
exports.AST = ast;
|
||||
exports.RegExpParser = RegExpParser;
|
||||
exports.RegExpSyntaxError = RegExpSyntaxError;
|
||||
exports.RegExpValidator = RegExpValidator;
|
||||
exports.parseRegExpLiteral = parseRegExpLiteral;
|
||||
exports.validateRegExpLiteral = validateRegExpLiteral;
|
||||
exports.visitRegExpAST = visitRegExpAST;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@eslint-community/regexpp/index.js.map
generated
vendored
Normal file
1
node_modules/@eslint-community/regexpp/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2737
node_modules/@eslint-community/regexpp/index.mjs
generated
vendored
Normal file
2737
node_modules/@eslint-community/regexpp/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,2737 @@
|
||||
var ast = /*#__PURE__*/Object.freeze({
|
||||
__proto__: null
|
||||
});
|
||||
|
||||
const latestEcmaVersion = 2024;
|
||||
|
||||
let largeIdStartRanges = undefined;
|
||||
let largeIdContinueRanges = undefined;
|
||||
function isIdStart(cp) {
|
||||
if (cp < 0x41)
|
||||
return false;
|
||||
if (cp < 0x5b)
|
||||
return true;
|
||||
if (cp < 0x61)
|
||||
return false;
|
||||
if (cp < 0x7b)
|
||||
return true;
|
||||
return isLargeIdStart(cp);
|
||||
}
|
||||
function isIdContinue(cp) {
|
||||
if (cp < 0x30)
|
||||
return false;
|
||||
if (cp < 0x3a)
|
||||
return true;
|
||||
if (cp < 0x41)
|
||||
return false;
|
||||
if (cp < 0x5b)
|
||||
return true;
|
||||
if (cp === 0x5f)
|
||||
return true;
|
||||
if (cp < 0x61)
|
||||
return false;
|
||||
if (cp < 0x7b)
|
||||
return true;
|
||||
return isLargeIdStart(cp) || isLargeIdContinue(cp);
|
||||
}
|
||||
function isLargeIdStart(cp) {
|
||||
return isInRange(cp, largeIdStartRanges !== null && largeIdStartRanges !== void 0 ? largeIdStartRanges : (largeIdStartRanges = initLargeIdStartRanges()));
|
||||
}
|
||||
function isLargeIdContinue(cp) {
|
||||
return isInRange(cp, largeIdContinueRanges !== null && largeIdContinueRanges !== void 0 ? largeIdContinueRanges : (largeIdContinueRanges = initLargeIdContinueRanges()));
|
||||
}
|
||||
function initLargeIdStartRanges() {
|
||||
return restoreRanges("4q 0 b 0 5 0 6 m 2 u 2 cp 5 b f 4 8 0 2 0 3m 4 2 1 3 3 2 0 7 0 2 2 2 0 2 j 2 2a 2 3u 9 4l 2 11 3 0 7 14 20 q 5 3 1a 16 10 1 2 2q 2 0 g 1 8 1 b 2 3 0 h 0 2 t u 2g c 0 p w a 1 5 0 6 l 5 0 a 0 4 0 o o 8 a 6 n 2 5 i 15 1n 1h 4 0 j 0 8 9 g f 5 7 3 1 3 l 2 6 2 0 4 3 4 0 h 0 e 1 2 2 f 1 b 0 9 5 5 1 3 l 2 6 2 1 2 1 2 1 w 3 2 0 k 2 h 8 2 2 2 l 2 6 2 1 2 4 4 0 j 0 g 1 o 0 c 7 3 1 3 l 2 6 2 1 2 4 4 0 v 1 2 2 g 0 i 0 2 5 4 2 2 3 4 1 2 0 2 1 4 1 4 2 4 b n 0 1h 7 2 2 2 m 2 f 4 0 r 2 3 0 3 1 v 0 5 7 2 2 2 m 2 9 2 4 4 0 w 1 2 1 g 1 i 8 2 2 2 14 3 0 h 0 6 2 9 2 p 5 6 h 4 n 2 8 2 0 3 6 1n 1b 2 1 d 6 1n 1 2 0 2 4 2 n 2 0 2 9 2 1 a 0 3 4 2 0 m 3 x 0 1s 7 2 z s 4 38 16 l 0 h 5 5 3 4 0 4 1 8 2 5 c d 0 i 11 2 0 6 0 3 16 2 98 2 3 3 6 2 0 2 3 3 14 2 3 3 w 2 3 3 6 2 0 2 3 3 e 2 1k 2 3 3 1u 12 f h 2d 3 5 4 h7 3 g 2 p 6 22 4 a 8 h e i f h f c 2 2 g 1f 10 0 5 0 1w 2g 8 14 2 0 6 1x b u 1e t 3 4 c 17 5 p 1j m a 1g 2b 0 2m 1a i 7 1j t e 1 b 17 r z 16 2 b z 3 8 8 16 3 2 16 3 2 5 2 1 4 0 6 5b 1t 7p 3 5 3 11 3 5 3 7 2 0 2 0 2 0 2 u 3 1g 2 6 2 0 4 2 2 6 4 3 3 5 5 c 6 2 2 6 39 0 e 0 h c 2u 0 5 0 3 9 2 0 3 5 7 0 2 0 2 0 2 f 3 3 6 4 5 0 i 14 22g 6c 7 3 4 1 d 11 2 0 6 0 3 1j 8 0 h m a 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 fb 2 q 8 8 4 3 4 5 2d 5 4 2 2h 2 3 6 16 2 2l i v 1d f e9 533 1t h3g 1w 19 3 7g 4 f b 1 l 1a h u 3 27 14 8 3 2u 3 1r 6 1 2 0 2 4 p f 2 2 2 3 2 m u 1f f 1d 1r 5 4 0 2 1 c r b m q s 8 1a t 0 h 4 2 9 b 4 2 14 o 2 2 7 l m 4 0 4 1d 2 0 4 1 3 4 3 0 2 0 p 2 3 a 8 2 d 5 3 5 3 5 a 6 2 6 2 16 2 d 7 36 u 8mb d m 5 1c 6it a5 3 2x 13 6 d 4 6 0 2 9 2 c 2 4 2 0 2 1 2 1 2 2z y a2 j 1r 3 1h 15 b 39 4 2 3q 11 p 7 p c 2g 4 5 3 5 3 5 3 2 10 b 2 p 2 i 2 1 2 e 3 d z 3e 1y 1g 7g s 4 1c 1c v e t 6 11 b t 3 z 5 7 2 4 17 4d j z 5 z 5 13 9 1f d a 2 e 2 6 2 1 2 a 2 e 2 6 2 1 1w 8m a l b 7 p 5 2 15 2 8 1y 5 3 0 2 17 2 1 4 0 3 m b m a u 1u i 2 1 b l b p 1z 1j 7 1 1t 0 g 3 2 2 2 s 17 s 4 s 10 7 2 r s 1h b l b i e h 33 20 1k 1e e 1e e z 9p 15 7 1 27 s b 0 9 l 17 h 1b k s m d 1g 1m 1 3 0 e 18 x o r z u 0 3 0 9 y 4 0 d 1b f 3 m 0 2 0 10 h 2 o k 1 1s 6 2 0 2 3 2 e 2 9 8 1a 13 7 3 1 3 l 2 6 2 1 2 4 4 0 j 0 d 4 4f 1g j 3 l 2 v 1b l 1 2 0 55 1a 16 3 11 1b l 0 1o 16 e 0 20 q 12 6 56 17 39 1r w 7 3 0 3 7 2 1 2 n g 0 2 0 2n 7 3 12 h 0 2 0 t 0 b 13 8 0 m 0 c 19 k 0 j 20 7c 8 2 10 i 0 1e t 35 6 2 1 2 11 m 0 q 5 2 1 2 v f 0 94 i g 0 2 c 2 x 3h 0 28 pl 2v 32 i 5f 219 2o g tr i 5 33u g6 6nu fs 8 u i 26 i t j 1b h 3 w k 6 i j5 1r 3l 22 6 0 1v c 1t 1 2 0 t 4qf 9 yd 17 8 6w8 3 2 6 2 1 2 82 g 0 u 2 3 0 f 3 9 az 1s5 2y 6 c 4 8 8 9 4mf 2c 2 1y 2 1 3 0 3 1 3 3 2 b 2 0 2 6 2 1s 2 3 3 7 2 6 2 r 2 3 2 4 2 0 4 6 2 9f 3 o 2 o 2 u 2 o 2 u 2 o 2 u 2 o 2 u 2 o 2 7 1f9 u 7 5 7a 1p 43 18 b 6 h 0 8y t j 17 dh r l1 6 2 3 2 1 2 e 2 5g 1o 1v 8 0 xh 3 2 q 2 1 2 0 3 0 2 9 2 3 2 0 2 0 7 0 5 0 2 0 2 0 2 2 2 1 2 0 3 0 2 0 2 0 2 0 2 0 2 1 2 0 3 3 2 6 2 3 2 3 2 0 2 9 2 g 6 2 2 4 2 g 3et wyn x 37d 7 65 3 4g1 f 5rk g h9 1wj f1 15v 3t6 6 38f");
|
||||
}
|
||||
function initLargeIdContinueRanges() {
|
||||
return restoreRanges("53 0 g9 33 o 0 70 4 7e 18 2 0 2 1 2 1 2 0 21 a 1d u 7 0 2u 6 3 5 3 1 2 3 3 9 o 0 v q 2k a g 9 y 8 a 0 p 3 2 8 2 2 2 4 18 2 1p 7 17 n 2 w 1j 2 2 h 2 6 b 1 3 9 i 2 1l 0 2 6 3 1 3 2 a 0 b 1 3 9 f 0 3 2 1l 0 2 4 5 1 3 2 4 0 l b 4 0 c 2 1l 0 2 7 2 2 2 2 l 1 3 9 b 5 2 2 1l 0 2 6 3 1 3 2 8 2 b 1 3 9 j 0 1o 4 4 2 2 3 a 0 f 9 h 4 1k 0 2 6 2 2 2 3 8 1 c 1 3 9 i 2 1l 0 2 6 2 2 2 3 8 1 c 1 3 9 4 0 d 3 1k 1 2 6 2 2 2 3 a 0 b 1 3 9 i 2 1z 0 5 5 2 0 2 7 7 9 3 1 1q 0 3 6 d 7 2 9 2g 0 3 8 c 6 2 9 1r 1 7 9 c 0 2 0 2 0 5 1 1e j 2 1 6 a 2 z a 0 2t j 2 9 d 3 5 2 2 2 3 6 4 3 e b 2 e jk 2 a 8 pt 3 t 2 u 1 v 1 1t v a 0 3 9 y 2 2 a 40 0 3b b 5 b b 9 3l a 1p 4 1m 9 2 s 3 a 7 9 n d 2 f 1e 4 1c g c 9 i 8 d 2 v c 3 9 19 d 1d j 9 9 7 9 3b 2 2 k 5 0 7 0 3 2 5j 1r el 1 1e 1 k 0 3g c 5 0 4 b 2db 2 3y 0 2p v ff 5 2y 1 2p 0 n51 9 1y 0 5 9 x 1 29 1 7l 0 4 0 5 0 o 4 5 0 2c 1 1f h b 9 7 h e a t 7 q c 19 3 1c d g 9 c 0 b 9 1c d d 0 9 1 3 9 y 2 1f 0 2 2 3 1 6 1 2 0 16 4 6 1 6l 7 2 1 3 9 fmt 0 ki f h f 4 1 p 2 5d 9 12 0 12 0 ig 0 6b 0 46 4 86 9 120 2 2 1 6 3 15 2 5 0 4m 1 fy 3 9 9 aa 1 29 2 1z a 1e 3 3f 2 1i e w a 3 1 b 3 1a a 8 0 1a 9 7 2 11 d 2 9 6 1 19 0 d 2 1d d 9 3 2 b 2b b 7 0 3 0 4e b 6 9 7 3 1k 1 2 6 3 1 3 2 a 0 b 1 3 6 4 4 5d h a 9 5 0 2a j d 9 5y 6 3 8 s 1 2b g g 9 2a c 9 9 2c e 5 9 6r e 4m 9 1z 5 2 1 3 3 2 0 2 1 d 9 3c 6 3 6 4 0 t 9 15 6 2 3 9 0 a a 1b f ba 7 2 7 h 9 1l l 2 d 3f 5 4 0 2 1 2 6 2 0 9 9 1d 4 2 1 2 4 9 9 96 3 a 1 2 0 1d 6 4 4 e 9 44n 0 7 e aob 9 2f 9 13 4 1o 6 q 9 s6 0 2 1i 8 3 2a 0 c 1 f58 1 3mq 19 3 m f3 4 4 5 9 7 3 6 v 3 45 2 13e 1d e9 1i 5 1d 9 0 f 0 n 4 2 e 11t 6 2 g 3 6 2 1 2 4 2t 0 4h 6 a 9 9x 0 1q d dv d rb 6 32 6 6 9 3o7 9 gvt3 6n");
|
||||
}
|
||||
function isInRange(cp, ranges) {
|
||||
let l = 0, r = (ranges.length / 2) | 0, i = 0, min = 0, max = 0;
|
||||
while (l < r) {
|
||||
i = ((l + r) / 2) | 0;
|
||||
min = ranges[2 * i];
|
||||
max = ranges[2 * i + 1];
|
||||
if (cp < min) {
|
||||
r = i;
|
||||
}
|
||||
else if (cp > max) {
|
||||
l = i + 1;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function restoreRanges(data) {
|
||||
let last = 0;
|
||||
return data.split(" ").map((s) => (last += parseInt(s, 36) | 0));
|
||||
}
|
||||
|
||||
class DataSet {
|
||||
constructor(raw2018, raw2019, raw2020, raw2021, raw2022, raw2023, raw2024) {
|
||||
this._raw2018 = raw2018;
|
||||
this._raw2019 = raw2019;
|
||||
this._raw2020 = raw2020;
|
||||
this._raw2021 = raw2021;
|
||||
this._raw2022 = raw2022;
|
||||
this._raw2023 = raw2023;
|
||||
this._raw2024 = raw2024;
|
||||
}
|
||||
get es2018() {
|
||||
var _a;
|
||||
return ((_a = this._set2018) !== null && _a !== void 0 ? _a : (this._set2018 = new Set(this._raw2018.split(" "))));
|
||||
}
|
||||
get es2019() {
|
||||
var _a;
|
||||
return ((_a = this._set2019) !== null && _a !== void 0 ? _a : (this._set2019 = new Set(this._raw2019.split(" "))));
|
||||
}
|
||||
get es2020() {
|
||||
var _a;
|
||||
return ((_a = this._set2020) !== null && _a !== void 0 ? _a : (this._set2020 = new Set(this._raw2020.split(" "))));
|
||||
}
|
||||
get es2021() {
|
||||
var _a;
|
||||
return ((_a = this._set2021) !== null && _a !== void 0 ? _a : (this._set2021 = new Set(this._raw2021.split(" "))));
|
||||
}
|
||||
get es2022() {
|
||||
var _a;
|
||||
return ((_a = this._set2022) !== null && _a !== void 0 ? _a : (this._set2022 = new Set(this._raw2022.split(" "))));
|
||||
}
|
||||
get es2023() {
|
||||
var _a;
|
||||
return ((_a = this._set2023) !== null && _a !== void 0 ? _a : (this._set2023 = new Set(this._raw2023.split(" "))));
|
||||
}
|
||||
get es2024() {
|
||||
var _a;
|
||||
return ((_a = this._set2024) !== null && _a !== void 0 ? _a : (this._set2024 = new Set(this._raw2024.split(" "))));
|
||||
}
|
||||
}
|
||||
const gcNameSet = new Set(["General_Category", "gc"]);
|
||||
const scNameSet = new Set(["Script", "Script_Extensions", "sc", "scx"]);
|
||||
const gcValueSets = new DataSet("C Cased_Letter Cc Cf Close_Punctuation Cn Co Combining_Mark Connector_Punctuation Control Cs Currency_Symbol Dash_Punctuation Decimal_Number Enclosing_Mark Final_Punctuation Format Initial_Punctuation L LC Letter Letter_Number Line_Separator Ll Lm Lo Lowercase_Letter Lt Lu M Mark Math_Symbol Mc Me Mn Modifier_Letter Modifier_Symbol N Nd Nl No Nonspacing_Mark Number Open_Punctuation Other Other_Letter Other_Number Other_Punctuation Other_Symbol P Paragraph_Separator Pc Pd Pe Pf Pi Po Private_Use Ps Punctuation S Sc Separator Sk Sm So Space_Separator Spacing_Mark Surrogate Symbol Titlecase_Letter Unassigned Uppercase_Letter Z Zl Zp Zs cntrl digit punct", "", "", "", "", "", "");
|
||||
const scValueSets = new DataSet("Adlam Adlm Aghb Ahom Anatolian_Hieroglyphs Arab Arabic Armenian Armi Armn Avestan Avst Bali Balinese Bamu Bamum Bass Bassa_Vah Batak Batk Beng Bengali Bhaiksuki Bhks Bopo Bopomofo Brah Brahmi Brai Braille Bugi Buginese Buhd Buhid Cakm Canadian_Aboriginal Cans Cari Carian Caucasian_Albanian Chakma Cham Cher Cherokee Common Copt Coptic Cprt Cuneiform Cypriot Cyrillic Cyrl Deseret Deva Devanagari Dsrt Dupl Duployan Egyp Egyptian_Hieroglyphs Elba Elbasan Ethi Ethiopic Geor Georgian Glag Glagolitic Gonm Goth Gothic Gran Grantha Greek Grek Gujarati Gujr Gurmukhi Guru Han Hang Hangul Hani Hano Hanunoo Hatr Hatran Hebr Hebrew Hira Hiragana Hluw Hmng Hung Imperial_Aramaic Inherited Inscriptional_Pahlavi Inscriptional_Parthian Ital Java Javanese Kaithi Kali Kana Kannada Katakana Kayah_Li Khar Kharoshthi Khmer Khmr Khoj Khojki Khudawadi Knda Kthi Lana Lao Laoo Latin Latn Lepc Lepcha Limb Limbu Lina Linb Linear_A Linear_B Lisu Lyci Lycian Lydi Lydian Mahajani Mahj Malayalam Mand Mandaic Mani Manichaean Marc Marchen Masaram_Gondi Meetei_Mayek Mend Mende_Kikakui Merc Mero Meroitic_Cursive Meroitic_Hieroglyphs Miao Mlym Modi Mong Mongolian Mro Mroo Mtei Mult Multani Myanmar Mymr Nabataean Narb Nbat New_Tai_Lue Newa Nko Nkoo Nshu Nushu Ogam Ogham Ol_Chiki Olck Old_Hungarian Old_Italic Old_North_Arabian Old_Permic Old_Persian Old_South_Arabian Old_Turkic Oriya Orkh Orya Osage Osge Osma Osmanya Pahawh_Hmong Palm Palmyrene Pau_Cin_Hau Pauc Perm Phag Phags_Pa Phli Phlp Phnx Phoenician Plrd Prti Psalter_Pahlavi Qaac Qaai Rejang Rjng Runic Runr Samaritan Samr Sarb Saur Saurashtra Sgnw Sharada Shavian Shaw Shrd Sidd Siddham SignWriting Sind Sinh Sinhala Sora Sora_Sompeng Soyo Soyombo Sund Sundanese Sylo Syloti_Nagri Syrc Syriac Tagalog Tagb Tagbanwa Tai_Le Tai_Tham Tai_Viet Takr Takri Tale Talu Tamil Taml Tang Tangut Tavt Telu Telugu Tfng Tglg Thaa Thaana Thai Tibetan Tibt Tifinagh Tirh Tirhuta Ugar Ugaritic Vai Vaii Wara Warang_Citi Xpeo Xsux Yi Yiii Zanabazar_Square Zanb Zinh Zyyy", "Dogr Dogra Gong Gunjala_Gondi Hanifi_Rohingya Maka Makasar Medefaidrin Medf Old_Sogdian Rohg Sogd Sogdian Sogo", "Elym Elymaic Hmnp Nand Nandinagari Nyiakeng_Puachue_Hmong Wancho Wcho", "Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi", "Cpmn Cypro_Minoan Old_Uyghur Ougr Tangsa Tnsa Toto Vith Vithkuqi", "Hrkt Katakana_Or_Hiragana Kawi Nag_Mundari Nagm Unknown Zzzz", "");
|
||||
const binPropertySets = new DataSet("AHex ASCII ASCII_Hex_Digit Alpha Alphabetic Any Assigned Bidi_C Bidi_Control Bidi_M Bidi_Mirrored CI CWCF CWCM CWKCF CWL CWT CWU Case_Ignorable Cased Changes_When_Casefolded Changes_When_Casemapped Changes_When_Lowercased Changes_When_NFKC_Casefolded Changes_When_Titlecased Changes_When_Uppercased DI Dash Default_Ignorable_Code_Point Dep Deprecated Dia Diacritic Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Ext Extender Gr_Base Gr_Ext Grapheme_Base Grapheme_Extend Hex Hex_Digit IDC IDS IDSB IDST IDS_Binary_Operator IDS_Trinary_Operator ID_Continue ID_Start Ideo Ideographic Join_C Join_Control LOE Logical_Order_Exception Lower Lowercase Math NChar Noncharacter_Code_Point Pat_Syn Pat_WS Pattern_Syntax Pattern_White_Space QMark Quotation_Mark RI Radical Regional_Indicator SD STerm Sentence_Terminal Soft_Dotted Term Terminal_Punctuation UIdeo Unified_Ideograph Upper Uppercase VS Variation_Selector White_Space XIDC XIDS XID_Continue XID_Start space", "Extended_Pictographic", "", "EBase EComp EMod EPres ExtPict", "", "", "");
|
||||
const binPropertyOfStringsSets = new DataSet("", "", "", "", "", "", "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji RGI_Emoji_Flag_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence");
|
||||
function isValidUnicodeProperty(version, name, value) {
|
||||
if (gcNameSet.has(name)) {
|
||||
return version >= 2018 && gcValueSets.es2018.has(value);
|
||||
}
|
||||
if (scNameSet.has(name)) {
|
||||
return ((version >= 2018 && scValueSets.es2018.has(value)) ||
|
||||
(version >= 2019 && scValueSets.es2019.has(value)) ||
|
||||
(version >= 2020 && scValueSets.es2020.has(value)) ||
|
||||
(version >= 2021 && scValueSets.es2021.has(value)) ||
|
||||
(version >= 2022 && scValueSets.es2022.has(value)) ||
|
||||
(version >= 2023 && scValueSets.es2023.has(value)));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isValidLoneUnicodeProperty(version, value) {
|
||||
return ((version >= 2018 && binPropertySets.es2018.has(value)) ||
|
||||
(version >= 2019 && binPropertySets.es2019.has(value)) ||
|
||||
(version >= 2021 && binPropertySets.es2021.has(value)));
|
||||
}
|
||||
function isValidLoneUnicodePropertyOfString(version, value) {
|
||||
return version >= 2024 && binPropertyOfStringsSets.es2024.has(value);
|
||||
}
|
||||
|
||||
const BACKSPACE = 0x08;
|
||||
const CHARACTER_TABULATION = 0x09;
|
||||
const LINE_FEED = 0x0a;
|
||||
const LINE_TABULATION = 0x0b;
|
||||
const FORM_FEED = 0x0c;
|
||||
const CARRIAGE_RETURN = 0x0d;
|
||||
const EXCLAMATION_MARK = 0x21;
|
||||
const NUMBER_SIGN = 0x23;
|
||||
const DOLLAR_SIGN = 0x24;
|
||||
const PERCENT_SIGN = 0x25;
|
||||
const AMPERSAND = 0x26;
|
||||
const LEFT_PARENTHESIS = 0x28;
|
||||
const RIGHT_PARENTHESIS = 0x29;
|
||||
const ASTERISK = 0x2a;
|
||||
const PLUS_SIGN = 0x2b;
|
||||
const COMMA = 0x2c;
|
||||
const HYPHEN_MINUS = 0x2d;
|
||||
const FULL_STOP = 0x2e;
|
||||
const SOLIDUS = 0x2f;
|
||||
const DIGIT_ZERO = 0x30;
|
||||
const DIGIT_ONE = 0x31;
|
||||
const DIGIT_SEVEN = 0x37;
|
||||
const DIGIT_NINE = 0x39;
|
||||
const COLON = 0x3a;
|
||||
const SEMICOLON = 0x3b;
|
||||
const LESS_THAN_SIGN = 0x3c;
|
||||
const EQUALS_SIGN = 0x3d;
|
||||
const GREATER_THAN_SIGN = 0x3e;
|
||||
const QUESTION_MARK = 0x3f;
|
||||
const COMMERCIAL_AT = 0x40;
|
||||
const LATIN_CAPITAL_LETTER_A = 0x41;
|
||||
const LATIN_CAPITAL_LETTER_B = 0x42;
|
||||
const LATIN_CAPITAL_LETTER_D = 0x44;
|
||||
const LATIN_CAPITAL_LETTER_F = 0x46;
|
||||
const LATIN_CAPITAL_LETTER_P = 0x50;
|
||||
const LATIN_CAPITAL_LETTER_S = 0x53;
|
||||
const LATIN_CAPITAL_LETTER_W = 0x57;
|
||||
const LATIN_CAPITAL_LETTER_Z = 0x5a;
|
||||
const LOW_LINE = 0x5f;
|
||||
const LATIN_SMALL_LETTER_A = 0x61;
|
||||
const LATIN_SMALL_LETTER_B = 0x62;
|
||||
const LATIN_SMALL_LETTER_C = 0x63;
|
||||
const LATIN_SMALL_LETTER_D = 0x64;
|
||||
const LATIN_SMALL_LETTER_F = 0x66;
|
||||
const LATIN_SMALL_LETTER_G = 0x67;
|
||||
const LATIN_SMALL_LETTER_I = 0x69;
|
||||
const LATIN_SMALL_LETTER_K = 0x6b;
|
||||
const LATIN_SMALL_LETTER_M = 0x6d;
|
||||
const LATIN_SMALL_LETTER_N = 0x6e;
|
||||
const LATIN_SMALL_LETTER_P = 0x70;
|
||||
const LATIN_SMALL_LETTER_Q = 0x71;
|
||||
const LATIN_SMALL_LETTER_R = 0x72;
|
||||
const LATIN_SMALL_LETTER_S = 0x73;
|
||||
const LATIN_SMALL_LETTER_T = 0x74;
|
||||
const LATIN_SMALL_LETTER_U = 0x75;
|
||||
const LATIN_SMALL_LETTER_V = 0x76;
|
||||
const LATIN_SMALL_LETTER_W = 0x77;
|
||||
const LATIN_SMALL_LETTER_X = 0x78;
|
||||
const LATIN_SMALL_LETTER_Y = 0x79;
|
||||
const LATIN_SMALL_LETTER_Z = 0x7a;
|
||||
const LEFT_SQUARE_BRACKET = 0x5b;
|
||||
const REVERSE_SOLIDUS = 0x5c;
|
||||
const RIGHT_SQUARE_BRACKET = 0x5d;
|
||||
const CIRCUMFLEX_ACCENT = 0x5e;
|
||||
const GRAVE_ACCENT = 0x60;
|
||||
const LEFT_CURLY_BRACKET = 0x7b;
|
||||
const VERTICAL_LINE = 0x7c;
|
||||
const RIGHT_CURLY_BRACKET = 0x7d;
|
||||
const TILDE = 0x7e;
|
||||
const ZERO_WIDTH_NON_JOINER = 0x200c;
|
||||
const ZERO_WIDTH_JOINER = 0x200d;
|
||||
const LINE_SEPARATOR = 0x2028;
|
||||
const PARAGRAPH_SEPARATOR = 0x2029;
|
||||
const MIN_CODE_POINT = 0x00;
|
||||
const MAX_CODE_POINT = 0x10ffff;
|
||||
function isLatinLetter(code) {
|
||||
return ((code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_Z) ||
|
||||
(code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_Z));
|
||||
}
|
||||
function isDecimalDigit(code) {
|
||||
return code >= DIGIT_ZERO && code <= DIGIT_NINE;
|
||||
}
|
||||
function isOctalDigit(code) {
|
||||
return code >= DIGIT_ZERO && code <= DIGIT_SEVEN;
|
||||
}
|
||||
function isHexDigit(code) {
|
||||
return ((code >= DIGIT_ZERO && code <= DIGIT_NINE) ||
|
||||
(code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) ||
|
||||
(code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F));
|
||||
}
|
||||
function isLineTerminator(code) {
|
||||
return (code === LINE_FEED ||
|
||||
code === CARRIAGE_RETURN ||
|
||||
code === LINE_SEPARATOR ||
|
||||
code === PARAGRAPH_SEPARATOR);
|
||||
}
|
||||
function isValidUnicode(code) {
|
||||
return code >= MIN_CODE_POINT && code <= MAX_CODE_POINT;
|
||||
}
|
||||
function digitToInt(code) {
|
||||
if (code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F) {
|
||||
return code - LATIN_SMALL_LETTER_A + 10;
|
||||
}
|
||||
if (code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) {
|
||||
return code - LATIN_CAPITAL_LETTER_A + 10;
|
||||
}
|
||||
return code - DIGIT_ZERO;
|
||||
}
|
||||
function isLeadSurrogate(code) {
|
||||
return code >= 0xd800 && code <= 0xdbff;
|
||||
}
|
||||
function isTrailSurrogate(code) {
|
||||
return code >= 0xdc00 && code <= 0xdfff;
|
||||
}
|
||||
function combineSurrogatePair(lead, trail) {
|
||||
return (lead - 0xd800) * 0x400 + (trail - 0xdc00) + 0x10000;
|
||||
}
|
||||
|
||||
const legacyImpl = {
|
||||
at(s, end, i) {
|
||||
return i < end ? s.charCodeAt(i) : -1;
|
||||
},
|
||||
width(c) {
|
||||
return 1;
|
||||
},
|
||||
};
|
||||
const unicodeImpl = {
|
||||
at(s, end, i) {
|
||||
return i < end ? s.codePointAt(i) : -1;
|
||||
},
|
||||
width(c) {
|
||||
return c > 0xffff ? 2 : 1;
|
||||
},
|
||||
};
|
||||
class Reader {
|
||||
constructor() {
|
||||
this._impl = legacyImpl;
|
||||
this._s = "";
|
||||
this._i = 0;
|
||||
this._end = 0;
|
||||
this._cp1 = -1;
|
||||
this._w1 = 1;
|
||||
this._cp2 = -1;
|
||||
this._w2 = 1;
|
||||
this._cp3 = -1;
|
||||
this._w3 = 1;
|
||||
this._cp4 = -1;
|
||||
}
|
||||
get source() {
|
||||
return this._s;
|
||||
}
|
||||
get index() {
|
||||
return this._i;
|
||||
}
|
||||
get currentCodePoint() {
|
||||
return this._cp1;
|
||||
}
|
||||
get nextCodePoint() {
|
||||
return this._cp2;
|
||||
}
|
||||
get nextCodePoint2() {
|
||||
return this._cp3;
|
||||
}
|
||||
get nextCodePoint3() {
|
||||
return this._cp4;
|
||||
}
|
||||
reset(source, start, end, uFlag) {
|
||||
this._impl = uFlag ? unicodeImpl : legacyImpl;
|
||||
this._s = source;
|
||||
this._end = end;
|
||||
this.rewind(start);
|
||||
}
|
||||
rewind(index) {
|
||||
const impl = this._impl;
|
||||
this._i = index;
|
||||
this._cp1 = impl.at(this._s, this._end, index);
|
||||
this._w1 = impl.width(this._cp1);
|
||||
this._cp2 = impl.at(this._s, this._end, index + this._w1);
|
||||
this._w2 = impl.width(this._cp2);
|
||||
this._cp3 = impl.at(this._s, this._end, index + this._w1 + this._w2);
|
||||
this._w3 = impl.width(this._cp3);
|
||||
this._cp4 = impl.at(this._s, this._end, index + this._w1 + this._w2 + this._w3);
|
||||
}
|
||||
advance() {
|
||||
if (this._cp1 !== -1) {
|
||||
const impl = this._impl;
|
||||
this._i += this._w1;
|
||||
this._cp1 = this._cp2;
|
||||
this._w1 = this._w2;
|
||||
this._cp2 = this._cp3;
|
||||
this._w2 = impl.width(this._cp2);
|
||||
this._cp3 = this._cp4;
|
||||
this._w3 = impl.width(this._cp3);
|
||||
this._cp4 = impl.at(this._s, this._end, this._i + this._w1 + this._w2 + this._w3);
|
||||
}
|
||||
}
|
||||
eat(cp) {
|
||||
if (this._cp1 === cp) {
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eat2(cp1, cp2) {
|
||||
if (this._cp1 === cp1 && this._cp2 === cp2) {
|
||||
this.advance();
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eat3(cp1, cp2, cp3) {
|
||||
if (this._cp1 === cp1 && this._cp2 === cp2 && this._cp3 === cp3) {
|
||||
this.advance();
|
||||
this.advance();
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class RegExpSyntaxError extends SyntaxError {
|
||||
constructor(message, index) {
|
||||
super(message);
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
function newRegExpSyntaxError(srcCtx, flags, index, message) {
|
||||
let source = "";
|
||||
if (srcCtx.kind === "literal") {
|
||||
const literal = srcCtx.source.slice(srcCtx.start, srcCtx.end);
|
||||
if (literal) {
|
||||
source = `: ${literal}`;
|
||||
}
|
||||
}
|
||||
else if (srcCtx.kind === "pattern") {
|
||||
const pattern = srcCtx.source.slice(srcCtx.start, srcCtx.end);
|
||||
const flagsText = `${flags.unicode ? "u" : ""}${flags.unicodeSets ? "v" : ""}`;
|
||||
source = `: /${pattern}/${flagsText}`;
|
||||
}
|
||||
return new RegExpSyntaxError(`Invalid regular expression${source}: ${message}`, index);
|
||||
}
|
||||
|
||||
const SYNTAX_CHARACTER = new Set([
|
||||
CIRCUMFLEX_ACCENT,
|
||||
DOLLAR_SIGN,
|
||||
REVERSE_SOLIDUS,
|
||||
FULL_STOP,
|
||||
ASTERISK,
|
||||
PLUS_SIGN,
|
||||
QUESTION_MARK,
|
||||
LEFT_PARENTHESIS,
|
||||
RIGHT_PARENTHESIS,
|
||||
LEFT_SQUARE_BRACKET,
|
||||
RIGHT_SQUARE_BRACKET,
|
||||
LEFT_CURLY_BRACKET,
|
||||
RIGHT_CURLY_BRACKET,
|
||||
VERTICAL_LINE,
|
||||
]);
|
||||
const CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR_CHARACTER = new Set([
|
||||
AMPERSAND,
|
||||
EXCLAMATION_MARK,
|
||||
NUMBER_SIGN,
|
||||
DOLLAR_SIGN,
|
||||
PERCENT_SIGN,
|
||||
ASTERISK,
|
||||
PLUS_SIGN,
|
||||
COMMA,
|
||||
FULL_STOP,
|
||||
COLON,
|
||||
SEMICOLON,
|
||||
LESS_THAN_SIGN,
|
||||
EQUALS_SIGN,
|
||||
GREATER_THAN_SIGN,
|
||||
QUESTION_MARK,
|
||||
COMMERCIAL_AT,
|
||||
CIRCUMFLEX_ACCENT,
|
||||
GRAVE_ACCENT,
|
||||
TILDE,
|
||||
]);
|
||||
const CLASS_SET_SYNTAX_CHARACTER = new Set([
|
||||
LEFT_PARENTHESIS,
|
||||
RIGHT_PARENTHESIS,
|
||||
LEFT_SQUARE_BRACKET,
|
||||
RIGHT_SQUARE_BRACKET,
|
||||
LEFT_CURLY_BRACKET,
|
||||
RIGHT_CURLY_BRACKET,
|
||||
SOLIDUS,
|
||||
HYPHEN_MINUS,
|
||||
REVERSE_SOLIDUS,
|
||||
VERTICAL_LINE,
|
||||
]);
|
||||
const CLASS_SET_RESERVED_PUNCTUATOR = new Set([
|
||||
AMPERSAND,
|
||||
HYPHEN_MINUS,
|
||||
EXCLAMATION_MARK,
|
||||
NUMBER_SIGN,
|
||||
PERCENT_SIGN,
|
||||
COMMA,
|
||||
COLON,
|
||||
SEMICOLON,
|
||||
LESS_THAN_SIGN,
|
||||
EQUALS_SIGN,
|
||||
GREATER_THAN_SIGN,
|
||||
COMMERCIAL_AT,
|
||||
GRAVE_ACCENT,
|
||||
TILDE,
|
||||
]);
|
||||
function isSyntaxCharacter(cp) {
|
||||
return SYNTAX_CHARACTER.has(cp);
|
||||
}
|
||||
function isClassSetReservedDoublePunctuatorCharacter(cp) {
|
||||
return CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR_CHARACTER.has(cp);
|
||||
}
|
||||
function isClassSetSyntaxCharacter(cp) {
|
||||
return CLASS_SET_SYNTAX_CHARACTER.has(cp);
|
||||
}
|
||||
function isClassSetReservedPunctuator(cp) {
|
||||
return CLASS_SET_RESERVED_PUNCTUATOR.has(cp);
|
||||
}
|
||||
function isIdentifierStartChar(cp) {
|
||||
return isIdStart(cp) || cp === DOLLAR_SIGN || cp === LOW_LINE;
|
||||
}
|
||||
function isIdentifierPartChar(cp) {
|
||||
return (isIdContinue(cp) ||
|
||||
cp === DOLLAR_SIGN ||
|
||||
cp === ZERO_WIDTH_NON_JOINER ||
|
||||
cp === ZERO_WIDTH_JOINER);
|
||||
}
|
||||
function isUnicodePropertyNameCharacter(cp) {
|
||||
return isLatinLetter(cp) || cp === LOW_LINE;
|
||||
}
|
||||
function isUnicodePropertyValueCharacter(cp) {
|
||||
return isUnicodePropertyNameCharacter(cp) || isDecimalDigit(cp);
|
||||
}
|
||||
class RegExpValidator {
|
||||
constructor(options) {
|
||||
this._reader = new Reader();
|
||||
this._unicodeMode = false;
|
||||
this._unicodeSetsMode = false;
|
||||
this._nFlag = false;
|
||||
this._lastIntValue = 0;
|
||||
this._lastRange = {
|
||||
min: 0,
|
||||
max: Number.POSITIVE_INFINITY,
|
||||
};
|
||||
this._lastStrValue = "";
|
||||
this._lastAssertionIsQuantifiable = false;
|
||||
this._numCapturingParens = 0;
|
||||
this._groupNames = new Set();
|
||||
this._backreferenceNames = new Set();
|
||||
this._srcCtx = null;
|
||||
this._options = options !== null && options !== void 0 ? options : {};
|
||||
}
|
||||
validateLiteral(source, start = 0, end = source.length) {
|
||||
this._srcCtx = { source, start, end, kind: "literal" };
|
||||
this._unicodeSetsMode = this._unicodeMode = this._nFlag = false;
|
||||
this.reset(source, start, end);
|
||||
this.onLiteralEnter(start);
|
||||
if (this.eat(SOLIDUS) && this.eatRegExpBody() && this.eat(SOLIDUS)) {
|
||||
const flagStart = this.index;
|
||||
const unicode = source.includes("u", flagStart);
|
||||
const unicodeSets = source.includes("v", flagStart);
|
||||
this.validateFlagsInternal(source, flagStart, end);
|
||||
this.validatePatternInternal(source, start + 1, flagStart - 1, {
|
||||
unicode,
|
||||
unicodeSets,
|
||||
});
|
||||
}
|
||||
else if (start >= end) {
|
||||
this.raise("Empty");
|
||||
}
|
||||
else {
|
||||
const c = String.fromCodePoint(this.currentCodePoint);
|
||||
this.raise(`Unexpected character '${c}'`);
|
||||
}
|
||||
this.onLiteralLeave(start, end);
|
||||
}
|
||||
validateFlags(source, start = 0, end = source.length) {
|
||||
this._srcCtx = { source, start, end, kind: "flags" };
|
||||
this.validateFlagsInternal(source, start, end);
|
||||
}
|
||||
validatePattern(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
|
||||
this._srcCtx = { source, start, end, kind: "pattern" };
|
||||
this.validatePatternInternal(source, start, end, uFlagOrFlags);
|
||||
}
|
||||
validatePatternInternal(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
|
||||
const mode = this._parseFlagsOptionToMode(uFlagOrFlags, end);
|
||||
this._unicodeMode = mode.unicodeMode;
|
||||
this._nFlag = mode.nFlag;
|
||||
this._unicodeSetsMode = mode.unicodeSetsMode;
|
||||
this.reset(source, start, end);
|
||||
this.consumePattern();
|
||||
if (!this._nFlag &&
|
||||
this.ecmaVersion >= 2018 &&
|
||||
this._groupNames.size > 0) {
|
||||
this._nFlag = true;
|
||||
this.rewind(start);
|
||||
this.consumePattern();
|
||||
}
|
||||
}
|
||||
validateFlagsInternal(source, start, end) {
|
||||
const existingFlags = new Set();
|
||||
let global = false;
|
||||
let ignoreCase = false;
|
||||
let multiline = false;
|
||||
let sticky = false;
|
||||
let unicode = false;
|
||||
let dotAll = false;
|
||||
let hasIndices = false;
|
||||
let unicodeSets = false;
|
||||
for (let i = start; i < end; ++i) {
|
||||
const flag = source.charCodeAt(i);
|
||||
if (existingFlags.has(flag)) {
|
||||
this.raise(`Duplicated flag '${source[i]}'`, { index: start });
|
||||
}
|
||||
existingFlags.add(flag);
|
||||
if (flag === LATIN_SMALL_LETTER_G) {
|
||||
global = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_I) {
|
||||
ignoreCase = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_M) {
|
||||
multiline = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_U &&
|
||||
this.ecmaVersion >= 2015) {
|
||||
unicode = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_Y &&
|
||||
this.ecmaVersion >= 2015) {
|
||||
sticky = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_S &&
|
||||
this.ecmaVersion >= 2018) {
|
||||
dotAll = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_D &&
|
||||
this.ecmaVersion >= 2022) {
|
||||
hasIndices = true;
|
||||
}
|
||||
else if (flag === LATIN_SMALL_LETTER_V &&
|
||||
this.ecmaVersion >= 2024) {
|
||||
unicodeSets = true;
|
||||
}
|
||||
else {
|
||||
this.raise(`Invalid flag '${source[i]}'`, { index: start });
|
||||
}
|
||||
}
|
||||
this.onRegExpFlags(start, end, {
|
||||
global,
|
||||
ignoreCase,
|
||||
multiline,
|
||||
unicode,
|
||||
sticky,
|
||||
dotAll,
|
||||
hasIndices,
|
||||
unicodeSets,
|
||||
});
|
||||
}
|
||||
_parseFlagsOptionToMode(uFlagOrFlags, sourceEnd) {
|
||||
let unicode = false;
|
||||
let unicodeSets = false;
|
||||
if (uFlagOrFlags && this.ecmaVersion >= 2015) {
|
||||
if (typeof uFlagOrFlags === "object") {
|
||||
unicode = Boolean(uFlagOrFlags.unicode);
|
||||
if (this.ecmaVersion >= 2024) {
|
||||
unicodeSets = Boolean(uFlagOrFlags.unicodeSets);
|
||||
}
|
||||
}
|
||||
else {
|
||||
unicode = uFlagOrFlags;
|
||||
}
|
||||
}
|
||||
if (unicode && unicodeSets) {
|
||||
this.raise("Invalid regular expression flags", {
|
||||
index: sourceEnd + 1,
|
||||
unicode,
|
||||
unicodeSets,
|
||||
});
|
||||
}
|
||||
const unicodeMode = unicode || unicodeSets;
|
||||
const nFlag = (unicode && this.ecmaVersion >= 2018) ||
|
||||
unicodeSets ||
|
||||
Boolean(this._options.strict && this.ecmaVersion >= 2023);
|
||||
const unicodeSetsMode = unicodeSets;
|
||||
return { unicodeMode, nFlag, unicodeSetsMode };
|
||||
}
|
||||
get strict() {
|
||||
return Boolean(this._options.strict) || this._unicodeMode;
|
||||
}
|
||||
get ecmaVersion() {
|
||||
var _a;
|
||||
return (_a = this._options.ecmaVersion) !== null && _a !== void 0 ? _a : latestEcmaVersion;
|
||||
}
|
||||
onLiteralEnter(start) {
|
||||
if (this._options.onLiteralEnter) {
|
||||
this._options.onLiteralEnter(start);
|
||||
}
|
||||
}
|
||||
onLiteralLeave(start, end) {
|
||||
if (this._options.onLiteralLeave) {
|
||||
this._options.onLiteralLeave(start, end);
|
||||
}
|
||||
}
|
||||
onRegExpFlags(start, end, flags) {
|
||||
if (this._options.onRegExpFlags) {
|
||||
this._options.onRegExpFlags(start, end, flags);
|
||||
}
|
||||
if (this._options.onFlags) {
|
||||
this._options.onFlags(start, end, flags.global, flags.ignoreCase, flags.multiline, flags.unicode, flags.sticky, flags.dotAll, flags.hasIndices);
|
||||
}
|
||||
}
|
||||
onPatternEnter(start) {
|
||||
if (this._options.onPatternEnter) {
|
||||
this._options.onPatternEnter(start);
|
||||
}
|
||||
}
|
||||
onPatternLeave(start, end) {
|
||||
if (this._options.onPatternLeave) {
|
||||
this._options.onPatternLeave(start, end);
|
||||
}
|
||||
}
|
||||
onDisjunctionEnter(start) {
|
||||
if (this._options.onDisjunctionEnter) {
|
||||
this._options.onDisjunctionEnter(start);
|
||||
}
|
||||
}
|
||||
onDisjunctionLeave(start, end) {
|
||||
if (this._options.onDisjunctionLeave) {
|
||||
this._options.onDisjunctionLeave(start, end);
|
||||
}
|
||||
}
|
||||
onAlternativeEnter(start, index) {
|
||||
if (this._options.onAlternativeEnter) {
|
||||
this._options.onAlternativeEnter(start, index);
|
||||
}
|
||||
}
|
||||
onAlternativeLeave(start, end, index) {
|
||||
if (this._options.onAlternativeLeave) {
|
||||
this._options.onAlternativeLeave(start, end, index);
|
||||
}
|
||||
}
|
||||
onGroupEnter(start) {
|
||||
if (this._options.onGroupEnter) {
|
||||
this._options.onGroupEnter(start);
|
||||
}
|
||||
}
|
||||
onGroupLeave(start, end) {
|
||||
if (this._options.onGroupLeave) {
|
||||
this._options.onGroupLeave(start, end);
|
||||
}
|
||||
}
|
||||
onCapturingGroupEnter(start, name) {
|
||||
if (this._options.onCapturingGroupEnter) {
|
||||
this._options.onCapturingGroupEnter(start, name);
|
||||
}
|
||||
}
|
||||
onCapturingGroupLeave(start, end, name) {
|
||||
if (this._options.onCapturingGroupLeave) {
|
||||
this._options.onCapturingGroupLeave(start, end, name);
|
||||
}
|
||||
}
|
||||
onQuantifier(start, end, min, max, greedy) {
|
||||
if (this._options.onQuantifier) {
|
||||
this._options.onQuantifier(start, end, min, max, greedy);
|
||||
}
|
||||
}
|
||||
onLookaroundAssertionEnter(start, kind, negate) {
|
||||
if (this._options.onLookaroundAssertionEnter) {
|
||||
this._options.onLookaroundAssertionEnter(start, kind, negate);
|
||||
}
|
||||
}
|
||||
onLookaroundAssertionLeave(start, end, kind, negate) {
|
||||
if (this._options.onLookaroundAssertionLeave) {
|
||||
this._options.onLookaroundAssertionLeave(start, end, kind, negate);
|
||||
}
|
||||
}
|
||||
onEdgeAssertion(start, end, kind) {
|
||||
if (this._options.onEdgeAssertion) {
|
||||
this._options.onEdgeAssertion(start, end, kind);
|
||||
}
|
||||
}
|
||||
onWordBoundaryAssertion(start, end, kind, negate) {
|
||||
if (this._options.onWordBoundaryAssertion) {
|
||||
this._options.onWordBoundaryAssertion(start, end, kind, negate);
|
||||
}
|
||||
}
|
||||
onAnyCharacterSet(start, end, kind) {
|
||||
if (this._options.onAnyCharacterSet) {
|
||||
this._options.onAnyCharacterSet(start, end, kind);
|
||||
}
|
||||
}
|
||||
onEscapeCharacterSet(start, end, kind, negate) {
|
||||
if (this._options.onEscapeCharacterSet) {
|
||||
this._options.onEscapeCharacterSet(start, end, kind, negate);
|
||||
}
|
||||
}
|
||||
onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings) {
|
||||
if (this._options.onUnicodePropertyCharacterSet) {
|
||||
this._options.onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings);
|
||||
}
|
||||
}
|
||||
onCharacter(start, end, value) {
|
||||
if (this._options.onCharacter) {
|
||||
this._options.onCharacter(start, end, value);
|
||||
}
|
||||
}
|
||||
onBackreference(start, end, ref) {
|
||||
if (this._options.onBackreference) {
|
||||
this._options.onBackreference(start, end, ref);
|
||||
}
|
||||
}
|
||||
onCharacterClassEnter(start, negate, unicodeSets) {
|
||||
if (this._options.onCharacterClassEnter) {
|
||||
this._options.onCharacterClassEnter(start, negate, unicodeSets);
|
||||
}
|
||||
}
|
||||
onCharacterClassLeave(start, end, negate) {
|
||||
if (this._options.onCharacterClassLeave) {
|
||||
this._options.onCharacterClassLeave(start, end, negate);
|
||||
}
|
||||
}
|
||||
onCharacterClassRange(start, end, min, max) {
|
||||
if (this._options.onCharacterClassRange) {
|
||||
this._options.onCharacterClassRange(start, end, min, max);
|
||||
}
|
||||
}
|
||||
onClassIntersection(start, end) {
|
||||
if (this._options.onClassIntersection) {
|
||||
this._options.onClassIntersection(start, end);
|
||||
}
|
||||
}
|
||||
onClassSubtraction(start, end) {
|
||||
if (this._options.onClassSubtraction) {
|
||||
this._options.onClassSubtraction(start, end);
|
||||
}
|
||||
}
|
||||
onClassStringDisjunctionEnter(start) {
|
||||
if (this._options.onClassStringDisjunctionEnter) {
|
||||
this._options.onClassStringDisjunctionEnter(start);
|
||||
}
|
||||
}
|
||||
onClassStringDisjunctionLeave(start, end) {
|
||||
if (this._options.onClassStringDisjunctionLeave) {
|
||||
this._options.onClassStringDisjunctionLeave(start, end);
|
||||
}
|
||||
}
|
||||
onStringAlternativeEnter(start, index) {
|
||||
if (this._options.onStringAlternativeEnter) {
|
||||
this._options.onStringAlternativeEnter(start, index);
|
||||
}
|
||||
}
|
||||
onStringAlternativeLeave(start, end, index) {
|
||||
if (this._options.onStringAlternativeLeave) {
|
||||
this._options.onStringAlternativeLeave(start, end, index);
|
||||
}
|
||||
}
|
||||
get index() {
|
||||
return this._reader.index;
|
||||
}
|
||||
get currentCodePoint() {
|
||||
return this._reader.currentCodePoint;
|
||||
}
|
||||
get nextCodePoint() {
|
||||
return this._reader.nextCodePoint;
|
||||
}
|
||||
get nextCodePoint2() {
|
||||
return this._reader.nextCodePoint2;
|
||||
}
|
||||
get nextCodePoint3() {
|
||||
return this._reader.nextCodePoint3;
|
||||
}
|
||||
reset(source, start, end) {
|
||||
this._reader.reset(source, start, end, this._unicodeMode);
|
||||
}
|
||||
rewind(index) {
|
||||
this._reader.rewind(index);
|
||||
}
|
||||
advance() {
|
||||
this._reader.advance();
|
||||
}
|
||||
eat(cp) {
|
||||
return this._reader.eat(cp);
|
||||
}
|
||||
eat2(cp1, cp2) {
|
||||
return this._reader.eat2(cp1, cp2);
|
||||
}
|
||||
eat3(cp1, cp2, cp3) {
|
||||
return this._reader.eat3(cp1, cp2, cp3);
|
||||
}
|
||||
raise(message, context) {
|
||||
var _a, _b, _c;
|
||||
throw newRegExpSyntaxError(this._srcCtx, {
|
||||
unicode: (_a = context === null || context === void 0 ? void 0 : context.unicode) !== null && _a !== void 0 ? _a : (this._unicodeMode && !this._unicodeSetsMode),
|
||||
unicodeSets: (_b = context === null || context === void 0 ? void 0 : context.unicodeSets) !== null && _b !== void 0 ? _b : this._unicodeSetsMode,
|
||||
}, (_c = context === null || context === void 0 ? void 0 : context.index) !== null && _c !== void 0 ? _c : this.index, message);
|
||||
}
|
||||
eatRegExpBody() {
|
||||
const start = this.index;
|
||||
let inClass = false;
|
||||
let escaped = false;
|
||||
for (;;) {
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp === -1 || isLineTerminator(cp)) {
|
||||
const kind = inClass ? "character class" : "regular expression";
|
||||
this.raise(`Unterminated ${kind}`);
|
||||
}
|
||||
if (escaped) {
|
||||
escaped = false;
|
||||
}
|
||||
else if (cp === REVERSE_SOLIDUS) {
|
||||
escaped = true;
|
||||
}
|
||||
else if (cp === LEFT_SQUARE_BRACKET) {
|
||||
inClass = true;
|
||||
}
|
||||
else if (cp === RIGHT_SQUARE_BRACKET) {
|
||||
inClass = false;
|
||||
}
|
||||
else if ((cp === SOLIDUS && !inClass) ||
|
||||
(cp === ASTERISK && this.index === start)) {
|
||||
break;
|
||||
}
|
||||
this.advance();
|
||||
}
|
||||
return this.index !== start;
|
||||
}
|
||||
consumePattern() {
|
||||
const start = this.index;
|
||||
this._numCapturingParens = this.countCapturingParens();
|
||||
this._groupNames.clear();
|
||||
this._backreferenceNames.clear();
|
||||
this.onPatternEnter(start);
|
||||
this.consumeDisjunction();
|
||||
const cp = this.currentCodePoint;
|
||||
if (this.currentCodePoint !== -1) {
|
||||
if (cp === RIGHT_PARENTHESIS) {
|
||||
this.raise("Unmatched ')'");
|
||||
}
|
||||
if (cp === REVERSE_SOLIDUS) {
|
||||
this.raise("\\ at end of pattern");
|
||||
}
|
||||
if (cp === RIGHT_SQUARE_BRACKET || cp === RIGHT_CURLY_BRACKET) {
|
||||
this.raise("Lone quantifier brackets");
|
||||
}
|
||||
const c = String.fromCodePoint(cp);
|
||||
this.raise(`Unexpected character '${c}'`);
|
||||
}
|
||||
for (const name of this._backreferenceNames) {
|
||||
if (!this._groupNames.has(name)) {
|
||||
this.raise("Invalid named capture referenced");
|
||||
}
|
||||
}
|
||||
this.onPatternLeave(start, this.index);
|
||||
}
|
||||
countCapturingParens() {
|
||||
const start = this.index;
|
||||
let inClass = false;
|
||||
let escaped = false;
|
||||
let count = 0;
|
||||
let cp = 0;
|
||||
while ((cp = this.currentCodePoint) !== -1) {
|
||||
if (escaped) {
|
||||
escaped = false;
|
||||
}
|
||||
else if (cp === REVERSE_SOLIDUS) {
|
||||
escaped = true;
|
||||
}
|
||||
else if (cp === LEFT_SQUARE_BRACKET) {
|
||||
inClass = true;
|
||||
}
|
||||
else if (cp === RIGHT_SQUARE_BRACKET) {
|
||||
inClass = false;
|
||||
}
|
||||
else if (cp === LEFT_PARENTHESIS &&
|
||||
!inClass &&
|
||||
(this.nextCodePoint !== QUESTION_MARK ||
|
||||
(this.nextCodePoint2 === LESS_THAN_SIGN &&
|
||||
this.nextCodePoint3 !== EQUALS_SIGN &&
|
||||
this.nextCodePoint3 !== EXCLAMATION_MARK))) {
|
||||
count += 1;
|
||||
}
|
||||
this.advance();
|
||||
}
|
||||
this.rewind(start);
|
||||
return count;
|
||||
}
|
||||
consumeDisjunction() {
|
||||
const start = this.index;
|
||||
let i = 0;
|
||||
this.onDisjunctionEnter(start);
|
||||
do {
|
||||
this.consumeAlternative(i++);
|
||||
} while (this.eat(VERTICAL_LINE));
|
||||
if (this.consumeQuantifier(true)) {
|
||||
this.raise("Nothing to repeat");
|
||||
}
|
||||
if (this.eat(LEFT_CURLY_BRACKET)) {
|
||||
this.raise("Lone quantifier brackets");
|
||||
}
|
||||
this.onDisjunctionLeave(start, this.index);
|
||||
}
|
||||
consumeAlternative(i) {
|
||||
const start = this.index;
|
||||
this.onAlternativeEnter(start, i);
|
||||
while (this.currentCodePoint !== -1 && this.consumeTerm()) {
|
||||
}
|
||||
this.onAlternativeLeave(start, this.index, i);
|
||||
}
|
||||
consumeTerm() {
|
||||
if (this._unicodeMode || this.strict) {
|
||||
return (this.consumeAssertion() ||
|
||||
(this.consumeAtom() && this.consumeOptionalQuantifier()));
|
||||
}
|
||||
return ((this.consumeAssertion() &&
|
||||
(!this._lastAssertionIsQuantifiable ||
|
||||
this.consumeOptionalQuantifier())) ||
|
||||
(this.consumeExtendedAtom() && this.consumeOptionalQuantifier()));
|
||||
}
|
||||
consumeOptionalQuantifier() {
|
||||
this.consumeQuantifier();
|
||||
return true;
|
||||
}
|
||||
consumeAssertion() {
|
||||
const start = this.index;
|
||||
this._lastAssertionIsQuantifiable = false;
|
||||
if (this.eat(CIRCUMFLEX_ACCENT)) {
|
||||
this.onEdgeAssertion(start, this.index, "start");
|
||||
return true;
|
||||
}
|
||||
if (this.eat(DOLLAR_SIGN)) {
|
||||
this.onEdgeAssertion(start, this.index, "end");
|
||||
return true;
|
||||
}
|
||||
if (this.eat2(REVERSE_SOLIDUS, LATIN_CAPITAL_LETTER_B)) {
|
||||
this.onWordBoundaryAssertion(start, this.index, "word", true);
|
||||
return true;
|
||||
}
|
||||
if (this.eat2(REVERSE_SOLIDUS, LATIN_SMALL_LETTER_B)) {
|
||||
this.onWordBoundaryAssertion(start, this.index, "word", false);
|
||||
return true;
|
||||
}
|
||||
if (this.eat2(LEFT_PARENTHESIS, QUESTION_MARK)) {
|
||||
const lookbehind = this.ecmaVersion >= 2018 && this.eat(LESS_THAN_SIGN);
|
||||
let negate = false;
|
||||
if (this.eat(EQUALS_SIGN) ||
|
||||
(negate = this.eat(EXCLAMATION_MARK))) {
|
||||
const kind = lookbehind ? "lookbehind" : "lookahead";
|
||||
this.onLookaroundAssertionEnter(start, kind, negate);
|
||||
this.consumeDisjunction();
|
||||
if (!this.eat(RIGHT_PARENTHESIS)) {
|
||||
this.raise("Unterminated group");
|
||||
}
|
||||
this._lastAssertionIsQuantifiable = !lookbehind && !this.strict;
|
||||
this.onLookaroundAssertionLeave(start, this.index, kind, negate);
|
||||
return true;
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeQuantifier(noConsume = false) {
|
||||
const start = this.index;
|
||||
let min = 0;
|
||||
let max = 0;
|
||||
let greedy = false;
|
||||
if (this.eat(ASTERISK)) {
|
||||
min = 0;
|
||||
max = Number.POSITIVE_INFINITY;
|
||||
}
|
||||
else if (this.eat(PLUS_SIGN)) {
|
||||
min = 1;
|
||||
max = Number.POSITIVE_INFINITY;
|
||||
}
|
||||
else if (this.eat(QUESTION_MARK)) {
|
||||
min = 0;
|
||||
max = 1;
|
||||
}
|
||||
else if (this.eatBracedQuantifier(noConsume)) {
|
||||
({ min, max } = this._lastRange);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
greedy = !this.eat(QUESTION_MARK);
|
||||
if (!noConsume) {
|
||||
this.onQuantifier(start, this.index, min, max, greedy);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
eatBracedQuantifier(noError) {
|
||||
const start = this.index;
|
||||
if (this.eat(LEFT_CURLY_BRACKET)) {
|
||||
if (this.eatDecimalDigits()) {
|
||||
const min = this._lastIntValue;
|
||||
let max = min;
|
||||
if (this.eat(COMMA)) {
|
||||
max = this.eatDecimalDigits()
|
||||
? this._lastIntValue
|
||||
: Number.POSITIVE_INFINITY;
|
||||
}
|
||||
if (this.eat(RIGHT_CURLY_BRACKET)) {
|
||||
if (!noError && max < min) {
|
||||
this.raise("numbers out of order in {} quantifier");
|
||||
}
|
||||
this._lastRange = { min, max };
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!noError && (this._unicodeMode || this.strict)) {
|
||||
this.raise("Incomplete quantifier");
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeAtom() {
|
||||
return (this.consumePatternCharacter() ||
|
||||
this.consumeDot() ||
|
||||
this.consumeReverseSolidusAtomEscape() ||
|
||||
Boolean(this.consumeCharacterClass()) ||
|
||||
this.consumeUncapturingGroup() ||
|
||||
this.consumeCapturingGroup());
|
||||
}
|
||||
consumeDot() {
|
||||
if (this.eat(FULL_STOP)) {
|
||||
this.onAnyCharacterSet(this.index - 1, this.index, "any");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeReverseSolidusAtomEscape() {
|
||||
const start = this.index;
|
||||
if (this.eat(REVERSE_SOLIDUS)) {
|
||||
if (this.consumeAtomEscape()) {
|
||||
return true;
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeUncapturingGroup() {
|
||||
const start = this.index;
|
||||
if (this.eat3(LEFT_PARENTHESIS, QUESTION_MARK, COLON)) {
|
||||
this.onGroupEnter(start);
|
||||
this.consumeDisjunction();
|
||||
if (!this.eat(RIGHT_PARENTHESIS)) {
|
||||
this.raise("Unterminated group");
|
||||
}
|
||||
this.onGroupLeave(start, this.index);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeCapturingGroup() {
|
||||
const start = this.index;
|
||||
if (this.eat(LEFT_PARENTHESIS)) {
|
||||
let name = null;
|
||||
if (this.ecmaVersion >= 2018) {
|
||||
if (this.consumeGroupSpecifier()) {
|
||||
name = this._lastStrValue;
|
||||
}
|
||||
}
|
||||
else if (this.currentCodePoint === QUESTION_MARK) {
|
||||
this.raise("Invalid group");
|
||||
}
|
||||
this.onCapturingGroupEnter(start, name);
|
||||
this.consumeDisjunction();
|
||||
if (!this.eat(RIGHT_PARENTHESIS)) {
|
||||
this.raise("Unterminated group");
|
||||
}
|
||||
this.onCapturingGroupLeave(start, this.index, name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeExtendedAtom() {
|
||||
return (this.consumeDot() ||
|
||||
this.consumeReverseSolidusAtomEscape() ||
|
||||
this.consumeReverseSolidusFollowedByC() ||
|
||||
Boolean(this.consumeCharacterClass()) ||
|
||||
this.consumeUncapturingGroup() ||
|
||||
this.consumeCapturingGroup() ||
|
||||
this.consumeInvalidBracedQuantifier() ||
|
||||
this.consumeExtendedPatternCharacter());
|
||||
}
|
||||
consumeReverseSolidusFollowedByC() {
|
||||
const start = this.index;
|
||||
if (this.currentCodePoint === REVERSE_SOLIDUS &&
|
||||
this.nextCodePoint === LATIN_SMALL_LETTER_C) {
|
||||
this._lastIntValue = this.currentCodePoint;
|
||||
this.advance();
|
||||
this.onCharacter(start, this.index, REVERSE_SOLIDUS);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeInvalidBracedQuantifier() {
|
||||
if (this.eatBracedQuantifier(true)) {
|
||||
this.raise("Nothing to repeat");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumePatternCharacter() {
|
||||
const start = this.index;
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp !== -1 && !isSyntaxCharacter(cp)) {
|
||||
this.advance();
|
||||
this.onCharacter(start, this.index, cp);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeExtendedPatternCharacter() {
|
||||
const start = this.index;
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp !== -1 &&
|
||||
cp !== CIRCUMFLEX_ACCENT &&
|
||||
cp !== DOLLAR_SIGN &&
|
||||
cp !== REVERSE_SOLIDUS &&
|
||||
cp !== FULL_STOP &&
|
||||
cp !== ASTERISK &&
|
||||
cp !== PLUS_SIGN &&
|
||||
cp !== QUESTION_MARK &&
|
||||
cp !== LEFT_PARENTHESIS &&
|
||||
cp !== RIGHT_PARENTHESIS &&
|
||||
cp !== LEFT_SQUARE_BRACKET &&
|
||||
cp !== VERTICAL_LINE) {
|
||||
this.advance();
|
||||
this.onCharacter(start, this.index, cp);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeGroupSpecifier() {
|
||||
if (this.eat(QUESTION_MARK)) {
|
||||
if (this.eatGroupName()) {
|
||||
if (!this._groupNames.has(this._lastStrValue)) {
|
||||
this._groupNames.add(this._lastStrValue);
|
||||
return true;
|
||||
}
|
||||
this.raise("Duplicate capture group name");
|
||||
}
|
||||
this.raise("Invalid group");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeAtomEscape() {
|
||||
if (this.consumeBackreference() ||
|
||||
this.consumeCharacterClassEscape() ||
|
||||
this.consumeCharacterEscape() ||
|
||||
(this._nFlag && this.consumeKGroupName())) {
|
||||
return true;
|
||||
}
|
||||
if (this.strict || this._unicodeMode) {
|
||||
this.raise("Invalid escape");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeBackreference() {
|
||||
const start = this.index;
|
||||
if (this.eatDecimalEscape()) {
|
||||
const n = this._lastIntValue;
|
||||
if (n <= this._numCapturingParens) {
|
||||
this.onBackreference(start - 1, this.index, n);
|
||||
return true;
|
||||
}
|
||||
if (this.strict || this._unicodeMode) {
|
||||
this.raise("Invalid escape");
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeCharacterClassEscape() {
|
||||
var _a;
|
||||
const start = this.index;
|
||||
if (this.eat(LATIN_SMALL_LETTER_D)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "digit", false);
|
||||
return {};
|
||||
}
|
||||
if (this.eat(LATIN_CAPITAL_LETTER_D)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "digit", true);
|
||||
return {};
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_S)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "space", false);
|
||||
return {};
|
||||
}
|
||||
if (this.eat(LATIN_CAPITAL_LETTER_S)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "space", true);
|
||||
return {};
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_W)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "word", false);
|
||||
return {};
|
||||
}
|
||||
if (this.eat(LATIN_CAPITAL_LETTER_W)) {
|
||||
this._lastIntValue = -1;
|
||||
this.onEscapeCharacterSet(start - 1, this.index, "word", true);
|
||||
return {};
|
||||
}
|
||||
let negate = false;
|
||||
if (this._unicodeMode &&
|
||||
this.ecmaVersion >= 2018 &&
|
||||
(this.eat(LATIN_SMALL_LETTER_P) ||
|
||||
(negate = this.eat(LATIN_CAPITAL_LETTER_P)))) {
|
||||
this._lastIntValue = -1;
|
||||
let result = null;
|
||||
if (this.eat(LEFT_CURLY_BRACKET) &&
|
||||
(result = this.eatUnicodePropertyValueExpression()) &&
|
||||
this.eat(RIGHT_CURLY_BRACKET)) {
|
||||
if (negate && result.strings) {
|
||||
this.raise("Invalid property name");
|
||||
}
|
||||
this.onUnicodePropertyCharacterSet(start - 1, this.index, "property", result.key, result.value, negate, (_a = result.strings) !== null && _a !== void 0 ? _a : false);
|
||||
return { mayContainStrings: result.strings };
|
||||
}
|
||||
this.raise("Invalid property name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
consumeCharacterEscape() {
|
||||
const start = this.index;
|
||||
if (this.eatControlEscape() ||
|
||||
this.eatCControlLetter() ||
|
||||
this.eatZero() ||
|
||||
this.eatHexEscapeSequence() ||
|
||||
this.eatRegExpUnicodeEscapeSequence() ||
|
||||
(!this.strict &&
|
||||
!this._unicodeMode &&
|
||||
this.eatLegacyOctalEscapeSequence()) ||
|
||||
this.eatIdentityEscape()) {
|
||||
this.onCharacter(start - 1, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeKGroupName() {
|
||||
const start = this.index;
|
||||
if (this.eat(LATIN_SMALL_LETTER_K)) {
|
||||
if (this.eatGroupName()) {
|
||||
const groupName = this._lastStrValue;
|
||||
this._backreferenceNames.add(groupName);
|
||||
this.onBackreference(start - 1, this.index, groupName);
|
||||
return true;
|
||||
}
|
||||
this.raise("Invalid named reference");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeCharacterClass() {
|
||||
const start = this.index;
|
||||
if (this.eat(LEFT_SQUARE_BRACKET)) {
|
||||
const negate = this.eat(CIRCUMFLEX_ACCENT);
|
||||
this.onCharacterClassEnter(start, negate, this._unicodeSetsMode);
|
||||
const result = this.consumeClassContents();
|
||||
if (!this.eat(RIGHT_SQUARE_BRACKET)) {
|
||||
if (this.currentCodePoint === -1) {
|
||||
this.raise("Unterminated character class");
|
||||
}
|
||||
this.raise("Invalid character in character class");
|
||||
}
|
||||
if (negate && result.mayContainStrings) {
|
||||
this.raise("Negated character class may contain strings");
|
||||
}
|
||||
this.onCharacterClassLeave(start, this.index, negate);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
consumeClassContents() {
|
||||
if (this._unicodeSetsMode) {
|
||||
if (this.currentCodePoint === RIGHT_SQUARE_BRACKET) {
|
||||
return {};
|
||||
}
|
||||
const result = this.consumeClassSetExpression();
|
||||
return result;
|
||||
}
|
||||
const strict = this.strict || this._unicodeMode;
|
||||
for (;;) {
|
||||
const rangeStart = this.index;
|
||||
if (!this.consumeClassAtom()) {
|
||||
break;
|
||||
}
|
||||
const min = this._lastIntValue;
|
||||
if (!this.eat(HYPHEN_MINUS)) {
|
||||
continue;
|
||||
}
|
||||
this.onCharacter(this.index - 1, this.index, HYPHEN_MINUS);
|
||||
if (!this.consumeClassAtom()) {
|
||||
break;
|
||||
}
|
||||
const max = this._lastIntValue;
|
||||
if (min === -1 || max === -1) {
|
||||
if (strict) {
|
||||
this.raise("Invalid character class");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (min > max) {
|
||||
this.raise("Range out of order in character class");
|
||||
}
|
||||
this.onCharacterClassRange(rangeStart, this.index, min, max);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
consumeClassAtom() {
|
||||
const start = this.index;
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp !== -1 &&
|
||||
cp !== REVERSE_SOLIDUS &&
|
||||
cp !== RIGHT_SQUARE_BRACKET) {
|
||||
this.advance();
|
||||
this._lastIntValue = cp;
|
||||
this.onCharacter(start, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
if (this.eat(REVERSE_SOLIDUS)) {
|
||||
if (this.consumeClassEscape()) {
|
||||
return true;
|
||||
}
|
||||
if (!this.strict &&
|
||||
this.currentCodePoint === LATIN_SMALL_LETTER_C) {
|
||||
this._lastIntValue = REVERSE_SOLIDUS;
|
||||
this.onCharacter(start, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
if (this.strict || this._unicodeMode) {
|
||||
this.raise("Invalid escape");
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeClassEscape() {
|
||||
const start = this.index;
|
||||
if (this.eat(LATIN_SMALL_LETTER_B)) {
|
||||
this._lastIntValue = BACKSPACE;
|
||||
this.onCharacter(start - 1, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
if (this._unicodeMode && this.eat(HYPHEN_MINUS)) {
|
||||
this._lastIntValue = HYPHEN_MINUS;
|
||||
this.onCharacter(start - 1, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
let cp = 0;
|
||||
if (!this.strict &&
|
||||
!this._unicodeMode &&
|
||||
this.currentCodePoint === LATIN_SMALL_LETTER_C &&
|
||||
(isDecimalDigit((cp = this.nextCodePoint)) || cp === LOW_LINE)) {
|
||||
this.advance();
|
||||
this.advance();
|
||||
this._lastIntValue = cp % 0x20;
|
||||
this.onCharacter(start - 1, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
return (Boolean(this.consumeCharacterClassEscape()) ||
|
||||
this.consumeCharacterEscape());
|
||||
}
|
||||
consumeClassSetExpression() {
|
||||
const start = this.index;
|
||||
let mayContainStrings = false;
|
||||
let result = null;
|
||||
if (this.consumeClassSetCharacter()) {
|
||||
if (this.consumeClassSetRangeFromOperator(start)) {
|
||||
this.consumeClassUnionRight({});
|
||||
return {};
|
||||
}
|
||||
mayContainStrings = false;
|
||||
}
|
||||
else if ((result = this.consumeClassSetOperand())) {
|
||||
mayContainStrings = result.mayContainStrings;
|
||||
}
|
||||
else {
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp === REVERSE_SOLIDUS) {
|
||||
this.advance();
|
||||
this.raise("Invalid escape");
|
||||
}
|
||||
if (cp === this.nextCodePoint &&
|
||||
isClassSetReservedDoublePunctuatorCharacter(cp)) {
|
||||
this.raise("Invalid set operation in character class");
|
||||
}
|
||||
this.raise("Invalid character in character class");
|
||||
}
|
||||
if (this.eat2(AMPERSAND, AMPERSAND)) {
|
||||
while (this.currentCodePoint !== AMPERSAND &&
|
||||
(result = this.consumeClassSetOperand())) {
|
||||
this.onClassIntersection(start, this.index);
|
||||
if (!result.mayContainStrings) {
|
||||
mayContainStrings = false;
|
||||
}
|
||||
if (this.eat2(AMPERSAND, AMPERSAND)) {
|
||||
continue;
|
||||
}
|
||||
return { mayContainStrings };
|
||||
}
|
||||
this.raise("Invalid character in character class");
|
||||
}
|
||||
if (this.eat2(HYPHEN_MINUS, HYPHEN_MINUS)) {
|
||||
while (this.consumeClassSetOperand()) {
|
||||
this.onClassSubtraction(start, this.index);
|
||||
if (this.eat2(HYPHEN_MINUS, HYPHEN_MINUS)) {
|
||||
continue;
|
||||
}
|
||||
return { mayContainStrings };
|
||||
}
|
||||
this.raise("Invalid character in character class");
|
||||
}
|
||||
return this.consumeClassUnionRight({ mayContainStrings });
|
||||
}
|
||||
consumeClassUnionRight(leftResult) {
|
||||
let mayContainStrings = leftResult.mayContainStrings;
|
||||
for (;;) {
|
||||
const start = this.index;
|
||||
if (this.consumeClassSetCharacter()) {
|
||||
this.consumeClassSetRangeFromOperator(start);
|
||||
continue;
|
||||
}
|
||||
const result = this.consumeClassSetOperand();
|
||||
if (result) {
|
||||
if (result.mayContainStrings) {
|
||||
mayContainStrings = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return { mayContainStrings };
|
||||
}
|
||||
consumeClassSetRangeFromOperator(start) {
|
||||
const currentStart = this.index;
|
||||
const min = this._lastIntValue;
|
||||
if (this.eat(HYPHEN_MINUS)) {
|
||||
if (this.consumeClassSetCharacter()) {
|
||||
const max = this._lastIntValue;
|
||||
if (min === -1 || max === -1) {
|
||||
this.raise("Invalid character class");
|
||||
}
|
||||
if (min > max) {
|
||||
this.raise("Range out of order in character class");
|
||||
}
|
||||
this.onCharacterClassRange(start, this.index, min, max);
|
||||
return true;
|
||||
}
|
||||
this.rewind(currentStart);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
consumeClassSetOperand() {
|
||||
let result = null;
|
||||
if ((result = this.consumeNestedClass())) {
|
||||
return result;
|
||||
}
|
||||
if ((result = this.consumeClassStringDisjunction())) {
|
||||
return result;
|
||||
}
|
||||
if (this.consumeClassSetCharacter()) {
|
||||
return {};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
consumeNestedClass() {
|
||||
const start = this.index;
|
||||
if (this.eat(LEFT_SQUARE_BRACKET)) {
|
||||
const negate = this.eat(CIRCUMFLEX_ACCENT);
|
||||
this.onCharacterClassEnter(start, negate, true);
|
||||
const result = this.consumeClassContents();
|
||||
if (!this.eat(RIGHT_SQUARE_BRACKET)) {
|
||||
this.raise("Unterminated character class");
|
||||
}
|
||||
if (negate && result.mayContainStrings) {
|
||||
this.raise("Negated character class may contain strings");
|
||||
}
|
||||
this.onCharacterClassLeave(start, this.index, negate);
|
||||
return result;
|
||||
}
|
||||
if (this.eat(REVERSE_SOLIDUS)) {
|
||||
const result = this.consumeCharacterClassEscape();
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
consumeClassStringDisjunction() {
|
||||
const start = this.index;
|
||||
if (this.eat3(REVERSE_SOLIDUS, LATIN_SMALL_LETTER_Q, LEFT_CURLY_BRACKET)) {
|
||||
this.onClassStringDisjunctionEnter(start);
|
||||
let i = 0;
|
||||
let mayContainStrings = false;
|
||||
do {
|
||||
if (this.consumeClassString(i++).mayContainStrings) {
|
||||
mayContainStrings = true;
|
||||
}
|
||||
} while (this.eat(VERTICAL_LINE));
|
||||
if (this.eat(RIGHT_CURLY_BRACKET)) {
|
||||
this.onClassStringDisjunctionLeave(start, this.index);
|
||||
return { mayContainStrings };
|
||||
}
|
||||
this.raise("Unterminated class string disjunction");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
consumeClassString(i) {
|
||||
const start = this.index;
|
||||
let count = 0;
|
||||
this.onStringAlternativeEnter(start, i);
|
||||
while (this.currentCodePoint !== -1 &&
|
||||
this.consumeClassSetCharacter()) {
|
||||
count++;
|
||||
}
|
||||
this.onStringAlternativeLeave(start, this.index, i);
|
||||
return { mayContainStrings: count !== 1 };
|
||||
}
|
||||
consumeClassSetCharacter() {
|
||||
const start = this.index;
|
||||
const cp = this.currentCodePoint;
|
||||
if (cp !== this.nextCodePoint ||
|
||||
!isClassSetReservedDoublePunctuatorCharacter(cp)) {
|
||||
if (cp !== -1 && !isClassSetSyntaxCharacter(cp)) {
|
||||
this._lastIntValue = cp;
|
||||
this.advance();
|
||||
this.onCharacter(start, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (this.eat(REVERSE_SOLIDUS)) {
|
||||
if (this.consumeCharacterEscape()) {
|
||||
return true;
|
||||
}
|
||||
if (isClassSetReservedPunctuator(this.currentCodePoint)) {
|
||||
this._lastIntValue = this.currentCodePoint;
|
||||
this.advance();
|
||||
this.onCharacter(start, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_B)) {
|
||||
this._lastIntValue = BACKSPACE;
|
||||
this.onCharacter(start, this.index, this._lastIntValue);
|
||||
return true;
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatGroupName() {
|
||||
if (this.eat(LESS_THAN_SIGN)) {
|
||||
if (this.eatRegExpIdentifierName() && this.eat(GREATER_THAN_SIGN)) {
|
||||
return true;
|
||||
}
|
||||
this.raise("Invalid capture group name");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpIdentifierName() {
|
||||
if (this.eatRegExpIdentifierStart()) {
|
||||
this._lastStrValue = String.fromCodePoint(this._lastIntValue);
|
||||
while (this.eatRegExpIdentifierPart()) {
|
||||
this._lastStrValue += String.fromCodePoint(this._lastIntValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpIdentifierStart() {
|
||||
const start = this.index;
|
||||
const forceUFlag = !this._unicodeMode && this.ecmaVersion >= 2020;
|
||||
let cp = this.currentCodePoint;
|
||||
this.advance();
|
||||
if (cp === REVERSE_SOLIDUS &&
|
||||
this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
|
||||
cp = this._lastIntValue;
|
||||
}
|
||||
else if (forceUFlag &&
|
||||
isLeadSurrogate(cp) &&
|
||||
isTrailSurrogate(this.currentCodePoint)) {
|
||||
cp = combineSurrogatePair(cp, this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
if (isIdentifierStartChar(cp)) {
|
||||
this._lastIntValue = cp;
|
||||
return true;
|
||||
}
|
||||
if (this.index !== start) {
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpIdentifierPart() {
|
||||
const start = this.index;
|
||||
const forceUFlag = !this._unicodeMode && this.ecmaVersion >= 2020;
|
||||
let cp = this.currentCodePoint;
|
||||
this.advance();
|
||||
if (cp === REVERSE_SOLIDUS &&
|
||||
this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
|
||||
cp = this._lastIntValue;
|
||||
}
|
||||
else if (forceUFlag &&
|
||||
isLeadSurrogate(cp) &&
|
||||
isTrailSurrogate(this.currentCodePoint)) {
|
||||
cp = combineSurrogatePair(cp, this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
if (isIdentifierPartChar(cp)) {
|
||||
this._lastIntValue = cp;
|
||||
return true;
|
||||
}
|
||||
if (this.index !== start) {
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatCControlLetter() {
|
||||
const start = this.index;
|
||||
if (this.eat(LATIN_SMALL_LETTER_C)) {
|
||||
if (this.eatControlLetter()) {
|
||||
return true;
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatZero() {
|
||||
if (this.currentCodePoint === DIGIT_ZERO &&
|
||||
!isDecimalDigit(this.nextCodePoint)) {
|
||||
this._lastIntValue = 0;
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatControlEscape() {
|
||||
if (this.eat(LATIN_SMALL_LETTER_F)) {
|
||||
this._lastIntValue = FORM_FEED;
|
||||
return true;
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_N)) {
|
||||
this._lastIntValue = LINE_FEED;
|
||||
return true;
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_R)) {
|
||||
this._lastIntValue = CARRIAGE_RETURN;
|
||||
return true;
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_T)) {
|
||||
this._lastIntValue = CHARACTER_TABULATION;
|
||||
return true;
|
||||
}
|
||||
if (this.eat(LATIN_SMALL_LETTER_V)) {
|
||||
this._lastIntValue = LINE_TABULATION;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatControlLetter() {
|
||||
const cp = this.currentCodePoint;
|
||||
if (isLatinLetter(cp)) {
|
||||
this.advance();
|
||||
this._lastIntValue = cp % 0x20;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpUnicodeEscapeSequence(forceUFlag = false) {
|
||||
const start = this.index;
|
||||
const uFlag = forceUFlag || this._unicodeMode;
|
||||
if (this.eat(LATIN_SMALL_LETTER_U)) {
|
||||
if ((uFlag && this.eatRegExpUnicodeSurrogatePairEscape()) ||
|
||||
this.eatFixedHexDigits(4) ||
|
||||
(uFlag && this.eatRegExpUnicodeCodePointEscape())) {
|
||||
return true;
|
||||
}
|
||||
if (this.strict || uFlag) {
|
||||
this.raise("Invalid unicode escape");
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpUnicodeSurrogatePairEscape() {
|
||||
const start = this.index;
|
||||
if (this.eatFixedHexDigits(4)) {
|
||||
const lead = this._lastIntValue;
|
||||
if (isLeadSurrogate(lead) &&
|
||||
this.eat(REVERSE_SOLIDUS) &&
|
||||
this.eat(LATIN_SMALL_LETTER_U) &&
|
||||
this.eatFixedHexDigits(4)) {
|
||||
const trail = this._lastIntValue;
|
||||
if (isTrailSurrogate(trail)) {
|
||||
this._lastIntValue = combineSurrogatePair(lead, trail);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatRegExpUnicodeCodePointEscape() {
|
||||
const start = this.index;
|
||||
if (this.eat(LEFT_CURLY_BRACKET) &&
|
||||
this.eatHexDigits() &&
|
||||
this.eat(RIGHT_CURLY_BRACKET) &&
|
||||
isValidUnicode(this._lastIntValue)) {
|
||||
return true;
|
||||
}
|
||||
this.rewind(start);
|
||||
return false;
|
||||
}
|
||||
eatIdentityEscape() {
|
||||
const cp = this.currentCodePoint;
|
||||
if (this.isValidIdentityEscape(cp)) {
|
||||
this._lastIntValue = cp;
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
isValidIdentityEscape(cp) {
|
||||
if (cp === -1) {
|
||||
return false;
|
||||
}
|
||||
if (this._unicodeMode) {
|
||||
return isSyntaxCharacter(cp) || cp === SOLIDUS;
|
||||
}
|
||||
if (this.strict) {
|
||||
return !isIdContinue(cp);
|
||||
}
|
||||
if (this._nFlag) {
|
||||
return !(cp === LATIN_SMALL_LETTER_C || cp === LATIN_SMALL_LETTER_K);
|
||||
}
|
||||
return cp !== LATIN_SMALL_LETTER_C;
|
||||
}
|
||||
eatDecimalEscape() {
|
||||
this._lastIntValue = 0;
|
||||
let cp = this.currentCodePoint;
|
||||
if (cp >= DIGIT_ONE && cp <= DIGIT_NINE) {
|
||||
do {
|
||||
this._lastIntValue = 10 * this._lastIntValue + (cp - DIGIT_ZERO);
|
||||
this.advance();
|
||||
} while ((cp = this.currentCodePoint) >= DIGIT_ZERO &&
|
||||
cp <= DIGIT_NINE);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatUnicodePropertyValueExpression() {
|
||||
const start = this.index;
|
||||
if (this.eatUnicodePropertyName() && this.eat(EQUALS_SIGN)) {
|
||||
const key = this._lastStrValue;
|
||||
if (this.eatUnicodePropertyValue()) {
|
||||
const value = this._lastStrValue;
|
||||
if (isValidUnicodeProperty(this.ecmaVersion, key, value)) {
|
||||
return {
|
||||
key,
|
||||
value: value || null,
|
||||
};
|
||||
}
|
||||
this.raise("Invalid property name");
|
||||
}
|
||||
}
|
||||
this.rewind(start);
|
||||
if (this.eatLoneUnicodePropertyNameOrValue()) {
|
||||
const nameOrValue = this._lastStrValue;
|
||||
if (isValidUnicodeProperty(this.ecmaVersion, "General_Category", nameOrValue)) {
|
||||
return {
|
||||
key: "General_Category",
|
||||
value: nameOrValue || null,
|
||||
};
|
||||
}
|
||||
if (isValidLoneUnicodeProperty(this.ecmaVersion, nameOrValue)) {
|
||||
return {
|
||||
key: nameOrValue,
|
||||
value: null,
|
||||
};
|
||||
}
|
||||
if (this._unicodeSetsMode &&
|
||||
isValidLoneUnicodePropertyOfString(this.ecmaVersion, nameOrValue)) {
|
||||
return {
|
||||
key: nameOrValue,
|
||||
value: null,
|
||||
strings: true,
|
||||
};
|
||||
}
|
||||
this.raise("Invalid property name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
eatUnicodePropertyName() {
|
||||
this._lastStrValue = "";
|
||||
while (isUnicodePropertyNameCharacter(this.currentCodePoint)) {
|
||||
this._lastStrValue += String.fromCodePoint(this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
return this._lastStrValue !== "";
|
||||
}
|
||||
eatUnicodePropertyValue() {
|
||||
this._lastStrValue = "";
|
||||
while (isUnicodePropertyValueCharacter(this.currentCodePoint)) {
|
||||
this._lastStrValue += String.fromCodePoint(this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
return this._lastStrValue !== "";
|
||||
}
|
||||
eatLoneUnicodePropertyNameOrValue() {
|
||||
return this.eatUnicodePropertyValue();
|
||||
}
|
||||
eatHexEscapeSequence() {
|
||||
const start = this.index;
|
||||
if (this.eat(LATIN_SMALL_LETTER_X)) {
|
||||
if (this.eatFixedHexDigits(2)) {
|
||||
return true;
|
||||
}
|
||||
if (this._unicodeMode || this.strict) {
|
||||
this.raise("Invalid escape");
|
||||
}
|
||||
this.rewind(start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatDecimalDigits() {
|
||||
const start = this.index;
|
||||
this._lastIntValue = 0;
|
||||
while (isDecimalDigit(this.currentCodePoint)) {
|
||||
this._lastIntValue =
|
||||
10 * this._lastIntValue + digitToInt(this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
return this.index !== start;
|
||||
}
|
||||
eatHexDigits() {
|
||||
const start = this.index;
|
||||
this._lastIntValue = 0;
|
||||
while (isHexDigit(this.currentCodePoint)) {
|
||||
this._lastIntValue =
|
||||
16 * this._lastIntValue + digitToInt(this.currentCodePoint);
|
||||
this.advance();
|
||||
}
|
||||
return this.index !== start;
|
||||
}
|
||||
eatLegacyOctalEscapeSequence() {
|
||||
if (this.eatOctalDigit()) {
|
||||
const n1 = this._lastIntValue;
|
||||
if (this.eatOctalDigit()) {
|
||||
const n2 = this._lastIntValue;
|
||||
if (n1 <= 3 && this.eatOctalDigit()) {
|
||||
this._lastIntValue = n1 * 64 + n2 * 8 + this._lastIntValue;
|
||||
}
|
||||
else {
|
||||
this._lastIntValue = n1 * 8 + n2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._lastIntValue = n1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
eatOctalDigit() {
|
||||
const cp = this.currentCodePoint;
|
||||
if (isOctalDigit(cp)) {
|
||||
this.advance();
|
||||
this._lastIntValue = cp - DIGIT_ZERO;
|
||||
return true;
|
||||
}
|
||||
this._lastIntValue = 0;
|
||||
return false;
|
||||
}
|
||||
eatFixedHexDigits(length) {
|
||||
const start = this.index;
|
||||
this._lastIntValue = 0;
|
||||
for (let i = 0; i < length; ++i) {
|
||||
const cp = this.currentCodePoint;
|
||||
if (!isHexDigit(cp)) {
|
||||
this.rewind(start);
|
||||
return false;
|
||||
}
|
||||
this._lastIntValue = 16 * this._lastIntValue + digitToInt(cp);
|
||||
this.advance();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const DUMMY_PATTERN = {};
|
||||
const DUMMY_FLAGS = {};
|
||||
const DUMMY_CAPTURING_GROUP = {};
|
||||
function isClassSetOperand(node) {
|
||||
return (node.type === "Character" ||
|
||||
node.type === "CharacterSet" ||
|
||||
node.type === "CharacterClass" ||
|
||||
node.type === "ExpressionCharacterClass" ||
|
||||
node.type === "ClassStringDisjunction");
|
||||
}
|
||||
class RegExpParserState {
|
||||
constructor(options) {
|
||||
var _a;
|
||||
this._node = DUMMY_PATTERN;
|
||||
this._expressionBufferMap = new Map();
|
||||
this._flags = DUMMY_FLAGS;
|
||||
this._backreferences = [];
|
||||
this._capturingGroups = [];
|
||||
this.source = "";
|
||||
this.strict = Boolean(options === null || options === void 0 ? void 0 : options.strict);
|
||||
this.ecmaVersion = (_a = options === null || options === void 0 ? void 0 : options.ecmaVersion) !== null && _a !== void 0 ? _a : latestEcmaVersion;
|
||||
}
|
||||
get pattern() {
|
||||
if (this._node.type !== "Pattern") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
return this._node;
|
||||
}
|
||||
get flags() {
|
||||
if (this._flags.type !== "Flags") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
return this._flags;
|
||||
}
|
||||
onRegExpFlags(start, end, { global, ignoreCase, multiline, unicode, sticky, dotAll, hasIndices, unicodeSets, }) {
|
||||
this._flags = {
|
||||
type: "Flags",
|
||||
parent: null,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
global,
|
||||
ignoreCase,
|
||||
multiline,
|
||||
unicode,
|
||||
sticky,
|
||||
dotAll,
|
||||
hasIndices,
|
||||
unicodeSets,
|
||||
};
|
||||
}
|
||||
onPatternEnter(start) {
|
||||
this._node = {
|
||||
type: "Pattern",
|
||||
parent: null,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
alternatives: [],
|
||||
};
|
||||
this._backreferences.length = 0;
|
||||
this._capturingGroups.length = 0;
|
||||
}
|
||||
onPatternLeave(start, end) {
|
||||
this._node.end = end;
|
||||
this._node.raw = this.source.slice(start, end);
|
||||
for (const reference of this._backreferences) {
|
||||
const ref = reference.ref;
|
||||
const group = typeof ref === "number"
|
||||
? this._capturingGroups[ref - 1]
|
||||
: this._capturingGroups.find((g) => g.name === ref);
|
||||
reference.resolved = group;
|
||||
group.references.push(reference);
|
||||
}
|
||||
}
|
||||
onAlternativeEnter(start) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Assertion" &&
|
||||
parent.type !== "CapturingGroup" &&
|
||||
parent.type !== "Group" &&
|
||||
parent.type !== "Pattern") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._node = {
|
||||
type: "Alternative",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
elements: [],
|
||||
};
|
||||
parent.alternatives.push(this._node);
|
||||
}
|
||||
onAlternativeLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
onGroupEnter(start) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._node = {
|
||||
type: "Group",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
alternatives: [],
|
||||
};
|
||||
parent.elements.push(this._node);
|
||||
}
|
||||
onGroupLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "Group" || node.parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
onCapturingGroupEnter(start, name) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._node = {
|
||||
type: "CapturingGroup",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
name,
|
||||
alternatives: [],
|
||||
references: [],
|
||||
};
|
||||
parent.elements.push(this._node);
|
||||
this._capturingGroups.push(this._node);
|
||||
}
|
||||
onCapturingGroupLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "CapturingGroup" ||
|
||||
node.parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
onQuantifier(start, end, min, max, greedy) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const element = parent.elements.pop();
|
||||
if (element == null ||
|
||||
element.type === "Quantifier" ||
|
||||
(element.type === "Assertion" && element.kind !== "lookahead")) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = {
|
||||
type: "Quantifier",
|
||||
parent,
|
||||
start: element.start,
|
||||
end,
|
||||
raw: this.source.slice(element.start, end),
|
||||
min,
|
||||
max,
|
||||
greedy,
|
||||
element,
|
||||
};
|
||||
parent.elements.push(node);
|
||||
element.parent = node;
|
||||
}
|
||||
onLookaroundAssertionEnter(start, kind, negate) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = (this._node = {
|
||||
type: "Assertion",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
kind,
|
||||
negate,
|
||||
alternatives: [],
|
||||
});
|
||||
parent.elements.push(node);
|
||||
}
|
||||
onLookaroundAssertionLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "Assertion" || node.parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
onEdgeAssertion(start, end, kind) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push({
|
||||
type: "Assertion",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
kind,
|
||||
});
|
||||
}
|
||||
onWordBoundaryAssertion(start, end, kind, negate) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push({
|
||||
type: "Assertion",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
kind,
|
||||
negate,
|
||||
});
|
||||
}
|
||||
onAnyCharacterSet(start, end, kind) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push({
|
||||
type: "CharacterSet",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
kind,
|
||||
});
|
||||
}
|
||||
onEscapeCharacterSet(start, end, kind, negate) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push({
|
||||
type: "CharacterSet",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
kind,
|
||||
negate,
|
||||
});
|
||||
}
|
||||
onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const base = {
|
||||
type: "CharacterSet",
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
kind,
|
||||
key,
|
||||
};
|
||||
if (strings) {
|
||||
if ((parent.type === "CharacterClass" && !parent.unicodeSets) ||
|
||||
negate ||
|
||||
value !== null) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push(Object.assign(Object.assign({}, base), { parent, strings, value, negate }));
|
||||
}
|
||||
else {
|
||||
parent.elements.push(Object.assign(Object.assign({}, base), { parent, strings, value, negate }));
|
||||
}
|
||||
}
|
||||
onCharacter(start, end, value) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative" &&
|
||||
parent.type !== "CharacterClass" &&
|
||||
parent.type !== "StringAlternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push({
|
||||
type: "Character",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
value,
|
||||
});
|
||||
}
|
||||
onBackreference(start, end, ref) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "Alternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = {
|
||||
type: "Backreference",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
ref,
|
||||
resolved: DUMMY_CAPTURING_GROUP,
|
||||
};
|
||||
parent.elements.push(node);
|
||||
this._backreferences.push(node);
|
||||
}
|
||||
onCharacterClassEnter(start, negate, unicodeSets) {
|
||||
const parent = this._node;
|
||||
const base = {
|
||||
type: "CharacterClass",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
unicodeSets,
|
||||
negate,
|
||||
elements: [],
|
||||
};
|
||||
if (parent.type === "Alternative") {
|
||||
const node = Object.assign(Object.assign({}, base), { parent });
|
||||
this._node = node;
|
||||
parent.elements.push(node);
|
||||
}
|
||||
else if (parent.type === "CharacterClass" &&
|
||||
parent.unicodeSets &&
|
||||
unicodeSets) {
|
||||
const node = Object.assign(Object.assign({}, base), { parent,
|
||||
unicodeSets });
|
||||
this._node = node;
|
||||
parent.elements.push(node);
|
||||
}
|
||||
else {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
}
|
||||
onCharacterClassLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "CharacterClass" ||
|
||||
(node.parent.type !== "Alternative" &&
|
||||
node.parent.type !== "CharacterClass")) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const parent = node.parent;
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = parent;
|
||||
const expression = this._expressionBufferMap.get(node);
|
||||
if (!expression) {
|
||||
return;
|
||||
}
|
||||
if (node.elements.length > 0) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._expressionBufferMap.delete(node);
|
||||
const newNode = {
|
||||
type: "ExpressionCharacterClass",
|
||||
parent,
|
||||
start: node.start,
|
||||
end: node.end,
|
||||
raw: node.raw,
|
||||
negate: node.negate,
|
||||
expression,
|
||||
};
|
||||
expression.parent = newNode;
|
||||
if (node !== parent.elements.pop()) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
parent.elements.push(newNode);
|
||||
}
|
||||
onCharacterClassRange(start, end) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "CharacterClass") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const elements = parent.elements;
|
||||
const max = elements.pop();
|
||||
if (!max || max.type !== "Character") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
if (!parent.unicodeSets) {
|
||||
const hyphen = elements.pop();
|
||||
if (!hyphen ||
|
||||
hyphen.type !== "Character" ||
|
||||
hyphen.value !== HYPHEN_MINUS) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
}
|
||||
const min = elements.pop();
|
||||
if (!min || min.type !== "Character") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = {
|
||||
type: "CharacterClassRange",
|
||||
parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
min,
|
||||
max,
|
||||
};
|
||||
min.parent = node;
|
||||
max.parent = node;
|
||||
elements.push(node);
|
||||
}
|
||||
onClassIntersection(start, end) {
|
||||
var _a;
|
||||
const parent = this._node;
|
||||
if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const right = parent.elements.pop();
|
||||
const left = (_a = this._expressionBufferMap.get(parent)) !== null && _a !== void 0 ? _a : parent.elements.pop();
|
||||
if (!left ||
|
||||
!right ||
|
||||
left.type === "ClassSubtraction" ||
|
||||
(left.type !== "ClassIntersection" && !isClassSetOperand(left)) ||
|
||||
!isClassSetOperand(right)) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = {
|
||||
type: "ClassIntersection",
|
||||
parent: parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
left,
|
||||
right,
|
||||
};
|
||||
left.parent = node;
|
||||
right.parent = node;
|
||||
this._expressionBufferMap.set(parent, node);
|
||||
}
|
||||
onClassSubtraction(start, end) {
|
||||
var _a;
|
||||
const parent = this._node;
|
||||
if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const right = parent.elements.pop();
|
||||
const left = (_a = this._expressionBufferMap.get(parent)) !== null && _a !== void 0 ? _a : parent.elements.pop();
|
||||
if (!left ||
|
||||
!right ||
|
||||
left.type === "ClassIntersection" ||
|
||||
(left.type !== "ClassSubtraction" && !isClassSetOperand(left)) ||
|
||||
!isClassSetOperand(right)) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
const node = {
|
||||
type: "ClassSubtraction",
|
||||
parent: parent,
|
||||
start,
|
||||
end,
|
||||
raw: this.source.slice(start, end),
|
||||
left,
|
||||
right,
|
||||
};
|
||||
left.parent = node;
|
||||
right.parent = node;
|
||||
this._expressionBufferMap.set(parent, node);
|
||||
}
|
||||
onClassStringDisjunctionEnter(start) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._node = {
|
||||
type: "ClassStringDisjunction",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
alternatives: [],
|
||||
};
|
||||
parent.elements.push(this._node);
|
||||
}
|
||||
onClassStringDisjunctionLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "ClassStringDisjunction" ||
|
||||
node.parent.type !== "CharacterClass") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
onStringAlternativeEnter(start) {
|
||||
const parent = this._node;
|
||||
if (parent.type !== "ClassStringDisjunction") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
this._node = {
|
||||
type: "StringAlternative",
|
||||
parent,
|
||||
start,
|
||||
end: start,
|
||||
raw: "",
|
||||
elements: [],
|
||||
};
|
||||
parent.alternatives.push(this._node);
|
||||
}
|
||||
onStringAlternativeLeave(start, end) {
|
||||
const node = this._node;
|
||||
if (node.type !== "StringAlternative") {
|
||||
throw new Error("UnknownError");
|
||||
}
|
||||
node.end = end;
|
||||
node.raw = this.source.slice(start, end);
|
||||
this._node = node.parent;
|
||||
}
|
||||
}
|
||||
class RegExpParser {
|
||||
constructor(options) {
|
||||
this._state = new RegExpParserState(options);
|
||||
this._validator = new RegExpValidator(this._state);
|
||||
}
|
||||
parseLiteral(source, start = 0, end = source.length) {
|
||||
this._state.source = source;
|
||||
this._validator.validateLiteral(source, start, end);
|
||||
const pattern = this._state.pattern;
|
||||
const flags = this._state.flags;
|
||||
const literal = {
|
||||
type: "RegExpLiteral",
|
||||
parent: null,
|
||||
start,
|
||||
end,
|
||||
raw: source,
|
||||
pattern,
|
||||
flags,
|
||||
};
|
||||
pattern.parent = literal;
|
||||
flags.parent = literal;
|
||||
return literal;
|
||||
}
|
||||
parseFlags(source, start = 0, end = source.length) {
|
||||
this._state.source = source;
|
||||
this._validator.validateFlags(source, start, end);
|
||||
return this._state.flags;
|
||||
}
|
||||
parsePattern(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
|
||||
this._state.source = source;
|
||||
this._validator.validatePattern(source, start, end, uFlagOrFlags);
|
||||
return this._state.pattern;
|
||||
}
|
||||
}
|
||||
|
||||
class RegExpVisitor {
|
||||
constructor(handlers) {
|
||||
this._handlers = handlers;
|
||||
}
|
||||
visit(node) {
|
||||
switch (node.type) {
|
||||
case "Alternative":
|
||||
this.visitAlternative(node);
|
||||
break;
|
||||
case "Assertion":
|
||||
this.visitAssertion(node);
|
||||
break;
|
||||
case "Backreference":
|
||||
this.visitBackreference(node);
|
||||
break;
|
||||
case "CapturingGroup":
|
||||
this.visitCapturingGroup(node);
|
||||
break;
|
||||
case "Character":
|
||||
this.visitCharacter(node);
|
||||
break;
|
||||
case "CharacterClass":
|
||||
this.visitCharacterClass(node);
|
||||
break;
|
||||
case "CharacterClassRange":
|
||||
this.visitCharacterClassRange(node);
|
||||
break;
|
||||
case "CharacterSet":
|
||||
this.visitCharacterSet(node);
|
||||
break;
|
||||
case "ClassIntersection":
|
||||
this.visitClassIntersection(node);
|
||||
break;
|
||||
case "ClassStringDisjunction":
|
||||
this.visitClassStringDisjunction(node);
|
||||
break;
|
||||
case "ClassSubtraction":
|
||||
this.visitClassSubtraction(node);
|
||||
break;
|
||||
case "ExpressionCharacterClass":
|
||||
this.visitExpressionCharacterClass(node);
|
||||
break;
|
||||
case "Flags":
|
||||
this.visitFlags(node);
|
||||
break;
|
||||
case "Group":
|
||||
this.visitGroup(node);
|
||||
break;
|
||||
case "Pattern":
|
||||
this.visitPattern(node);
|
||||
break;
|
||||
case "Quantifier":
|
||||
this.visitQuantifier(node);
|
||||
break;
|
||||
case "RegExpLiteral":
|
||||
this.visitRegExpLiteral(node);
|
||||
break;
|
||||
case "StringAlternative":
|
||||
this.visitStringAlternative(node);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown type: ${node.type}`);
|
||||
}
|
||||
}
|
||||
visitAlternative(node) {
|
||||
if (this._handlers.onAlternativeEnter) {
|
||||
this._handlers.onAlternativeEnter(node);
|
||||
}
|
||||
node.elements.forEach(this.visit, this);
|
||||
if (this._handlers.onAlternativeLeave) {
|
||||
this._handlers.onAlternativeLeave(node);
|
||||
}
|
||||
}
|
||||
visitAssertion(node) {
|
||||
if (this._handlers.onAssertionEnter) {
|
||||
this._handlers.onAssertionEnter(node);
|
||||
}
|
||||
if (node.kind === "lookahead" || node.kind === "lookbehind") {
|
||||
node.alternatives.forEach(this.visit, this);
|
||||
}
|
||||
if (this._handlers.onAssertionLeave) {
|
||||
this._handlers.onAssertionLeave(node);
|
||||
}
|
||||
}
|
||||
visitBackreference(node) {
|
||||
if (this._handlers.onBackreferenceEnter) {
|
||||
this._handlers.onBackreferenceEnter(node);
|
||||
}
|
||||
if (this._handlers.onBackreferenceLeave) {
|
||||
this._handlers.onBackreferenceLeave(node);
|
||||
}
|
||||
}
|
||||
visitCapturingGroup(node) {
|
||||
if (this._handlers.onCapturingGroupEnter) {
|
||||
this._handlers.onCapturingGroupEnter(node);
|
||||
}
|
||||
node.alternatives.forEach(this.visit, this);
|
||||
if (this._handlers.onCapturingGroupLeave) {
|
||||
this._handlers.onCapturingGroupLeave(node);
|
||||
}
|
||||
}
|
||||
visitCharacter(node) {
|
||||
if (this._handlers.onCharacterEnter) {
|
||||
this._handlers.onCharacterEnter(node);
|
||||
}
|
||||
if (this._handlers.onCharacterLeave) {
|
||||
this._handlers.onCharacterLeave(node);
|
||||
}
|
||||
}
|
||||
visitCharacterClass(node) {
|
||||
if (this._handlers.onCharacterClassEnter) {
|
||||
this._handlers.onCharacterClassEnter(node);
|
||||
}
|
||||
node.elements.forEach(this.visit, this);
|
||||
if (this._handlers.onCharacterClassLeave) {
|
||||
this._handlers.onCharacterClassLeave(node);
|
||||
}
|
||||
}
|
||||
visitCharacterClassRange(node) {
|
||||
if (this._handlers.onCharacterClassRangeEnter) {
|
||||
this._handlers.onCharacterClassRangeEnter(node);
|
||||
}
|
||||
this.visitCharacter(node.min);
|
||||
this.visitCharacter(node.max);
|
||||
if (this._handlers.onCharacterClassRangeLeave) {
|
||||
this._handlers.onCharacterClassRangeLeave(node);
|
||||
}
|
||||
}
|
||||
visitCharacterSet(node) {
|
||||
if (this._handlers.onCharacterSetEnter) {
|
||||
this._handlers.onCharacterSetEnter(node);
|
||||
}
|
||||
if (this._handlers.onCharacterSetLeave) {
|
||||
this._handlers.onCharacterSetLeave(node);
|
||||
}
|
||||
}
|
||||
visitClassIntersection(node) {
|
||||
if (this._handlers.onClassIntersectionEnter) {
|
||||
this._handlers.onClassIntersectionEnter(node);
|
||||
}
|
||||
this.visit(node.left);
|
||||
this.visit(node.right);
|
||||
if (this._handlers.onClassIntersectionLeave) {
|
||||
this._handlers.onClassIntersectionLeave(node);
|
||||
}
|
||||
}
|
||||
visitClassStringDisjunction(node) {
|
||||
if (this._handlers.onClassStringDisjunctionEnter) {
|
||||
this._handlers.onClassStringDisjunctionEnter(node);
|
||||
}
|
||||
node.alternatives.forEach(this.visit, this);
|
||||
if (this._handlers.onClassStringDisjunctionLeave) {
|
||||
this._handlers.onClassStringDisjunctionLeave(node);
|
||||
}
|
||||
}
|
||||
visitClassSubtraction(node) {
|
||||
if (this._handlers.onClassSubtractionEnter) {
|
||||
this._handlers.onClassSubtractionEnter(node);
|
||||
}
|
||||
this.visit(node.left);
|
||||
this.visit(node.right);
|
||||
if (this._handlers.onClassSubtractionLeave) {
|
||||
this._handlers.onClassSubtractionLeave(node);
|
||||
}
|
||||
}
|
||||
visitExpressionCharacterClass(node) {
|
||||
if (this._handlers.onExpressionCharacterClassEnter) {
|
||||
this._handlers.onExpressionCharacterClassEnter(node);
|
||||
}
|
||||
this.visit(node.expression);
|
||||
if (this._handlers.onExpressionCharacterClassLeave) {
|
||||
this._handlers.onExpressionCharacterClassLeave(node);
|
||||
}
|
||||
}
|
||||
visitFlags(node) {
|
||||
if (this._handlers.onFlagsEnter) {
|
||||
this._handlers.onFlagsEnter(node);
|
||||
}
|
||||
if (this._handlers.onFlagsLeave) {
|
||||
this._handlers.onFlagsLeave(node);
|
||||
}
|
||||
}
|
||||
visitGroup(node) {
|
||||
if (this._handlers.onGroupEnter) {
|
||||
this._handlers.onGroupEnter(node);
|
||||
}
|
||||
node.alternatives.forEach(this.visit, this);
|
||||
if (this._handlers.onGroupLeave) {
|
||||
this._handlers.onGroupLeave(node);
|
||||
}
|
||||
}
|
||||
visitPattern(node) {
|
||||
if (this._handlers.onPatternEnter) {
|
||||
this._handlers.onPatternEnter(node);
|
||||
}
|
||||
node.alternatives.forEach(this.visit, this);
|
||||
if (this._handlers.onPatternLeave) {
|
||||
this._handlers.onPatternLeave(node);
|
||||
}
|
||||
}
|
||||
visitQuantifier(node) {
|
||||
if (this._handlers.onQuantifierEnter) {
|
||||
this._handlers.onQuantifierEnter(node);
|
||||
}
|
||||
this.visit(node.element);
|
||||
if (this._handlers.onQuantifierLeave) {
|
||||
this._handlers.onQuantifierLeave(node);
|
||||
}
|
||||
}
|
||||
visitRegExpLiteral(node) {
|
||||
if (this._handlers.onRegExpLiteralEnter) {
|
||||
this._handlers.onRegExpLiteralEnter(node);
|
||||
}
|
||||
this.visitPattern(node.pattern);
|
||||
this.visitFlags(node.flags);
|
||||
if (this._handlers.onRegExpLiteralLeave) {
|
||||
this._handlers.onRegExpLiteralLeave(node);
|
||||
}
|
||||
}
|
||||
visitStringAlternative(node) {
|
||||
if (this._handlers.onStringAlternativeEnter) {
|
||||
this._handlers.onStringAlternativeEnter(node);
|
||||
}
|
||||
node.elements.forEach(this.visit, this);
|
||||
if (this._handlers.onStringAlternativeLeave) {
|
||||
this._handlers.onStringAlternativeLeave(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parseRegExpLiteral(source, options) {
|
||||
return new RegExpParser(options).parseLiteral(String(source));
|
||||
}
|
||||
function validateRegExpLiteral(source, options) {
|
||||
new RegExpValidator(options).validateLiteral(source);
|
||||
}
|
||||
function visitRegExpAST(node, handlers) {
|
||||
new RegExpVisitor(handlers).visit(node);
|
||||
}
|
||||
|
||||
export { ast as AST, RegExpParser, RegExpSyntaxError, RegExpValidator, parseRegExpLiteral, validateRegExpLiteral, visitRegExpAST };
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
1
node_modules/@eslint-community/regexpp/index.mjs.map
generated
vendored
Normal file
1
node_modules/@eslint-community/regexpp/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
93
node_modules/@eslint-community/regexpp/package.json
generated
vendored
Normal file
93
node_modules/@eslint-community/regexpp/package.json
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
{
|
||||
"name": "@eslint-community/regexpp",
|
||||
"version": "4.10.0",
|
||||
"description": "Regular expression parser for ECMAScript.",
|
||||
"keywords": [
|
||||
"regexp",
|
||||
"regular",
|
||||
"expression",
|
||||
"parser",
|
||||
"validator",
|
||||
"ast",
|
||||
"abstract",
|
||||
"syntax",
|
||||
"tree",
|
||||
"ecmascript",
|
||||
"es2015",
|
||||
"es2016",
|
||||
"es2017",
|
||||
"es2018",
|
||||
"es2019",
|
||||
"es2020",
|
||||
"es2021",
|
||||
"annexB"
|
||||
],
|
||||
"homepage": "https://github.com/eslint-community/regexpp#readme",
|
||||
"bugs": {
|
||||
"url": "https://github.com/eslint-community/regexpp/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/eslint-community/regexpp"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "Toru Nagashima",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./index.d.ts",
|
||||
"import": "./index.mjs",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "index",
|
||||
"files": [
|
||||
"index.*"
|
||||
],
|
||||
"scripts": {
|
||||
"prebuild": "npm run -s clean",
|
||||
"build": "run-s build:*",
|
||||
"build:tsc": "tsc --module es2015",
|
||||
"build:rollup": "rollup -c",
|
||||
"build:dts": "npm run -s build:tsc -- --removeComments false && dts-bundle --name @eslint-community/regexpp --main .temp/index.d.ts --out ../index.d.ts && prettier --write index.d.ts",
|
||||
"clean": "rimraf .temp index.*",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"test": "nyc _mocha \"test/*.ts\" --reporter dot --timeout 10000",
|
||||
"debug": "mocha --require ts-node/register/transpile-only \"test/*.ts\" --reporter dot --timeout 10000",
|
||||
"update:test": "ts-node scripts/update-fixtures.ts",
|
||||
"update:unicode": "run-s update:unicode:*",
|
||||
"update:unicode:ids": "ts-node scripts/update-unicode-ids.ts",
|
||||
"update:unicode:props": "ts-node scripts/update-unicode-properties.ts",
|
||||
"update:test262:extract": "ts-node -T scripts/extract-test262.ts",
|
||||
"preversion": "npm test && npm run -s build",
|
||||
"postversion": "git push && git push --tags",
|
||||
"prewatch": "npm run -s clean",
|
||||
"watch": "_mocha \"test/*.ts\" --require ts-node/register --reporter dot --timeout 10000 --watch-extensions ts --watch --growl"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@eslint-community/eslint-plugin-mysticatea": "^15.5.1",
|
||||
"@rollup/plugin-node-resolve": "^14.1.0",
|
||||
"@types/eslint": "^8.44.3",
|
||||
"@types/jsdom": "^16.2.15",
|
||||
"@types/mocha": "^9.1.1",
|
||||
"@types/node": "^12.20.55",
|
||||
"dts-bundle": "^0.7.3",
|
||||
"eslint": "^8.50.0",
|
||||
"js-tokens": "^8.0.2",
|
||||
"jsdom": "^19.0.0",
|
||||
"mocha": "^9.2.2",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^14.1.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "^2.79.1",
|
||||
"rollup-plugin-sourcemaps": "^0.6.3",
|
||||
"test262": "git+https://github.com/tc39/test262.git",
|
||||
"test262-stream": "^1.4.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "~5.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.0.0 || ^14.0.0 || >=16.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user