"use strict";
/**
 * Copyright: (c) Myia SAS 2026.
 * This file and its contents are licensed under the AGPLv3 License.
 * Please see the LICENSE file at the root of this repository
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createVariableDeclarationHoister = createVariableDeclarationHoister;
function createVariableDeclarationHoister(t) {
    return function hoistVariableDeclaration(declaration) {
        const bindingNames = new Set();
        for (const d of declaration.declarations) {
            Object.keys(t.getBindingIdentifiers(d.id)).forEach((n) => bindingNames.add(n));
        }
        const hoistDecl = t.variableDeclaration('let', [...bindingNames].map((n) => t.variableDeclarator(t.identifier(n))));
        hoistDecl._traced = true;
        const assignments = declaration.declarations
            .filter((d) => d.init != null)
            .map((d) => {
            const stmt = t.expressionStatement(t.assignmentExpression('=', d.id, d.init));
            stmt._traced = true;
            return stmt;
        });
        const varsObject = t.objectExpression([...bindingNames].map((n) => t.objectProperty(t.identifier(n), t.identifier(n), false, true)));
        return { bindingNames, hoistDecl, assignments, varsObject };
    };
}
