From d025ea470d37eff87b88f088b9f33d62a5a6314c Mon Sep 17 00:00:00 2001 From: Zamiell <5511220+Zamiell@users.noreply.github.com> Date: Thu, 18 Nov 2021 18:49:31 -0500 Subject: [PATCH 1/2] fixing broken printer example --- docs/api/plugins.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/api/plugins.md b/docs/api/plugins.md index fabaa2f7..0fb84853 100644 --- a/docs/api/plugins.md +++ b/docs/api/plugins.md @@ -75,18 +75,31 @@ export default plugin; ### `printer` -Printer is a function that overrides standard implementation of Lua AST printer. It receives some information about the file and transformed Lua AST. See [Printer](printer.md) page for more information. +`printer` is a function that overrides the standard implementation of the Lua AST printer. It receives some information about the file and the transformed Lua AST. See the [LuaPrinter](printer.md) page for more information. Example: ```ts +import * as ts from "typescript"; import * as tstl from "typescript-to-lua"; -class CustomLuaPrinter extends tstl.LuaPrinter {} +const CUSTOM_COMMENT_HEADER = "-- This code was generated with a custom plugin!\n"; + +class CustomLuaPrinter extends tstl.LuaPrinter { + printCustom(file: tstl.File) { + const printResult = this.print(file); + printResult.code = CUSTOM_COMMENT_HEADER + printResult.code; + return printResult; + } +} const plugin: tstl.Plugin = { - printer: (program, emitHost, fileName, block, luaLibFeatures) => - new CustomLuaPrinter(program.getCompilerOptions(), emitHost, fileName).print(block, luaLibFeatures), + printer: ( + program: ts.Program, + emitHost: tstl.EmitHost, + fileName: string, + file: tstl.File, + ) => new CustomLuaPrinter(emitHost, program, fileName).printCustom(file), }; export default plugin; From b4a4429564d6dcbd27ad9dc3977ae03b74900adb Mon Sep 17 00:00:00 2001 From: Zamiell <5511220+Zamiell@users.noreply.github.com> Date: Thu, 18 Nov 2021 18:50:36 -0500 Subject: [PATCH 2/2] prettier --- docs/api/plugins.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/docs/api/plugins.md b/docs/api/plugins.md index 0fb84853..3f1676cf 100644 --- a/docs/api/plugins.md +++ b/docs/api/plugins.md @@ -94,12 +94,8 @@ class CustomLuaPrinter extends tstl.LuaPrinter { } const plugin: tstl.Plugin = { - printer: ( - program: ts.Program, - emitHost: tstl.EmitHost, - fileName: string, - file: tstl.File, - ) => new CustomLuaPrinter(emitHost, program, fileName).printCustom(file), + printer: (program: ts.Program, emitHost: tstl.EmitHost, fileName: string, file: tstl.File) => + new CustomLuaPrinter(emitHost, program, fileName).printCustom(file), }; export default plugin;