PlaceholderAPI / Javascript-Expansion

Adds javascript placeholders
GNU General Public License v3.0
22 stars 24 forks source link

JavaScript Expansion - EcmaScript 6 support #9

Closed tabatintores closed 3 years ago

tabatintores commented 4 years ago

The current expansion JavaScript supports only ES5. Can you add the ES6 support to the expansion?

aBooDyy commented 4 years ago

Hello there, This has been suggested several times, and they will look for a solution for this as the current JavaScript engine the expansion is using is not supported in Java anymore.

Would be great if you open the issue in the correct repository next time 👍

PiggyPiglet commented 4 years ago

We're doing research on this in relation to PAPI 3. Look forward to a new engine, with es6 support in the future.

MTM123 commented 4 years ago

Simple fix(might be temporary fix) is to add this to jvm args: -Dnashorn.args=--language=es6. This works on Java 11 not entirely sure about other versions though

Edit: This works on Java 8, however, there is selective support(during my testing lambdas didn't work) for es6 in java 8.

This can be done without specifying jvm arguments too:

import javax.script.ScriptEngine;
import javax.script.ScriptException;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;

public class NashornFactory {
    public static void main(String[] args) throws ScriptException {
        NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
        ScriptEngine engine = factory.getScriptEngine("--language=es6");
        engine.eval("const a = 100");
    }
}

Reference: https://developer.oracle.com/databases/nashorn-javascript-part2.html

BlitzOffline commented 3 years ago

New version that darbyjack linked has support for quick_js.