@@ -6,22 +6,36 @@ open Fable.AST
6
6
open Fable.AST .Fable
7
7
8
8
[<assembly: ScanForPlugins>]
9
- do ()
9
+ do () // Prompts fable to utilise this plugin
10
10
11
11
module internal rec AST =
12
+ /// <summary>
13
+ /// AST Representation for a JSX Attribute/property. Tuple of name and value
14
+ /// </summary>
12
15
type PropInfo = string * Expr
16
+ /// <summary>
17
+ /// List of AST property name value pairs
18
+ /// </summary>
13
19
type Props = PropInfo list
14
20
15
21
type TagSource =
16
22
| AutoImport of tagName : string
17
23
| LibraryImport of imp : Expr
18
-
24
+ /// <summary>
25
+ /// DU which distinguishes between a user call instantiating the tag with children, without children (props only),
26
+ /// or with both children AND properties.
27
+ /// </summary>
19
28
type TagInfo =
20
29
| WithChildren of tagName : TagSource * propsAndChildren : CallInfo * range : SourceLocation option
21
30
| NoChildren of tagName : TagSource * props : Expr list * range : SourceLocation option
22
31
| Combined of tagName : TagSource * props : Expr list * propsAndChildren : CallInfo * range : SourceLocation option
23
32
24
-
33
+ /// <summary>
34
+ /// Pattern matches expressions for Tags calls.
35
+ /// </summary>
36
+ /// <param name="condition"><c>ImportInfo</c></param>
37
+ /// <remarks>Apostrophised tagnames are cleaned of the apostrophe during transpilation</remarks>
38
+ /// <returns><c>TagSource * CallInfo * SourceLocation option</c></returns>
25
39
let (| CallTag | _ |) condition =
26
40
function
27
41
| Call( Import( importInfo, LambdaType(_, DeclaredType( typ, _)), _), callInfo, _, range) when condition importInfo ->
@@ -43,13 +57,19 @@ module internal rec AST =
43
57
AutoImport finalTagName
44
58
Some( tagImport, callInfo, range)
45
59
| _ -> None
46
-
60
+ /// <summary>
61
+ /// Pattern matches expressions to Tags calls without children
62
+ /// </summary>
63
+ /// <returns><c>TagInfo.NoChildren</c></returns>
47
64
let (| TagNoChildren | _ |) ( expr : Expr ) =
48
65
let condition = _. Selector.EndsWith( " _$ctor" )
49
66
match expr with
50
67
| CallTag condition ( tagName, _, range) -> Some( tagName, range)
51
68
| _ -> None
52
-
69
+ /// <summary>
70
+ /// Pattern matches expressions to Tag calls with children
71
+ /// </summary>
72
+ /// <returns><c>TagInfo.WithChildren</c></returns>
53
73
let (| TagWithChildren | _ |) ( expr : Expr ) =
54
74
let condition =
55
75
fun importInfo ->
@@ -58,22 +78,34 @@ module internal rec AST =
58
78
match expr with
59
79
| CallTag condition tagCallInfo -> Some tagCallInfo
60
80
| _ -> None
61
-
81
+ /// <summary>
82
+ /// Pattern matches <c>let</c> bindings that start with <c>element</c>
83
+ /// </summary>
84
+ /// <returns><c>unit</c></returns>
62
85
let (| LetElement | _ |) =
63
86
function
64
87
| Let({ Name = name }, _, _) when name.StartsWith( " element" ) -> Some()
65
88
| _ -> None
66
-
89
+ /// <summary>
90
+ /// Pattern matches <c>let</c> bindings for Tags with children
91
+ /// </summary>
92
+ /// <returns><c>TagInfo.WithChildren</c></returns>
67
93
let (| LetTagWithChildren | _ |) =
68
94
function
69
95
| Let(_, TagWithChildren( tagName, callInfo, range), _) -> TagInfo.WithChildren( tagName, callInfo, range) |> Some
70
96
| _ -> None
71
-
97
+ /// <summary>
98
+ /// Pattern matches <c>let</c> bindings for Tags without children (but with props)
99
+ /// </summary>
100
+ /// <returns><c>TagInfo.NoChildren</c></returns>
72
101
let (| LetTagNoChildrenWithProps | _ |) =
73
102
function
74
103
| Let(_, TagNoChildren( tagName, range), Sequential exprs) -> TagInfo.NoChildren( tagName, exprs, range) |> Some
75
104
| _ -> None
76
-
105
+ /// <summary>
106
+ /// Pattern matches expressions (<c>let</c> or otherwise) for tags without children directly to Tag calls
107
+ /// </summary>
108
+ /// <returns><c>TagInfo.NoChildren</c></returns>
77
109
let (| CallTagNoChildrenWithHandler | _ |) ( expr : Expr ) =
78
110
match expr with
79
111
| Call( Import( importInfo, _, _),
@@ -98,25 +130,36 @@ module internal rec AST =
98
130
range) when importInfo.Selector.StartsWith( " HtmlElementExtensions_" ) -> // on, attr, data, ref
99
131
TagInfo.NoChildren( tagName, expr :: props, range) |> Some
100
132
| _ -> None
101
-
133
+ /// <summary>
134
+ /// Pattern matches <c>let</c> bindings for tags without children or props
135
+ /// </summary>
136
+ /// <returns><c>TagInfo.NoChildren</c></returns>
102
137
let (| LetTagNoChildrenNoProps | _ |) =
103
138
function
104
139
| Let(_, TagNoChildren( tagName, range), _) -> TagInfo.NoChildren( tagName, [], range) |> Some
105
140
| _ -> None
106
-
141
+ /// <summary>
142
+ /// Pattern matches expressions that are text in isolation (no siblings)
143
+ /// </summary>
144
+ /// <returns><c>Expr</c> of text</returns>
107
145
let (| TextNoSiblings | _ |) =
108
146
function
109
147
| Lambda({ Name = cont }, TypeCast( textBody, Unit), None) when cont.StartsWith( " cont" ) -> Some textBody
110
148
| _ -> None
111
-
149
+ /// <summary>
150
+ /// Matches expressions for tags that are imported from a namespace starting with <c>Oxpecker.Solid</c>
151
+ /// </summary>
152
+ /// <returns><c>Expr * SourceLocation</c></returns>
112
153
let (| LibraryTagImport | _ |) ( expr : Expr ) =
113
154
match expr with
114
155
| Call( Import({ Kind = UserImport false }, Any, _) as imp, { Tags = [ " new" ] }, DeclaredType( typ, []), range) when
115
156
typ.FullName.StartsWith( " Oxpecker.Solid" )
116
157
->
117
158
Some( imp, range)
118
159
| _ -> None
119
-
160
+ /// <summary>
161
+ /// Plugin type declaration for JSX Element
162
+ /// </summary>
120
163
let jsxElementType =
121
164
Type.DeclaredType(
122
165
ref = {
@@ -125,7 +168,9 @@ module internal rec AST =
125
168
},
126
169
genericArgs = []
127
170
)
128
-
171
+ /// <summary>
172
+ /// Plugin import declaration for JSX <c>create</c>
173
+ /// </summary>
129
174
let importJsxCreate =
130
175
Import(
131
176
info = {
@@ -453,7 +498,10 @@ module internal rec AST =
453
498
range = range
454
499
)
455
500
456
-
501
+ /// <summary>
502
+ /// Registers a function as a SolidComponent for transformation by
503
+ /// the <c>Oxpecker.Solid.FablePlugin</c>
504
+ /// </summary>
457
505
type SolidComponentAttribute () =
458
506
inherit MemberDeclarationPluginAttribute()
459
507
0 commit comments