@@ -80,22 +80,30 @@ export default plugin;
8080Example:
8181
8282``` ts
83+ import { SourceNode } from " source-map" ;
8384import * as ts from " typescript" ;
8485import * as tstl from " typescript-to-lua" ;
8586
8687const CUSTOM_COMMENT_HEADER = " -- This code was generated with a custom plugin!\n " ;
8788
88- class CustomLuaPrinter extends tstl .LuaPrinter {
89- printCustom(file : tstl .File ) {
90- const printResult = this .print (file );
91- printResult .code = CUSTOM_COMMENT_HEADER + printResult .code ;
92- return printResult ;
89+ class CustomPrinter extends tstl .LuaPrinter {
90+ /* Override printFile */
91+ protected printFile(file : tstl .File ): SourceNode {
92+ const originalResult = super .printFile (file );
93+ // Add header comment at the top of the file
94+ return this .createSourceNode (file , [` ${CUSTOM_COMMENT_HEADER } ${this .luaFile }\n ` , originalResult ]);
95+ }
96+
97+ /* Override printBoolean */
98+ public printBooleanLiteral(expression : tstl .BooleanLiteral ): SourceNode {
99+ // Print any boolean as 'true'
100+ return this .createSourceNode (expression , " true" );
93101 }
94102}
95103
96104const plugin: tstl .Plugin = {
97105 printer : (program : ts .Program , emitHost : tstl .EmitHost , fileName : string , file : tstl .File ) =>
98- new CustomLuaPrinter (emitHost , program , fileName ).printCustom (file ),
106+ new CustomPrinter (emitHost , program , fileName ).print (file ),
99107};
100108
101109export default plugin ;
0 commit comments