Taritsyn / JavaScriptEngineSwitcher

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines. This library allows you to quickly and easily switch to using of another JavaScript engine.
Apache License 2.0
446 stars 49 forks source link

ChakraCore compatibility with ES6 modules #62

Open Zenexer opened 6 years ago

Zenexer commented 6 years ago

Is it possible to get ChakraCore to work with ES6 modules? I'm attempting to use it with ReactJS.NET, and I can't find a way around this error:

ReactScriptLoadException: Error while loading "js\components\Test.jsx": Compile error: Module import or export statement unexpected here
Line: 14
Column:1
React.ReactEnvironment.EnsureUserScriptsLoaded()
Taritsyn commented 6 years ago

ES6 modules are not supported by the JavaScript Engine Switcher library. I want to remind for what purpose the JavaScript Engine Switcher library was created:

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines (MSIE JavaScript Engine for .Net, Microsoft ClearScript.V8, Jurassic, Jint, ChakraCore and VroomJs). This library allows you to quickly and easily switch to using of another JavaScript engine.

Zenexer commented 6 years ago

Does that mean they are supported by the underlying .NET libraries (e.g., ClearScript.V8), and would therefore be usable if I interfaced with those directly? I've been scouring the web for resources and have found very few answers, unfortunately.

Taritsyn commented 6 years ago

I can not promise anything, but on weekend I'll try to investigate this problem.

Taritsyn commented 6 years ago

Hello, Paul!

I checked support of ES6 modules by JS engines, which are used in the JavaScript Engine Switcher. I was very surprised to learn that the Microsoft ClearScript.V8 and prerelease version of Jint do not support them. Support is available only in the ChakraCore (a lot of things need to implement yourself) and NiL.JS (so far very raw support and many errors).

To implement modules, at least two methods (EvaluateModule and ExecuteModule) must be added to the IJsEngine interface. Plus, need to provide hosting of modules: resolving paths and loading code from the file system. This is a large amount of work (for the most part research). Therefore, third version of the JavaScript Engine Switcher will be released without this functionality. While leave the implementation of this functionality for the future (fourth version).

Diaskhan commented 5 years ago

The case scenario!

I'am trying to make C# bundler via nodejs envirement! But all comes to One to use managed code and wrapper ?

@Taritsyn Is there possible to make some bundler in C# like webpack do it ? Analyze dependecies zipped and save to file ? How its possible to implement in C# world ?

Enterpise Scenarion When Developers write code on js! And Tooling budle them!

Taritsyn commented 5 years ago

@Diaskhan Hello! You can use the EmbedHostObject and EmbedHostType methods to pass .NET objects and types to script, but there are some limitations (for example, collections are not supported). Interop is still the weak side of this library.

If I were you, I would look at specialized libraries for working with Node.js: Edge.js or Microsoft.AspNetCore.NodeServices.