diff --git a/lib/referencer.js b/lib/referencer.js index 0147f68..6a5da52 100644 --- a/lib/referencer.js +++ b/lib/referencer.js @@ -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; diff --git a/lib/scope-manager.js b/lib/scope-manager.js index e41d471..d2270f1 100644 --- a/lib/scope-manager.js +++ b/lib/scope-manager.js @@ -65,7 +65,7 @@ class ScopeManager { return this.__options.ignoreEval; } - __isNodejsScope() { + isGlobalReturn() { return this.__options.nodejsScope || this.__options.sourceType === "commonjs"; } diff --git a/tests/nodejs-scope.js b/tests/nodejs-scope.js index 609ba00..d532075 100644 --- a/tests/nodejs-scope.js +++ b/tests/nodejs-scope.js @@ -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]; @@ -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]; @@ -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];