Skip to content

import-module-string v4.0.0

Latest

Choose a tag to compare

@zachleat zachleat released this 05 Nov 18:47
e59ee15
  • Breaking: compileAsFunction now returns an async function. This allows top-level await to be used in passed code.
  • Breaking: compileAsFunction supports implicitExports. When the code has no export, the function now resolves with its top-level declarations (including import specifiers) instead of {}. implicitExports: false reverts to old behavior.
let mod = await importFromString("const a = await fn(b);", { compileAsFunction: true });
await mod.default({ fn: async n => n * 2, b: 2 });
// { a: 4 }
  • Added: compileAsFunction supports export aliases (export { a as b }) and re-exports (export { default as x } from "…"), export * as ns from "…" and export * from "…" (#3).
  • Fix: Relative and bare specifiers in export … from and export * from now resolve like import specifiers. They previously failed with "Invalid relative URL".