Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-scope

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-scope - npm Package Compare versions

Comparing version 5.1.1 to 6.0.0

dist/eslint-scope.cjs

8

CHANGELOG.md

@@ -0,1 +1,9 @@

v6.0.0 - July 23, 2021
* [`4ee1d80`](https://github.com/eslint/eslint-scope/commit/4ee1d80ce7dab961d9a158bc664d781bb663b570) Fix: Ensure correct version in package (#73) (Nicholas C. Zakas)
* [`82a7e6d`](https://github.com/eslint/eslint-scope/commit/82a7e6d9de8f4fca48e99779e9573dd46adbc18c) Breaking: Switch to ESM (fixes #70) (#71) (Brett Zamir)
* [`0b4a5f1`](https://github.com/eslint/eslint-scope/commit/0b4a5f132fb65520eee31bcd166078656b6e158e) Update: support class fields (refs eslint/eslint#14343) (#69) (Toru Nagashima)
* [`39f8cfc`](https://github.com/eslint/eslint-scope/commit/39f8cfc026d9b9b7c02e07368323350e74698f29) Chore: upgrade estraverse to version 5 (#68) (Rouven Weßling)
* [`ae27ff3`](https://github.com/eslint/eslint-scope/commit/ae27ff3692ab13cf62075b8659f0e17dfa44acd1) Docs: Add range to espree options in README (fixes #66) (#67) (Alan Liang)
v5.1.1 - September 12, 2020

@@ -2,0 +10,0 @@

15

lib/definition.js

@@ -24,8 +24,7 @@ /*

*/
"use strict";
const Variable = require("./variable");
import Variable from "./variable.js";
/**
* @class Definition
* @constructor Definition
*/

@@ -36,3 +35,3 @@ class Definition {

/**
* @member {String} Definition#type - type of the occurrence (e.g. "Parameter", "Variable", ...).
* @member {string} Definition#type - type of the occurrence (e.g. "Parameter", "Variable", ...).
*/

@@ -57,3 +56,3 @@ this.type = type;

/**
* @member {Number?} Definition#index - the index in the declaration statement.
* @member {number?} Definition#index - the index in the declaration statement.
*/

@@ -63,3 +62,3 @@ this.index = index;

/**
* @member {String?} Definition#kind - the kind of the declaration statement.
* @member {string?} Definition#kind - the kind of the declaration statement.
*/

@@ -71,3 +70,3 @@ this.kind = kind;

/**
* @class ParameterDefinition
* @constructor ParameterDefinition
*/

@@ -86,3 +85,3 @@ class ParameterDefinition extends Definition {

module.exports = {
export {
ParameterDefinition,

@@ -89,0 +88,0 @@ Definition

@@ -48,15 +48,13 @@ /*

*/
"use strict";
/* eslint no-underscore-dangle: ["error", { "allow": ["__currentScope"] }] */
const assert = require("assert");
import assert from "assert";
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 ScopeManager from "./scope-manager.js";
import Referencer from "./referencer.js";
import Reference from "./reference.js";
import Variable from "./variable.js";
import eslintScopeVersion from "./version.js";
/**

@@ -81,4 +79,4 @@ * Set the default options

* 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

@@ -90,3 +88,3 @@ */

* Is hash object
* @param {Object} value - Test value
* @param {Object} value Test value
* @returns {boolean} Result

@@ -120,16 +118,16 @@ */

* @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.directive=false] the directive 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' 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.
* @returns {ScopeManager} ScopeManager

@@ -149,6 +147,6 @@ */

module.exports = {
export {
/** @name module:escope.version */
version,
eslintScopeVersion as version,

@@ -161,11 +159,20 @@ /** @name module:escope.Reference */

/** @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 : */

@@ -24,12 +24,13 @@ /*

*/
"use strict";
/* eslint-disable no-undefined */
const Syntax = require("estraverse").Syntax;
const esrecurse = require("esrecurse");
import estraverse from "estraverse";
import esrecurse from "esrecurse";
const { Syntax } = estraverse;
/**
* Get last array element
* @param {array} xs - array
* @param {Array} xs array
* @returns {any} Last elment

@@ -151,4 +152,4 @@ */

module.exports = PatternVisitor;
export default PatternVisitor;
/* vim: set sw=4 ts=4 et tw=80 : */

@@ -24,3 +24,2 @@ /*

*/
"use strict";

@@ -33,3 +32,3 @@ const READ = 0x1;

* A Reference represents a single occurrence of an identifier in code.
* @class Reference
* @constructor Reference
*/

@@ -96,3 +95,3 @@ class Reference {

* Whether the reference is static.
* @method Reference#isStatic
* @function Reference#isStatic
* @returns {boolean} static

@@ -106,3 +105,3 @@ */

* Whether the reference is writeable.
* @method Reference#isWrite
* @function Reference#isWrite
* @returns {boolean} write

@@ -116,3 +115,3 @@ */

* Whether the reference is readable.
* @method Reference#isRead
* @function Reference#isRead
* @returns {boolean} read

@@ -126,3 +125,3 @@ */

* Whether the reference is read-only.
* @method Reference#isReadOnly
* @function Reference#isReadOnly
* @returns {boolean} read only

@@ -136,3 +135,3 @@ */

* Whether the reference is write-only.
* @method Reference#isWriteOnly
* @function Reference#isWriteOnly
* @returns {boolean} write only

@@ -146,3 +145,3 @@ */

* Whether the reference is read-write.
* @method Reference#isReadWrite
* @function Reference#isReadWrite
* @returns {boolean} read write

@@ -173,4 +172,4 @@ */

module.exports = Reference;
export default Reference;
/* vim: set sw=4 ts=4 et tw=80 : */

@@ -24,3 +24,2 @@ /*

*/
"use strict";

@@ -30,19 +29,18 @@ /* eslint-disable no-underscore-dangle */

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");
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";
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}

@@ -214,4 +212,4 @@ */

* Visit pattern callback
* @param {pattern} pattern - pattern
* @param {Object} info - info
* @param {pattern} pattern pattern
* @param {Object} info info
* @returns {void}

@@ -440,2 +438,8 @@ */

// eslint-disable-next-line class-methods-use-this
PrivateIdentifier() {
// Do nothing.
}
UpdateExpression(node) {

@@ -460,2 +464,15 @@ if (PatternVisitor.isPattern(node.argument)) {

PropertyDefinition(node) {
const { computed, key, value } = node;
if (computed) {
this.visit(key);
}
if (value) {
this.scopeManager.__nestClassFieldInitializerScope(value);
this.visit(value);
this.close(value);
}
}
MethodDefinition(node) {

@@ -632,4 +649,4 @@ this.visitProperty(node);

module.exports = Referencer;
export default Referencer;
/* vim: set sw=4 ts=4 et tw=80 : */

@@ -24,22 +24,22 @@ /*

*/
"use strict";
/* eslint-disable no-underscore-dangle */
const Scope = require("./scope");
const assert = require("assert");
import {
BlockScope,
CatchScope,
ClassFieldInitializerScope,
ClassScope,
ForScope,
FunctionExpressionNameScope,
FunctionScope,
GlobalScope,
ModuleScope,
SwitchScope,
WithScope
} from "./scope.js";
import assert from "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;
/**
* @class ScopeManager
* @constructor ScopeManager
*/

@@ -95,4 +95,3 @@ class ScopeManager {

* 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.

@@ -106,5 +105,5 @@ */

* 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

@@ -116,3 +115,3 @@ */

* predicate
* @param {Scope} testScope - scope to test
* @param {Scope} testScope scope to test
* @returns {boolean} predicate

@@ -162,4 +161,4 @@ */

* 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

@@ -173,5 +172,5 @@ */

* 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.

@@ -234,2 +233,6 @@ */

__nestClassFieldInitializerScope(node) {
return this.__nestScope(new ClassFieldInitializerScope(this, this.__currentScope, node));
}
__nestSwitchScope(node) {

@@ -252,4 +255,4 @@ return this.__nestScope(new SwitchScope(this, this.__currentScope, node));

module.exports = ScopeManager;
export default ScopeManager;
/* vim: set sw=4 ts=4 et tw=80 : */

@@ -24,3 +24,2 @@ /*

*/
"use strict";

@@ -30,15 +29,17 @@ /* eslint-disable no-underscore-dangle */

const Syntax = require("estraverse").Syntax;
import estraverse from "estraverse";
const Reference = require("./reference");
const Variable = require("./variable");
const Definition = require("./definition").Definition;
const assert = require("assert");
import Reference from "./reference.js";
import Variable from "./variable.js";
import { Definition } from "./definition.js";
import assert from "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
* @param {boolean} useDirective use directive
* @returns {boolean} is strict scope

@@ -126,4 +127,4 @@ */

* Register scope
* @param {ScopeManager} scopeManager - scope manager
* @param {Scope} scope - scope
* @param {ScopeManager} scopeManager scope manager
* @param {Scope} scope scope
* @returns {void}

@@ -145,3 +146,3 @@ */

* Should be statically
* @param {Object} def - def
* @param {Object} def def
* @returns {boolean} should be statically

@@ -157,3 +158,3 @@ */

/**
* @class Scope
* @constructor Scope
*/

@@ -165,3 +166,3 @@ class Scope {

* One of 'module', 'block', 'switch', 'function', 'catch', 'with', 'function', 'class', 'global'.
* @member {String} Scope#type
* @member {string} Scope#type
*/

@@ -233,3 +234,3 @@ this.type = type;

this.variableScope =
(this.type === "global" || this.type === "function" || this.type === "module") ? this : upperScope.variableScope;
(this.type === "global" || this.type === "function" || this.type === "module" || this.type === "class-field-initializer") ? this : upperScope.variableScope;

@@ -471,4 +472,4 @@ /**

* 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

@@ -492,3 +493,3 @@ */

* returns this scope is static
* @method Scope#isStatic
* @function Scope#isStatic
* @returns {boolean} static

@@ -502,3 +503,3 @@ */

* returns this scope has materialized arguments
* @method Scope#isArgumentsMaterialized
* @function Scope#isArgumentsMaterialized
* @returns {boolean} arguemnts materialized

@@ -512,3 +513,3 @@ */

* returns this scope has materialized `this` reference
* @method Scope#isThisMaterialized
* @function Scope#isThisMaterialized
* @returns {boolean} this materialized

@@ -541,6 +542,6 @@ */

/**
* 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: []

@@ -746,3 +747,9 @@ };

module.exports = {
class ClassFieldInitializerScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, "class-field-initializer", upperScope, block, true);
}
}
export {
Scope,

@@ -758,5 +765,6 @@ GlobalScope,

ForScope,
ClassScope
ClassScope,
ClassFieldInitializerScope
};
/* vim: set sw=4 ts=4 et tw=80 : */

@@ -24,3 +24,2 @@ /*

*/
"use strict";

@@ -30,3 +29,3 @@ /**

* functions.
* @class Variable
* @constructor Variable
*/

@@ -38,3 +37,3 @@ class Variable {

* The variable name, as given in the source code.
* @member {String} Variable#name
* @member {string} Variable#name
*/

@@ -89,4 +88,4 @@ this.name = name;

module.exports = Variable;
export default Variable;
/* vim: set sw=4 ts=4 et tw=80 : */

@@ -5,6 +5,14 @@ {

"homepage": "http://github.com/eslint/eslint-scope",
"main": "lib/index.js",
"version": "5.1.1",
"main": "./dist/eslint-scope.cjs",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./dist/eslint-scope.cjs"
},
"./package.json": "./package.json"
},
"version": "6.0.0",
"engines": {
"node": ">=8.0.0"
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},

@@ -17,4 +25,7 @@ "repository": "eslint/eslint-scope",

"scripts": {
"test": "node Makefile.js test",
"lint": "node Makefile.js lint",
"build": "rollup -c",
"lint": "npm run build && node Makefile.js lint",
"update-version": "node tools/update-version.js",
"test": "npm run build && node Makefile.js test",
"prepublishOnly": "npm run update-version && npm run build",
"generate-release": "eslint-generate-release",

@@ -29,23 +40,26 @@ "generate-alpharelease": "eslint-generate-prerelease alpha",

"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": "^4.28.1",
"c8": "^7.7.3",
"chai": "^4.3.4",
"eslint": "^7.29.0",
"eslint-config-eslint": "^7.0.0",
"eslint-plugin-jsdoc": "^35.4.1",
"eslint-plugin-node": "^11.1.0",
"eslint-release": "^3.1.2",
"eslint-visitor-keys": "^3.0.0",
"espree": "^8.0.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.4",
"typescript": "^4.3.5"
}
}

@@ -5,6 +5,4 @@ # ESLint Scope

## Usage
## Install
Install:
```

@@ -14,16 +12,30 @@ 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');
```
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 ast = espree.parse(code, { range: true });
const scopeManager = eslintScope.analyze(ast);
var currentScope = scopeManager.acquire(ast); // global scope
const currentScope = scopeManager.acquire(ast); // global scope
estraverse.traverse(ast, {
enter: function(node, parent) {
enter (node, parent) {
// do stuff

@@ -35,3 +47,3 @@

},
leave: function(node, parent) {
leave(node, parent) {
if (/Function/.test(node.type)) {

@@ -38,0 +50,0 @@ currentScope = currentScope.upper; // set to parent scope

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc