1 | import * as ts from 'typescript';
|
2 | import * as Lint from 'tslint';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export class ErrorTolerantWalker extends Lint.RuleWalker {
|
9 | public static DEBUG: boolean = false;
|
10 |
|
11 | protected visitNode(node: ts.Node): void {
|
12 | try {
|
13 | super.visitNode(node);
|
14 | } catch (error) {
|
15 |
|
16 | if (ErrorTolerantWalker.DEBUG) {
|
17 | const msg: string =
|
18 | 'An error occurred visiting a node.' +
|
19 | '\nWalker: ' +
|
20 | this.getClassName() +
|
21 | '\nNode: ' +
|
22 | (node.getFullText ? node.getFullText() : '<unknown>') +
|
23 | '\n' +
|
24 | error;
|
25 |
|
26 | this.addFailureAt(node.getStart ? node.getStart() : 0, node.getWidth ? node.getWidth() : 0, msg);
|
27 | }
|
28 | }
|
29 | }
|
30 |
|
31 | private getClassName(): string {
|
32 |
|
33 |
|
34 | const result: string = this.constructor.toString().match(/function\s+([\w\$]+)\s*\(/)[1] || '';
|
35 | if (result == null || result.length === 0) {
|
36 | throw new Error('Could not determine class name from input: ' + this.constructor.toString());
|
37 | }
|
38 | return result;
|
39 | }
|
40 | }
|