"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.createLeafStatementClassifier = createLeafStatementClassifier;
function createLeafStatementClassifier(t) {
    const isLeafStatement = (node) => t.isExpressionStatement(node) ||
        t.isVariableDeclaration(node) ||
        t.isReturnStatement(node) ||
        t.isThrowStatement(node) ||
        t.isBreakStatement(node) ||
        t.isContinueStatement(node) ||
        t.isDebuggerStatement(node);
    const kindOf = (node) => {
        if (t.isExpressionStatement(node))
            return 'expression';
        if (t.isVariableDeclaration(node))
            return 'variable';
        if (t.isReturnStatement(node))
            return 'return';
        if (t.isThrowStatement(node))
            return 'throw';
        if (t.isBreakStatement(node))
            return 'break';
        if (t.isContinueStatement(node))
            return 'continue';
        if (t.isDebuggerStatement(node))
            return 'debugger';
        return node.type;
    };
    const containsAwait = (node) => {
        let found = false;
        const walk = (n) => {
            if (!n || found || typeof n !== 'object')
                return;
            const asNode = n;
            if (t.isAwaitExpression(asNode)) {
                found = true;
                return;
            }
            if (t.isFunction(asNode))
                return;
            for (const key of Object.keys(asNode)) {
                if (key === 'loc' || key === 'type' || key === 'start' || key === 'end')
                    continue;
                const v = asNode[key];
                if (v == null)
                    continue;
                if (Array.isArray(v)) {
                    for (const item of v)
                        if (item && item.type)
                            walk(item);
                }
                else if (v.type) {
                    walk(v);
                }
            }
        };
        walk(node);
        return found;
    };
    return { isLeafStatement, kindOf, containsAwait };
}
