/**
 * Shared helpers for yield-lowering-pass tests.
 */
import { describe, it } from "mocha";
import { expect } from "chai";
import { runYieldLoweringPass } from "../yield-lowering-pass.js";
export { describe, it, expect, runYieldLoweringPass };
/**
 * Assert value is not null/undefined and return it typed as non-null.
 */
export const assertDefined = (value, msg) => {
    if (value === null || value === undefined) {
        throw new Error(msg ?? "Expected value to be defined");
    }
    return value;
};
/**
 * Helper to create a minimal generator function module
 */
export const createGeneratorModule = (body, options = {}) => ({
    kind: "module",
    filePath: "/src/test.ts",
    namespace: "Test",
    className: "test",
    isStaticContainer: true,
    imports: [],
    body: [
        {
            kind: "functionDeclaration",
            name: "testGen",
            parameters: [],
            returnType: options.returnType ?? {
                kind: "referenceType",
                name: "Generator",
                typeArguments: [
                    { kind: "primitiveType", name: "number" },
                    { kind: "voidType" },
                    { kind: "primitiveType", name: "number" },
                ],
            },
            body: { kind: "blockStatement", statements: body },
            isAsync: false,
            isGenerator: options.isGenerator ?? true,
            isExported: true,
        },
    ],
    exports: [],
});
/**
 * Helper to create a yield expression
 */
export const createYield = (value, delegate = false) => ({
    kind: "yield",
    expression: value,
    delegate,
});
/**
 * Helper to extract the function body from a module
 */
export const getGeneratorBody = (module) => {
    const func = module.body[0];
    if (func?.kind === "functionDeclaration") {
        return func.body.statements;
    }
    return [];
};
export const getTempNameFromSingleDeclarator = (stmt) => {
    expect(stmt.kind).to.equal("variableDeclaration");
    const decl = stmt
        .declarations[0];
    expect(decl?.name.kind).to.equal("identifierPattern");
    return (decl?.name ?? {
        name: "",
    }).name;
};
//# sourceMappingURL=helpers.js.map