core
core copied to clipboard
Read special type information (delegates, enums) with FCS/Roslyn
WebSharper has support for using some kinds of types that have no JavaScript attribute (these can be even from assemblies that are not compiled with WebSharper). These are:
- Delegates
- Enums
- F# unions, translated to plain JS objects
- F# records, translated to plain JS objects
This is currently done by the compiler on reflecting on the type. The references of the currently translated project are added to assembly resolution, this is also needed for supporting metaprogramming (macros/generators). However, this can fail if the assembly fails to load for any reason (for example a conflicting version, most notably FSharp.Core could cause problems, this is alleviated by #931).
It would be possible to look at these type shapes by just using information available in FCS/Roslyn. The architecture for this is already in place, just currently both compilers call the common function using reflection: https://github.com/dotnet-websharper/core/blob/master/src/compiler/WebSharper.Compiler.FSharp/ProjectReader.fs#L982