paulbartrum / jurassic

A .NET library to parse and execute JavaScript code.
MIT License
868 stars 121 forks source link

Automatic conversion from C# to Jurassic JavaScript #225

Open immitev opened 9 months ago

immitev commented 9 months ago

There is a relatively popular open-source conversion library from C# to VB.NET https://github.com/icsharpcode/CodeConverter . I wonder how easy or complex will be to have something similar for C# to Jurassic JS?

paulbartrum commented 9 months ago

It's probably not too difficult to convert the core C# language to JavaScript. (Harder than C# to VB.NET mind you.) But converting the .NET base class libraries (BCL) to the equivalent JavaScript standard library functions is basically an impossible task, because a) the BCL is huge, and b) there's lots of BCL functionality that simply doesn't exist in JavaScript. It might be possible if you restrict yourself to a subset of the BCL though.

immitev commented 9 months ago

Indeed, the BCL is huge. I guess something more manageable will be as a default to use the BCL types/classes directly in the generated Jurassic code, and try to convert to pure JavaScript only some basic stuff.

Probably the code translator should be able to generate working JS code in plenty of scenarios, assuming there is available a helper function getClrType that can be used like this:

var File = getClrType('System.IO.File');
File.WriteAllText('C:\temp\test.txt', 'test');