fix(visitor): module_dependencies renames dependency usages
This commit is contained in:
parent
160a092896
commit
588296abcd
|
@ -18,16 +18,45 @@ local function get_all_types_in_node(node: Node): { string }
|
||||||
parameters_types or {})
|
parameters_types or {})
|
||||||
end
|
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
|
local record Module_Dependencies
|
||||||
visit: function(node: Node, mod: Node, d: Dag)
|
visit: function(node: Node, mod: Node, d: Dag)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Module_Dependencies.visit(node: Node, mod: Node, d: Dag)
|
function Module_Dependencies.visit(node: Node, mod: Node, d: Dag)
|
||||||
local all_types <const> = get_all_types_in_node(node)
|
local all_types <const> = get_all_types_in_node(node)
|
||||||
for _, v in ipairs(all_types) do
|
for _, type_name in ipairs(all_types) do
|
||||||
local dependency = d.modules[v]
|
local dependency = d.modules[type_name] or d.modules[utils.lowercase(type_name)]
|
||||||
if dependency then
|
if dependency then
|
||||||
mod.dependencies[dependency.name] = dependency.module_path
|
mod.dependencies[dependency.name] = dependency.module_path
|
||||||
|
replace_in_node_type(node, dependency.module_path, dependency.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue