Skip to content

Commit

Permalink
Fix #2302: Fable.JsonProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Dec 2, 2020
1 parent a377994 commit 74a47b7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Fable.Cli/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ let rec startCompilation (changes: Set<string>) (state: State) = async {
logs, deps
| Error e ->
let log = Log.MakeError(e.Exception.Message, fileName=e.File, tag="EXCEPTION")
Log.verbose(lazy e.Exception.StackTrace)
Array.append logs [|log|], deps)

return logs, watchDependencies, { state with FableCompilationMs = ms }
Expand Down
4 changes: 4 additions & 0 deletions src/Fable.Transforms/FSharp2Fable.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ type FsEnt(ent: FSharpEntity) =
match ent.Namespace with
| Some ns -> ns + "." + ent.CompiledName
| None -> ent.CompiledName
#if !FABLE_COMPILER
| None when ent.IsProvided ->
ent.LogicalName
#endif
| None ->
match ent.TryFullName with
| Some n -> n
Expand Down
1 change: 1 addition & 0 deletions tests/Main/Fable.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Expecto" Version="5.1.2" />
<PackageReference Include="AltCover" Version="5.3.675" />
<PackageReference Include="Fable.JsonProvider" Version="1.0.1" />
<PackageReference Include="FSharp.Core" Version="5.0.0" />
<PackageReference Include="FSharp.Data.Adaptive" Version="1.0.1" />
<PackageReference Include="FSharp.UMX" Version="1.0.0" />
Expand Down
52 changes: 52 additions & 0 deletions tests/Main/MiscTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,45 @@ open Fable.Core
open Util.Testing
open Util2.Extensions

let [<Literal>] LITERAL_JSON = """{
"widget": {
"debug": true,
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": [{ "width": 36, "height": 40 }],
"style": "bold",
"name": "text1",
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}
}"""

let ANOTHER_JSON = """{
"widget": {
"debug": false,
"text": {
"data": "lots of",
"size": [{"width": 5}, { "height": 80 }],
"vOffset": 500
}
}
}"""

// We can have aliases with same name in same file #1662
module One =
type Id = System.Guid
Expand Down Expand Up @@ -388,10 +427,23 @@ type Order =
quantity : int<kg>
}

#if !FABLE_COMPILER_JS
type LiteralJson = Fable.JsonProvider.Generator<LITERAL_JSON>
#endif

let tests =
testList "Miscellaneous" [

#if FABLE_COMPILER
#if !FABLE_COMPILER_JS
testCase "Fable.JsonProvider works" <| fun _ ->
let parsed = LiteralJson(ANOTHER_JSON)
parsed.widget.debug |> equal false
parsed.widget.text.data |> equal "lots of"
parsed.widget.text.size.[1].height |> equal 80.
parsed.widget.text.vOffset |> equal 500.
#endif

testCase "Can check compiler version with constant" <| fun _ ->
let mutable x = 0
#if FABLE_COMPILER
Expand Down

0 comments on commit 74a47b7

Please sign in to comment.