.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / language / walker / scopeAwareRuleWalker.js
1 "use strict";
2 /**
3  * @license
4  * Copyright 2013 Palantir Technologies, Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 Object.defineProperty(exports, "__esModule", { value: true });
19 var tslib_1 = require("tslib");
20 var ts = require("typescript");
21 var utils_1 = require("../utils");
22 var ruleWalker_1 = require("./ruleWalker");
23 /**
24  * @deprecated Prefer to manually maintain any contextual information.
25  *
26  * For example, imagine a `no-break` rule that warns on `break` in `for` but not in `switch`:
27  *
28  * function walk(ctx: Lint.WalkContext): void {
29  *     let isInFor = false;
30  *     ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void {
31  *         switch (node.kind) {
32  *             case ts.SyntaxKind.Break:
33  *                 if (isInFor) {
34  *                     ctx.addFailureAtNode(node, "!");
35  *                 }
36  *                 break;
37  *             case ts.SyntaxKind.ForStatement: {
38  *                 const old = isInFor;
39  *                 isInFor = true;
40  *                 ts.forEachChild(node, cb);
41  *                 isInFor = old;
42  *                 break;
43  *             }
44  *             case ts.SyntaxKind.SwitchStatement: {
45  *                 const old = isInFor;
46  *                 isInFor = false;
47  *                 ts.forEachChild(node, cb);
48  *                 isInFor = old;
49  *                 break;
50  *             }
51  *             default:
52  *                 ts.forEachChild(node, cb);
53  *         }
54  *     });
55  * }
56  */
57 // tslint:disable-next-line deprecation
58 var ScopeAwareRuleWalker = /** @class */ (function (_super) {
59     tslib_1.__extends(ScopeAwareRuleWalker, _super);
60     function ScopeAwareRuleWalker(sourceFile, options) {
61         var _this = _super.call(this, sourceFile, options) || this;
62         // initialize with global scope if file is not a module
63         _this.scopeStack = ts.isExternalModule(sourceFile) ? [] : [_this.createScope(sourceFile)];
64         return _this;
65     }
66     ScopeAwareRuleWalker.prototype.getCurrentScope = function () {
67         return this.scopeStack[this.scopeStack.length - 1];
68     };
69     // get all scopes available at this depth
70     ScopeAwareRuleWalker.prototype.getAllScopes = function () {
71         return this.scopeStack;
72     };
73     ScopeAwareRuleWalker.prototype.getCurrentDepth = function () {
74         return this.scopeStack.length;
75     };
76     // callback notifier when a scope begins
77     ScopeAwareRuleWalker.prototype.onScopeStart = function () {
78         return;
79     };
80     // callback notifier when a scope ends
81     ScopeAwareRuleWalker.prototype.onScopeEnd = function () {
82         return;
83     };
84     ScopeAwareRuleWalker.prototype.visitNode = function (node) {
85         var isNewScope = this.isScopeBoundary(node);
86         if (isNewScope) {
87             this.scopeStack.push(this.createScope(node));
88             this.onScopeStart();
89         }
90         _super.prototype.visitNode.call(this, node);
91         if (isNewScope) {
92             this.onScopeEnd();
93             this.scopeStack.pop();
94         }
95     };
96     ScopeAwareRuleWalker.prototype.isScopeBoundary = function (node) {
97         return utils_1.isScopeBoundary(node); // tslint:disable-line:deprecation
98     };
99     return ScopeAwareRuleWalker;
100 }(ruleWalker_1.RuleWalker));
101 exports.ScopeAwareRuleWalker = ScopeAwareRuleWalker;