unplugin / unplugin-macros

Macros plugin for bundlers.
https://jsr.io/@unplugin/macros
MIT License
159 stars 3 forks source link

Support for calling other macros as shown in the Bun example #48

Open herkulano opened 3 days ago

herkulano commented 3 days ago

Clear and concise description of the problem

Currently the Bun example doesn't work, arguments can only be literal strings, objects and arrays in unplugin-macros.

import {getText} from './getText.ts' with { type: 'macro' };
import {getFoo} from './getFoo.ts' with { type: 'macro' };

export function howLong() {
  // this works because getFoo() is statically known
  const foo = getFoo();
  const text = getText(`https://example.com/${foo}`);
  console.log("The page is", text.length, "characters long");
}

Suggested solution

Support macro functions as arguments. Not sure if the implementation of https://github.com/unplugin/unplugin-macros/issues/12 would solve this.

Alternative

No response

Additional context

No response

Validations

sxzz commented 3 days ago

12 should fix this, but I haven't found a good solution for this feature.