fix(visitor): module_dependencies renames dependency usages

This commit is contained in:
Aire-One 2023-07-31 19:02:05 +02:00
parent 4f24725351
commit 6441a6a50b
1 changed files with 31 additions and 2 deletions

View File

@ -18,16 +18,45 @@ local function get_all_types_in_node(node: Node): { string }
parameters_types or {})
end
local function replace_in_node_type(node: Node, old_type: string, new_type: string)
if node.parameters then
for _, v in ipairs(node.parameters) do
for i, t in ipairs(v.types) do
if t == old_type then
v.types[i] = new_type
end
end
end
end
if node.types then
for i, t in ipairs(node.types) do
if t == old_type then
node.types[i] = new_type
end
end
end
if node.return_types then
for i, t in ipairs(node.return_types) do
if t == old_type then
node.return_types[i] = new_type
end
end
end
end
local record Module_Dependencies
visit: function(node: Node, mod: Node, d: Dag)
end
function Module_Dependencies.visit(node: Node, mod: Node, d: Dag)
local all_types <const> = get_all_types_in_node(node)
for _, v in ipairs(all_types) do
local dependency = d.modules[v]
for _, type_name in ipairs(all_types) do
local dependency = d.modules[type_name] or d.modules[utils.lowercase(type_name)]
if dependency then
mod.dependencies[dependency.name] = dependency.module_path
replace_in_node_type(node, dependency.module_path, dependency.name)
end
end
end