Skip to content

Commit

Permalink
fix: regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed May 3, 2020
1 parent da0883a commit 895f1a2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
10 changes: 10 additions & 0 deletions packages/scope-manager/src/Variable.ts
Expand Up @@ -60,13 +60,23 @@ 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));
}

/**
* `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));
}
}
Expand Down
22 changes: 22 additions & 0 deletions packages/scope-manager/src/referencer/Referencer.ts
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 1 addition & 5 deletions packages/scope-manager/src/scope/FunctionScope.ts
Expand Up @@ -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.
Expand Down

0 comments on commit 895f1a2

Please sign in to comment.