Any way to use JSImportGenerator in another generator library? #87346
-
I'm currently figuring how to port my JS interop library to the new JS iterop API introduced in .NET 7 and have an issue with the source generators used there. I'm using source generator myself to generate the JS bindings based on C# interfaces, but the new interop also uses a generator for Is this by design that source generators in general are not meant to be chained or consumed by other generators or I'm missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
cc @pavelsavara |
Beta Was this translation helpful? Give feedback.
-
I think it is by design, yes. Mainly because source generators were never able to see the output of each other as that would certainly create more problems than solve. Now the "chaining" can happen if source generator itself is designed as 2 parts: Library( analyze stage, IR stage) and Emitter (write text based on IR). I don't think Emitter can be generally reused as it is just "write some text to the output based on some IR". Obviously whacky string manipulations can come to mind but I don't think it is a good way. But I think the analyze and IR can be reused as it is just a library basically. It is all based on the design of a particular SG. |
Beta Was this translation helpful? Give feedback.
-
For generating JS/TS, there is relevant discussion in dotnet/roslyn#57608, so far it seems to say use MSBuild target and run Roslyn again and read the AST. I didn't explore deeper how to do that. Small demo would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
Making NuGet package out of generators would force us to keep backward compatible API. And possibly generate more stable code which could be wrapped/extended. I think we currently don't have bandwidth for that in my team.
|
Beta Was this translation helpful? Give feedback.
We have long term plans to ship the core of the interop generators as a library. We can include the JS generator infra as well. Probably .NET 9 at the earliest though.