-
Notifications
You must be signed in to change notification settings - Fork 321
Expand file tree
/
Copy pathFable.Core.Util.fs
More file actions
99 lines (76 loc) · 3.11 KB
/
Fable.Core.Util.fs
File metadata and controls
99 lines (76 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
namespace Fable.Core
open System
[<AutoOpen>]
module Util =
/// Used to indicate that a member is only implemented in the native target language
let inline nativeOnly<'T> : 'T =
// try/catch is just for padding so it doesn't get optimized
try failwith "You've hit dummy code used for Fable bindings. This probably means you're compiling Fable code to .NET by mistake, please check."
with ex -> raise ex
/// Alias of nativeOnly
let inline jsNative<'T> : 'T = nativeOnly<'T>
module Experimental =
/// Reads the name of an identifier, a property or a type
let inline nameof(expr: 'a): string = nativeOnly
/// Like nameof but also returns the expression as second element of the tuple
let inline nameof2(expr: 'a): string * 'a = nativeOnly
/// Reads the name of a property or a type from the lambda body
let inline nameofLambda(f: 'a -> 'b): string = nativeOnly
/// Reads the names of an access path from the lambda body. E.g (fun x -> x.foo.bar) gives [|"foo"; "bar"|]
let inline namesofLambda(f: 'a -> 'b): string[] = nativeOnly
/// Reads the case name and field count of a simple match: `casenameWithFieldCount(function Foo _ -> true | _ -> false)`
let casenameWithFieldCount<'T> (f: 'T -> bool): string * int = nativeOnly
/// Reads the case name and field index of a simple match: `casenameWithFieldIndex(function Bar(_,i) -> i | _ -> failwith "")`
let casenameWithFieldIndex<'T, 'O> (f: 'T -> 'O): string * int = nativeOnly
module Testing =
type Assert =
static member AreEqual(actual: 'T, expected: 'T, ?msg: string): unit = nativeOnly
static member NotEqual(actual: 'T, expected: 'T, ?msg: string): unit = nativeOnly
module Reflection =
open FSharp.Reflection
let isUnion (x: obj): bool =
#if FABLE_COMPILER
nativeOnly
#else
FSharpType.IsUnion(x.GetType())
#endif
let isRecord (x: obj): bool =
#if FABLE_COMPILER
nativeOnly
#else
FSharpType.IsRecord(x.GetType())
#endif
let getCaseTag (x: obj): int =
#if FABLE_COMPILER
nativeOnly
#else
let uci, _ = FSharpValue.GetUnionFields(x, x.GetType())
uci.Tag
#endif
let getCaseName (x: obj): string =
#if FABLE_COMPILER
nativeOnly
#else
let uci, _ = FSharpValue.GetUnionFields(x, x.GetType())
uci.Name
#endif
let getCaseFields (x: obj): obj[] =
#if FABLE_COMPILER
nativeOnly
#else
FSharpValue.GetUnionFields(x, x.GetType()) |> snd
#endif
module Compiler =
/// Compiler full version as string
let version: string = ""
/// Compiler major/minor version as number (e.g. 3.6)
let majorMinorVersion: float = 0.
/// Indicates if compiler is running in debug mode
let debugMode: bool = false
/// Indicates if Fable will compile numeric arrays as JS typed arrays
let typedArrays: bool = false
/// Extension used for generated files
let extension: string = ".fs.js"
/// In watch compilations, indicates if the file is being recompiled
/// not because of a direct change, but because a dependency has changed
let triggeredByDependency: bool = false