1 | var __extends = (this && this.__extends) || function (d, b) {
|
2 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
3 | function __() { this.constructor = d; }
|
4 | __.prototype = b.prototype;
|
5 | d.prototype = new __();
|
6 | };
|
7 | var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker');
|
8 | var SyntaxKind = require('./utils/SyntaxKind');
|
9 | var Rule = (function (_super) {
|
10 | __extends(Rule, _super);
|
11 | function Rule() {
|
12 | _super.apply(this, arguments);
|
13 | }
|
14 | Rule.prototype.apply = function (sourceFile) {
|
15 | return this.applyWithWalker(new NoInvalidRegexpRuleWalker(sourceFile, this.getOptions()));
|
16 | };
|
17 | return Rule;
|
18 | })(Lint.Rules.AbstractRule);
|
19 | exports.Rule = Rule;
|
20 | var NoInvalidRegexpRuleWalker = (function (_super) {
|
21 | __extends(NoInvalidRegexpRuleWalker, _super);
|
22 | function NoInvalidRegexpRuleWalker() {
|
23 | _super.apply(this, arguments);
|
24 | }
|
25 | NoInvalidRegexpRuleWalker.prototype.visitNewExpression = function (node) {
|
26 | this.validateCall(node);
|
27 | _super.prototype.visitNewExpression.call(this, node);
|
28 | };
|
29 | NoInvalidRegexpRuleWalker.prototype.visitCallExpression = function (node) {
|
30 | this.validateCall(node);
|
31 | _super.prototype.visitCallExpression.call(this, node);
|
32 | };
|
33 | NoInvalidRegexpRuleWalker.prototype.validateCall = function (expression) {
|
34 | if (expression.expression.getText() === 'RegExp') {
|
35 | if (expression.arguments.length > 0) {
|
36 | var arg1 = expression.arguments[0];
|
37 | if (arg1.kind === SyntaxKind.current().StringLiteral) {
|
38 | var regexpText = arg1.text;
|
39 | try {
|
40 | var regex = new RegExp(regexpText);
|
41 | }
|
42 | catch (e) {
|
43 | this.addFailure(this.createFailure(arg1.getStart(), arg1.getWidth(), e.message));
|
44 | }
|
45 | }
|
46 | }
|
47 | }
|
48 | };
|
49 | return NoInvalidRegexpRuleWalker;
|
50 | })(ErrorTolerantWalker);
|
51 |
|
\ | No newline at end of file |