"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.queryDependsMap = exports.queryDepends = void 0;
var core_1 = require("@babel/core");
var utils_1 = require("./utils");
require("@babel/preset-typescript");
var readFileAst = function (code, filename) {
    var ast = (0, core_1.parseSync)(code, {
        filename: filename,
        presets: [
            '@babel/preset-typescript'
        ]
    });
    if (!ast) {
        throw new Error("Unknown error: AST is null");
    }
    return ast;
};
var queryRelations = function (code, file) {
    var depends = [];
    var ast = readFileAst(code, file);
    (0, core_1.traverse)(ast, {
        ImportDeclaration: function (path) {
            var node = path.node;
            depends.push(node.source.value);
        },
        CallExpression: function (path) {
            var node = path.node;
            if (core_1.types.isIdentifier(node.callee)
                && ['require', 'import'].includes(node.callee.name)
                && node.arguments.length > 0
                && core_1.types.isStringLiteral(node.arguments[0])) {
                depends.push(node.arguments[0].value);
            }
        }
    });
    return depends;
};
exports.queryDepends = (0, utils_1.createQueryDepends)(queryRelations);
exports.queryDependsMap = (0, utils_1.createQueryDependsMap)(queryRelations);
