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

const is replaced by var #623

Closed
2beers opened this issue Dec 28, 2020 · 5 comments
Closed

const is replaced by var #623

2beers opened this issue Dec 28, 2020 · 5 comments

Comments

@2beers
Copy link

2beers commented Dec 28, 2020

// a.js
export const a = {
    a: "a"
};

// main.js
import {a} from "./a";
const v1 = a;
console.log(v1);


//out.js
// src/a.js
var a = {
  a: "a"
};

// src/main.js
var v1 = a;
console.log(v1);

I use the following command
esbuild src/main.js --bundle --format=esm --target=es2020 --outfile=out.js

const v1 = a; is replaced with var v1 = a;

Is there an option to keep const instead of var?

@remorses
Copy link
Contributor

remorses commented Dec 28, 2020

This is because in Safari declarations with const were much slower than var, is there any reason you want to keep const?

@evanw
Copy link
Owner

evanw commented Dec 29, 2020

There are also some other reasons, which are described here: #598 (comment).

@2beers
Copy link
Author

2beers commented Dec 30, 2020

@remorses Not really. I assume only top level const/let are replaced with var?
I'm testing esbuild to see if I can replace rollup in a production project.

Maybe an option to enable/disable this behavior.

@evanw
Copy link
Owner

evanw commented Dec 30, 2020

As mentioned above, this behavior is deliberate and is done for at least three reasons. It sounds like you don’t have a reason you need to keep const since you said “not really”? If so, I would like to close this issue and just keep the current behavior. I’m trying to keep the number of options that esbuild exposes low to avoid esbuild being unnecessarily complex to configure as a user and to avoid it being unnecessarily complex to develop and test for me. Each option has a cost and I’m not going to throw in more options unless there are strong reasons for them.

@2beers
Copy link
Author

2beers commented Dec 30, 2020

Sure. I understand. You can close this thread. I don't mind if it's using var on top level. It just looked weird when I saw it the first time, but I read your comment on the other thread and made more sense.

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

3 participants