dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
594 stars 52 forks source link

Make "UseJavaScriptSymbol": true the default for Proxy projects #1298

Closed Jand42 closed 1 year ago

Jand42 commented 1 year ago

This adds the JAVASCRIPT conditional compilation symbol so that #if JAVASCRIPT blocks are used.

WebSharper is translating Proxy projects only in a single pass, to generate JS code only, no .NET code generated. So there is no compilation time degradation from this.

On regular F# WebSharper projects, .NET and JS translation are done usually with a single F# parser+typecheck pass to save on compiler running time, for this reason "UseJavaScriptSymbol" setting should be enabled explicitly when you want to differentiate server/client code with a compilation symbol. (An alternative is using the WebSharper.JavaScript.Pervasives.IsClient constant - or just IsClient if you have open WebSharper.JavaScript in F#)

ALSO: this can introduce F# errors that are not present without the JAVASCRIPT symbol, make sure those are printed.

WebSharper's C# compiler currently runs a separate code parser, but maybe best to keep the explicit setting there too, bc this might change with new Roslyn features.