Skip to content

addMetaParam

A preset that can be used to find call expressions such as foo(), new Foo(), or foo.bar.baz() and append meta as an argument:

source.ts
ts
import type { Meta } from "@monstermann/meta";

function runExample(meta?: Meta) {
    // { path: "source.ts", line: 8, name: "example" }
    console.log(meta);
}

const example = runExample();
Rolldown
ts
import meta, { addMetaParam } from "@monstermann/unplugin-meta/rolldown";

export default {
    plugins: [
        meta({
            resolve: addMetaParam(["runExample"]),
        }),
    ],
};
Output
ts
const path = "source.ts";
const meta = { path, line: 8, name: "example" };

function runExample(meta?: Meta) {
    // { path: "source.ts", line: 8, name: "example" }
    console.log(meta);
}

const example = runExample();
const example = runExample(meta);