You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a project where classes need to retain their names. The --keep-names works almost, but not quite for my purposes.
If I have code that looks like:
export class TestClass {
say() {
console.log("hello");
}
}
It is translated to:
var TestClass = class {
init() {
console.log("hello");
}
};
__name(TestClass, "TestClass");
...
where __name calls defineProperty. (With options --bundle --keep-names --format=esm)
While this works (i.e. returns "TestClass") when thatClass.name is accessed, if thatClass.toString() is called and then result is eval()'ed , the resulting class object is anonymous as toString() does not insert the name after the class keyword.
It'd be great if the result produced with --keep-names is:
var TestClass = class TestClass {
init() {
console.log("hello");
}
};
, or with the __name() line added.
Otherwise I really like this project!
The text was updated successfully, but these errors were encountered:
Using toString() on functions and classes with esbuild is not supported: https://esbuild.github.io/content-types/#function-tostring. This is problematic in more cases than just --keep-names so changing how that feature is implemented is still a brittle solution and may randomly break in the future, since this is still an unsupported use case and esbuild uses helper functions for other things too. If you still want to use esbuild, you should instead build the source code in a separate build step and then insert it as a string into your code that needs the string.
I have a project where classes need to retain their names. The --keep-names works almost, but not quite for my purposes.
If I have code that looks like:
It is translated to:
where __name calls defineProperty. (With options
--bundle --keep-names --format=esm
)While this works (i.e. returns "TestClass") when
thatClass.name
is accessed, ifthatClass.toString()
is called and then result is eval()'ed , the resulting class object is anonymous as toString() does not insert the name after theclass
keyword.It'd be great if the result produced with --keep-names is:
, or with the __name() line added.
Otherwise I really like this project!
The text was updated successfully, but these errors were encountered: