Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scope-manager): ignore ECMA version #5881

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/scope-manager/src/ScopeManager.ts
Expand Up @@ -28,7 +28,6 @@ interface ScopeManagerOptions {
globalReturn?: boolean;
sourceType?: 'module' | 'script';
impliedStrict?: boolean;
ecmaVersion?: number;
}

class ScopeManager {
Expand Down Expand Up @@ -77,13 +76,6 @@ class ScopeManager {
public isImpliedStrict(): boolean {
return this.#options.impliedStrict === true;
}
public isStrictModeSupported(): boolean {
return this.#options.ecmaVersion != null && this.#options.ecmaVersion >= 5;
}

public isES6(): boolean {
return this.#options.ecmaVersion != null && this.#options.ecmaVersion >= 6;
}
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get the variables that a given AST node defines. The gotten variables' `def[].node`/`def[].parent` property is the node.
Expand Down
17 changes: 5 additions & 12 deletions packages/scope-manager/src/referencer/Referencer.ts
Expand Up @@ -371,9 +371,7 @@ class Referencer extends Visitor {
}

protected BlockStatement(node: TSESTree.BlockStatement): void {
if (this.scopeManager.isES6()) {
this.scopeManager.nestBlockScope(node);
}
this.scopeManager.nestBlockScope(node);

this.visitChildren(node);

Expand Down Expand Up @@ -487,7 +485,7 @@ class Referencer extends Visitor {

protected ImportDeclaration(node: TSESTree.ImportDeclaration): void {
assert(
this.scopeManager.isES6() && this.scopeManager.isModule(),
this.scopeManager.isModule(),
'ImportDeclaration should appear when the mode is ES6 and in the module context.',
);

Expand Down Expand Up @@ -579,14 +577,11 @@ class Referencer extends Visitor {
this.scopeManager.nestFunctionScope(node, false);
}

if (this.scopeManager.isES6() && this.scopeManager.isModule()) {
if (this.scopeManager.isModule()) {
this.scopeManager.nestModuleScope(node);
}

if (
this.scopeManager.isStrictModeSupported() &&
this.scopeManager.isImpliedStrict()
) {
if (this.scopeManager.isImpliedStrict()) {
this.currentScope().isStrict = true;
}

Expand All @@ -601,9 +596,7 @@ class Referencer extends Visitor {
protected SwitchStatement(node: TSESTree.SwitchStatement): void {
this.visit(node.discriminant);

if (this.scopeManager.isES6()) {
this.scopeManager.nestSwitchScope(node);
}
this.scopeManager.nestSwitchScope(node);

for (const switchCase of node.cases) {
this.visit(switchCase);
Expand Down
25 changes: 0 additions & 25 deletions packages/scope-manager/tests/eslint-scope/implied-strict.test.ts
Expand Up @@ -42,31 +42,6 @@ describe('impliedStrict option', () => {
expect(scope.isStrict).toBeTruthy();
});

it('ensures impliedStrict option is only effective when ecmaVersion option >= 5', () => {
const { scopeManager } = parseAndAnalyze(
`
function foo() {}
`,
{
ecmaVersion: 3,
impliedStrict: true,
},
);

expect(scopeManager.scopes).toHaveLength(2);

let scope = scopeManager.scopes[0];

expectToBeGlobalScope(scope);
expect(scope.block.type).toBe(AST_NODE_TYPES.Program);
expect(scope.isStrict).toBeFalsy();

scope = scopeManager.scopes[1];
expectToBeFunctionScope(scope);
expect(scope.block.type).toBe(AST_NODE_TYPES.FunctionDeclaration);
expect(scope.isStrict).toBeFalsy();
});

it('omits a nodejs global scope when ensuring all user scopes are strict', () => {
const { scopeManager } = parseAndAnalyze(
`
Expand Down