(tsContent: string, target?: string)
| 102 | } |
| 103 | |
| 104 | async function compileTsToJs(tsContent: string, target?: string): Promise<string> { |
| 105 | // Honor the test case's `target` so ES5 fixtures get downleveled (tagged templates -> |
| 106 | // `__makeTemplateObject`, classes -> functions), matching ngtsc's compliance goldens. |
| 107 | const scriptTarget = |
| 108 | (target |
| 109 | ? (ts.ScriptTarget as unknown as Record<string, ts.ScriptTarget>)[target.toUpperCase()] |
| 110 | : undefined) ?? ts.ScriptTarget.ES2022; |
| 111 | |
| 112 | const result = ts.transpileModule(tsContent, { |
| 113 | compilerOptions: { |
| 114 | target: scriptTarget, |
| 115 | module: ts.ModuleKind.ES2015, |
| 116 | experimentalDecorators: true, |
| 117 | emitDecoratorMetadata: true, |
| 118 | removeComments: false, |
| 119 | }, |
| 120 | }); |
| 121 | |
| 122 | const outputText = result.outputText.replace(/\r\n/g, '\n').replace(/\/virtual_project\//g, '/'); |
| 123 | |
| 124 | try { |
| 125 | return await prettier.format(outputText, { |
| 126 | parser: 'babel', |
| 127 | printWidth: 100, |
| 128 | singleQuote: false, |
| 129 | trailingComma: 'none', |
| 130 | arrowParens: 'avoid', |
| 131 | quoteProps: 'preserve', |
| 132 | }); |
| 133 | } catch { |
| 134 | return outputText; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | const LOCAL_EXTRA_CHECK_FUNCTIONS: Record<string, (generated: string, ...args: any[]) => boolean> = |
| 139 | { |
no test coverage detected