-
Notifications
You must be signed in to change notification settings - Fork 10
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
var
scoping is completely wrong
#36
Comments
Aha, this is biting me in the ass too. Trying to use TypeScript and their helper functions rely on function scoped var as well. Is this a regression? I don't recall this coming up on previous versions. I was using TypeScript + rollup to bundle scripts on Minecraft 1.16 without issue. |
It is an "intentional" regression, as in someone (cough @LatvianModder) thought "oh you shouldn't be using var anyways, and this is not supposed to be a faithful brwoser-compatible js engine, it's meant for a block game and it's meant to be usable by noobs", and the way var was done upstream has also been broken-ish in upstream Rhino, so... that's where we've ended up ^^; |
I think generally enough semi-recentish ES functions are implemented that you don't need to resort to a lot of polyfills or transformations (if you're just writing regular JS rather than TS) so I have mostly worked around this issue (varargs would be nice, though). The only babel plugins I have enabled are classes and numeric separators now. I did have a look at what might cause this whilst fixing other bugs and I have a good idea of where to look but I'm more focused on using KubeJS right now so I'll likely get back to it in a few weeks time and have a proper attempt then. |
It does kind of make life hard for folks who want nice things like TypeScript and modern JS features, because it's kind of all or nothing. Transpiling to ES5 with TS or Babel used to work great, but now KubeJS chokes because of the scoping changes. I don't see where this helps anybody. |
Input code:
Node output:
exists!
Mozilla Rhino output:
exists!
This repo output:
dev.latvian.mods.rhino.EcmaError: ReferenceError: "thing" is not defined.
In ECMA
var
is function scoped. Is this a bad idea? Yes. Should you usevar
overlet
/const
? Definitely not. Yet, things such as Babel will usevar
anyway e.g. to polyfill in varargs.Discovered whilst investigating #35.
The text was updated successfully, but these errors were encountered: