I need to parse JavaScript from java. I have already tried the NashornScriptEngine (builtin in the jdk), and RhinoScriptEngine, but they both (apparently) do not support the "class" keyword.
This is what i tried:
public static void main(String[] args) throws Throwable {
RhinoScriptEngineFactory factory = new RhinoScriptEngineFactory();
RhinoScriptEngine engine = (RhinoScriptEngine) factory.getScriptEngine();
engine.eval(new FileReader("js/SomeClass.js"));
}
And this is the content of SomeClass.js:
class SomeTestClass {
}
function start() {
print("hello")
}
And this is the stacktrace:
Exception in thread "main" javax.script.ScriptException: identifier is a reserved word: class in eval at line number 0 at column number 6
at org.mozilla.javascript.engine.RhinoScriptEngine.eval(RhinoScriptEngine.java:124)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
at com.clut.MyMain.main(MyMain.java:21)
So what can i do to parse javascript containing classes? I can even use another library if its needed
I found out that GraalVm has builtin javascript parsing