Use registerJSModule when available (#1573)

This commit is contained in:
Andrea Giammarchi
2023-06-29 22:50:35 +02:00
committed by GitHub
parent 7813c3f03f
commit a14e701be4
24 changed files with 81 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
import "@ungap/with-resolvers";
import { getBuffer } from "../fetch-utils.js";
import { absoluteURL } from "../utils.js";
import { absoluteURL, entries } from "../utils.js";
/**
* Trim code only if it's a single line that prettier or other tools might have modified.
@@ -131,3 +131,12 @@ export const fetchPaths = (module, interpreter, config_fetch) =>
.then((buffer) => module.writeFile(interpreter, path, buffer)),
),
);
// this is a fallback for interpreters unable to register JS modules
// all defined keys will end up as globally available references
// REQUIRES INTEGRATION TEST
/* c8 ignore start */
export function registerJSModule(interpreter, _, value) {
for (const [k, v] of entries(value)) this.setGlobal(interpreter, k, v);
}
/* c8 ignore stop */