"use strict";
/*
 * edge-parser
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const transformAst_1 = require("../Parser/transformAst");
const edge_error_1 = require("edge-error");
exports.default = {
    toStatement(statement, filename, parser) {
        parser.stack.defineScope();
        statement.params.forEach((param) => {
            if (param.type === 'Identifier') {
                parser.stack.defineVariable(param.name);
            }
            else if (param.type === 'ObjectPattern') {
                parser.utils.collectObjectExpressionProperties(param).forEach((prop) => {
                    parser.stack.defineVariable(prop);
                });
            }
            else if (param.type === 'ArrayPattern') {
                parser.utils.collectArrayExpressionProperties(param).forEach((prop) => {
                    parser.stack.defineVariable(prop);
                });
            }
            else {
                const { line, col } = parser.utils.getExpressionLoc(param);
                throw new edge_error_1.EdgeError(`Report this error to the maintainers: Unexpected arrow function property type ${param.type}`, 'E_PARSER_ERROR', {
                    line,
                    col,
                    filename,
                });
            }
        });
        statement.body = (0, transformAst_1.transformAst)(statement.body, filename, parser);
        parser.stack.clearScope();
        return statement;
    },
};
