import { getFunctionExpressionBody } from "../util.js";
export function toValueFunction(expression) {
    // Get the function code - preserve exact formatting for consistency with tests
    let functionCode;
    if (expression.isArrowFunctionExpression()) {
        // Arrow functions: use toString() which preserves spacing
        functionCode = expression.toString();
    }
    else {
        // Function expressions: check if they use 'this' or are named
        const usesThis = expression.toString().includes("this.");
        const isNamed = expression.node.type === "FunctionExpression" &&
            expression.node.id !== null;
        if (!usesThis && !isNamed) {
            // Only convert anonymous functions that don't use 'this' to arrow function format
            const body = getFunctionExpressionBody(expression);
            functionCode = `() => { ${body} }`;
        }
        else {
            // Keep function format but ensure consistent spacing
            const originalCode = expression.toString();
            // Normalize spacing to match test expectations
            functionCode = originalCode
                .replace(/function\s*\(\s*\)/g, "function()")
                .replace(/\{\s+/g, "{ ")
                .replace(/\s+\}/g, " }")
                .replace(/;\s+/g, "; ");
        }
    }
    // Return the function code directly
    return functionCode;
}
//# sourceMappingURL=to-value-function.js.map