Having the following test.js file:
export default class Test {}
Test.something = 'ok'
will throw an error with [email protected]
node -r esm test.js
file:///home/..../test.js:1
ReferenceError: Test is not defined
at Object.(file:///home/.../test.js:3:1)
at Generator.next ()
but not with [email protected] nor [email protected]
_Originally posted by @manniL in https://github.com/standard-things/esm/issues/722#issuecomment-461065919_
thank you @manniL for bringing this up!
@jdalton seems to be an introduced bug by acorn? https://github.com/acornjs/acorn/blob/master/acorn/CHANGELOG.md#bug-fixes
fwiw, hoisting still works for exported default function declarations:
export default function Test() {}
Test.something = "ok";
somewhat surprised that there isn't a test262 test for this which could have caught this. gonna check over there as well.
Thanks for the report @manniL and thanks for digging in @dnalborczyk!
After review it is not an Acorn issue but an esm issue introduced by this commit https://github.com/standard-things/esm/commit/9f8af435d1d49ade2fcb14e18523c5c7ac6b0ce5.
Update:
Patch https://github.com/standard-things/esm/commit/55d92f8fd02dacd0acf9cd641fb384eb1cd3c86a; Tests https://github.com/standard-things/esm/commit/a24a4a97b5de36d74662df3605060eba0c9c777e;
Thanks for the quick fix @jdalton
Credits to @pimlie who noticed the bug while working on a new Nuxt.js feature. :+1:
v3.2.2 is released :tada:
We actually had the same issue, see acornjs/acorn#810.