我正在尝试在Nashorn中运行browser.js,在库中使用babel.transform来处理某些Isomorphic Webapp。
npm i babel-core
以下是BabelTransformer类的来源:
public BabelTransformer() throws ScriptException, IOException{
try
{
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine nashorn = mgr.getEngineByName("nashorn");
nashorn.eval("var process = {env:{}}"); // node-modules expect that
nashorn.eval("var global = this;"); // react expects that
nashorn.eval(getScript("com/facebook/babel/jvm-npm.js"));
nashorn.eval(getScript("com/facebook/babel/node_modules/babel-core/browser.min.js")); //The line 43
babel = (ScriptObjectMirror)nashorn.eval("babel");
invocable = (Invocable) nashorn;
}
catch(ScriptException | IOException e)
{
throw new Error(e); //this is line 49
}
}
但是我有一个错误,我无法诊断/解决:
Testcase: testTransformOnHtmlElement(com.facebook.babel.BabelTransformerTest): Caused an ERROR
javax.script.ScriptException: <eval>:1:1 Expected ; but found error
^ in <eval> at line number 1 at column number 1
java.lang.Error: javax.script.ScriptException: <eval>:1:1 Expected ; but found error
^ in <eval> at line number 1 at column number 1
at com.facebook.babel.BabelTransformer.<init>(BabelTransformer.java:49)
at com.facebook.babel.BabelTransformerTest.setUp(BabelTransformerTest.java:16)
Caused by: javax.script.ScriptException: <eval>:1:1 Expected ; but found error
^ in <eval> at line number 1 at column number 1
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:534)
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:521)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at com.facebook.babel.BabelTransformer.<init>(BabelTransformer.java:43)
Caused by: jdk.nashorn.internal.runtime.ParserException: <eval>:1:1 Expected ; but found error
^
at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:292)
at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:277)
at jdk.nashorn.internal.parser.AbstractParser.expectDontAdvance(AbstractParser.java:348)
at jdk.nashorn.internal.parser.AbstractParser.expect(AbstractParser.java:335)
at jdk.nashorn.internal.parser.Parser.endOfLine(Parser.java:3369)
at jdk.nashorn.internal.parser.Parser.expressionStatement(Parser.java:1162)
at jdk.nashorn.internal.parser.Parser.statement(Parser.java:969)
at jdk.nashorn.internal.parser.Parser.sourceElements(Parser.java:775)
at jdk.nashorn.internal.parser.Parser.program(Parser.java:711)
at jdk.nashorn.internal.parser.Parser.parse(Parser.java:284)
at jdk.nashorn.internal.parser.Parser.parse(Parser.java:250)
at jdk.nashorn.internal.runtime.Context.compile(Context.java:1281)
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1248)
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:629)
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:532)
如何在Nashorn中运行browser.js?