UNPKG

2.2 kBJavaScriptView Raw
1var __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};
7var SyntaxKind = require('./utils/SyntaxKind');
8var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker');
9var Rule = (function (_super) {
10 __extends(Rule, _super);
11 function Rule() {
12 _super.apply(this, arguments);
13 }
14 Rule.prototype.apply = function (sourceFile) {
15 var noDeleteExpression = new NoDeleteExpression(sourceFile, this.getOptions());
16 return this.applyWithWalker(noDeleteExpression);
17 };
18 Rule.FAILURE_STRING = 'Variables should not be deleted: ';
19 return Rule;
20})(Lint.Rules.AbstractRule);
21exports.Rule = Rule;
22var NoDeleteExpression = (function (_super) {
23 __extends(NoDeleteExpression, _super);
24 function NoDeleteExpression() {
25 _super.apply(this, arguments);
26 }
27 NoDeleteExpression.prototype.visitExpressionStatement = function (node) {
28 _super.prototype.visitExpressionStatement.call(this, node);
29 if (node.expression.kind === SyntaxKind.current().DeleteExpression) {
30 var deletedObject = node.expression.getChildren()[1];
31 if (deletedObject.kind === SyntaxKind.current().ElementAccessExpression) {
32 var deletedExpression = deletedObject.expression;
33 if (deletedExpression.kind !== SyntaxKind.current().PropertyAccessExpression) {
34 this.addNoDeleteFailure(deletedObject);
35 }
36 }
37 else if (deletedObject.kind !== SyntaxKind.current().PropertyAccessExpression) {
38 this.addNoDeleteFailure(deletedObject);
39 }
40 }
41 };
42 NoDeleteExpression.prototype.addNoDeleteFailure = function (deletedObject) {
43 var msg = Rule.FAILURE_STRING + deletedObject.getFullText().trim();
44 this.addFailure(this.createFailure(deletedObject.getStart(), deletedObject.getWidth(), msg));
45 };
46 return NoDeleteExpression;
47})(ErrorTolerantWalker);
48//# sourceMappingURL=noDeleteExpressionRule.js.map
\No newline at end of file