var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "./Reporter", "istanbul-lib-coverage", "istanbul-lib-report", "istanbul-reports"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Reporter_1 = require("./Reporter");
    var istanbul_lib_coverage_1 = require("istanbul-lib-coverage");
    var istanbul_lib_report_1 = require("istanbul-lib-report");
    var istanbul_reports_1 = require("istanbul-reports");
    var eventHandler = Reporter_1.createEventHandler();
    var Coverage = (function (_super) {
        __extends(Coverage, _super);
        function Coverage(executor, options) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, executor, options) || this;
            _this.reportType = 'text';
            if (options.filename) {
                _this.filename = options.filename;
            }
            if (options.watermarks) {
                _this.watermarks = options.watermarks;
            }
            return _this;
        }
        Coverage.prototype.createCoverageReport = function (type, data) {
            var map;
            if (isCoverageMap(data)) {
                map = data;
            }
            else {
                map = istanbul_lib_coverage_1.createCoverageMap(data);
            }
            var transformed = this.executor.sourceMapStore.transformCoverage(map).map;
            var context = istanbul_lib_report_1.createContext();
            var tree = istanbul_lib_report_1.summarizers.pkg(transformed);
            tree.visit(istanbul_reports_1.create(type, {
                file: this.filename,
                watermarks: this.watermarks
            }), context);
        };
        Coverage.prototype.runEnd = function () {
            this.createCoverageReport(this.reportType, this.executor.coverageMap);
        };
        __decorate([
            eventHandler()
        ], Coverage.prototype, "runEnd", null);
        return Coverage;
    }(Reporter_1.default));
    exports.default = Coverage;
    function isCoverageMap(value) {
        return value != null && typeof value.files === 'function';
    }
});
//# sourceMappingURL=Coverage.js.map