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 Rule = (function (_super) {
|
9 | __extends(Rule, _super);
|
10 | function Rule() {
|
11 | _super.apply(this, arguments);
|
12 | }
|
13 | Rule.prototype.apply = function (sourceFile) {
|
14 | return this.applyWithWalker(new NoFunctionExpressionRuleWalker(sourceFile, this.getOptions()));
|
15 | };
|
16 | Rule.FAILURE_STRING = 'Use arrow function instead of function expression';
|
17 | return Rule;
|
18 | })(Lint.Rules.AbstractRule);
|
19 | exports.Rule = Rule;
|
20 | var NoFunctionExpressionRuleWalker = (function (_super) {
|
21 | __extends(NoFunctionExpressionRuleWalker, _super);
|
22 | function NoFunctionExpressionRuleWalker() {
|
23 | _super.apply(this, arguments);
|
24 | }
|
25 | NoFunctionExpressionRuleWalker.prototype.visitFunctionExpression = function (node) {
|
26 | var walker = new SingleFunctionWalker(this.getSourceFile(), this.getOptions());
|
27 | node.getChildren().forEach(function (node) {
|
28 | walker.walk(node);
|
29 | });
|
30 | if (!walker.isAccessingThis) {
|
31 | this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
|
32 | }
|
33 | _super.prototype.visitFunctionExpression.call(this, node);
|
34 | };
|
35 | return NoFunctionExpressionRuleWalker;
|
36 | })(ErrorTolerantWalker);
|
37 | var SingleFunctionWalker = (function (_super) {
|
38 | __extends(SingleFunctionWalker, _super);
|
39 | function SingleFunctionWalker() {
|
40 | _super.apply(this, arguments);
|
41 | this.isAccessingThis = false;
|
42 | }
|
43 | SingleFunctionWalker.prototype.visitNode = function (node) {
|
44 | if (node.getText() === 'this') {
|
45 | this.isAccessingThis = true;
|
46 | }
|
47 | _super.prototype.visitNode.call(this, node);
|
48 | };
|
49 | SingleFunctionWalker.prototype.visitFunctionExpression = function (node) {
|
50 | };
|
51 | SingleFunctionWalker.prototype.visitArrowFunction = function (node) {
|
52 | };
|
53 | return SingleFunctionWalker;
|
54 | })(ErrorTolerantWalker);
|
55 |
|
\ | No newline at end of file |