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

JS loader caues unnecessary/unwanted/unexpected transformations #15996

Open
spamshaker opened this issue Dec 26, 2024 · 0 comments
Open

JS loader caues unnecessary/unwanted/unexpected transformations #15996

spamshaker opened this issue Dec 26, 2024 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@spamshaker
Copy link

What version of Bun is running?

1.1.40+b5b51004e

What platform is your computer?

Darwin 24.2.0 arm64 arm

What steps can reproduce the bug?

given I have an input sample.mjs:

export const  __filename = new URL(import.meta.url).pathname;
export const __dirname = __filename.split('/').slice(0, -1).join('/');

console.log({ __dirname, __filename });

run
bun build sample.mjs

What is the expected behavior?

the output should not be touched and look like following which esbuild does
esbuild sample.mjs gives correct result:

"use strict";
export const __filename = new URL(import.meta.url).pathname;
export const __dirname = __filename.split("/").slice(0, -1).join("/");
console.log({ __dirname, __filename });

What do you see instead?

// sample.mjs
var __filename2 = new URL(import.meta.url).pathname;
var __dirname2 = __filename2.split("/").slice(0, -1).join("/");
console.log({ __dirname: __dirname2, __filename: __filename2 });
export {
  __filename2 as __filename,
  __dirname2 as __dirname
};

Additional information

const should never be transformed to var in esm as it has different behaviors

@spamshaker spamshaker added bug Something isn't working needs triage labels Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant