rxjs-tslint-rules
Version:
TSLint rules for RxJS
66 lines (65 loc) • 2.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScopeWalker = void 0;
var tslib_1 = require("tslib");
var Lint = tslib_1.__importStar(require("tslint"));
var tsutils = tslib_1.__importStar(require("tsutils"));
var knowns_1 = require("./knowns");
var ScopeWalker = (function (_super) {
tslib_1.__extends(ScopeWalker, _super);
function ScopeWalker() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.callbackMap = new Map();
_this.callbackStack = [];
_this.knownNames = {};
return _this;
}
ScopeWalker.prototype.visitArrowFunction = function (node) {
if (this.callbackMap.has(node)) {
this.callbackStack.push(node);
_super.prototype.visitArrowFunction.call(this, node);
this.callbackStack.pop();
}
else {
_super.prototype.visitArrowFunction.call(this, node);
}
};
ScopeWalker.prototype.visitCallExpression = function (node) {
var _this = this;
var args = node.arguments, expression = node.expression;
var name;
if (tsutils.isIdentifier(expression)) {
name = expression.getText();
}
else if (tsutils.isPropertyAccessExpression(expression)) {
var propertyName = expression.name;
name = propertyName.getText();
}
if (name &&
(this.knownNames[name] ||
knowns_1.knownOperators[name] ||
knowns_1.knownPipeableOperators[name])) {
var callbacks = args.filter(function (arg) {
return tsutils.isArrowFunction(arg) || tsutils.isFunctionExpression(arg);
});
callbacks.forEach(function (callback) { return _this.callbackMap.set(callback, name); });
_super.prototype.visitCallExpression.call(this, node);
callbacks.forEach(function (callback) { return _this.callbackMap.delete(callback); });
}
else {
_super.prototype.visitCallExpression.call(this, node);
}
};
ScopeWalker.prototype.visitFunctionExpression = function (node) {
if (this.callbackMap.has(node)) {
this.callbackStack.push(node);
_super.prototype.visitFunctionExpression.call(this, node);
this.callbackStack.pop();
}
else {
_super.prototype.visitFunctionExpression.call(this, node);
}
};
return ScopeWalker;
}(Lint.ProgramAwareRuleWalker));
exports.ScopeWalker = ScopeWalker;