-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Class renaming breaks const
usage
#3222
Comments
I cannot reproduce your issue because the code you have provided is not valid JavaScript (there's a missing comma among other problems): const Foo = {
components: {}
init: function () {
Console.log("Foo.init")
}
}
Foo.init()
Foo.components.Bar = {
someval: "data"
init(): function () {
Console.log("Foo.components.Bar.init")
}
} Please demonstrate your issue by getting it to happen on https://esbuild.github.io/try/ and then pasting the link here. I'm marking this issue as |
Thanks for the link and apologies for the broken example, I was working pretty late. After trying to reproduce the issue at the link you provided, the In const FooCore = {
components: {},
init: function () {
const that = this;
Console.log("Foo.init");
}
}
FooCore.init() In FooCore.components.Bar = {
someval: {},
init: function () {
Console.log("Foo.components.Bar.init")
}
} In import "./foo.core.js"
import "./foo.bar.js" The bundled output produced looks like this: (() => {
// js/foo.core.js
// ### This should be FooCore ###
var FooCore2 = {
components: {},
init: function() {
const that = this;
Console.log("Foo.init");
}
};
FooCore2.init();
// js/foo.bar.js
FooCore.components.Bar = {
someval: {},
init: function() {
Console.log("Foo.components.Bar.init");
}
};
})(); If I put the contents of |
I see. I believe you may be confused about how modules work in JavaScript. JavaScript does not allow you to reference a local variable from another module directly by name. Instead you need to export that variable from one file and import it into another. So instead of doing this you should do this. |
Ahhhh. Thank you. It's all just clicked. The code base I'm using was originally designed to be used with gulp. Where it takes all the JS and bundles it into one big file, crudely. Thank you so much for your time on this. I really appreciate it considering it's not an esbuild issue. |
I'm trying to bundle some JS produced by a third-party and the authors use of a
const
seems to be incompatible with esbuild.Having gone through #510 I can't seem to find a way of getting a pattern like the following to work:
The outputted JS is:
This results in the cast to
Foo.components.Bar
to fail asFoo
hasn't been declared as it's been renamed toFoo2
. I've triedkeep-names
but from my limited understanding of what that flag does, it's not going to help me here. I can't find any other solutions from docs.Apologies if I'm missed something obvious. Annoyingly this use of a
const
occurs throughout a larger JS code base so refactoring would take considerable amounts of work. Any help would be greatly appreciated.The text was updated successfully, but these errors were encountered: