MCPcopy Index your code
hub / github.com/bytecodealliance/ComponentizeJS / detectKnownSourceExportNames

Function detectKnownSourceExportNames

src/componentize.js:627–651  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

625 * @returns {Promise<string[]>} A Promise that resolves to a list of string that represent unversioned interfaces
626 */
627async 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}

Callers 1

componentizeFunction · 0.85

Calls 1

addMethod · 0.45

Tested by

no test coverage detected