Skip to content

Commit

Permalink
feat: add a scope when a type has generics
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed May 3, 2020
1 parent b7f4005 commit da0883a
Show file tree
Hide file tree
Showing 11 changed files with 353 additions and 322 deletions.
56 changes: 31 additions & 25 deletions packages/scope-manager/src/ScopeManager.ts
Expand Up @@ -11,6 +11,7 @@ import {
ModuleScope,
Scope,
SwitchScope,
TypeScope,
WithScope,
} from './scope';

Expand Down Expand Up @@ -144,62 +145,67 @@ class ScopeManager {
return scope;
}

public nestGlobalScope(node: GlobalScope['block']): Scope {
return this.nestScope(new GlobalScope(this, node));
}

public nestBlockScope(node: BlockScope['block']): Scope {
assert(this.currentScope);
return this.nestScope(new BlockScope(this, this.currentScope, node));
}

public nestFunctionScope(
node: FunctionScope['block'],
isMethodDefinition: boolean,
): Scope {
public nestCatchScope(node: CatchScope['block']): Scope {
assert(this.currentScope);
return this.nestScope(
new FunctionScope(this, this.currentScope, node, isMethodDefinition),
);
return this.nestScope(new CatchScope(this, this.currentScope, node));
}

public nestClassScope(node: ClassScope['block']): Scope {
assert(this.currentScope);
return this.nestScope(new ClassScope(this, this.currentScope, node));
}

public nestForScope(node: ForScope['block']): Scope {
assert(this.currentScope);
return this.nestScope(new ForScope(this, this.currentScope, node));
}

public nestCatchScope(node: CatchScope['block']): Scope {
public nestFunctionExpressionNameScope(
node: FunctionExpressionNameScope['block'],
): Scope {
assert(this.currentScope);
return this.nestScope(new CatchScope(this, this.currentScope, node));
return this.nestScope(
new FunctionExpressionNameScope(this, this.currentScope, node),
);
}

public nestWithScope(node: WithScope['block']): Scope {
public nestFunctionScope(
node: FunctionScope['block'],
isMethodDefinition: boolean,
): Scope {
assert(this.currentScope);
return this.nestScope(new WithScope(this, this.currentScope, node));
return this.nestScope(
new FunctionScope(this, this.currentScope, node, isMethodDefinition),
);
}

public nestClassScope(node: ClassScope['block']): Scope {
public nestGlobalScope(node: GlobalScope['block']): Scope {
return this.nestScope(new GlobalScope(this, node));
}

public nestModuleScope(node: ModuleScope['block']): Scope {
assert(this.currentScope);
return this.nestScope(new ClassScope(this, this.currentScope, node));
return this.nestScope(new ModuleScope(this, this.currentScope, node));
}

public nestSwitchScope(node: SwitchScope['block']): Scope {
assert(this.currentScope);
return this.nestScope(new SwitchScope(this, this.currentScope, node));
}

public nestModuleScope(node: ModuleScope['block']): Scope {
public nestTypeScope(node: TypeScope['block']): Scope {
assert(this.currentScope);
return this.nestScope(new ModuleScope(this, this.currentScope, node));
return this.nestScope(new TypeScope(this, this.currentScope, node));
}

public nestFunctionExpressionNameScope(
node: FunctionExpressionNameScope['block'],
): Scope {
public nestWithScope(node: WithScope['block']): Scope {
assert(this.currentScope);
return this.nestScope(
new FunctionExpressionNameScope(this, this.currentScope, node),
);
return this.nestScope(new WithScope(this, this.currentScope, node));
}
}

Expand Down

0 comments on commit da0883a

Please sign in to comment.