* Detect known exports that correspond to certain interfaces * * @param {string} filename - filename * @param {string} code - JS source code * @returns {Promise } A Promise that resolves to a list of string that represent unversioned interfaces
(filename, code)
| 625 | * @returns {Promise<string[]>} A Promise that resolves to a list of string that represent unversioned interfaces |
| 626 | */ |
| 627 | async function detectKnownSourceExportNames(filename, code) { |
| 628 | if (!filename) { |
| 629 | throw new Error('missing filename'); |
| 630 | } |
| 631 | if (!code) { |
| 632 | throw new Error('missing JS code'); |
| 633 | } |
| 634 | |
| 635 | const names = new Set(); |
| 636 | |
| 637 | const results = await oxc.parseAsync(filename, code); |
| 638 | if (results.errors.length > 0) { |
| 639 | throw new Error( |
| 640 | `failed to parse JS source, encountered [${results.errors.length}] errors`, |
| 641 | ); |
| 642 | } |
| 643 | |
| 644 | for (const staticExport of results.module.staticExports) { |
| 645 | for (const entry of staticExport.entries) { |
| 646 | names.add(entry.exportName.name); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | return names; |
| 651 | } |