From 73f8dca79e151ec5198a3fd9a5450b4aa4e202b3 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Mon, 21 Jun 2021 06:33:19 +0800 Subject: [PATCH] Breaking: Switch to ESM Also adds eslint-plugin-jsdoc for linter --- .editorconfig | 15 ++++++++++++ .eslintrc.cjs | 25 +++++++++++++++++++ .eslintrc.js | 16 ------------ .gitignore | 1 + Makefile.js | 26 ++++++++++++-------- README.md | 34 +++++++++++++++++--------- lib/definition.js | 5 ++-- lib/index.js | 27 ++++++++++---------- lib/pattern-visitor.js | 7 +++--- lib/reference.js | 3 +-- lib/referencer.js | 20 ++++++--------- lib/scope-manager.js | 29 +++++++++++----------- lib/scope.js | 13 +++++----- lib/variable.js | 3 +-- package.json | 17 ++++++++++--- rollup.config.js | 9 +++++++ tests/arguments.js | 7 +++--- tests/catch-scope.js | 7 +++--- tests/child-visitor-keys.js | 7 +++--- tests/es6-arrow-function-expression.js | 7 +++--- tests/es6-block-scope.js | 7 +++--- tests/es6-catch.js | 7 +++--- tests/es6-class.js | 7 +++--- tests/es6-default-parameters.js | 7 +++--- tests/es6-destructuring-assignments.js | 7 +++--- tests/es6-export.js | 7 +++--- tests/es6-import.js | 7 +++--- tests/es6-iteration-scope.js | 7 +++--- tests/es6-new-target.js | 7 +++--- tests/es6-object.js | 7 +++--- tests/es6-rest-args.js | 7 +++--- tests/es6-super.js | 7 +++--- tests/es6-switch.js | 7 +++--- tests/es6-template-literal.js | 7 +++--- tests/export-star-as-ns-from-source.js | 10 ++++---- tests/fallback.js | 8 +++--- tests/function-expression-name.js | 7 +++--- tests/get-declared-variables.js | 9 +++---- tests/global-increment.js | 7 +++--- tests/implicit-global-reference.js | 7 +++--- tests/implied-strict.js | 7 +++--- tests/label.js | 7 +++--- tests/nodejs-scope.js | 7 +++--- tests/object-expression.js | 6 ++--- tests/optimistic.js | 7 +++--- tests/references.js | 7 +++--- tests/typescript.js | 11 +++++---- tests/util/espree.js | 13 +++++++--- tests/with-scope.js | 7 +++--- 49 files changed, 261 insertions(+), 235 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc.cjs delete mode 100644 .eslintrc.js create mode 100644 rollup.config.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9fe93ed --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +; EditorConfig file: https://EditorConfig.org +; Install the "EditorConfig" plugin into your editor to use + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[package.json] +indent_size = 2 diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..b83959c --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,25 @@ +"use strict"; + +module.exports = { + root: true, + extends: [ + "eslint", + "plugin:node/recommended-module" + ], + parserOptions: { + sourceType: "module", + ecmaVersion: "2020" + }, + overrides: [ + { + files: ".eslintrc.js", + extends: ["eslint", "plugin:node/recommended-script"] + }, + { + files: ["tests/**/*"], + env: { + mocha: true + } + } + ] +}; diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index bc0737e..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict"; - -module.exports = { - root: true, - extends: [ - "eslint" - ], - overrides: [ - { - files: ["tests/**/*"], - env: { - mocha: true - } - } - ] -}; diff --git a/.gitignore b/.gitignore index 3222b4e..f191c4c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ npm-debug.log /.vscode .sublimelinterrc .eslint-release-info.json +dist diff --git a/Makefile.js b/Makefile.js index 8226648..ee4760b 100644 --- a/Makefile.js +++ b/Makefile.js @@ -6,17 +6,20 @@ */ /* global echo, exec, exit, set, target */ -"use strict"; - /* eslint no-console: 0*/ //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ -require("shelljs/make"); -set("+e"); +import path from "path"; +import { fileURLToPath } from "url"; + +import "shelljs/make.js"; +import checker from "npm-license"; -const checker = require("npm-license"); +const dirname = path.dirname(fileURLToPath(import.meta.url)); + +set("+e"); //------------------------------------------------------------------------------ // Settings @@ -31,12 +34,15 @@ const OPEN_SOURCE_LICENSES = [ //------------------------------------------------------------------------------ const NODE = "node", - NODE_MODULES = "./node_modules/", + NODE_MODULES = "./node_modules", // Utilities - intentional extra space at the end of each string - MOCHA = `${NODE_MODULES}mocha/bin/_mocha `, + MOCHA = `${NODE_MODULES}/mocha/bin/_mocha `, ESLINT = `${NODE} ${NODE_MODULES}/eslint/bin/eslint `, - ISTANBUL = `${NODE} ${NODE_MODULES}/istanbul/lib/cli.js `, + + // If switching back to Istanbul when may be working with ESM + // ISTANBUL = `${NODE} ${NODE_MODULES}/istanbul/lib/cli.js `, + C8 = `${NODE} ${NODE_MODULES}/c8/bin/c8.js`, // Files MAKEFILE = "./Makefile.js", @@ -80,7 +86,7 @@ target.lint = function() { target.test = function() { let errors = 0; - const lastReturn = exec(`${ISTANBUL} cover ${MOCHA} -- -R progress -c ${TEST_FILES}`); + const lastReturn = exec(`${C8} ${MOCHA} -- -R progress -c ${TEST_FILES}`); if (lastReturn.code !== 0) { errors++; @@ -116,7 +122,7 @@ target.checkLicenses = function() { echo("Validating licenses"); checker.init({ - start: __dirname + start: dirname }, deps => { const impermissible = Object.keys(deps).map(dependency => ({ name: dependency, diff --git a/README.md b/README.md index e824b42..d5449a2 100644 --- a/README.md +++ b/README.md @@ -2,35 +2,47 @@ 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 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 eslintScope from 'eslint-scope'; +import espree from 'espree'; +import estraverse from 'estraverse'; -var ast = espree.parse(code, { range: true }); -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 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 } diff --git a/lib/definition.js b/lib/definition.js index ce7094b..9744ef4 100644 --- a/lib/definition.js +++ b/lib/definition.js @@ -21,9 +21,8 @@ (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"; /** * @constructor Definition @@ -78,7 +77,7 @@ class ParameterDefinition extends Definition { } } -module.exports = { +export { ParameterDefinition, Definition }; diff --git a/lib/index.js b/lib/index.js index cf28d16..41f4d0d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -45,18 +45,19 @@ * The main interface is the {@link analyze} function. * @module escope */ -"use strict"; - /* eslint no-underscore-dangle: ["error", { "allow": ["__currentScope"] }] */ -const assert = require("assert"); +import { readFileSync } from "fs"; +import assert from "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; +const { version } = JSON.parse( + readFileSync(new URL("../package.json", import.meta.url)) +); /** * Set the default options @@ -142,7 +143,7 @@ function analyze(tree, providedOptions) { return scopeManager; } -module.exports = { +export { /** @name module:escope.version */ version, @@ -153,13 +154,13 @@ module.exports = { /** @name module:escope.Variable */ Variable, - /** @name module:escope.Scope */ - Scope, - /** @name module:escope.ScopeManager */ ScopeManager, analyze }; +/** @name module:escope.Scope */ +export * from "./scope.js"; + /* vim: set sw=4 ts=4 et tw=80 : */ diff --git a/lib/pattern-visitor.js b/lib/pattern-visitor.js index 19f01f8..08c036d 100644 --- a/lib/pattern-visitor.js +++ b/lib/pattern-visitor.js @@ -21,12 +21,11 @@ (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 */ -const Syntax = require("estraverse").Syntax; -const esrecurse = require("esrecurse"); +import { Syntax } from "estraverse"; +import esrecurse from "esrecurse"; /** * Get last array element @@ -147,6 +146,6 @@ class PatternVisitor extends esrecurse.Visitor { } } -module.exports = PatternVisitor; +export default PatternVisitor; /* vim: set sw=4 ts=4 et tw=80 : */ diff --git a/lib/reference.js b/lib/reference.js index 1942716..e657d62 100644 --- a/lib/reference.js +++ b/lib/reference.js @@ -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; @@ -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 : */ diff --git a/lib/referencer.js b/lib/referencer.js index 9ddb2d5..8ac89e7 100644 --- a/lib/referencer.js +++ b/lib/referencer.js @@ -21,21 +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"; /* eslint-disable no-underscore-dangle */ /* eslint-disable no-undefined */ -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; +import { Syntax } 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"; /** * Traverse identifier in pattern @@ -624,6 +620,6 @@ class Referencer extends esrecurse.Visitor { } } -module.exports = Referencer; +export default Referencer; /* vim: set sw=4 ts=4 et tw=80 : */ diff --git a/lib/scope-manager.js b/lib/scope-manager.js index f3d2a8a..238e263 100644 --- a/lib/scope-manager.js +++ b/lib/scope-manager.js @@ -21,23 +21,22 @@ (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 { + GlobalScope, + CatchScope, + WithScope, + ModuleScope, + ClassScope, + SwitchScope, + FunctionScope, + ForScope, + FunctionExpressionNameScope, + BlockScope +} from "./scope.js"; +import assert from "assert"; /** * @constructor ScopeManager @@ -241,6 +240,6 @@ class ScopeManager { } } -module.exports = ScopeManager; +export default ScopeManager; /* vim: set sw=4 ts=4 et tw=80 : */ diff --git a/lib/scope.js b/lib/scope.js index 52a3b2b..f0f056f 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -21,17 +21,16 @@ (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 */ -const Syntax = require("estraverse").Syntax; +import { Syntax } 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"; /** * Test if scope is struct @@ -731,7 +730,7 @@ class ClassScope extends Scope { } } -module.exports = { +export { Scope, GlobalScope, ModuleScope, diff --git a/lib/variable.js b/lib/variable.js index 261d780..286202f 100644 --- a/lib/variable.js +++ b/lib/variable.js @@ -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"; /** * A Variable represents a locally scoped identifier. These include arguments to @@ -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 : */ diff --git a/package.json b/package.json index e2748f8..4fa09ec 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,15 @@ "name": "eslint-scope", "description": "ECMAScript scope analyzer for ESLint", "homepage": "http://github.com/eslint/eslint-scope", - "main": "lib/index.js", + "main": "./dist/eslint-scope.cjs", + "type": "module", + "exports": { + "import": "./lib/index.js", + "require": "./dist/eslint-scope.cjs" + }, "version": "5.1.1", "engines": { - "node": ">=8.0.0" + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, "repository": "eslint/eslint-scope", "bugs": { @@ -13,6 +18,8 @@ }, "license": "BSD-2-Clause", "scripts": { + "prepare": "npm run build", + "build": "rollup -c", "test": "node Makefile.js test", "lint": "node Makefile.js lint", "generate-release": "eslint-generate-release", @@ -31,17 +38,19 @@ "estraverse": "^5.2.0" }, "devDependencies": { - "@typescript-eslint/parser": "^4.27.0", + "@typescript-eslint/parser": "^4.28.0", + "c8": "^7.7.3", "chai": "^4.3.4", "eslint": "^7.29.0", "eslint-config-eslint": "^7.0.0", + "eslint-plugin-jsdoc": "^35.4.0", "eslint-plugin-node": "^11.1.0", "eslint-release": "^3.1.2", "eslint-visitor-keys": "^2.1.0", "espree": "^7.3.1", - "istanbul": "^0.4.5", "mocha": "^9.0.1", "npm-license": "^0.3.3", + "rollup": "^2.52.2", "shelljs": "^0.8.4", "typescript": "^4.3.4" } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..ea61d9c --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,9 @@ +export default { + input: "./lib/index.js", + external: ["fs", "assert", "estraverse", "esrecurse"], + output: { + exports: "named", + format: "cjs", + file: "dist/eslint-scope.cjs" + } +}; diff --git a/tests/arguments.js b/tests/arguments.js index 60038d7..268f210 100644 --- a/tests/arguments.js +++ b/tests/arguments.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("arguments", () => { it("arguments are correctly materialized", () => { diff --git a/tests/catch-scope.js b/tests/catch-scope.js index 62c52d1..e27f7f6 100644 --- a/tests/catch-scope.js +++ b/tests/catch-scope.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("catch", () => { it("creates scope", () => { diff --git a/tests/child-visitor-keys.js b/tests/child-visitor-keys.js index 8ff0be5..d700424 100644 --- a/tests/child-visitor-keys.js +++ b/tests/child-visitor-keys.js @@ -20,11 +20,10 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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 expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("childVisitorKeys option", () => { it("should handle as a known node if the childVisitorKeys option was given.", () => { diff --git a/tests/es6-arrow-function-expression.js b/tests/es6-arrow-function-expression.js index 998ef73..87beafc 100644 --- a/tests/es6-arrow-function-expression.js +++ b/tests/es6-arrow-function-expression.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 arrow function expression", () => { it("materialize scope for arrow function expression", () => { diff --git a/tests/es6-block-scope.js b/tests/es6-block-scope.js index 1e5a21e..8ddf5bc 100644 --- a/tests/es6-block-scope.js +++ b/tests/es6-block-scope.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 block scope", () => { it("let is materialized in ES6 block scope#1", () => { diff --git a/tests/es6-catch.js b/tests/es6-catch.js index afc24e9..26419f3 100644 --- a/tests/es6-catch.js +++ b/tests/es6-catch.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 catch", () => { it("takes binding pattern", () => { diff --git a/tests/es6-class.js b/tests/es6-class.js index 93c5620..0816458 100644 --- a/tests/es6-class.js +++ b/tests/es6-class.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 class", () => { it("declaration name creates class scope", () => { diff --git a/tests/es6-default-parameters.js b/tests/es6-default-parameters.js index d88adc2..ef7f28d 100644 --- a/tests/es6-default-parameters.js +++ b/tests/es6-default-parameters.js @@ -20,14 +20,13 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ /* eslint-disable guard-for-in */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 default parameters:", () => { describe("a default parameter creates a writable reference for its initialization:", () => { diff --git a/tests/es6-destructuring-assignments.js b/tests/es6-destructuring-assignments.js index 89fa664..9a85808 100644 --- a/tests/es6-destructuring-assignments.js +++ b/tests/es6-destructuring-assignments.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 destructuring assignments", () => { it("Pattern in var in ForInStatement", () => { diff --git a/tests/es6-export.js b/tests/es6-export.js index d015b42..b683f62 100644 --- a/tests/es6-export.js +++ b/tests/es6-export.js @@ -20,11 +20,10 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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 expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("export declaration", () => { diff --git a/tests/es6-import.js b/tests/es6-import.js index 6a03886..0cd8e9d 100644 --- a/tests/es6-import.js +++ b/tests/es6-import.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("import declaration", () => { diff --git a/tests/es6-iteration-scope.js b/tests/es6-iteration-scope.js index fb478e6..2ed630f 100644 --- a/tests/es6-iteration-scope.js +++ b/tests/es6-iteration-scope.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 iteration scope", () => { it("let materialize iteration scope for ForInStatement#1", () => { diff --git a/tests/es6-new-target.js b/tests/es6-new-target.js index 16d5cdd..dc10c58 100644 --- a/tests/es6-new-target.js +++ b/tests/es6-new-target.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 new.target", () => { it("should not make references of new.target", () => { diff --git a/tests/es6-object.js b/tests/es6-object.js index 8f9e700..e94967d 100644 --- a/tests/es6-object.js +++ b/tests/es6-object.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 object", () => { it("method definition", () => { diff --git a/tests/es6-rest-args.js b/tests/es6-rest-args.js index 637f1f2..36dc61e 100644 --- a/tests/es6-rest-args.js +++ b/tests/es6-rest-args.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 rest arguments", () => { it("materialize rest argument in scope", () => { diff --git a/tests/es6-super.js b/tests/es6-super.js index 7a74edf..dc42e2e 100644 --- a/tests/es6-super.js +++ b/tests/es6-super.js @@ -20,11 +20,10 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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 expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 super", () => { it("is not handled as reference", () => { diff --git a/tests/es6-switch.js b/tests/es6-switch.js index 780a6e1..05be10c 100644 --- a/tests/es6-switch.js +++ b/tests/es6-switch.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 switch", () => { it("materialize scope", () => { diff --git a/tests/es6-template-literal.js b/tests/es6-template-literal.js index 8b1f4ec..d72a5bb 100644 --- a/tests/es6-template-literal.js +++ b/tests/es6-template-literal.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ES6 template literal", () => { it("refer variables", () => { diff --git a/tests/export-star-as-ns-from-source.js b/tests/export-star-as-ns-from-source.js index 49d4257..27f6d8a 100644 --- a/tests/export-star-as-ns-from-source.js +++ b/tests/export-star-as-ns-from-source.js @@ -1,9 +1,9 @@ -"use strict"; +import assert from "assert"; +import espree from "espree"; +import evk from "eslint-visitor-keys"; +import { analyze } from "../lib/index.js"; -const assert = require("assert"); -const espree = require("espree"); -const { KEYS } = require("eslint-visitor-keys"); -const { analyze } = require("../lib/index"); +const { KEYS } = evk; describe("export * as ns from 'source'", () => { let scopes; diff --git a/tests/fallback.js b/tests/fallback.js index 6c7dde5..cfbc6a3 100644 --- a/tests/fallback.js +++ b/tests/fallback.js @@ -20,12 +20,10 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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 expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("fallback option", () => { it("should raise an error when it encountered an unknown node if no fallback.", () => { diff --git a/tests/function-expression-name.js b/tests/function-expression-name.js index f982b83..ef238d8 100644 --- a/tests/function-expression-name.js +++ b/tests/function-expression-name.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("function name", () => { it("should create its special scope", () => { diff --git a/tests/get-declared-variables.js b/tests/get-declared-variables.js index 5221343..7ca51db 100644 --- a/tests/get-declared-variables.js +++ b/tests/get-declared-variables.js @@ -20,12 +20,11 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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 expect = require("chai").expect; -const visit = require("esrecurse").visit; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import { visit } from "esrecurse"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("ScopeManager.prototype.getDeclaredVariables", () => { /* eslint-disable jsdoc/require-jsdoc */ diff --git a/tests/global-increment.js b/tests/global-increment.js index df48b94..53517d9 100644 --- a/tests/global-increment.js +++ b/tests/global-increment.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("global increment", () => { it("becomes read/write", () => { diff --git a/tests/implicit-global-reference.js b/tests/implicit-global-reference.js index 011a5f8..4c869ff 100644 --- a/tests/implicit-global-reference.js +++ b/tests/implicit-global-reference.js @@ -19,11 +19,10 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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 expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("implicit global reference", () => { it("assignments global scope", () => { diff --git a/tests/implied-strict.js b/tests/implied-strict.js index 3896941..2d07869 100644 --- a/tests/implied-strict.js +++ b/tests/implied-strict.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("impliedStrict option", () => { it("ensures all user scopes are strict if ecmaVersion >= 5", () => { diff --git a/tests/label.js b/tests/label.js index 1605a23..f3330b3 100644 --- a/tests/label.js +++ b/tests/label.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("label", () => { it("should not create variables", () => { diff --git a/tests/nodejs-scope.js b/tests/nodejs-scope.js index 2ce8cf7..c3a90ca 100644 --- a/tests/nodejs-scope.js +++ b/tests/nodejs-scope.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("nodejsScope option", () => { it("creates a function scope following the global scope immediately", () => { diff --git a/tests/object-expression.js b/tests/object-expression.js index 81b4a9d..f3440d7 100644 --- a/tests/object-expression.js +++ b/tests/object-expression.js @@ -1,7 +1,5 @@ -"use strict"; - -const expect = require("chai").expect; -const analyze = require("..").analyze; +import { expect } from "chai"; +import { analyze } from "../lib/index.js"; describe("object expression", () => { it("doesn't require property type", () => { diff --git a/tests/optimistic.js b/tests/optimistic.js index ddf0d06..941e724 100644 --- a/tests/optimistic.js +++ b/tests/optimistic.js @@ -19,11 +19,10 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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 expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("optimistic", () => { it("direct call to eval", () => { diff --git a/tests/references.js b/tests/references.js index 6de0a1b..b9b4213 100644 --- a/tests/references.js +++ b/tests/references.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("References:", () => { describe("When there is a `let` declaration on global,", () => { diff --git a/tests/typescript.js b/tests/typescript.js index 0b312b3..1ef8e0a 100644 --- a/tests/typescript.js +++ b/tests/typescript.js @@ -2,7 +2,6 @@ * @fileoverview Typescript scope tests * @author Reyad Attiyat */ -"use strict"; /* eslint-disable no-unused-expressions */ @@ -10,9 +9,9 @@ // Requirements //------------------------------------------------------------------------------ -const expect = require("chai").expect, - parse = require("@typescript-eslint/parser").parse, - analyze = require("..").analyze; +import { expect } from "chai"; +import { parse } from "@typescript-eslint/parser"; +import { analyze } from "../lib/index.js"; //------------------------------------------------------------------------------ // Tests @@ -27,7 +26,9 @@ describe("typescript", () => { function foo(bar: string | number): string | number { return bar; } - `); + `, { + range: true + }); const scopeManager = analyze(ast); diff --git a/tests/util/espree.js b/tests/util/espree.js index 5afb2a9..eb0be96 100644 --- a/tests/util/espree.js +++ b/tests/util/espree.js @@ -21,16 +21,21 @@ (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 espree = require("espree"); +import espree from "espree"; -module.exports = function(code, sourceType = "module") { +/** + * Parse into Espree AST. + * @param {string} code The code + * @param {"module"|"script"} [sourceType="module"] The source type + * @returns {Object} The parsed Espree AST + */ +export default function(code, sourceType = "module") { return espree.parse(code, { range: true, ecmaVersion: 7, sourceType }); -}; +} /* vim: set sw=4 ts=4 et tw=80 : */ diff --git a/tests/with-scope.js b/tests/with-scope.js index 2d33e3d..f90bd33 100644 --- a/tests/with-scope.js +++ b/tests/with-scope.js @@ -20,13 +20,12 @@ // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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-unused-expressions */ -const expect = require("chai").expect; -const espree = require("./util/espree"); -const analyze = require("..").analyze; +import { expect } from "chai"; +import espree from "./util/espree.js"; +import { analyze } from "../lib/index.js"; describe("with", () => { it("creates scope", () => {