summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/esquery/dist/esquery.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/esquery/dist/esquery.js')
-rw-r--r--tools/node_modules/eslint/node_modules/esquery/dist/esquery.js109
1 files changed, 33 insertions, 76 deletions
diff --git a/tools/node_modules/eslint/node_modules/esquery/dist/esquery.js b/tools/node_modules/eslint/node_modules/esquery/dist/esquery.js
index b7a2af0c0b..f303a2b496 100644
--- a/tools/node_modules/eslint/node_modules/esquery/dist/esquery.js
+++ b/tools/node_modules/eslint/node_modules/esquery/dist/esquery.js
@@ -1129,17 +1129,7 @@
},
peg$c100 = ":",
peg$c101 = peg$literalExpectation(":", false),
- peg$c102 = "statement",
- peg$c103 = peg$literalExpectation("statement", true),
- peg$c104 = "expression",
- peg$c105 = peg$literalExpectation("expression", true),
- peg$c106 = "declaration",
- peg$c107 = peg$literalExpectation("declaration", true),
- peg$c108 = "function",
- peg$c109 = peg$literalExpectation("function", true),
- peg$c110 = "pattern",
- peg$c111 = peg$literalExpectation("pattern", true),
- peg$c112 = function peg$c112(c) {
+ peg$c102 = function peg$c102(c) {
return {
type: 'class',
name: c
@@ -3301,61 +3291,9 @@
}
}
if (s1 !== peg$FAILED) {
- if (input.substr(peg$currPos, 9).toLowerCase() === peg$c102) {
- s2 = input.substr(peg$currPos, 9);
- peg$currPos += 9;
- } else {
- s2 = peg$FAILED;
- {
- peg$fail(peg$c103);
- }
- }
- if (s2 === peg$FAILED) {
- if (input.substr(peg$currPos, 10).toLowerCase() === peg$c104) {
- s2 = input.substr(peg$currPos, 10);
- peg$currPos += 10;
- } else {
- s2 = peg$FAILED;
- {
- peg$fail(peg$c105);
- }
- }
- if (s2 === peg$FAILED) {
- if (input.substr(peg$currPos, 11).toLowerCase() === peg$c106) {
- s2 = input.substr(peg$currPos, 11);
- peg$currPos += 11;
- } else {
- s2 = peg$FAILED;
- {
- peg$fail(peg$c107);
- }
- }
- if (s2 === peg$FAILED) {
- if (input.substr(peg$currPos, 8).toLowerCase() === peg$c108) {
- s2 = input.substr(peg$currPos, 8);
- peg$currPos += 8;
- } else {
- s2 = peg$FAILED;
- {
- peg$fail(peg$c109);
- }
- }
- if (s2 === peg$FAILED) {
- if (input.substr(peg$currPos, 7).toLowerCase() === peg$c110) {
- s2 = input.substr(peg$currPos, 7);
- peg$currPos += 7;
- } else {
- s2 = peg$FAILED;
- {
- peg$fail(peg$c111);
- }
- }
- }
- }
- }
- }
+ s2 = peg$parseidentifierName();
if (s2 !== peg$FAILED) {
- s1 = peg$c112(s2);
+ s1 = peg$c102(s2);
s0 = s1;
} else {
peg$currPos = s0;
@@ -3545,8 +3483,9 @@
case 'identifier':
{
var value = selector.value.toLowerCase();
- return function (node) {
- return value === node.type.toLowerCase();
+ return function (node, ancestry, options) {
+ var nodeTypeKey = options && options.nodeTypeKey || 'type';
+ return value === node[nodeTypeKey].toLowerCase();
};
}
case 'field':
@@ -3747,8 +3686,12 @@
}
case 'class':
{
- var name = selector.name.toLowerCase();
- return function (node, ancestry) {
+ return function (node, ancestry, options) {
+ if (options && options.matchClass) {
+ return options.matchClass(selector.name, node, ancestry);
+ }
+ if (options && options.nodeTypeKey) return false;
+ var name = selector.name.toLowerCase();
switch (name) {
case 'statement':
if (node.type.slice(-9) === 'Statement') return true;
@@ -3775,10 +3718,21 @@
* @param {external:AST} node The given node.
* @returns {string[]} An array of visitor keys for the given node.
*/
+
+ /**
+ * @callback ClassMatcher
+ * @param {string} className The name of the class to match.
+ * @param {external:AST} node The node to match against.
+ * @param {Array<external:AST>} ancestry The ancestry of the node.
+ * @returns {boolean} True if the node matches the class, false if not.
+ */
+
/**
* @typedef {object} ESQueryOptions
+ * @property {string} [nodeTypeKey="type"] By passing `nodeTypeKey`, we can allow other ASTs to use ESQuery.
* @property { { [nodeType: string]: string[] } } [visitorKeys] By passing `visitorKeys` mapping, we can extend the properties of the nodes that traverse the node.
* @property {TraverseOptionFallback} [fallback] By passing `fallback` option, we can control the properties of traversing nodes when encountering unknown nodes.
+ * @property {ClassMatcher} [matchClass] By passing `matchClass` option, we can customize the interpretation of classes.
*/
/**
@@ -3812,7 +3766,8 @@
* @returns {string[]} Visitor keys of the node.
*/
function getVisitorKeys(node, options) {
- var nodeType = node.type;
+ var nodeTypeKey = options && options.nodeTypeKey || 'type';
+ var nodeType = node[nodeTypeKey];
if (options && options.visitorKeys && options.visitorKeys[nodeType]) {
return options.visitorKeys[nodeType];
}
@@ -3824,17 +3779,19 @@
}
// 'iteration' fallback
return Object.keys(node).filter(function (key) {
- return key !== 'type';
+ return key !== nodeTypeKey;
});
}
/**
* Check whether the given value is an ASTNode or not.
* @param {any} node The value to check.
+ * @param {ESQueryOptions|undefined} options The options to use.
* @returns {boolean} `true` if the value is an ASTNode.
*/
- function isNode(node) {
- return node !== null && _typeof(node) === 'object' && typeof node.type === 'string';
+ function isNode(node, options) {
+ var nodeTypeKey = options && options.nodeTypeKey || 'type';
+ return node !== null && _typeof(node) === 'object' && typeof node[nodeTypeKey] === 'string';
}
/**
@@ -3871,7 +3828,7 @@
upperBound = listProp.length;
}
for (var k = lowerBound; k < upperBound; ++k) {
- if (isNode(listProp[k]) && matcher(listProp[k], ancestry, options)) {
+ if (isNode(listProp[k], options) && matcher(listProp[k], ancestry, options)) {
return true;
}
}
@@ -3904,10 +3861,10 @@
if (idx < 0) {
continue;
}
- if (side === LEFT_SIDE && idx > 0 && isNode(listProp[idx - 1]) && matcher(listProp[idx - 1], ancestry, options)) {
+ if (side === LEFT_SIDE && idx > 0 && isNode(listProp[idx - 1], options) && matcher(listProp[idx - 1], ancestry, options)) {
return true;
}
- if (side === RIGHT_SIDE && idx < listProp.length - 1 && isNode(listProp[idx + 1]) && matcher(listProp[idx + 1], ancestry, options)) {
+ if (side === RIGHT_SIDE && idx < listProp.length - 1 && isNode(listProp[idx + 1], options) && matcher(listProp[idx + 1], ancestry, options)) {
return true;
}
}