(
emitHost: EmitHost,
writeFileResult: ts.WriteFileCallback,
{ program, sourceFiles: targetSourceFiles, customTransformers = {}, plugins = [] }: TranspileOptions
)
| 22 | } |
| 23 | |
| 24 | export function getProgramTranspileResult( |
| 25 | emitHost: EmitHost, |
| 26 | writeFileResult: ts.WriteFileCallback, |
| 27 | { program, sourceFiles: targetSourceFiles, customTransformers = {}, plugins = [] }: TranspileOptions |
| 28 | ): TranspileResult { |
| 29 | performance.startSection("beforeTransform"); |
| 30 | |
| 31 | const options = program.getCompilerOptions() as CompilerOptions; |
| 32 | |
| 33 | if (options.tstlVerbose) { |
| 34 | console.log("Parsing project settings"); |
| 35 | } |
| 36 | |
| 37 | const diagnostics = validateOptions(options); |
| 38 | let transpiledFiles: ProcessedFile[] = []; |
| 39 | |
| 40 | if (options.noEmitOnError) { |
| 41 | const preEmitDiagnostics = [ |
| 42 | ...diagnostics, |
| 43 | ...program.getOptionsDiagnostics(), |
| 44 | ...program.getGlobalDiagnostics(), |
| 45 | ]; |
| 46 | |
| 47 | if (targetSourceFiles) { |
| 48 | for (const sourceFile of targetSourceFiles) { |
| 49 | preEmitDiagnostics.push(...program.getSyntacticDiagnostics(sourceFile)); |
| 50 | preEmitDiagnostics.push(...program.getSemanticDiagnostics(sourceFile)); |
| 51 | } |
| 52 | } else { |
| 53 | preEmitDiagnostics.push(...program.getSyntacticDiagnostics()); |
| 54 | preEmitDiagnostics.push(...program.getSemanticDiagnostics()); |
| 55 | } |
| 56 | |
| 57 | if (preEmitDiagnostics.length === 0 && (options.declaration || options.composite)) { |
| 58 | preEmitDiagnostics.push(...program.getDeclarationDiagnostics()); |
| 59 | } |
| 60 | |
| 61 | if (preEmitDiagnostics.length > 0) { |
| 62 | performance.endSection("beforeTransform"); |
| 63 | return { diagnostics: preEmitDiagnostics, transpiledFiles }; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | for (const plugin of plugins) { |
| 68 | if (plugin.beforeTransform) { |
| 69 | const pluginDiagnostics = plugin.beforeTransform(program, options, emitHost) ?? []; |
| 70 | diagnostics.push(...pluginDiagnostics); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | const visitorMap = createVisitorMap(plugins.map(p => p.visitors).filter(isNonNull)); |
| 75 | const printer = createPrinter(plugins.map(p => p.printer).filter(isNonNull)); |
| 76 | |
| 77 | const processSourceFile = (sourceFile: ts.SourceFile) => { |
| 78 | if (options.tstlVerbose) { |
| 79 | console.log(`Transforming ${sourceFile.fileName}`); |
| 80 | } |
| 81 |
no test coverage detected