fix(visitor): module_dependencies renames dependency usages
ci/woodpecker/pr/docker-build Pipeline was successful Details
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/build Pipeline was successful Details
ci/woodpecker/pr/test Pipeline was successful Details

This commit is contained in:
Aire-One 2023-07-31 19:02:05 +02:00
parent 160a092896
commit 588296abcd
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