Home
Insert
Update snippet 'WebSharper: compile a quotation to JavaScript'
Title
Description
This function compiles an F# quotation to a JavaScript string, or prints errors to stderr and returns None on failure.
Source code
open Microsoft.FSharp.Quotations open WebSharper type AR = IntelliFactory.Core.AssemblyResolution.AssemblyResolver module FE = WebSharper.Compiler.FrontEnd let compile (expr: Expr) : string option = let loader = FE.Loader.Create (AR.Create()) (eprintfn "%O") let options = { FE.Options.Default with References = List.map loader.LoadFile [ // These contain the JavaScript implementation for most of the standard library "WebSharper.Main.dll" "WebSharper.Collections.dll" "WebSharper.Control.dll" // Add any other assemblies used in the quotation... ] } let compiler = FE.Prepare options (eprintfn "%O") compiler.Compile expr |> Option.map (fun e -> e.ReadableJavaScript)
Tags
websharper
javascript
quotations
web
websharper
javascript
quotations
web
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update