Hi, I develop WebSharper. Good question!
Roughly the compilation looks like this:
a.dll: a.fs b.fs c.fs
fsc ...
a.dll.js: a.dll
WebSharper.exe ..
When functions are annotated with [<JavaScript>]
, which is an alias for [<ReflectedDefinition>]
, the F# compiler does not only compile these functions to .NET IL, but also stores the representation of their syntax in the DLL metadata. This representation has type Quotations.Expr
and can be recovered by reflection. Have a look at Quotations.DerivedPatterns.MethodWithReflectedDefinition
.
WebSharper is therefore a source to source translator, and it is pretty direct (preserves lambdas, for example). In WebSharper 2.0 we have an intermediate Scheme-like language, but that is only there to help optimize the generated code.