paulbartrum / jurassic

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

Has anyone written an app or script that uses this to convert TypeScript to CIL? #196

Open MappingSteve opened 3 years ago

MappingSteve commented 3 years ago

I think this means using VSCode to compile TS to JS, and then using this library to compile JS to CIL.

But I’m not sure how to put those two steps together into an automated process. Something like:

A post-build action that calls a small C# app that invokes this library?

Pointers to any example code that would fit into such a solution would be great. (I’ve never written a post-build action, so I’m fuzzy on details.)

I see examples in wiki that show how to execute a script. But I don’t want to immediately execute - I want to create CIL, that could be executed later, BUT might instead be fed into a static code analyzer. How do I store that CIL as an assembly? Goal is static analysis as if it were C# originally, including symbol references to/from existing C# code or libraries.

OR conversion from CIL into C# might also be a solution. An extra step, but then I could make a traditional C# project, so existing tools would all work.

(The big picture is for a dev shop that is mainly .NET, to write TS code for browser today, but be able to elevate it into .NET code, once .NET -> WASM is fully mature, assuming WASM eventually can do everything JS can, without performance issues. Might also allow us to use that code in our Xamarin apps, without maintaining two independent sources. The reason to not use C# to ts/js solutions, is that we are hiring/contracting js-stack web-trained devs for web projects. TS is acceptable to mandate, but dependence on .NET is not - I’m trying to loosely integrate the web work with ongoing C# mobile/tablet work. Would love .NET to be universal solution, but that isn’t viable yet. TS code is closer in style and robustness to our c# code base.)

eaglemc commented 3 years ago

It takes some work, but you can save the IL Jurassic generates as a DLL. See https://github.com/paulbartrum/jurassic/issues/176 or maybe https://github.com/paulbartrum/jurassic/issues/15 might be a starting point (that might be outdated...).

But generally this is not going to work the way you're hoping. Jurassic doesn't do anything by itself, you need C# classes for it to expose to your javascript. And a lot of stuff is resolved at runtime due to the nature of javascript, so I don't know if static code analysis would be able to do much.