feat(visitors): implement remove_duplicate_fields
ci/woodpecker/pr/docker-build/1 Pipeline was successful
Details
ci/woodpecker/pr/docker-build/3 Pipeline was successful
Details
ci/woodpecker/pr/docker-build/2 Pipeline was successful
Details
ci/woodpecker/pr/docker-build/4 Pipeline was successful
Details
ci/woodpecker/pr/build-and-run Pipeline is running
Details
ci/woodpecker/pr/lint Pipeline failed
Details
ci/woodpecker/pr/test Pipeline failed
Details
ci/woodpecker/pr/docker-build/1 Pipeline was successful
Details
ci/woodpecker/pr/docker-build/3 Pipeline was successful
Details
ci/woodpecker/pr/docker-build/2 Pipeline was successful
Details
ci/woodpecker/pr/docker-build/4 Pipeline was successful
Details
ci/woodpecker/pr/build-and-run Pipeline is running
Details
ci/woodpecker/pr/lint Pipeline failed
Details
ci/woodpecker/pr/test Pipeline failed
Details
This commit is contained in:
parent
8cfb6f887e
commit
35c904c16d
|
@ -15,6 +15,7 @@ local module_descendants <const> = require("awesomewmdtl.visitors.module_descend
|
|||
local type Node = require("awesomewmdtl.types.Node")
|
||||
local node_fixer <const> = require("awesomewmdtl.visitors.node_fixer")
|
||||
local property <const> = require("awesomewmdtl.property")
|
||||
local remove_duplicate_fields <const> = require("awesomewmdtl.visitors.remove_duplicate_fields")
|
||||
local scraper <const> = require("awesomewmdtl.scraper")
|
||||
local type_mapping <const> = require("awesomewmdtl.visitors.type_mapping")
|
||||
local utils <const> = require("awesomewmdtl.utils")
|
||||
|
@ -111,6 +112,9 @@ for _,root in dag.iter_global_nodes(module_dag) do
|
|||
end
|
||||
|
||||
for root in dag.iter_modules(module_dag) do
|
||||
ast.in_order_visitor(root, function(node: Node)
|
||||
remove_duplicate_fields.visit(node)
|
||||
end)
|
||||
ast.in_order_visitor(root, function(node: Node)
|
||||
node_fixer.visit(node, root)
|
||||
end)
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
local type Node = require("awesomewmdtl.types.Node")
|
||||
local utils <const> = require("awesomewmdtl.utils")
|
||||
|
||||
local has_item <const> = utils.has_item
|
||||
|
||||
-- This is quick hack to remove duplicate fields from a module
|
||||
-- We can have duplicated fields in a module, because we currently
|
||||
-- don't make difference between module record and instance record.
|
||||
-- So static module fields and instance level fields are mixed together.
|
||||
|
||||
local record Remove_Duplicate_Fields
|
||||
visit: function(node: Node)
|
||||
end
|
||||
|
||||
function Remove_Duplicate_Fields.visit(node: Node)
|
||||
if node.token ~= "module" then
|
||||
return
|
||||
end
|
||||
|
||||
local fields: { string } = {}
|
||||
|
||||
for i, n in ipairs(node.children) do
|
||||
if has_item(fields, n.name) then
|
||||
table.remove(node.children, i)
|
||||
else
|
||||
table.insert(fields, n.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Remove_Duplicate_Fields
|
Loading…
Reference in New Issue