Skip to content

Commit

Permalink
use protected in syntax walker
Browse files Browse the repository at this point in the history
- fixes palantir#272
  • Loading branch information
ashwinr committed Feb 3, 2015
1 parent 5311cf1 commit 9ec89de
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 135 deletions.
114 changes: 57 additions & 57 deletions lib/tslint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,63 +49,63 @@ declare module Lint {
}
declare module Lint {
class SyntaxWalker {
visitAnyKeyword(node: ts.Node): void;
visitArrowFunction(node: ts.FunctionLikeDeclaration): void;
visitBinaryExpression(node: ts.BinaryExpression): void;
visitBlock(node: ts.Block): void;
visitBreakStatement(node: ts.BreakOrContinueStatement): void;
visitCallExpression(node: ts.CallExpression): void;
visitCaseClause(node: ts.CaseClause): void;
visitClassDeclaration(node: ts.ClassDeclaration): void;
visitCatchClause(node: ts.CatchClause): void;
visitConditionalExpression(node: ts.ConditionalExpression): void;
visitConstructorDeclaration(node: ts.ConstructorDeclaration): void;
visitConstructorType(node: ts.Node): void;
visitContinueStatement(node: ts.BreakOrContinueStatement): void;
visitDebuggerStatement(node: ts.Statement): void;
visitDefaultClause(node: ts.DefaultClause): void;
visitDoStatement(node: ts.DoStatement): void;
visitElementAccessExpression(node: ts.ElementAccessExpression): void;
visitEnumDeclaration(node: ts.EnumDeclaration): void;
visitExportAssignment(node: ts.ExportAssignment): void;
visitExpressionStatement(node: ts.ExpressionStatement): void;
visitForStatement(node: ts.ForStatement): void;
visitForInStatement(node: ts.ForInStatement): void;
visitFunctionDeclaration(node: ts.FunctionDeclaration): void;
visitFunctionExpression(node: ts.FunctionExpression): void;
visitFunctionType(node: ts.Node): void;
visitGetAccessor(node: ts.AccessorDeclaration): void;
visitIdentifier(node: ts.Identifier): void;
visitIfStatement(node: ts.IfStatement): void;
visitImportDeclaration(node: ts.ImportDeclaration): void;
visitIndexSignatureDeclaration(node: ts.IndexSignatureDeclaration): void;
visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void;
visitLabeledStatement(node: ts.LabeledStatement): void;
visitMethodDeclaration(node: ts.MethodDeclaration): void;
visitModuleDeclaration(node: ts.ModuleDeclaration): void;
visitNewExpression(node: ts.NewExpression): void;
visitObjectLiteralExpression(node: ts.ObjectLiteralExpression): void;
visitParameterDeclaration(node: ts.ParameterDeclaration): void;
visitPostfixUnaryExpression(node: ts.PostfixUnaryExpression): void;
visitPrefixUnaryExpression(node: ts.PrefixUnaryExpression): void;
visitPropertyAccessExpression(node: ts.PropertyAccessExpression): void;
visitPropertyAssignment(node: ts.PropertyAssignment): void;
visitPropertyDeclaration(node: ts.PropertyDeclaration): void;
visitRegularExpressionLiteral(node: ts.Node): void;
visitReturnStatement(node: ts.ReturnStatement): void;
visitSetAccessor(node: ts.AccessorDeclaration): void;
visitSourceFile(node: ts.SourceFile): void;
visitSwitchStatement(node: ts.SwitchStatement): void;
visitThrowStatement(node: ts.ThrowStatement): void;
visitTryBlock(node: ts.Block): void;
visitTryStatement(node: ts.TryStatement): void;
visitTypeAssertionExpression(node: ts.TypeAssertion): void;
visitVariableDeclaration(node: ts.VariableDeclaration): void;
visitVariableStatement(node: ts.VariableStatement): void;
visitWhileStatement(node: ts.WhileStatement): void;
walk(node: ts.Node): void;
walkChildren(node: ts.Node): void;
visitNode(node: ts.Node): void;
protected visitAnyKeyword(node: ts.Node): void;
protected visitArrowFunction(node: ts.FunctionLikeDeclaration): void;
protected visitBinaryExpression(node: ts.BinaryExpression): void;
protected visitBlock(node: ts.Block): void;
protected visitBreakStatement(node: ts.BreakOrContinueStatement): void;
protected visitCallExpression(node: ts.CallExpression): void;
protected visitCaseClause(node: ts.CaseClause): void;
protected visitClassDeclaration(node: ts.ClassDeclaration): void;
protected visitCatchClause(node: ts.CatchClause): void;
protected visitConditionalExpression(node: ts.ConditionalExpression): void;
protected visitConstructorDeclaration(node: ts.ConstructorDeclaration): void;
protected visitConstructorType(node: ts.Node): void;
protected visitContinueStatement(node: ts.BreakOrContinueStatement): void;
protected visitDebuggerStatement(node: ts.Statement): void;
protected visitDefaultClause(node: ts.DefaultClause): void;
protected visitDoStatement(node: ts.DoStatement): void;
protected visitElementAccessExpression(node: ts.ElementAccessExpression): void;
protected visitEnumDeclaration(node: ts.EnumDeclaration): void;
protected visitExportAssignment(node: ts.ExportAssignment): void;
protected visitExpressionStatement(node: ts.ExpressionStatement): void;
protected visitForStatement(node: ts.ForStatement): void;
protected visitForInStatement(node: ts.ForInStatement): void;
protected visitFunctionDeclaration(node: ts.FunctionDeclaration): void;
protected visitFunctionExpression(node: ts.FunctionExpression): void;
protected visitFunctionType(node: ts.Node): void;
protected visitGetAccessor(node: ts.AccessorDeclaration): void;
protected visitIdentifier(node: ts.Identifier): void;
protected visitIfStatement(node: ts.IfStatement): void;
protected visitImportDeclaration(node: ts.ImportDeclaration): void;
protected visitIndexSignatureDeclaration(node: ts.IndexSignatureDeclaration): void;
protected visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void;
protected visitLabeledStatement(node: ts.LabeledStatement): void;
protected visitMethodDeclaration(node: ts.MethodDeclaration): void;
protected visitModuleDeclaration(node: ts.ModuleDeclaration): void;
protected visitNewExpression(node: ts.NewExpression): void;
protected visitObjectLiteralExpression(node: ts.ObjectLiteralExpression): void;
protected visitParameterDeclaration(node: ts.ParameterDeclaration): void;
protected visitPostfixUnaryExpression(node: ts.PostfixUnaryExpression): void;
protected visitPrefixUnaryExpression(node: ts.PrefixUnaryExpression): void;
protected visitPropertyAccessExpression(node: ts.PropertyAccessExpression): void;
protected visitPropertyAssignment(node: ts.PropertyAssignment): void;
protected visitPropertyDeclaration(node: ts.PropertyDeclaration): void;
protected visitRegularExpressionLiteral(node: ts.Node): void;
protected visitReturnStatement(node: ts.ReturnStatement): void;
protected visitSetAccessor(node: ts.AccessorDeclaration): void;
protected visitSourceFile(node: ts.SourceFile): void;
protected visitSwitchStatement(node: ts.SwitchStatement): void;
protected visitThrowStatement(node: ts.ThrowStatement): void;
protected visitTryBlock(node: ts.Block): void;
protected visitTryStatement(node: ts.TryStatement): void;
protected visitTypeAssertionExpression(node: ts.TypeAssertion): void;
protected visitVariableDeclaration(node: ts.VariableDeclaration): void;
protected visitVariableStatement(node: ts.VariableStatement): void;
protected visitWhileStatement(node: ts.WhileStatement): void;
protected visitNode(node: ts.Node): void;
private walkChildren(node);
}
}
declare module Lint {
Expand Down Expand Up @@ -191,12 +191,12 @@ declare module Lint {
class ScopeAwareRuleWalker<T> extends RuleWalker {
private scopeStack;
constructor(sourceFile: ts.SourceFile, options?: any);
visitNode(node: ts.Node): void;
createScope(): T;
getCurrentScope(): T;
getCurrentDepth(): number;
onScopeStart(): void;
onScopeEnd(): void;
protected visitNode(node: ts.Node): void;
private isScopeBoundary(node);
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/language/walker/scopeAwareRuleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ module Lint {
this.scopeStack = [this.createScope()];
}

public visitNode(node: ts.Node): void {
var isNewScope = this.isScopeBoundary(node);

if (isNewScope) {
this.scopeStack.push(this.createScope());
}

this.onScopeStart();
super.visitNode(node);
this.onScopeEnd();

if (isNewScope) {
this.scopeStack.pop();
}
}

// create a new scope
public createScope(): T {
throw Lint.abstract();
Expand All @@ -68,6 +52,22 @@ module Lint {
return;
}

protected visitNode(node: ts.Node): void {
var isNewScope = this.isScopeBoundary(node);

if (isNewScope) {
this.scopeStack.push(this.createScope());
}

this.onScopeStart();
super.visitNode(node);
this.onScopeEnd();

if (isNewScope) {
this.scopeStack.pop();
}
}

private isScopeBoundary(node: ts.Node): boolean {
return node.kind === ts.SyntaxKind.FunctionDeclaration
|| node.kind === ts.SyntaxKind.FunctionExpression
Expand Down
Loading

0 comments on commit 9ec89de

Please sign in to comment.