(
{ source, filename, preprocessOptions }: SFCTemplateCompileOptions,
preprocessor: PreProcessor,
)
| 81 | } |
| 82 | |
| 83 | function preprocess( |
| 84 | { source, filename, preprocessOptions }: SFCTemplateCompileOptions, |
| 85 | preprocessor: PreProcessor, |
| 86 | ): string { |
| 87 | // Consolidate exposes a callback based API, but the callback is in fact |
| 88 | // called synchronously for most templating engines. In our case, we have to |
| 89 | // expose a synchronous API so that it is usable in Jest transforms (which |
| 90 | // have to be sync because they are applied via Node.js require hooks) |
| 91 | let res: string = '' |
| 92 | let err: Error | null = null |
| 93 | |
| 94 | preprocessor.render( |
| 95 | source, |
| 96 | { filename, ...preprocessOptions }, |
| 97 | (_err, _res) => { |
| 98 | if (_err) err = _err |
| 99 | res = _res |
| 100 | }, |
| 101 | ) |
| 102 | |
| 103 | if (err) throw err |
| 104 | return res |
| 105 | } |
| 106 | |
| 107 | export function compileTemplate( |
| 108 | options: SFCTemplateCompileOptions, |
no test coverage detected