Socket
Socket
Sign inDemoInstall

eslint-scope

Package Overview
Dependencies
2
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.2.2 to 8.0.0

2

lib/index.js

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

optimistic: false,
directive: false,
nodejsScope: false,

@@ -119,3 +118,2 @@ impliedStrict: false,

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

@@ -122,0 +120,0 @@ * @param {boolean} [providedOptions.nodejsScope=false] whether the whole

4

lib/referencer.js

@@ -275,4 +275,2 @@ /*

this.visit(node.superClass);
this.scopeManager.__nestClassScope(node);

@@ -288,2 +286,4 @@

}
this.visit(node.superClass);
this.visit(node.body);

@@ -290,0 +290,0 @@

@@ -56,6 +56,2 @@ /*

__useDirective() {
return this.__options.directive;
}
__isOptimistic() {

@@ -62,0 +58,0 @@ return this.__options.optimistic;

@@ -42,6 +42,5 @@ /*

* @param {boolean} isMethodDefinition is method definition
* @param {boolean} useDirective use directive
* @returns {boolean} is strict scope
*/
function isStrictScope(scope, block, isMethodDefinition, useDirective) {
function isStrictScope(scope, block, isMethodDefinition) {
let body;

@@ -86,37 +85,25 @@

// 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;

@@ -269,3 +256,3 @@ }

this.isStrict = scopeManager.isStrictModeSupported()
? isStrictScope(this, block, isMethodDefinition, scopeManager.__useDirective())
? isStrictScope(this, block, isMethodDefinition)
: false;

@@ -272,0 +259,0 @@

@@ -1,3 +0,3 @@

const version = "7.2.2";
const version = "8.0.0";
export default version;

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

},
"version": "7.2.2",
"version": "8.0.0",
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},

@@ -27,11 +27,13 @@ "repository": "eslint/eslint-scope",

"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",
"generate-alpharelease": "eslint-generate-prerelease alpha",
"generate-betarelease": "eslint-generate-prerelease beta",
"generate-rcrelease": "eslint-generate-prerelease rc",
"publish-release": "eslint-publish-release"
"build:update-version": "node tools/update-version.js",
"lint": "node Makefile.js lint",
"prelint": "npm run build",
"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"
},

@@ -38,0 +40,0 @@ "files": [

@@ -29,2 +29,14 @@ [![npm version](https://img.shields.io/npm/v/eslint-scope.svg)](https://www.npmjs.com/package/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/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:

@@ -37,5 +49,10 @@

const ast = espree.parse(code, { range: true });
const scopeManager = eslintScope.analyze(ast);
const options = {
ecmaVersion: 2022,
sourceType: "module"
};
const ast = espree.parse(code, { range: true, ...options });
const scopeManager = eslintScope.analyze(ast, options);
const currentScope = scopeManager.acquire(ast); // global scope

@@ -42,0 +59,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc