1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | exports.BlockScopeAwareRuleWalker = void 0;
|
20 | var tslib_1 = require("tslib");
|
21 | var ts = require("typescript");
|
22 | var utils_1 = require("../utils");
|
23 | var scopeAwareRuleWalker_1 = require("./scopeAwareRuleWalker");
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var BlockScopeAwareRuleWalker = (function (_super) {
|
32 | tslib_1.__extends(BlockScopeAwareRuleWalker, _super);
|
33 | function BlockScopeAwareRuleWalker(sourceFile, options) {
|
34 | var _this = _super.call(this, sourceFile, options) || this;
|
35 |
|
36 | _this.blockScopeStack = ts.isExternalModule(sourceFile)
|
37 | ? []
|
38 | : [_this.createBlockScope(sourceFile)];
|
39 | return _this;
|
40 | }
|
41 |
|
42 | BlockScopeAwareRuleWalker.prototype.getAllBlockScopes = function () {
|
43 | return this.blockScopeStack;
|
44 | };
|
45 | BlockScopeAwareRuleWalker.prototype.getCurrentBlockScope = function () {
|
46 | return this.blockScopeStack[this.blockScopeStack.length - 1];
|
47 | };
|
48 | BlockScopeAwareRuleWalker.prototype.getCurrentBlockDepth = function () {
|
49 | return this.blockScopeStack.length;
|
50 | };
|
51 |
|
52 | BlockScopeAwareRuleWalker.prototype.onBlockScopeStart = function () {
|
53 | return;
|
54 | };
|
55 |
|
56 | BlockScopeAwareRuleWalker.prototype.onBlockScopeEnd = function () {
|
57 | return;
|
58 | };
|
59 | BlockScopeAwareRuleWalker.prototype.findBlockScope = function (predicate) {
|
60 |
|
61 | for (var i = this.blockScopeStack.length - 1; i >= 0; i--) {
|
62 | if (predicate(this.blockScopeStack[i])) {
|
63 | return this.blockScopeStack[i];
|
64 | }
|
65 | }
|
66 | return undefined;
|
67 | };
|
68 | BlockScopeAwareRuleWalker.prototype.visitNode = function (node) {
|
69 | var isNewBlockScope = this.isBlockScopeBoundary(node);
|
70 | if (isNewBlockScope) {
|
71 | this.blockScopeStack.push(this.createBlockScope(node));
|
72 | this.onBlockScopeStart();
|
73 | }
|
74 | _super.prototype.visitNode.call(this, node);
|
75 | if (isNewBlockScope) {
|
76 | this.onBlockScopeEnd();
|
77 | this.blockScopeStack.pop();
|
78 | }
|
79 | };
|
80 | BlockScopeAwareRuleWalker.prototype.isBlockScopeBoundary = function (node) {
|
81 | return utils_1.isBlockScopeBoundary(node);
|
82 | };
|
83 | return BlockScopeAwareRuleWalker;
|
84 | }(scopeAwareRuleWalker_1.ScopeAwareRuleWalker));
|
85 | exports.BlockScopeAwareRuleWalker = BlockScopeAwareRuleWalker;
|