summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/eslint-utils/index.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/eslint-utils/index.mjs')
-rw-r--r--tools/node_modules/eslint/node_modules/eslint-utils/index.mjs56
1 files changed, 44 insertions, 12 deletions
diff --git a/tools/node_modules/eslint/node_modules/eslint-utils/index.mjs b/tools/node_modules/eslint/node_modules/eslint-utils/index.mjs
index 2e6391e9b3..4b2a20edf5 100644
--- a/tools/node_modules/eslint/node_modules/eslint-utils/index.mjs
+++ b/tools/node_modules/eslint/node_modules/eslint-utils/index.mjs
@@ -234,7 +234,18 @@ function getFunctionHeadLocation(node, sourceCode) {
}
}
-/* globals BigInt */
+/* globals BigInt, 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([
@@ -310,13 +321,13 @@ const callAllowed = new Set(
Number.parseFloat,
Number.parseInt,
Object,
- Object.entries, //eslint-disable-line @mysticatea/node/no-unsupported-features/es-builtins
+ Object.entries,
Object.is,
Object.isExtensible,
Object.isFrozen,
Object.isSealed,
Object.keys,
- Object.values, //eslint-disable-line @mysticatea/node/no-unsupported-features/es-builtins
+ Object.values,
parseFloat,
parseInt,
RegExp,
@@ -528,9 +539,9 @@ const operations = Object.freeze({
variable != null &&
variable.defs.length === 0 &&
builtinNames.has(variable.name) &&
- variable.name in global
+ variable.name in globalObject
) {
- return { value: global[variable.name] }
+ return { value: globalObject[variable.name] }
}
// Constants.
@@ -1281,7 +1292,6 @@ class PatternMatcher {
}
}
-const SENTINEL_TYPE = /^(?:.+?Statement|.+?Declaration|(?:Array|ArrowFunction|Assignment|Call|Class|Function|Member|New|Object)Expression|AssignmentPattern|Program|VariableDeclarator)$/u;
const IMPORT_TYPE = /^(?:Import|Export(?:All|Default|Named))Declaration$/u;
const has = Function.call.bind(Object.hasOwnProperty);
@@ -1306,6 +1316,28 @@ function isModifiedGlobal(variable) {
}
/**
+ * 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
+
+ default:
+ return false
+ }
+}
+
+/**
* The reference tracker.
*/
class ReferenceTracker {
@@ -1441,11 +1473,11 @@ class ReferenceTracker {
esm
? nextTraceMap
: this.mode === "legacy"
- ? Object.assign(
- { default: nextTraceMap },
- nextTraceMap
- )
- : { default: nextTraceMap }
+ ? Object.assign(
+ { default: nextTraceMap },
+ nextTraceMap
+ )
+ : { default: nextTraceMap }
);
if (esm) {
@@ -1506,7 +1538,7 @@ class ReferenceTracker {
//eslint-disable-next-line complexity
*_iteratePropertyReferences(rootNode, path, traceMap) {
let node = rootNode;
- while (!SENTINEL_TYPE.test(node.parent.type)) {
+ while (isPassThrough(node)) {
node = node.parent;
}