Array functions don't work
When using array.includes() in JavaScript, the code doesn't convert to Java functions properly.
Server error: TypeError: o.includes is not a function
Hi @NexelOfficial, could you provide a snippet of the code? I'm happy to look into this.
Sure. Take this very basic example that doesn't work:
const arr = ["itemA", "itemB"];
if (arr.includes("itemA")) {
console.log("It's in!");
}
I think this has to do with nashorn not being set to ES6 mode. By the way, did you guys get my email? I would love to contribute to this project.
There's a great improvement @NexelOfficial ... let us move beyond Nashorn!
I don't know if there are good insights available on Walterhiggens one ( https://github.com/walterhiggins/ScriptCraft/tree/development/src/main/java/bukkit/org/scriptcraftjs), but let's try to keep all those improvements in this one. As long as we don't get the core system bloated!
@NexelOfficial I think we're on the right track with Nashorn. But the core library needs some polyfills for full ES6 compatibility. For this specific case...
Array.prototype.includes = function(searchElement: any, fromIndex?: number) {
return this.indexOf(searchElement, fromIndex) !== -1;
};
We could use lots of help. Our email account was just setup after being down for a while. Please forward your email to [email protected] again and we should receive it!
Pull request to add this polyfill: https://github.com/customrealms/core/pull/43
Changing the target to ES2015 in the tsconfig might also work. Array.prototype.includes was introduced in ES2016 and I think the default Nashorn version is ES2015. Might be worth checking out.
Edit: From the Nashorn wiki page: It provides a 100% support of ECMAScript 5.1.[9] It was the first JavaScript implementation to achieve 100% pass rate on the ECMAScript 5.1 test suite.[10]
ES5 it is!
@connerdouglass Could you please generate a new link to the Discord and send it to me? The old one is expired.
@NexelOfficial https://discord.gg/bsTearKQsm