Skip to content

--keep-names flag for bun build does not have the intended effect #25332

@mcmah309

Description

@mcmah309

What version of Bun is running?

1.3.3+274e01c73

What platform is your computer?

Linux

What steps can reproduce the bug?

Can be reproduced with:

echo -e "export function hello(name: string): void {\n\tconsole.log(\`Hello \${name}\`);\n}" > index.ts;
bun build index.ts --minify --keep-names;
bun build index.ts --minify;

Output:

function l(o){console.log(`Hello ${o}`)}export{l as hello};
function l(o){console.log(`Hello ${o}`)}export{l as hello};

I would expect --keep-names to have an effect, like preserving names internally:

function hello(o){console.log(`Hello ${o}`)}export{hello};
function l(o){console.log(`Hello ${o}`)}export{l as hello};

The following demonstrates the "effect" --keep-names has, but not the intended effect anyone desires.

echo -e "function testFuncNames() {\n\tconst myFunc = function OriginalName() {};\n\tconsole.log(myFunc.name);\n}\n\nexport function entry() {\n\ttestFuncNames();\n}" > index.ts;
bun build index.ts --minify --keep-names;
bun build index.ts --minify;

output

function n(){console.log(function o(){}.name)}function t(){n()}export{t as entry};
function n(){console.log(function(){}.name)}function t(){n()}export{t as entry};

I would expect the following

function testFuncNames(){console.log(function OriginalName(){}.name)}function entry(){testFuncNames()}export{entry};
function n(){console.log(function(){}.name)}function t(){n()}export{t as entry};

This is also more in line with the description of the flag - "Preserve original function and class names when minifying".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions