Skip to content

Commit

Permalink
feat: Add isGlobalReturn method on scopeManager. (#96)
Browse files Browse the repository at this point in the history
Renames the private __isNodejsScope to isGlobalReturn to formally make
it part of the interface and available in ESLint.

Refs eslint/eslint#16999
  • Loading branch information
nzakas committed Apr 12, 2023
1 parent 3dbad80 commit 70c8db1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/referencer.js
Expand Up @@ -409,7 +409,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;
Expand Down
2 changes: 1 addition & 1 deletion lib/scope-manager.js
Expand Up @@ -65,7 +65,7 @@ class ScopeManager {
return this.__options.ignoreEval;
}

__isNodejsScope() {
isGlobalReturn() {
return this.__options.nodejsScope || this.__options.sourceType === "commonjs";
}

Expand Down
3 changes: 3 additions & 0 deletions tests/nodejs-scope.js
Expand Up @@ -38,6 +38,7 @@ describe("nodejsScope option", () => {
const scopeManager = analyze(ast, { ecmaVersion: 6, nodejsScope: true });

expect(scopeManager.scopes).to.have.length(2);
expect(scopeManager.isGlobalReturn()).to.be.true;

let scope = scopeManager.scopes[0];

Expand All @@ -64,6 +65,7 @@ describe("nodejsScope option", () => {
const scopeManager = analyze(ast, { ecmaVersion: 6, sourceType: "commonjs" });

expect(scopeManager.scopes).to.have.length(2);
expect(scopeManager.isGlobalReturn()).to.be.true;

let scope = scopeManager.scopes[0];

Expand All @@ -87,6 +89,7 @@ describe("nodejsScope option", () => {
const scopeManager = analyze(ast, { ecmaVersion: 6, nodejsScope: true, sourceType: "module" });

expect(scopeManager.scopes).to.have.length(3);
expect(scopeManager.isGlobalReturn()).to.be.true;

let scope = scopeManager.scopes[0];

Expand Down

0 comments on commit 70c8db1

Please sign in to comment.