diff options
Diffstat (limited to 'tools/node_modules/eslint/node_modules/eslint-utils/index.js')
-rw-r--r-- | tools/node_modules/eslint/node_modules/eslint-utils/index.js | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/tools/node_modules/eslint/node_modules/eslint-utils/index.js b/tools/node_modules/eslint/node_modules/eslint-utils/index.js index 7805b05ef3..f5d3f3e609 100644 --- a/tools/node_modules/eslint/node_modules/eslint-utils/index.js +++ b/tools/node_modules/eslint/node_modules/eslint-utils/index.js @@ -240,7 +240,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([ @@ -316,13 +327,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, @@ -534,9 +545,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. @@ -1287,7 +1298,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); @@ -1312,6 +1322,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 { @@ -1447,11 +1479,11 @@ class ReferenceTracker { esm ? nextTraceMap : this.mode === "legacy" - ? Object.assign( - { default: nextTraceMap }, - nextTraceMap - ) - : { default: nextTraceMap } + ? Object.assign( + { default: nextTraceMap }, + nextTraceMap + ) + : { default: nextTraceMap } ); if (esm) { @@ -1512,7 +1544,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; } |