var ComputedParser = /** @class */ (function () {
    function ComputedParser() {
    }
    ComputedParser.prototype.onStart = function (context) {
        this.computed = {};
        this.funcs = {};
    };
    ComputedParser.prototype.parseModule = function (pageId, mod) {
        var computedFuncs = mod.exports.default || mod.exports;
        if (typeof computedFuncs !== 'object') {
            throw new Error('computed must export an object');
        }
        this.computed[pageId] = createComputed(computedFuncs);
        this.funcs[pageId] = computedFuncs;
    };
    ComputedParser.prototype.onEnd = function (context) {
        context.computed = this.computed;
        context.computedFuncs = this.funcs;
    };
    return ComputedParser;
}());
export { ComputedParser };
export function createComputed(computedFuncs, thisArg) {
    var computedObj = {};
    Object.keys(computedFuncs).forEach(function (name) {
        var getter = computedFuncs[name];
        Object.defineProperty(computedObj, name, {
            get: thisArg ? getter.bind(thisArg) : getter,
            enumerable: true,
        });
    });
    return computedObj;
}
//# sourceMappingURL=computedParser.js.map