{"size": 2476, "ext": "js", "max_stars_repo_path": "packages/cli/packages/babelPlugins/transformIfFun.js", "max_stars_repo_name": "DavidWong9785/anu", "max_stars_repo_stars_event_min_datetime": "2019-03-30T04:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-21T05:21:55.000Z", "max_issues_repo_path": "packages/cli/packages/babelPlugins/transformIfFun.js", "max_issues_repo_name": "DavidWong9785/anu", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/cli/packages/babelPlugins/transformIfFun.js", "max_forks_repo_name": "DavidWong9785/anu", "max_forks_repo_forks_event_min_datetime": "2020-04-07T03:50:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-06T10:06:59.000Z"}
{"max_stars_count": 40, "max_issues_count": null, "max_forks_count": 11, "avg_line_length": 42.6896551724, "max_line_length": 194, "alphanum_fraction": 0.4644588045}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = __importDefault(require("../../config/config"));
const platforms_1 = __importDefault(require("../../consts/platforms"));
let visitor = {
    ClassMethod: {
        enter(astPath) {
            const node = astPath.node;
            const methodName = node.key.name;
            if (!methodName) {
                return;
            }
            const siblingsNodes = astPath.container;
            const hasCurrentPlatformMethod = siblingsNodes.some(siblingsNode => siblingsNode.type === 'ClassMethod' && siblingsNode.key.name === (methodName + '_' + config_1.default.buildType));
            if (hasCurrentPlatformMethod) {
                astPath.remove();
                return false;
            }
            try {
                for (let i = 0, pLen = platforms_1.default.length; i < pLen; i++) {
                    const platformType = platforms_1.default[i].buildType;
                    if (methodName.endsWith(`_${platformType}`)) {
                        if (platformType === config_1.default.buildType) {
                            const methodNameWithoutSuf = methodName.substr(0, methodName.length - platformType.length - 1);
                            let indexWithoutSuf = -1;
                            for (let j = 0, len = siblingsNodes.length; j < len; j++) {
                                if (siblingsNodes[j].type === 'ClassMethod' && siblingsNodes[j].key.name === methodNameWithoutSuf) {
                                    indexWithoutSuf = j;
                                    break;
                                }
                            }
                            if (indexWithoutSuf != -1) {
                                astPath.getSibling(indexWithoutSuf).remove();
                            }
                            astPath.node.key.name = methodNameWithoutSuf;
                        }
                        else {
                            astPath.remove();
                        }
                        break;
                    }
                }
            }
            catch (error) {
                console.error("transformIfFun-error:", error);
            }
        }
    }
};
module.exports = function () {
    return {
        visitor: visitor
    };
};
