feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

View File

@@ -1,70 +0,0 @@
v5.1.1 - September 12, 2020
* [`9b528d7`](https://github.com/eslint/eslint-scope/commit/9b528d778c381718c12dabfb7f1c0e0dc6b36e49) Upgrade: esrecurse version to ^4.3.0 (#64) (Timofey Kachalov)
* [`f758bbc`](https://github.com/eslint/eslint-scope/commit/f758bbc3d49b9b9ea2289a5d6a6bba8dcf2c4903) Chore: fix definiton -> definition typo in comments (#63) (Kevin Kirsche)
* [`7513734`](https://github.com/eslint/eslint-scope/commit/751373473375b3f2edc4eaf1c8d2763d8435bb72) Chore: move to GitHub Actions (#62) (Kai Cataldo)
v5.1.0 - June 4, 2020
* [`d4a3764`](https://github.com/eslint/eslint-scope/commit/d4a376434b16289c1a428d7e304576e997520873) Update: support new export syntax (#56) (Toru Nagashima)
v5.0.0 - July 20, 2019
* [`e9fa22e`](https://github.com/eslint/eslint-scope/commit/e9fa22ea412c26cf2761fa98af7e715644bdb464) Upgrade: update dependencies after dropping support for Node <8 (#53) (Kai Cataldo)
* [`ee9f7c1`](https://github.com/eslint/eslint-scope/commit/ee9f7c12721aa195ba7e0e69551f49bfdb479951) Breaking: drop support for Node v6 (#54) (Kai Cataldo)
v4.0.3 - March 15, 2019
* [`299df64`](https://github.com/eslint/eslint-scope/commit/299df64bdafb30b4d9372e4b7af0cf51a3818c4a) Fix: arrow function scope strictness (take 2) (#52) (futpib)
v4.0.2 - March 1, 2019
* [`c925600`](https://github.com/eslint/eslint-scope/commit/c925600a684ae0f71b96f85339437a43b4d50d99) Revert "Fix: Arrow function scope strictness (fixes #49) (#50)" (#51) (Teddy Katz)
v4.0.1 - March 1, 2019
* [`2533966`](https://github.com/eslint/eslint-scope/commit/2533966faf317df5a3847fab937ba462c16808b8) Fix: Arrow function scope strictness (fixes #49) (#50) (futpib)
* [`0cbeea5`](https://github.com/eslint/eslint-scope/commit/0cbeea51dfb66ab88ea34b0e3b4ad5e6cc210f2f) Chore: add supported Node.js versions to CI (#47) (Kai Cataldo)
* [`b423057`](https://github.com/eslint/eslint-scope/commit/b42305760638b8edf4667acf1445e450869bd983) Upgrade: eslint-release@1.0.0 (#46) (Teddy Katz)
v4.0.0 - June 21, 2018
v4.0.0-rc.0 - June 9, 2018
* 3b919b8 Build: Adding rc release script to package.json (#38) (Kevin Partington)
* 137732a Chore: avoid creating package-lock.json files (#37) (Teddy Katz)
v4.0.0-alpha.0 - April 27, 2018
* 7cc3769 Upgrade: eslint-release ^0.11.1 (#36) (Teddy Katz)
* c9f6967 Breaking: remove TDZScope (refs eslint/eslint#10245) (#35) (Toru Nagashima)
* 982a71f Fix: wrong resolution about default parameters (#33) (Toru Nagashima)
* 57889f1 Docs: Remove extra header line from LICENSE (#32) (Gyandeep Singh)
v3.7.1 - April 12, 2017
* ced6262 Fix: restore previous Scope API exports from escope (#31) (Vitor Balocco)
* 5c3d966 Fix: Remove and Modify tests that contain invalid ES6 syntax (#29) (Reyad Attiyat)
v3.7.0 - March 17, 2017
* 9e27835 Chore: Add files section to package.json (#24) (Ilya Volodin)
* 3e4d123 Upgrade: eslint-config-eslint to 4.0.0 (#21) (Teddy Katz)
* 38c50fb Chore: Rename src to lib and test to tests (#20) (Corbin Uselton)
* f4cd920 Chore: Remove esprima (#19) (Corbin Uselton)
* f81fad5 Revert "Chore: Remove esprima" (#18) (James Henry)
* 31b0085 Chore: Remove es6-map and es6-weakmap as they are included in node4 (#10) (#13) (Corbin Uselton)
* 12a1ca1 Add Makefile.js and eslint (#15) (Reyad Attiyat)
* 7d23f8e Chore: Remove es6-map and es6-weakmap as they are included in node4 (#10) (Corbin Uselton)
* 019441e Chore: Convert to ES6 that is supported on Node 4, commonjs modules and remove Babel (#14) (Corbin Uselton)
* c647f65 Update: Add check for node.body in referencer (#2) (Corbin Uselton)
* eb5c9db Remove browserify and jsdoc (#12) (Corbin Uselton)
* cf38df0 Chore: Update README.md (#3) (James Henry)
* 8a142ca Chore: Add eslint-release scripts (#6) (James Henry)
* e60d8cb Chore: Remove unused bower.json (#5) (James Henry)
* 049c545 Chore: Fix tests for eslint-scope (#4) (James Henry)
* f026aab Chore: Update package.json for eslint fork (#1) (James Henry)
* a94d281 Chore: Update license with JSF copyright (Nicholas C. Zakas)

78
node_modules/eslint-scope/README.md generated vendored
View File

@@ -1,36 +1,69 @@
[![npm version](https://img.shields.io/npm/v/eslint-scope.svg)](https://www.npmjs.com/package/eslint-scope)
[![Downloads](https://img.shields.io/npm/dm/eslint-scope.svg)](https://www.npmjs.com/package/eslint-scope)
[![Build Status](https://github.com/eslint/js/workflows/CI/badge.svg)](https://github.com/eslint/js/actions)
# ESLint Scope
ESLint Scope is the [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm) scope analyzer used in ESLint. It is a fork of [escope](http://github.com/estools/escope).
## Usage
Install:
## Install
```
npm i eslint-scope --save
```
## 📖 Usage
To use in an ESM file:
```js
import * as eslintScope from 'eslint-scope';
```
To use in a CommonJS file:
```js
const eslintScope = require('eslint-scope');
```
In order to analyze scope, you'll need to have an [ESTree](https://github.com/estree/estree) compliant AST structure to run it on. The primary method is `eslintScope.analyze()`, which takes two arguments:
1. `ast` - the ESTree-compliant AST structure to analyze.
2. `options` (optional) - Options to adjust how the scope is analyzed, including:
* `ignoreEval` (default: `false`) - Set to `true` to ignore all `eval()` calls (which would normally create scopes).
* `nodejsScope` (default: `false`) - Set to `true` to create a top-level function scope needed for CommonJS evaluation.
* `impliedStrict` (default: `false`) - Set to `true` to evaluate the code in strict mode even outside of modules and without `"use strict"`.
* `ecmaVersion` (default: `5`) - The version of ECMAScript to use to evaluate the code.
* `sourceType` (default: `"script"`) - The type of JavaScript file to evaluate. Change to `"module"` for ECMAScript module code.
* `childVisitorKeys` (default: `null`) - An object with visitor key information (like [`eslint-visitor-keys`](https://github.com/eslint/js/tree/main/packages/eslint-visitor-keys)). Without this, `eslint-scope` finds child nodes to visit algorithmically. Providing this option is a performance enhancement.
* `fallback` (default: `"iteration"`) - The strategy to use when `childVisitorKeys` is not specified. May be a function.
Example:
```js
var eslintScope = require('eslint-scope');
var espree = require('espree');
var estraverse = require('estraverse');
import * as eslintScope from 'eslint-scope';
import * as espree from 'espree';
import estraverse from 'estraverse';
var ast = espree.parse(code);
var scopeManager = eslintScope.analyze(ast);
const options = {
ecmaVersion: 2022,
sourceType: "module"
};
var currentScope = scopeManager.acquire(ast); // global scope
const ast = espree.parse(code, { range: true, ...options });
const scopeManager = eslintScope.analyze(ast, options);
const currentScope = scopeManager.acquire(ast); // global scope
estraverse.traverse(ast, {
enter: function(node, parent) {
enter (node, parent) {
// do stuff
if (/Function/.test(node.type)) {
currentScope = scopeManager.acquire(node); // get current function scope
}
},
leave: function(node, parent) {
leave(node, parent) {
if (/Function/.test(node.type)) {
currentScope = currentScope.upper; // set to parent scope
}
@@ -42,7 +75,11 @@ estraverse.traverse(ast, {
## Contributing
Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/eslint-scope/issues).
Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/js/issues).
## Security Policy
We work hard to ensure that ESLint Scope is safe for everyone and that security issues are addressed quickly and responsibly. Read the full [security policy](https://github.com/eslint/.github/blob/master/SECURITY.md).
## Build Commands
@@ -52,3 +89,20 @@ Issues and pull requests will be triaged and responded to as quickly as possible
## License
ESLint Scope is licensed under a permissive BSD 2-clause license.
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
<!--sponsorsstart-->
## Sponsors
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate)
to get your logo on our READMEs and [website](https://eslint.org/sponsors).
<h3>Platinum Sponsors</h3>
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="128"></a></p><h3>Gold Sponsors</h3>
<p><a href="https://trunk.io/"><img src="https://images.opencollective.com/trunkio/fb92d60/avatar.png" alt="trunk.io" height="96"></a></p><h3>Silver Sponsors</h3>
<p><a href="https://www.jetbrains.com/"><img src="https://images.opencollective.com/jetbrains/fe76f99/logo.png" alt="JetBrains" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301?v=4" alt="American Express" height="64"></a> <a href="https://www.workleap.com"><img src="https://avatars.githubusercontent.com/u/53535748?u=d1e55d7661d724bf2281c1bfd33cb8f99fe2465f&v=4" alt="Workleap" height="64"></a></p><h3>Bronze Sponsors</h3>
<p><a href="https://www.wordhint.net/"><img src="https://images.opencollective.com/wordhint/be86813/avatar.png" alt="WordHint" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340?v=4" alt="GitBook" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104?v=4" alt="Nx" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774?v=4" alt="HeroCoders" height="32"></a></p>
<h3>Technology Sponsors</h3>
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
<!--sponsorsend-->

View File

@@ -21,18 +21,17 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";
const Variable = require("./variable");
import Variable from "./variable.js";
/**
* @class Definition
* @constructor Definition
*/
class Definition {
constructor(type, name, node, parent, index, kind) {
/**
* @member {String} Definition#type - type of the occurrence (e.g. "Parameter", "Variable", ...).
* @member {string} Definition#type - type of the occurrence (e.g. "Parameter", "Variable", ...).
*/
this.type = type;
@@ -52,19 +51,19 @@ class Definition {
this.parent = parent;
/**
* @member {Number?} Definition#index - the index in the declaration statement.
* @member {number?} Definition#index - the index in the declaration statement.
*/
this.index = index;
/**
* @member {String?} Definition#kind - the kind of the declaration statement.
* @member {string?} Definition#kind - the kind of the declaration statement.
*/
this.kind = kind;
}
}
/**
* @class ParameterDefinition
* @constructor ParameterDefinition
*/
class ParameterDefinition extends Definition {
constructor(name, node, index, rest) {
@@ -78,7 +77,7 @@ class ParameterDefinition extends Definition {
}
}
module.exports = {
export {
ParameterDefinition,
Definition
};

View File

@@ -45,18 +45,15 @@
* The main interface is the {@link analyze} function.
* @module escope
*/
"use strict";
/* eslint no-underscore-dangle: ["error", { "allow": ["__currentScope"] }] */
import { assert } from "./assert.js";
const assert = require("assert");
import ScopeManager from "./scope-manager.js";
import Referencer from "./referencer.js";
import Reference from "./reference.js";
import Variable from "./variable.js";
const ScopeManager = require("./scope-manager");
const Referencer = require("./referencer");
const Reference = require("./reference");
const Variable = require("./variable");
const Scope = require("./scope").Scope;
const version = require("../package.json").version;
import eslintScopeVersion from "./version.js";
/**
* Set the default options
@@ -65,10 +62,9 @@ const version = require("../package.json").version;
function defaultOptions() {
return {
optimistic: false,
directive: false,
nodejsScope: false,
impliedStrict: false,
sourceType: "script", // one of ['script', 'module']
sourceType: "script", // one of ['script', 'module', 'commonjs']
ecmaVersion: 5,
childVisitorKeys: null,
fallback: "iteration"
@@ -77,15 +73,15 @@ function defaultOptions() {
/**
* Preform deep update on option object
* @param {Object} target - Options
* @param {Object} override - Updates
* @param {Object} target Options
* @param {Object} override Updates
* @returns {Object} Updated options
*/
function updateDeeply(target, override) {
/**
* Is hash object
* @param {Object} value - Test value
* @param {Object} value Test value
* @returns {boolean} Result
*/
function isHashObject(value) {
@@ -93,7 +89,7 @@ function updateDeeply(target, override) {
}
for (const key in override) {
if (Object.prototype.hasOwnProperty.call(override, key)) {
if (Object.hasOwn(override, key)) {
const val = override[key];
if (isHashObject(val)) {
@@ -114,20 +110,19 @@ function updateDeeply(target, override) {
* Main interface function. Takes an Espree syntax tree and returns the
* analyzed scopes.
* @function analyze
* @param {espree.Tree} tree - Abstract Syntax Tree
* @param {Object} providedOptions - Options that tailor the scope analysis
* @param {boolean} [providedOptions.optimistic=false] - the optimistic flag
* @param {boolean} [providedOptions.directive=false]- the directive flag
* @param {boolean} [providedOptions.ignoreEval=false]- whether to check 'eval()' calls
* @param {boolean} [providedOptions.nodejsScope=false]- whether the whole
* @param {espree.Tree} tree Abstract Syntax Tree
* @param {Object} providedOptions Options that tailor the scope analysis
* @param {boolean} [providedOptions.optimistic=false] the optimistic flag
* @param {boolean} [providedOptions.ignoreEval=false] whether to check 'eval()' calls
* @param {boolean} [providedOptions.nodejsScope=false] whether the whole
* script is executed under node.js environment. When enabled, escope adds
* a function scope immediately following the global scope.
* @param {boolean} [providedOptions.impliedStrict=false]- implied strict mode
* @param {boolean} [providedOptions.impliedStrict=false] implied strict mode
* (if ecmaVersion >= 5).
* @param {string} [providedOptions.sourceType='script']- the source type of the script. one of 'script' and 'module'
* @param {number} [providedOptions.ecmaVersion=5]- which ECMAScript version is considered
* @param {Object} [providedOptions.childVisitorKeys=null] - Additional known visitor keys. See [esrecurse](https://github.com/estools/esrecurse)'s the `childVisitorKeys` option.
* @param {string} [providedOptions.fallback='iteration'] - A kind of the fallback in order to encounter with unknown node. See [esrecurse](https://github.com/estools/esrecurse)'s the `fallback` option.
* @param {string} [providedOptions.sourceType='script'] the source type of the script. one of 'script', 'module', and 'commonjs'
* @param {number} [providedOptions.ecmaVersion=5] which ECMAScript version is considered
* @param {Object} [providedOptions.childVisitorKeys=null] Additional known visitor keys. See [esrecurse](https://github.com/estools/esrecurse)'s the `childVisitorKeys` option.
* @param {string} [providedOptions.fallback='iteration'] A kind of the fallback in order to encounter with unknown node. See [esrecurse](https://github.com/estools/esrecurse)'s the `fallback` option.
* @returns {ScopeManager} ScopeManager
*/
function analyze(tree, providedOptions) {
@@ -142,10 +137,10 @@ function analyze(tree, providedOptions) {
return scopeManager;
}
module.exports = {
export {
/** @name module:escope.version */
version,
eslintScopeVersion as version,
/** @name module:escope.Reference */
Reference,
@@ -153,13 +148,22 @@ module.exports = {
/** @name module:escope.Variable */
Variable,
/** @name module:escope.Scope */
Scope,
/** @name module:escope.ScopeManager */
ScopeManager,
/** @name module:escope.Referencer */
Referencer,
analyze
};
/** @name module:escope.Definition */
export { Definition } from "./definition.js";
/** @name module:escope.PatternVisitor */
export { default as PatternVisitor } from "./pattern-visitor.js";
/** @name module:escope.Scope */
export { Scope } from "./scope.js";
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -21,22 +21,24 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";
/* eslint-disable no-undefined */
import estraverse from "estraverse";
import esrecurse from "esrecurse";
const Syntax = require("estraverse").Syntax;
const esrecurse = require("esrecurse");
const { Syntax } = estraverse;
/**
* Get last array element
* @param {array} xs - array
* @param {Array} xs array
* @returns {any} Last elment
*/
function getLast(xs) {
return xs[xs.length - 1] || null;
return xs.at(-1) || null;
}
/**
* Visitor for destructuring patterns.
*/
class PatternVisitor extends esrecurse.Visitor {
static isPattern(node) {
const nodeType = node.type;
@@ -65,7 +67,7 @@ class PatternVisitor extends esrecurse.Visitor {
this.callback(pattern, {
topLevel: pattern === this.rootPattern,
rest: lastRestElement !== null && lastRestElement !== undefined && lastRestElement.argument === pattern,
rest: lastRestElement !== null && lastRestElement !== void 0 && lastRestElement.argument === pattern,
assignments: this.assignments
});
}
@@ -147,6 +149,6 @@ class PatternVisitor extends esrecurse.Visitor {
}
}
module.exports = PatternVisitor;
export default PatternVisitor;
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -21,7 +21,6 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";
const READ = 0x1;
const WRITE = 0x2;
@@ -29,7 +28,7 @@ const RW = READ | WRITE;
/**
* A Reference represents a single occurrence of an identifier in code.
* @class Reference
* @constructor Reference
*/
class Reference {
constructor(ident, scope, flag, writeExpr, maybeImplicitGlobal, partial, init) {
@@ -91,7 +90,7 @@ class Reference {
/**
* Whether the reference is static.
* @method Reference#isStatic
* @function Reference#isStatic
* @returns {boolean} static
*/
isStatic() {
@@ -100,7 +99,7 @@ class Reference {
/**
* Whether the reference is writeable.
* @method Reference#isWrite
* @function Reference#isWrite
* @returns {boolean} write
*/
isWrite() {
@@ -109,7 +108,7 @@ class Reference {
/**
* Whether the reference is readable.
* @method Reference#isRead
* @function Reference#isRead
* @returns {boolean} read
*/
isRead() {
@@ -118,7 +117,7 @@ class Reference {
/**
* Whether the reference is read-only.
* @method Reference#isReadOnly
* @function Reference#isReadOnly
* @returns {boolean} read only
*/
isReadOnly() {
@@ -127,7 +126,7 @@ class Reference {
/**
* Whether the reference is write-only.
* @method Reference#isWriteOnly
* @function Reference#isWriteOnly
* @returns {boolean} write only
*/
isWriteOnly() {
@@ -136,7 +135,7 @@ class Reference {
/**
* Whether the reference is read-write.
* @method Reference#isReadWrite
* @function Reference#isReadWrite
* @returns {boolean} read write
*/
isReadWrite() {
@@ -162,6 +161,6 @@ Reference.WRITE = WRITE;
*/
Reference.RW = RW;
module.exports = Reference;
export default Reference;
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -21,28 +21,23 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-undefined */
import estraverse from "estraverse";
import esrecurse from "esrecurse";
import Reference from "./reference.js";
import Variable from "./variable.js";
import PatternVisitor from "./pattern-visitor.js";
import { Definition, ParameterDefinition } from "./definition.js";
import { assert } from "./assert.js";
const Syntax = require("estraverse").Syntax;
const esrecurse = require("esrecurse");
const Reference = require("./reference");
const Variable = require("./variable");
const PatternVisitor = require("./pattern-visitor");
const definition = require("./definition");
const assert = require("assert");
const ParameterDefinition = definition.ParameterDefinition;
const Definition = definition.Definition;
const { Syntax } = estraverse;
/**
* Traverse identifier in pattern
* @param {Object} options - options
* @param {pattern} rootPattern - root pattern
* @param {Refencer} referencer - referencer
* @param {callback} callback - callback
* @param {Object} options options
* @param {pattern} rootPattern root pattern
* @param {Refencer} referencer referencer
* @param {callback} callback callback
* @returns {void}
*/
function traverseIdentifierInPattern(options, rootPattern, referencer, callback) {
@@ -53,7 +48,7 @@ function traverseIdentifierInPattern(options, rootPattern, referencer, callback)
visitor.visit(rootPattern);
// Process the right hand nodes recursively.
if (referencer !== null && referencer !== undefined) {
if (referencer !== null && referencer !== void 0) {
visitor.rightHandNodes.forEach(referencer.visit, referencer);
}
}
@@ -64,6 +59,9 @@ function traverseIdentifierInPattern(options, rootPattern, referencer, callback)
// FIXME: Now, we don't create module environment, because the context is
// implementation dependent.
/**
* Visitor for import specifiers.
*/
class Importer extends esrecurse.Visitor {
constructor(declaration, referencer) {
super(null, referencer.options);
@@ -110,7 +108,9 @@ class Importer extends esrecurse.Visitor {
}
}
// Referencing variables and creating bindings.
/**
* Referencing variables and creating bindings.
*/
class Referencer extends esrecurse.Visitor {
constructor(options, scopeManager) {
super(null, options);
@@ -209,8 +209,8 @@ class Referencer extends esrecurse.Visitor {
/**
* Visit pattern callback
* @param {pattern} pattern - pattern
* @param {Object} info - info
* @param {pattern} pattern pattern
* @param {Object} info info
* @returns {void}
*/
function visitPatternCallback(pattern, info) {
@@ -274,8 +274,6 @@ class Referencer extends esrecurse.Visitor {
));
}
this.visit(node.superClass);
this.scopeManager.__nestClassScope(node);
if (node.id) {
@@ -286,6 +284,8 @@ class Referencer extends esrecurse.Visitor {
node
));
}
this.visit(node.superClass);
this.visit(node.body);
this.close(node);
@@ -395,7 +395,7 @@ class Referencer extends esrecurse.Visitor {
this.currentScope().__define(pattern,
new Definition(
Variable.CatchClause,
node.param,
pattern,
node,
null,
null,
@@ -411,7 +411,7 @@ class Referencer extends esrecurse.Visitor {
Program(node) {
this.scopeManager.__nestGlobalScope(node);
if (this.scopeManager.__isNodejsScope()) {
if (this.scopeManager.isGlobalReturn()) {
// Force strictness of GlobalScope to false when using node.js scope.
this.currentScope().isStrict = false;
@@ -434,6 +434,12 @@ class Referencer extends esrecurse.Visitor {
this.currentScope().__referencing(node);
}
// eslint-disable-next-line class-methods-use-this -- Desired as instance method
PrivateIdentifier() {
// Do nothing.
}
UpdateExpression(node) {
if (PatternVisitor.isPattern(node.argument)) {
this.currentScope().__referencing(node.argument, Reference.RW, null);
@@ -453,13 +459,34 @@ class Referencer extends esrecurse.Visitor {
this.visitProperty(node);
}
PropertyDefinition(node) {
const { computed, key, value } = node;
if (computed) {
this.visit(key);
}
if (value) {
this.scopeManager.__nestClassFieldInitializerScope(value);
this.visit(value);
this.close(value);
}
}
StaticBlock(node) {
this.scopeManager.__nestClassStaticBlockScope(node);
this.visitChildren(node);
this.close(node);
}
MethodDefinition(node) {
this.visitProperty(node);
}
BreakStatement() {} // eslint-disable-line class-methods-use-this
BreakStatement() {} // eslint-disable-line class-methods-use-this -- Desired as instance method
ContinueStatement() {} // eslint-disable-line class-methods-use-this
ContinueStatement() {} // eslint-disable-line class-methods-use-this -- Desired as instance method
LabeledStatement(node) {
this.visit(node.body);
@@ -618,12 +645,12 @@ class Referencer extends esrecurse.Visitor {
this.visit(local);
}
MetaProperty() { // eslint-disable-line class-methods-use-this
MetaProperty() { // eslint-disable-line class-methods-use-this -- Desired as instance method
// do nothing.
}
}
module.exports = Referencer;
export default Referencer;
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -21,26 +21,25 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";
/* eslint-disable no-underscore-dangle */
const Scope = require("./scope");
const assert = require("assert");
const GlobalScope = Scope.GlobalScope;
const CatchScope = Scope.CatchScope;
const WithScope = Scope.WithScope;
const ModuleScope = Scope.ModuleScope;
const ClassScope = Scope.ClassScope;
const SwitchScope = Scope.SwitchScope;
const FunctionScope = Scope.FunctionScope;
const ForScope = Scope.ForScope;
const FunctionExpressionNameScope = Scope.FunctionExpressionNameScope;
const BlockScope = Scope.BlockScope;
import {
BlockScope,
CatchScope,
ClassFieldInitializerScope,
ClassStaticBlockScope,
ClassScope,
ForScope,
FunctionExpressionNameScope,
FunctionScope,
GlobalScope,
ModuleScope,
SwitchScope,
WithScope
} from "./scope.js";
import { assert } from "./assert.js";
/**
* @class ScopeManager
* @constructor ScopeManager
*/
class ScopeManager {
constructor(options) {
@@ -52,10 +51,6 @@ class ScopeManager {
this.__declaredVariables = new WeakMap();
}
__useDirective() {
return this.__options.directive;
}
__isOptimistic() {
return this.__options.optimistic;
}
@@ -64,8 +59,8 @@ class ScopeManager {
return this.__options.ignoreEval;
}
__isNodejsScope() {
return this.__options.nodejsScope;
isGlobalReturn() {
return this.__options.nodejsScope || this.__options.sourceType === "commonjs";
}
isModule() {
@@ -91,8 +86,7 @@ class ScopeManager {
* "are declared by the node" means the node is same as `Variable.defs[].node` or `Variable.defs[].parent`.
* If the node declares nothing, this method returns an empty array.
* CAUTION: This API is experimental. See https://github.com/estools/escope/pull/69 for more details.
*
* @param {Espree.Node} node - a node to get.
* @param {Espree.Node} node a node to get.
* @returns {Variable[]} variables that declared by the node.
*/
getDeclaredVariables(node) {
@@ -101,16 +95,16 @@ class ScopeManager {
/**
* acquire scope from node.
* @method ScopeManager#acquire
* @param {Espree.Node} node - node for the acquired scope.
* @param {boolean=} inner - look up the most inner scope, default value is false.
* @function ScopeManager#acquire
* @param {Espree.Node} node node for the acquired scope.
* @param {?boolean} [inner=false] look up the most inner scope, default value is false.
* @returns {Scope?} Scope from node
*/
acquire(node, inner) {
/**
* predicate
* @param {Scope} testScope - scope to test
* @param {Scope} testScope scope to test
* @returns {boolean} predicate
*/
function predicate(testScope) {
@@ -155,8 +149,8 @@ class ScopeManager {
/**
* acquire all scopes from node.
* @method ScopeManager#acquireAll
* @param {Espree.Node} node - node for the acquired scope.
* @function ScopeManager#acquireAll
* @param {Espree.Node} node node for the acquired scope.
* @returns {Scopes?} Scope array
*/
acquireAll(node) {
@@ -165,9 +159,9 @@ class ScopeManager {
/**
* release the node.
* @method ScopeManager#release
* @param {Espree.Node} node - releasing node.
* @param {boolean=} inner - look up the most inner scope, default value is false.
* @function ScopeManager#release
* @param {Espree.Node} node releasing node.
* @param {?boolean} [inner=false] look up the most inner scope, default value is false.
* @returns {Scope?} upper scope for the node.
*/
release(node, inner) {
@@ -184,9 +178,9 @@ class ScopeManager {
return null;
}
attach() { } // eslint-disable-line class-methods-use-this
attach() { } // eslint-disable-line class-methods-use-this -- Desired as instance method
detach() { } // eslint-disable-line class-methods-use-this
detach() { } // eslint-disable-line class-methods-use-this -- Desired as instance method
__nestScope(scope) {
if (scope instanceof GlobalScope) {
@@ -225,6 +219,14 @@ class ScopeManager {
return this.__nestScope(new ClassScope(this, this.__currentScope, node));
}
__nestClassFieldInitializerScope(node) {
return this.__nestScope(new ClassFieldInitializerScope(this, this.__currentScope, node));
}
__nestClassStaticBlockScope(node) {
return this.__nestScope(new ClassStaticBlockScope(this, this.__currentScope, node));
}
__nestSwitchScope(node) {
return this.__nestScope(new SwitchScope(this, this.__currentScope, node));
}
@@ -242,6 +244,6 @@ class ScopeManager {
}
}
module.exports = ScopeManager;
export default ScopeManager;
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -21,27 +21,24 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-undefined */
import estraverse from "estraverse";
const Syntax = require("estraverse").Syntax;
import Reference from "./reference.js";
import Variable from "./variable.js";
import { Definition } from "./definition.js";
import { assert } from "./assert.js";
const Reference = require("./reference");
const Variable = require("./variable");
const Definition = require("./definition").Definition;
const assert = require("assert");
const { Syntax } = estraverse;
/**
* Test if scope is struct
* @param {Scope} scope - scope
* @param {Block} block - block
* @param {boolean} isMethodDefinition - is method definition
* @param {boolean} useDirective - use directive
* @param {Scope} scope scope
* @param {Block} block block
* @param {boolean} isMethodDefinition is method definition
* @returns {boolean} is strict scope
*/
function isStrictScope(scope, block, isMethodDefinition, useDirective) {
function isStrictScope(scope, block, isMethodDefinition) {
let body;
// When upper scope is exists and strict, inner scope is also strict.
@@ -81,48 +78,36 @@ function isStrictScope(scope, block, isMethodDefinition, useDirective) {
return false;
}
// Search 'use strict' directive.
if (useDirective) {
for (let i = 0, iz = body.body.length; i < iz; ++i) {
const stmt = body.body[i];
// Search for a 'use strict' directive.
for (let i = 0, iz = body.body.length; i < iz; ++i) {
const stmt = body.body[i];
if (stmt.type !== Syntax.DirectiveStatement) {
break;
}
if (stmt.raw === "\"use strict\"" || stmt.raw === "'use strict'") {
return true;
}
/*
* Check if the current statement is a directive.
* If it isn't, then we're past the directive prologue
* so stop the search because directives cannot
* appear after this point.
*
* Some parsers set `directive:null` on non-directive
* statements, so the `typeof` check is safer than
* checking for property existence.
*/
if (typeof stmt.directive !== "string") {
break;
}
} else {
for (let i = 0, iz = body.body.length; i < iz; ++i) {
const stmt = body.body[i];
if (stmt.type !== Syntax.ExpressionStatement) {
break;
}
const expr = stmt.expression;
if (expr.type !== Syntax.Literal || typeof expr.value !== "string") {
break;
}
if (expr.raw !== null && expr.raw !== undefined) {
if (expr.raw === "\"use strict\"" || expr.raw === "'use strict'") {
return true;
}
} else {
if (expr.value === "use strict") {
return true;
}
}
if (stmt.directive === "use strict") {
return true;
}
}
return false;
}
/**
* Register scope
* @param {ScopeManager} scopeManager - scope manager
* @param {Scope} scope - scope
* @param {ScopeManager} scopeManager scope manager
* @param {Scope} scope scope
* @returns {void}
*/
function registerScope(scopeManager, scope) {
@@ -139,7 +124,7 @@ function registerScope(scopeManager, scope) {
/**
* Should be statically
* @param {Object} def - def
* @param {Object} def def
* @returns {boolean} should be statically
*/
function shouldBeStatically(def) {
@@ -150,14 +135,15 @@ function shouldBeStatically(def) {
}
/**
* @class Scope
* @constructor Scope
*/
class Scope {
constructor(scopeManager, type, upperScope, block, isMethodDefinition) {
/**
* One of 'module', 'block', 'switch', 'function', 'catch', 'with', 'function', 'class', 'global'.
* @member {String} Scope#type
* One of "global", "module", "function", "function-expression-name", "block", "switch", "catch", "with", "for",
* "class", "class-field-initializer", "class-static-block".
* @member {string} Scope#type
*/
this.type = type;
@@ -171,7 +157,8 @@ class Scope {
/**
* The tainted variables of this scope, as <code>{ Variable.name :
* boolean }</code>.
* @member {Map} Scope#taints */
* @member {Map} Scope#taints
*/
this.taints = new Map();
/**
@@ -224,7 +211,13 @@ class Scope {
* @member {Scope} Scope#variableScope
*/
this.variableScope =
(this.type === "global" || this.type === "function" || this.type === "module") ? this : upperScope.variableScope;
this.type === "global" ||
this.type === "module" ||
this.type === "function" ||
this.type === "class-field-initializer" ||
this.type === "class-static-block"
? this
: upperScope.variableScope;
/**
* Whether this scope is created by a FunctionExpression.
@@ -255,7 +248,9 @@ class Scope {
* Whether 'use strict' is in effect in this scope.
* @member {boolean} Scope#isStrict
*/
this.isStrict = isStrictScope(this, block, isMethodDefinition, scopeManager.__useDirective());
this.isStrict = scopeManager.isStrictModeSupported()
? isStrictScope(this, block, isMethodDefinition)
: false;
/**
* List of nested {@link Scope}s.
@@ -342,7 +337,7 @@ class Scope {
// To override by function scopes.
// References in default parameters isn't resolved to variables which are in their function body.
__isValidResolution(ref, variable) { // eslint-disable-line class-methods-use-this, no-unused-vars
__isValidResolution(ref, variable) { // eslint-disable-line class-methods-use-this, no-unused-vars -- Desired as instance method with signature
return true;
}
@@ -376,17 +371,17 @@ class Scope {
}
__addDeclaredVariablesOfNode(variable, node) {
if (node === null || node === undefined) {
if (node === null || node === void 0) {
return;
}
let variables = this.__declaredVariables.get(node);
if (variables === null || variables === undefined) {
if (variables === null || variables === void 0) {
variables = [];
this.__declaredVariables.set(node, variables);
}
if (variables.indexOf(variable) === -1) {
if (!variables.includes(variable)) {
variables.push(variable);
}
}
@@ -461,8 +456,8 @@ class Scope {
/**
* returns resolved {Reference}
* @method Scope#resolve
* @param {Espree.Identifier} ident - identifier to be resolved.
* @function Scope#resolve
* @param {Espree.Identifier} ident identifier to be resolved.
* @returns {Reference} reference
*/
resolve(ident) {
@@ -481,7 +476,7 @@ class Scope {
/**
* returns this scope is static
* @method Scope#isStatic
* @function Scope#isStatic
* @returns {boolean} static
*/
isStatic() {
@@ -490,19 +485,19 @@ class Scope {
/**
* returns this scope has materialized arguments
* @method Scope#isArgumentsMaterialized
* @function Scope#isArgumentsMaterialized
* @returns {boolean} arguemnts materialized
*/
isArgumentsMaterialized() { // eslint-disable-line class-methods-use-this
isArgumentsMaterialized() { // eslint-disable-line class-methods-use-this -- Desired as instance method
return true;
}
/**
* returns this scope has materialized `this` reference
* @method Scope#isThisMaterialized
* @function Scope#isThisMaterialized
* @returns {boolean} this materialized
*/
isThisMaterialized() { // eslint-disable-line class-methods-use-this
isThisMaterialized() { // eslint-disable-line class-methods-use-this -- Desired as instance method
return true;
}
@@ -519,6 +514,9 @@ class Scope {
}
}
/**
* Global scope.
*/
class GlobalScope extends Scope {
constructor(scopeManager, block) {
super(scopeManager, "global", null, block, false);
@@ -527,10 +525,10 @@ class GlobalScope extends Scope {
variables: [],
/**
* List of {@link Reference}s that are left to be resolved (i.e. which
* need to be linked to the variable they refer to).
* @member {Reference[]} Scope#implicit#left
*/
* List of {@link Reference}s that are left to be resolved (i.e. which
* need to be linked to the variable they refer to).
* @member {Reference[]} Scope#implicit#left
*/
left: []
};
}
@@ -580,12 +578,18 @@ class GlobalScope extends Scope {
}
}
/**
* Module scope.
*/
class ModuleScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "module", upperScope, block, false);
}
}
/**
* Function expression name scope.
*/
class FunctionExpressionNameScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "function-expression-name", upperScope, block, false);
@@ -602,12 +606,18 @@ class FunctionExpressionNameScope extends Scope {
}
}
/**
* Catch scope.
*/
class CatchScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "catch", upperScope, block, false);
}
}
/**
* With statement scope.
*/
class WithScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "with", upperScope, block, false);
@@ -630,18 +640,27 @@ class WithScope extends Scope {
}
}
/**
* Block scope.
*/
class BlockScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "block", upperScope, block, false);
}
}
/**
* Switch scope.
*/
class SwitchScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "switch", upperScope, block, false);
}
}
/**
* Function scope.
*/
class FunctionScope extends Scope {
constructor(scopeManager, upperScope, block, isMethodDefinition) {
super(scopeManager, "function", upperScope, block, isMethodDefinition);
@@ -719,19 +738,43 @@ class FunctionScope extends Scope {
}
}
/**
* Scope of for, for-in, and for-of statements.
*/
class ForScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "for", upperScope, block, false);
}
}
/**
* Class scope.
*/
class ClassScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "class", upperScope, block, false);
}
}
module.exports = {
/**
* Class field initializer scope.
*/
class ClassFieldInitializerScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "class-field-initializer", upperScope, block, true);
}
}
/**
* Class static block scope.
*/
class ClassStaticBlockScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "class-static-block", upperScope, block, true);
}
}
export {
Scope,
GlobalScope,
ModuleScope,
@@ -742,7 +785,9 @@ module.exports = {
SwitchScope,
FunctionScope,
ForScope,
ClassScope
ClassScope,
ClassFieldInitializerScope,
ClassStaticBlockScope
};
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -21,19 +21,18 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";
/**
* A Variable represents a locally scoped identifier. These include arguments to
* functions.
* @class Variable
* @constructor Variable
*/
class Variable {
constructor(name, scope) {
/**
* The variable name, as given in the source code.
* @member {String} Variable#name
* @member {string} Variable#name
*/
this.name = name;
@@ -83,6 +82,6 @@ Variable.Variable = "Variable";
Variable.ImportBinding = "ImportBinding";
Variable.ImplicitGlobalVariable = "ImplicitGlobalVariable";
module.exports = Variable;
export default Variable;
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -1,48 +1,59 @@
{
"name": "eslint-scope",
"description": "ECMAScript scope analyzer for ESLint",
"homepage": "http://github.com/eslint/eslint-scope",
"main": "lib/index.js",
"version": "5.1.1",
"engines": {
"node": ">=8.0.0"
"homepage": "https://github.com/eslint/js/blob/main/packages/eslint-scope/README.md",
"main": "./dist/eslint-scope.cjs",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./dist/eslint-scope.cjs"
},
"./package.json": "./package.json"
},
"repository": "eslint/eslint-scope",
"version": "8.2.0",
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},
"repository": "eslint/js",
"funding": "https://opencollective.com/eslint",
"bugs": {
"url": "https://github.com/eslint/eslint-scope/issues"
"url": "https://github.com/eslint/js/issues"
},
"license": "BSD-2-Clause",
"scripts": {
"test": "node Makefile.js test",
"lint": "node Makefile.js lint",
"generate-release": "eslint-generate-release",
"generate-alpharelease": "eslint-generate-prerelease alpha",
"generate-betarelease": "eslint-generate-prerelease beta",
"generate-rcrelease": "eslint-generate-prerelease rc",
"publish-release": "eslint-publish-release"
"build": "rollup -c",
"build:update-version": "node tools/update-version.js",
"prepublishOnly": "npm run build:update-version && npm run build",
"pretest": "npm run build",
"release:generate:latest": "eslint-generate-release",
"release:generate:alpha": "eslint-generate-prerelease alpha",
"release:generate:beta": "eslint-generate-prerelease beta",
"release:generate:rc": "eslint-generate-prerelease rc",
"release:publish": "eslint-publish-release",
"test": "node Makefile.js test"
},
"files": [
"LICENSE",
"README.md",
"lib"
"lib",
"dist/eslint-scope.cjs"
],
"dependencies": {
"esrecurse": "^4.3.0",
"estraverse": "^4.1.1"
"estraverse": "^5.2.0"
},
"devDependencies": {
"@typescript-eslint/parser": "^1.11.0",
"chai": "^4.2.0",
"eslint": "^6.0.1",
"eslint-config-eslint": "^5.0.1",
"eslint-plugin-node": "^9.1.0",
"eslint-release": "^1.0.0",
"eslint-visitor-keys": "^1.2.0",
"espree": "^7.1.0",
"istanbul": "^0.4.5",
"mocha": "^6.1.4",
"@typescript-eslint/parser": "^8.7.0",
"c8": "^7.7.3",
"chai": "^4.3.4",
"eslint-release": "^3.2.0",
"eslint-visitor-keys": "^4.2.0",
"espree": "^10.3.0",
"mocha": "^9.0.1",
"npm-license": "^0.3.3",
"shelljs": "^0.8.3",
"typescript": "^3.5.2"
"rollup": "^2.52.7",
"shelljs": "^0.8.5",
"typescript": "^5.4.2"
}
}