Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Introduce AbstractWalker for performance #2093

Merged
merged 9 commits into from
Feb 3, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove languageService property for now
ajafff committed Jan 25, 2017

Verified

This commit was signed with the committer’s verified signature.
clementguillot Clément Guillot
commit 0d7ae811427daeaf379ec30341fd97b6169e75ce
12 changes: 3 additions & 9 deletions src/language/rule/abstractRule.ts
Original file line number Diff line number Diff line change
@@ -65,15 +65,9 @@ export abstract class AbstractRule implements IRule {
}

protected applyWithFunction(sourceFile: ts.SourceFile, walkFn: (ctx: WalkContext<void>) => void): RuleFailure[];
protected applyWithFunction<T>(sourceFile: ts.SourceFile,
walkFn: (ctx: WalkContext<T>) => void,
options: T,
languageService?: ts.LanguageService): RuleFailure[];
protected applyWithFunction<T>(sourceFile: ts.SourceFile,
walkFn: (ctx: WalkContext<T | void>) => void,
options?: T,
languageService?: ts.LanguageService): RuleFailure[] {
const ctx = new WalkContext<T | void>(sourceFile, this.ruleName, options, languageService);
protected applyWithFunction<T>(sourceFile: ts.SourceFile, walkFn: (ctx: WalkContext<T>) => void, options: T): RuleFailure[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I don't think the generic option helps all that much since it's not constrained and only used by the user

protected applyWithFunction<T>(sourceFile: ts.SourceFile, walkFn: (ctx: WalkContext<T | void>) => void, options?: T): RuleFailure[] {
const ctx = new WalkContext(sourceFile, this.ruleName, options);
walkFn(ctx);
return this.filterFailures(ctx.failures);
}
7 changes: 2 additions & 5 deletions src/language/rule/rule.ts
Original file line number Diff line number Diff line change
@@ -283,12 +283,9 @@ export class WalkContext<T> {
public readonly failures: RuleFailure[];
private limit: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to sourceLastIndex or similar


constructor(public readonly sourceFile: ts.SourceFile,
public readonly ruleName: string,
public readonly options: T,
public readonly languageService?: ts.LanguageService) {
constructor(public readonly sourceFile: ts.SourceFile, public readonly ruleName: string, public readonly options: T) {
this.failures = [];
this.limit = sourceFile.getFullWidth();
this.limit = sourceFile.end;
}

/** Add a failure with any arbitrary span. Prefer `addFailureAtNode` if possible. */