问题
I'm trying to run browser.js in Nashorn, to use babel.transform in the library for some Isomorphic Webapp.
public BabelTransformer() throws ScriptException, IOException{
try
{
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine nashorn = mgr.getEngineByName("nashorn");
nashorn.eval(getScript("com/facebook/babel/node_modules/babel-core/browser.min.js")); //The line 38
babel = (ScriptObjectMirror)nashorn.eval("babel");
invocable = (Invocable) nashorn;
}
catch(ScriptException | IOException e)
{
throw new Error(e); //The line 42
}
}
Throws error:
javax.script.ScriptException: SyntaxError: empty range in char class in <eval> at line number 41
java.lang.Error: javax.script.ScriptException: SyntaxError: empty range in char class in <eval> at line number 41
at com.facebook.babel.BabelTransformer.<init>(BabelTransformer.java:42)
at com.facebook.babel.BabelTransformerTest.setUp(BabelTransformerTest.java:16)
Caused by: javax.script.ScriptException: SyntaxError: empty range in char class in <eval> at line number 41
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:451)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403)
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:38)
Caused by: <eval>:41 SyntaxError: empty range in char class
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
at jdk.nashorn.internal.runtime.ECMAErrors.asEcmaException(ECMAErrors.java:99)
at jdk.nashorn.internal.runtime.ECMAErrors.asEcmaException(ECMAErrors.java:69)
at jdk.nashorn.internal.runtime.ParserException.throwAsEcmaException(ParserException.java:107)
at jdk.nashorn.internal.objects.NativeRegExp.<init>(NativeRegExp.java:87)
at jdk.nashorn.internal.objects.NativeRegExp.<init>(NativeRegExp.java:95)
at jdk.nashorn.internal.objects.NativeRegExp.<init>(NativeRegExp.java:99)
at jdk.nashorn.internal.objects.NativeRegExp.newRegExp(NativeRegExp.java:212)
at jdk.nashorn.internal.objects.NativeRegExp.constructor(NativeRegExp.java:168)
at jdk.nashorn.internal.scripts.Script$Recompilation$391$1311181AAA$\^eval\_.L:1-1$L:41-4(<eval>:41)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:646)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.internal.objects.NativeFunction.call(NativeFunction.java:192)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$390$1216111AAA$\^eval\_.L:1-1$L:38-4(<eval>:38)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:646)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.internal.objects.NativeFunction.call(NativeFunction.java:192)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$389$1189230AAA$\^eval\_.L:1-1$L:38(<eval>:38)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:666)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.internal.objects.NativeFunction.call(NativeFunction.java:192)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$388$162846AAA$\^eval\_.L:1-1$L:6-3(<eval>:6)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:646)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.internal.objects.NativeFunction.call(NativeFunction.java:192)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$356$464391AAA$\^eval\_.L:1-1$L:15-5(<eval>:15)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:646)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.internal.objects.NativeFunction.call(NativeFunction.java:192)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$23$427195AAAAAAA$\^eval\_.L:1-1$L:14-3(<eval>:14)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$22$406298AAAAAAA$\^eval\_.L:1-1$L:13-17(<eval>:13)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$21$409242AAAAAAA$\^eval\_.L:1-1$L:13-19(<eval>:13)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$20$277993AAAAAAA$\^eval\_.L:1-1$L:9-7(<eval>:9)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$19$279372AAAAAAA$\^eval\_.L:1-1$L:9-8(<eval>:9)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$18$282286AAAAAAA$\^eval\_.L:1-1$L:9-9(<eval>:9)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$16$200937AAAAAAA$\^eval\_.:scopeCall(<eval>)
at jdk.nashorn.internal.scripts.Script$Recompilation$16$200937AAAAAAA$\^eval\_.L:1-1$L:7-3(<eval>:7)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$15$273814AAAAAAA$\^eval\_.L:1-1$L:9-6(<eval>:9)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$14$233503AAAAAAA$\^eval\_.L:1-1$L:8-2(<eval>:8)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$10$93534AAAAAAA$\^eval\_.:scopeCall(<eval>)
at jdk.nashorn.internal.scripts.Script$Recompilation$10$93534AAAAAAA$\^eval\_.L:1-1$L:3-12(<eval>:3)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$641A$\^eval\_.L:1-1$e$s$L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$8$91457A$\^eval\_.L:1-1$L:3-11$L:3(<eval>:3)
at jdk.nashorn.internal.scripts.Script$Recompilation$7$91439AAAAAAA$\^eval\_.L:1-1$L:3-11(<eval>:3)
at jdk.nashorn.internal.scripts.Script$Recompilation$6$396AA$\^eval\_.L:1-1$e$s(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$5$380AAA$\^eval\_.L:1-1$e(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$2$329$\^eval\_.L:1-1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$Recompilation$1$12A$\^eval\_.L:1(<eval>:1)
at jdk.nashorn.internal.scripts.Script$\^eval\_.:program(<eval>:1)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:640)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:446)
Caused by: jdk.nashorn.internal.runtime.ParserException: empty range in char class
at jdk.nashorn.internal.runtime.regexp.RegExp.throwParserException(RegExp.java:161)
at jdk.nashorn.internal.runtime.regexp.JoniRegExp.<init>(JoniRegExp.java:84)
at jdk.nashorn.internal.runtime.regexp.JoniRegExp$Factory.compile(JoniRegExp.java:104)
at jdk.nashorn.internal.runtime.regexp.RegExpFactory.create(RegExpFactory.java:92)
at jdk.nashorn.internal.objects.NativeRegExp.<init>(NativeRegExp.java:84)
What's wrong? Can anyone help please.
回答1:
This is likely the Nashorn version of this: https://github.com/babel/babel/issues/340
You'll need to ensure that file is loaded with the proper charset, UTF-8
, so that it can be properly interpreted.
来源:https://stackoverflow.com/questions/32972054/empty-range-in-char-class-in-eval-when-trying-to-run-browser-js-on-nashorn