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
bug: @@toStringTag property undefined, should be 'Module' #4336
Comments
esbuld is no different in this regard:
How would you model the bundle in order for such a thing to work? By explicitly setting that property in the generated namespace?
Does any code in the wild rely on this construct? |
it's a bug in
that might as well be all what's needed, yeah.
hard to know. it's in the spec, I would expect that a bundler should (ideally) not alter the runtime. it's a potential easy fix and aligns |
out of curiosity, I was wondering how |
I don't know about test262, but a while back rollup was run against uglify-js' ES6+ test suite and the dozen or so failures were filed and fixed. The I'd personally suggest to hold off adding Are there any other special ES module Symbol |
it's the TC39 ecmascript language spec test suite. that's the test suite language implementers run against.
interestingly I added the rollup-terser plugin on top in a subsequent run which unfortunately resulted in more failures. I'll try to file those issues in terser eventually as well. not sure how uglify would be doing, I gotta check [eventually as well].
I don't know, is that a good strategy? I would think one would preemptively fix any known bugs. I don't think it would be great if say
you mean if anyone is actually reading the property? sure, if that's possible. I don't know how much overhead that would add? 🤷♂️
I'm fairly sure that's it (I might have to report back on that one). the test is here btw: https://github.com/tc39/test262/blob/main/test/language/module-code/namespace/Symbol.toStringTag.js |
Thanks, I was familiar with the test suite but not its results with Rollup.
There are outright bugs, and then there are features that are not supported. NodeJS and Chrome have to be 100% ES spec compliant down to the most obscure feature. Rollup has a number of known limitations like the aforementioned lack of non-strict mode handling. I think this issue falls in that category.
In my opinion the small overhead to scan all AST string literals and properties would be worth it not to include the 30 odd bytes |
The output.namespaceToStringTag option is there to address this. It is decidedly an opt-in for various reasons. |
Good stuff. Next time I'll grep before I jump into a discussion. |
thank you @lukastaegert I had no clue, way too many options 😄 I'll give it a try ... edit: seems to work 🚀 , although, a small tiny nit: the property would need to be non-enumerable. since the code-gen is using Object.create(null, {
[Symbol.toStringTag]: { enumerable: false, value: 'Module' }
}); I'll have a look into a PR if that's ok. |
Acutally considering your last remark, Symbol properties are always non-enumerable, so there should be nothing to do (unless you can write a test that proves otherwise) Update: I did my googling and you are of course right, there is a difference in behaviour for |
interesting, I did not know that. |
just for posterity: const { freeze, getOwnPropertyDescriptor } = Object
console.log(
getOwnPropertyDescriptor({ [Symbol.toStringTag]: 'Module' }, Symbol.toStringTag)
)
// prints:
{
value: 'Module',
writable: true,
enumerable: true,
configurable: true
}
console.log(
getOwnPropertyDescriptor(freeze({ [Symbol.toStringTag]: 'Module' }), Symbol.toStringTag)
)
// prints:
{
value: 'Module',
writable: false,
enumerable: true,
configurable: false
} |
Rollup Version
2.62.0
Operating System (or Browser)
n/a
Node Version (if applicable)
n/a
Link To Reproduction
https://rollupjs.org/repl/?version=2.62.0&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMColMjBhcyUyMG5zJTIwZnJvbSUyMCcuJTJGZm9vLmpzJyUzQiU1Q24lNUNuY29uc29sZS5sb2cobnMlNUJTeW1ib2wudG9TdHJpbmdUYWclNUQlMjAlM0QlM0QlM0QlMjAnTW9kdWxlJyklMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCUyQyU3QiUyMm5hbWUlMjIlM0ElMjJmb28uanMlMjIlMkMlMjJjb2RlJTIyJTNBJTIyZXhwb3J0JTIwY29uc3QlMjBmb28lMjAlM0QlMjAnYmFyJyUyMiU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE
rollup bundle:
Expected Behaviour
prints: true
Actual Behaviour
prints: false
The text was updated successfully, but these errors were encountered: