Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass arguments to the codegen function #19

Open
milahu opened this issue Dec 10, 2022 · 0 comments
Open

feat: pass arguments to the codegen function #19

milahu opened this issue Dec 10, 2022 · 0 comments

Comments

@milahu
Copy link

milahu commented Dec 10, 2022

currently this throws on runtime

// index.js
import.meta.compileTime("./codegen.js", "someName");
// TypeError: (intermediate value).compileTime is not a function

expected: "someName" should be passed to the codegen function

// codegen.js
export default async ({ root, args }) => { // currently only "root" is passed
  const name = args[0];
  return {
    code: `const ${name} = 42;`,
  }
}

use case: generate code like

// static code
/** @type {Record<string, () => any>} */
const someFiles = {};

// generated code
someFiles["./a.js"] = () => import("./a.js");
someFiles["./b.js"] = () => import("./b.js");

... to allow some type-checking of the generated code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant