feat(printer): render `require` statements
This commit is contained in:
parent
e076a08572
commit
4d81aaef56
|
@ -161,7 +161,7 @@ ast.in_order_visitor(module_ast, function(node: Node)
|
|||
module_dependencies.visit(node, module_ast, {
|
||||
modules = {
|
||||
Screen = {
|
||||
name = "screen",
|
||||
name = "Screen",
|
||||
module_path = "awful.screen",
|
||||
token = "module",
|
||||
},
|
||||
|
|
|
@ -28,6 +28,14 @@ local function render_code(code: string, indent_level: integer): string
|
|||
return generated
|
||||
end
|
||||
|
||||
local function render_require(dependencies: { string : string }): string
|
||||
local generated = ""
|
||||
for dependency, path in pairs(dependencies) do
|
||||
generated = generated .. string.format("local %s = require(\"%s\")\n", dependency, path)
|
||||
end
|
||||
return generated:sub(1, -2) -- remove the last newline
|
||||
end
|
||||
|
||||
local record Node_Printer_Function
|
||||
on_node: function(node: Node, indent_level: integer): string, integer
|
||||
before_node: nil | function(node: Node, indent_level: integer): string, integer
|
||||
|
@ -45,9 +53,11 @@ local node_printer <total>: { Node.Token : Node_Printer_Function } = {
|
|||
string.format(
|
||||
[[
|
||||
-- This file was auto-generated.
|
||||
%s
|
||||
|
||||
local record %s
|
||||
]],
|
||||
render_require(node.dependencies),
|
||||
node.name),
|
||||
indent_level), indent_level + 1
|
||||
end,
|
||||
|
|
Loading…
Reference in New Issue