YantraJS (Machine in Sanskrit)
Please visit GitHub repo at YantraJS
YantraJS
Yantra (Machine in Sanskrit) is a Managed JavaScript Engine for .NET Standard written completely in C#.
NuGet
Name |
Package |
YantraJS (With CSX Module Support) |
 |
YantraJS.Core (Compiler) |
 |
YantraJS.ExpressionCompiler (IL Compiler) |
 |
Yantra JS.ModuleExtensions (Fluent interface for module registration) |
 |
Features
- Compiles JavaScript to .Net Assembly
- Strict Mode Only JavaScript*
- Arrow functions
- Classes
- Class members
- Enhanced object literals
- Template strings and tagged templates
- Destructuring
let
const
- 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
- Easily marshal CLR Object to JavaScript and other way around
- CSX Module support
- Mixed module system, YantraJS supports
require
and import
.
*
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.
Mixed modules
Currently YantraJS supports Both CommonJS and ES modules without any extra work, with little trick, module resolution is node like
, it does not take .js
extension into account. We are trying to make a workaround and we will update the product soon. 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, this may lead to some deadlocks.
Mixed Modules Roadmap
- Detect the loading order, first check if the same named file exists, if yes, load it, allow auto appending extension in the configuration, so module loader can load corresponding files accordingly.
- Create correct algorithm to resolve module name to support loading of CSX module in the mix. YantraJS supports loading module independent of the implementation. We can support other languages like python, php in the YantraJS. This is only possible to load modules without extension.
Documentation
- Introduction
- Expression Compiler
- JavaScript Engine
Discussions
We recommend using Github Discussion on this repository for any question regarding this product.
Special Thanks
- 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