Skip to content

Commit

Permalink
#1075 add support for UseJavaScriptSymbol
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Nov 29, 2019
1 parent 5052671 commit bd1527d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/compiler/WebSharper.CSharp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ let rec compileMain (argv: string[]) =

wsArgs := SetScriptBaseUrl !wsArgs

if (!wsArgs).UseJavaScriptSymbol then
let cArgs = (!wsArgs).CompilerArgs
if cArgs |> Array.contains "-define:JAVASCRIPT" |> not then
wsArgs :=
{ !wsArgs with
CompilerArgs = Array.append cArgs [|"-define:JAVASCRIPT"|]
}

try
Compile !wsArgs
0
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/WebSharper.Compiler/CommandTools.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type WsConfig =
MinJSOutputPath : string option
SingleNoJSErrors : bool
ProxyTargetName : string option
UseJavaScriptSymbol : bool
}

member this.ProjectDir =
Expand Down Expand Up @@ -116,6 +117,7 @@ type WsConfig =
MinJSOutputPath = None
SingleNoJSErrors = false
ProxyTargetName = None
UseJavaScriptSymbol = false
}

static member ParseAnalyzeClosures(c: string) =
Expand Down Expand Up @@ -220,6 +222,8 @@ type WsConfig =
res <- { res with SingleNoJSErrors = getBool k v }
| "proxytargetname" ->
res <- { res with ProxyTargetName = Some (getString k v) }
| "usejavascriptsymbol" ->
res <- { res with UseJavaScriptSymbol = getBool k v }
| "$schema" -> ()
| _ -> failwithf "Unrecognized setting in wsconfig.json: %s" k
res
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/WebSharper.FSharp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ let Compile (config : WsConfig) (warnSettings: WarnSettings) =
| Some (_, _, m) -> Some m
| _ -> None
)

let compilerArgs =
if not config.UseJavaScriptSymbol || compilerArgs |> Array.contains "--define:JAVASCRIPT" then
compilerArgs
else
Array.append compilerArgs [|"--define:JAVASCRIPT"|]

let comp =
compiler.Compile(refMeta, compilerArgs, config, thisName)

Expand Down
3 changes: 2 additions & 1 deletion tests/ProxyProjectTest.Proxy/wsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Project": "Proxy",
"ProxyTargetName": "ProxyProjectTest"
"ProxyTargetName": "ProxyProjectTest",
"UseJavaScriptSymbol": true
}
9 changes: 8 additions & 1 deletion tests/ProxyProjectTest/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@

module ProxyProjectTest.Functions

let add x y = x + y
let add x y = x + y

let isJS() =
#if JAVASCRIPT
true
#else
false
#endif
1 change: 1 addition & 0 deletions tests/WebSharper.Tests/Basis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -581,5 +581,6 @@ let Tests =

Test "Proxy project" {
equal (ProxyProjectTest.Functions.add 1 2) 3
isTrue (ProxyProjectTest.Functions.isJS())
}
}

0 comments on commit bd1527d

Please sign in to comment.