feat(printer): render `require` statements
This commit is contained in:
parent
03d6cf1ce0
commit
8a83146f41
|
@ -161,7 +161,7 @@ ast.in_order_visitor(module_ast, function(node: Node)
|
||||||
module_dependencies.visit(node, module_ast, {
|
module_dependencies.visit(node, module_ast, {
|
||||||
modules = {
|
modules = {
|
||||||
Screen = {
|
Screen = {
|
||||||
name = "screen",
|
name = "Screen",
|
||||||
module_path = "awful.screen",
|
module_path = "awful.screen",
|
||||||
token = "module",
|
token = "module",
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,6 +28,14 @@ local function render_code(code: string, indent_level: integer): string
|
||||||
return generated
|
return generated
|
||||||
end
|
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
|
local record Node_Printer_Function
|
||||||
on_node: function(node: Node, indent_level: integer): string, integer
|
on_node: function(node: Node, indent_level: integer): string, integer
|
||||||
before_node: nil | 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(
|
string.format(
|
||||||
[[
|
[[
|
||||||
-- This file was auto-generated.
|
-- This file was auto-generated.
|
||||||
|
%s
|
||||||
|
|
||||||
local record %s
|
local record %s
|
||||||
]],
|
]],
|
||||||
|
render_require(node.dependencies),
|
||||||
node.name),
|
node.name),
|
||||||
indent_level), indent_level + 1
|
indent_level), indent_level + 1
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue