UNPKG

1.74 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 ErrorTolerantWalker = require('./utils/ErrorTolerantWalker');
8var SyntaxKind = require('./utils/SyntaxKind');
9var Utils = require('./utils/Utils');
10var Rule = (function (_super) {
11 __extends(Rule, _super);
12 function Rule() {
13 _super.apply(this, arguments);
14 }
15 Rule.prototype.apply = function (sourceFile) {
16 return this.applyWithWalker(new NoSparseArraysRuleWalker(sourceFile, this.getOptions()));
17 };
18 Rule.FAILURE_STRING = 'Unexpected comma in middle of array';
19 return Rule;
20})(Lint.Rules.AbstractRule);
21exports.Rule = Rule;
22var NoSparseArraysRuleWalker = (function (_super) {
23 __extends(NoSparseArraysRuleWalker, _super);
24 function NoSparseArraysRuleWalker() {
25 _super.apply(this, arguments);
26 }
27 NoSparseArraysRuleWalker.prototype.visitNode = function (node) {
28 if (node.kind === SyntaxKind.current().ArrayLiteralExpression) {
29 if (this.isSparseArray(node)) {
30 this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
31 }
32 }
33 _super.prototype.visitNode.call(this, node);
34 };
35 NoSparseArraysRuleWalker.prototype.isSparseArray = function (node) {
36 return Utils.exists(node.elements, function (element) {
37 return element.kind === SyntaxKind.current().OmittedExpression;
38 });
39 };
40 return NoSparseArraysRuleWalker;
41})(ErrorTolerantWalker);
42//# sourceMappingURL=noSparseArraysRule.js.map
\No newline at end of file