"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ts = require("typescript");
var added_walker_1 = require("./added-walker");
var knowns_1 = require("./knowns");
var util_1 = require("./util");
var UsedWalker = (function (_super) {
    tslib_1.__extends(UsedWalker, _super);
    function UsedWalker() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.usedObservables = {};
        _this.usedOperators = {};
        _this.usedPrototypeMethods = {};
        _this.usedStaticMethods = {};
        return _this;
    }
    UsedWalker.prototype.visitCallExpression = function (node) {
        var _this = this;
        node.forEachChild(function (child) {
            if (child.kind === ts.SyntaxKind.PropertyAccessExpression) {
                var propertyAccessExpression = child;
                var name_1 = propertyAccessExpression.name.getText();
                var typeChecker = _this.getTypeChecker();
                var type = typeChecker.getTypeAtLocation(propertyAccessExpression.expression);
                if (util_1.isReferenceType(type)) {
                    if (knowns_1.knownOperators.hasOwnProperty(name_1) && util_1.couldBeType(type.target, "Observable")) {
                        UsedWalker.add(_this.usedOperators, name_1, propertyAccessExpression.name);
                    }
                    else if (knowns_1.knownPrototypeMethods.hasOwnProperty(name_1) && util_1.couldBeType(type.target, "Observable")) {
                        UsedWalker.add(_this.usedPrototypeMethods, name_1, propertyAccessExpression.name);
                    }
                }
                else {
                    if (knowns_1.knownObservables.hasOwnProperty(name_1) && util_1.couldBeType(type, "Observable")) {
                        UsedWalker.add(_this.usedObservables, name_1, propertyAccessExpression.name);
                    }
                    else if (knowns_1.knownStaticMethods.hasOwnProperty(name_1) && util_1.couldBeType(type, "Observable")) {
                        UsedWalker.add(_this.usedStaticMethods, name_1, propertyAccessExpression.name);
                    }
                }
            }
        });
        _super.prototype.visitCallExpression.call(this, node);
    };
    return UsedWalker;
}(added_walker_1.AddedWalker));
exports.UsedWalker = UsedWalker;
