export class ComputedParser {
    onStart(context) {
        this.computed = {};
        this.funcs = {};
    }
    parseModule(pageId, mod) {
        const 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;
    }
    onEnd(context) {
        context.computed = this.computed;
        context.computedFuncs = this.funcs;
    }
}
export function createComputed(computedFuncs, thisArg) {
    const computedObj = {};
    Object.keys(computedFuncs).forEach((name) => {
        const getter = computedFuncs[name];
        Object.defineProperty(computedObj, name, {
            get: thisArg ? getter.bind(thisArg) : getter,
            enumerable: true,
        });
    });
    return computedObj;
}
