(file: lua.File)
| 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(); |
no test coverage detected