export function json2map(json) {
    const res = new Map();
    for (const key in json) {
        const value = json[key];
        if (value === undefined) {
            throw new Error(`json parse failed: ${JSON.stringify(json)}`);
        }
        res.set(key, value);
    }
    return res;
}
/**
 * return if the functionName is in fileName.
 * @param fileName example: "assembly/assertCollector.ts"
 * @param functionName example:
 *    "start:assembly/assertCollector~anonymous|0"
 *    || "assemblly/assertCollector/addDescription"
 */
export function checkFunctionName(fileName, functionName) {
    const regex = new RegExp(`^(start:)?${fileName.slice(0, -3)}[/~]`);
    return regex.test(functionName);
}
export function isIncluded(r1, r2) {
    /**
     * range :[startLine, endLine]
     * determine if function r1 is included in function r2 by line range
     * r1 means function line range info from instrumenting
     * r2 means function line range info from transform
     */
    return r1[0] >= r2[0] && r1[1] <= r2[1];
}
export function checkGenerics(functionName) {
    const startIndex = functionName.indexOf("<");
    const endIndex = functionName.lastIndexOf(">");
    if (startIndex !== -1 && endIndex !== -1) {
        return functionName.slice(0, startIndex) + functionName.slice(endIndex + 1);
    }
    return undefined;
}
export function supplyDefaultFunction(infos, importObject) {
    for (const info of infos) {
        const module = info.module;
        const name = info.name;
        if (importObject[module]?.[name] === undefined) {
            if (importObject[module] === undefined) {
                importObject[module] = {};
            }
            // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
            importObject[module][name] = (..._args) => {
                return info.return?.kind === -2 /* TypeKind.i64 */ ? BigInt(0) : 0;
            };
        }
    }
}
//# sourceMappingURL=index.js.map