diff --git a/packages/scope-manager/src/Variable.ts b/packages/scope-manager/src/Variable.ts index 3460e52feb7..32f5daec4bb 100644 --- a/packages/scope-manager/src/Variable.ts +++ b/packages/scope-manager/src/Variable.ts @@ -60,6 +60,11 @@ class Variable { * `true` if the variable is valid in a type context, false otherwise */ public isTypeVariable(): boolean { + if (this.defs.length === 0) { + // we don't statically know whether this is a type or a value + return true; + } + return this.defs.some(def => TypeDefinitionTypes.has(def.type)); } @@ -67,6 +72,11 @@ class Variable { * `true` if the variable is valid in a value context, false otherwise */ public isValueVariable(): boolean { + if (this.defs.length === 0) { + // we don't statically know whether this is a type or a value + return true; + } + return this.defs.some(def => ValueDefinitionTypes.has(def.type)); } } diff --git a/packages/scope-manager/src/referencer/Referencer.ts b/packages/scope-manager/src/referencer/Referencer.ts index 77e3f5cc039..a100aca424e 100644 --- a/packages/scope-manager/src/referencer/Referencer.ts +++ b/packages/scope-manager/src/referencer/Referencer.ts @@ -368,6 +368,14 @@ class Referencer extends Visitor { this.close(node); } + protected BreakStatement(): void { + // don't reference the break statement's label + } + + protected ContinueStatement(): void { + // don't reference the continue statement's label + } + protected CallExpression(node: TSESTree.CallExpression): void { this.visitChildren(node); } @@ -402,6 +410,10 @@ class Referencer extends Visitor { this.visitClass(node); } + protected ExportAllDeclaration(): void { + // this defines no local variables + } + protected ExportDefaultDeclaration( node: TSESTree.ExportDefaultDeclaration, ): void { @@ -411,6 +423,12 @@ class Referencer extends Visitor { protected ExportNamedDeclaration( node: TSESTree.ExportNamedDeclaration, ): void { + if (node.source) { + // export ... from 'foo'; + // these are external identifiers so there shouldn't be references or defs + return; + } + if (node.declaration) { // export const x = 1; this.visit(node.declaration); @@ -482,6 +500,10 @@ class Referencer extends Visitor { } } + protected MetaProperty(): void { + // meta properties all builtin globals + } + protected MethodDefinition(node: TSESTree.MethodDefinition): void { this.visitProperty(node); } diff --git a/packages/scope-manager/src/scope/FunctionScope.ts b/packages/scope-manager/src/scope/FunctionScope.ts index 14df8263cae..03eb23df473 100644 --- a/packages/scope-manager/src/scope/FunctionScope.ts +++ b/packages/scope-manager/src/scope/FunctionScope.ts @@ -34,14 +34,10 @@ class FunctionScope extends ScopeBase< // section 9.2.13, FunctionDeclarationInstantiation. // NOTE Arrow functions never have an arguments objects. if (this.block.type !== AST_NODE_TYPES.ArrowFunctionExpression) { - this.defineArguments(); + this.defineVariable('arguments', this.set, this.variables, null, null); } } - private defineArguments(): void { - this.defineVariable('arguments', this.set, this.variables, null, null); - } - // References in default parameters isn't resolved to variables which are in their function body. // const x = 1 // function f(a = x) { // This `x` is resolved to the `x` in the outer scope.