Yantra (Machine in Sanskrit) is a Managed JavaScript Engine for .NET (Core and Standard 2) written completely in C#.
Node and V8's tight C++ intgration makes it difficult to write plugins, resulting in unresolved bugs and very complicated source code structure.
C# offers platform independent near native performance, so YantraJS is designed to replace parts of Node that requires high performance.
Multi threaded shared object cache are difficult to achieve in Node, but YantraJS offers smooth connectivity between C# and JavaScript as both objects live under same runtime.
| Name | Package |
|---|---|
| YantraJS (With CSX Module Support) | |
| YantraJS.Core (Compiler) | |
| YantraJS.ExpressionCompiler (IL Compiler) | |
| Yantra JS.ModuleExtensions (Fluent interface for module registration) |
- Compiles JavaScript to .Net Assembly
- Strict Mode Only JavaScript*
- Arrow functions
- Classes
- Class members
- Enhanced object literals
- Template strings and tagged templates
- Destructuring
letconst- Map, Set, WeakMap, WeakSet
- Symbols
- Subclassable built-ins
- Binary and Octal literals
- Module support
- Null coalesce
- Optional property chain
identifier?.[],identifier?.(,identifier?.identifier - Rest, Default and Spread Parameters
- Generators, iterators, for..of
- Async/Await
- Optional parameters
- Tail call optimization
- Many ES5 + ES6 features
- CommonJS & ES6 Module Support
- Decimal support, number with
0.2mprefix has a new literal type called decimal,typeof 0.2mis'decimal'. - Easily marshal CLR Object to JavaScript and other way around
- CSX Module support
- Mixed module system, YantraJS supports
requireandimport. - Explicit resource management with
usingandawait usingkeywords. - AOT ready (Source Generators have been used for loading Runtime Objects).
* Most JavaScript today is available in strict mode, we do not feel any need to support non strict mode as modules are strict by default.
Currently YantraJS supports Both CommonJS and ES modules without any extra work, with little trick, module resolution is node like. Module loader loads module asynchronously, so import will work without any extra effort. However, require will run AsyncPump to wait till the module is loaded correctly. Unless you do some multithreading, mixed modules will not lead to any deadlocks.
- Module names may or may not have extensions.
- File will be loaded if same name exists on disk.
- Engine will try to load
${name}.csxfile, if it exists it will load the module. - Engine will then try to load
${name}.jsfile, if it exits it will load the module. - Otherwise it will travel to parent directory and search modules in
node_modulesfolder in exact same order defined earlier.
As we often have difficulty in writing cross environment scripts (browser and process such as node), we want to first implement basic common features on both.
- Next in plan is Network API, Simple
fetchis available inYantraContext, we will focus on adding Stream API. - Unified API to access system resources through JavaScript modules that dynamically utilize .NET objects.
- Add node modules compatibility.
- V8 Protocol Implementation is in progress.
We recommend using Github Discussion on this repository for any question regarding this product.
- We are thankful to authors of Jurassic (we have incorporated number parser, promise and some unit tests from Jurassic.) https://github.com/paulbartrum/jurassic
- We are thankful to authors of EsprimaDotNet, we initially built prototype over EsprimaDotNet, but we chose to build our parser/scanner from scratch to support token spans. https://github.com/sebastienros/esprima-dotnet
- We are thankful to author of ILPack (we have incorporated saving IL to Assembly from this library.) https://github.com/Lokad/ILPack