| 27 | |
| 28 | /* Imports of `src`, classified, via the compiler (single source of truth). Returns [{ bare, spec }]. */ |
| 29 | function scanImports(src, exports) { |
| 30 | if (typeof exports.extract_imports !== 'function') { |
| 31 | throw new Error('compiler is missing extract_imports; runtime and wasm are out of sync'); |
| 32 | } |
| 33 | const bytes = TE.encode(src); |
| 34 | const len = Math.min(bytes.length, SOURCE_LIMIT); |
| 35 | new Uint8Array(exports.memory.buffer, exports.src_ptr(), len).set(bytes.subarray(0, len)); |
| 36 | const outLen = exports.extract_imports(len); |
| 37 | if (!outLen) return []; |
| 38 | const text = TD.decode(new Uint8Array(exports.memory.buffer, exports.out_ptr(), outLen)); |
| 39 | return text.split('\n').filter(Boolean).map((line) => ({ |
| 40 | bare: line[0] === 'b', |
| 41 | spec: line.slice(line.indexOf('\t') + 1), |
| 42 | })); |
| 43 | } |
| 44 | |
| 45 | export async function bfsPrefetch(rootSrc, exports, lockfile, ctx) { |
| 46 | const { fetchedSources, knownMissing, importsMap, mainThreadSpecs } = ctx; |