(opts: Opts, fn?: string)
| 7 | * @param fn filename |
| 8 | */ |
| 9 | export function parseScript(opts: Opts, fn?: string) { |
| 10 | return (source: string): void => { |
| 11 | let output |
| 12 | try { |
| 13 | debug('Using TS compiler to process file', fn) |
| 14 | output = ts.transpileModule(source, { |
| 15 | compilerOptions: { |
| 16 | allowJs: true, |
| 17 | target: ts.ScriptTarget.ESNext, |
| 18 | noEmit: true, |
| 19 | experimentalDecorators: true, |
| 20 | }, |
| 21 | reportDiagnostics: true, |
| 22 | fileName: fn, |
| 23 | transformers: { |
| 24 | before: [transformWithTs(ts, opts)], |
| 25 | }, |
| 26 | }) |
| 27 | } catch (e) { |
| 28 | if (e instanceof Error) { |
| 29 | e.message = `Error processing file ${fn} |
| 30 | ${e.message || ''}` |
| 31 | } |
| 32 | throw e |
| 33 | } |
| 34 | if (output.diagnostics) { |
| 35 | const errs = output.diagnostics.filter( |
| 36 | d => d.category === ts.DiagnosticCategory.Error |
| 37 | ) |
| 38 | if (errs.length) { |
| 39 | throw new Error( |
| 40 | ts.formatDiagnosticsWithColorAndContext(errs, { |
| 41 | getCanonicalFileName: fileName => fileName, |
| 42 | getCurrentDirectory: () => process.cwd(), |
| 43 | getNewLine: () => ts.sys.newLine, |
| 44 | }) |
| 45 | ) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
no test coverage detected