"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NormalModuleParser = void 0;
const common_1 = require("../../../utils/common");
const base_1 = require("./base");
class NormalModuleParser {
    onStart(context) {
        this.common = {};
    }
    parseModule(pageId, mod) {
        var _a, _b, _c;
        if (mod.name === '____index____')
            return;
        const targetModule = mod.exports;
        const defaultModule = (0, base_1.getDefaultModule)(targetModule);
        if (targetModule) {
            const keys = Object.keys(targetModule);
            if (keys.length === 1 && keys[0] === 'default') {
                // return targetModule.default;
            }
            else {
                try {
                    const tag = `resource.common`;
                    if (targetModule.default) {
                        (0, common_1.reportEvent)(`${tag}.bothexport`);
                        switch (typeof targetModule.default) {
                            case 'object': {
                                if (targetModule.default === null) {
                                    (0, common_1.reportEvent)(`${tag}.unmergeable`);
                                }
                                else {
                                    for (const key of keys) {
                                        if (((_a = targetModule.default) === null || _a === void 0 ? void 0 : _a[key]) && ((_b = targetModule.default) === null || _b === void 0 ? void 0 : _b[key]) !== targetModule[key]) {
                                            (0, common_1.reportEvent)(`${tag}.mergeconflict`);
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                            case 'function': {
                                break;
                            }
                            default: {
                                (0, common_1.reportEvent)(`${tag}.unmergeable`);
                            }
                        }
                    }
                    else {
                        (0, common_1.reportEvent)(`${tag}.nondefault`);
                        // console.warn(
                        //   '@deprecated: common module 中非 default 导出的内容(如 export function exportFunction(){})未来将无法通过 $app.common.xxx.exportFunction的方式访问，请将需要访问的内容通过 export default 进行导出。',
                        // );
                    }
                }
                catch (e) { }
            }
        }
        const [, , folder] = (_c = mod.path) === null || _c === void 0 ? void 0 : _c.split('/');
        if (folder) {
            this.common[pageId] = this.common[pageId] || {};
            this.common[pageId][folder] = defaultModule;
        }
        else {
            this.common[pageId] = defaultModule;
        }
    }
    onEnd(context) {
        context.common = this.common;
    }
}
exports.NormalModuleParser = NormalModuleParser;
//# sourceMappingURL=normalModuleParser.js.map