jurassic icon indicating copy to clipboard operation
jurassic copied to clipboard

{"SyntaxError: Expected an expression but found 'class' instead"}

Open sepehrbg opened this issue 5 years ago • 3 comments

When i am trying to execute a file of javascript, i am getting following error as it is containing a class. for other files which only contains functions it is not giving any errors, only for the file with javascript class it is throwing exception. here is the exception: {"SyntaxError: Expected an expression but found 'class' instead"} and here is my code:

        var scriptEngine = new ScriptEngine();
        scriptEngine.EnableDebugging = true;
        string console = "";
       scriptEngine.ExecuteFile(@"SQLProJSQueryFormatter.js");

Anybody can help??

sepehrbg avatar Mar 19 '20 10:03 sepehrbg

See https://github.com/paulbartrum/jurassic/blob/master/README.md class is a part of ECMAScript 6 that isn't supported yet. Your best bet is to transpile your script to ECMA 5.

eaglemc avatar Mar 29 '20 08:03 eaglemc

Hi, do you have any experience with transpiling? I tried to get this project working in jurassic: https://github.com/jpknoll/mjml-aspnetcore

It takes around 20ms to compile a small template and I thougt jurassic might be faster than a node service, but Just failed to get it transpile. Babel just doe not convert arrow functions.

SebastianStehle avatar Jun 09 '20 15:06 SebastianStehle

Not exactly. I've only done stuff with compiling TypeScript. The TypeScript compiler can handle arrow functions, but I'm not sure what it does if you give it a .js file instead of a .ts file as the input. However there is an --allowJs flag to let you do this, so maybe it would work?

eaglemc avatar Jun 09 '20 23:06 eaglemc