diff options
author | Node.js GitHub Bot <github-bot@iojs.org> | 2023-03-31 14:55:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-31 13:55:43 +0000 |
commit | 10928cb0a4643a11c02af7bab93fc4b5abe2ce7d (patch) | |
tree | 128ccbfbc07b6684c512d2f6c2b819ef94d78715 /tools/node_modules/eslint/node_modules/@babel/traverse/lib/path | |
parent | 553b052648ecaf533a928fbf9321ea4cbddff1a8 (diff) | |
download | node-new-10928cb0a4643a11c02af7bab93fc4b5abe2ce7d.tar.gz |
tools: update eslint to 8.37.0
PR-URL: https://github.com/nodejs/node/pull/47333
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'tools/node_modules/eslint/node_modules/@babel/traverse/lib/path')
-rw-r--r-- | tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/context.js | 6 | ||||
-rw-r--r-- | tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/evaluation.js | 52 |
2 files changed, 33 insertions, 25 deletions
diff --git a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/context.js b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/context.js index e62e9523b6..a184ae62d4 100644 --- a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/context.js +++ b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/context.js @@ -147,13 +147,15 @@ function _resyncKey() { if (Array.isArray(this.container)) { for (let i = 0; i < this.container.length; i++) { if (this.container[i] === this.node) { - return this.setKey(i); + this.setKey(i); + return; } } } else { for (const key of Object.keys(this.container)) { if (this.container[key] === this.node) { - return this.setKey(key); + this.setKey(key); + return; } } } diff --git a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/evaluation.js b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/evaluation.js index 33799d561d..2f96dc12ec 100644 --- a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/evaluation.js +++ b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/evaluation.js @@ -22,6 +22,7 @@ function deopt(path, state) { state.deoptPath = path; state.confident = false; } +const Globals = new Map([["undefined", undefined], ["Infinity", Infinity], ["NaN", NaN]]); function evaluateCached(path, state) { const { node @@ -111,28 +112,29 @@ function _evaluate(path, state) { } if (path.isReferencedIdentifier()) { const binding = path.scope.getBinding(path.node.name); - if (binding && binding.constantViolations.length > 0) { - return deopt(binding.path, state); + if (binding) { + if (binding.constantViolations.length > 0 || path.node.start < binding.path.node.end) { + deopt(binding.path, state); + return; + } + if (binding.hasValue) { + return binding.value; + } } - if (binding && path.node.start < binding.path.node.end) { - return deopt(binding.path, state); + const name = path.node.name; + if (Globals.has(name)) { + if (!binding) { + return Globals.get(name); + } + deopt(binding.path, state); + return; } - if (binding != null && binding.hasValue) { - return binding.value; + const resolved = path.resolve(); + if (resolved === path) { + deopt(path, state); + return; } else { - if (path.node.name === "undefined") { - return binding ? deopt(binding.path, state) : undefined; - } else if (path.node.name === "Infinity") { - return binding ? deopt(binding.path, state) : Infinity; - } else if (path.node.name === "NaN") { - return binding ? deopt(binding.path, state) : NaN; - } - const resolved = path.resolve(); - if (resolved === path) { - return deopt(path, state); - } else { - return evaluateCached(resolved, state); - } + return evaluateCached(resolved, state); } } if (path.isUnaryExpression({ @@ -168,7 +170,8 @@ function _evaluate(path, state) { if (elemValue.confident) { arr.push(elemValue.value); } else { - return deopt(elemValue.deopt, state); + deopt(elemValue.deopt, state); + return; } } return arr; @@ -178,14 +181,16 @@ function _evaluate(path, state) { const props = path.get("properties"); for (const prop of props) { if (prop.isObjectMethod() || prop.isSpreadElement()) { - return deopt(prop, state); + deopt(prop, state); + return; } const keyPath = prop.get("key"); let key; if (prop.node.computed) { key = keyPath.evaluate(); if (!key.confident) { - return deopt(key.deopt, state); + deopt(key.deopt, state); + return; } key = key.value; } else if (keyPath.isIdentifier()) { @@ -196,7 +201,8 @@ function _evaluate(path, state) { const valuePath = prop.get("value"); let value = valuePath.evaluate(); if (!value.confident) { - return deopt(value.deopt, state); + deopt(value.deopt, state); + return; } value = value.value; obj[key] = value; |