( code: string, filename = 'module.tsx', )
| 12 | * @returns the error messages; an empty array means the module is valid. |
| 13 | */ |
| 14 | export async function getModuleErrors( |
| 15 | code: string, |
| 16 | filename = 'module.tsx', |
| 17 | ): Promise<Array<string>> { |
| 18 | let javascript: string |
| 19 | try { |
| 20 | const result = await transformWithOxc(code, filename, { |
| 21 | jsx: 'preserve', |
| 22 | typescript: { onlyRemoveTypeImports: true }, |
| 23 | }) |
| 24 | javascript = result.code |
| 25 | } catch (error) { |
| 26 | return [stripVTControlCharacters((error as Error).message)] |
| 27 | } |
| 28 | const { errors } = parseSync('module.jsx', javascript, { |
| 29 | sourceType: 'module', |
| 30 | showSemanticErrors: true, |
| 31 | }) |
| 32 | return errors.map((error) => error.message) |
| 33 | } |
| 34 | |
| 35 | /** Matches a declaration of `name` in generated code, however it is printed. */ |
| 36 | export function declarationOf(name: string): RegExp { |
no outgoing calls