MCPcopy Index your code
hub / github.com/TypeScriptToLua/TypeScriptToLua / print

Method print

src/LuaPrinter.ts:174–199  ·  view source on GitHub ↗
(file: lua.File)

Source from the content-addressed store, hash-verified

172 }
173
174 public print(file: lua.File): PrintResult {
175 // Add traceback lualib if sourcemap traceback option is enabled
176 if (this.options.sourceMapTraceback) {
177 file.luaLibFeatures.add(LuaLibFeature.SourceMapTraceBack);
178 }
179
180 const sourceRoot = this.options.sourceRoot
181 ? // According to spec, sourceRoot is simply prepended to the source name, so the slash should be included
182 `${this.options.sourceRoot.replace(/[\\/]+$/, "")}/`
183 : "";
184 const rootSourceNode = this.printFile(file);
185 const sourceMap = this.buildSourceMap(sourceRoot, rootSourceNode);
186
187 let code = rootSourceNode.toString();
188
189 if (this.options.inlineSourceMap) {
190 code += "\n" + this.printInlineSourceMap(sourceMap);
191 }
192
193 if (this.options.sourceMapTraceback) {
194 const stackTraceOverride = this.printStackTraceOverride(rootSourceNode);
195 code = code.replace(LuaPrinter.sourceMapTracebackPlaceholder, stackTraceOverride);
196 }
197
198 return { code, sourceMap: sourceMap.toString(), sourceMapNode: rootSourceNode };
199 }
200
201 private printInlineSourceMap(sourceMap: SourceMapGenerator): string {
202 const map = sourceMap.toString();

Callers 3

printer.tsFile · 0.80
createPrinterFunction · 0.80
LuaLibPluginClass · 0.80

Calls 6

printFileMethod · 0.95
buildSourceMapMethod · 0.95
printInlineSourceMapMethod · 0.95
toStringMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected