Skip to content

Commit 2730fec

Browse files
authored
[Oxpecker.Solid][Docs] Add documentation to compiler plugin (Lanayx#47)
* Documentation while groking the compiler plugin * opinionated clarification of op flow * Revert "opinionated clarification of op flow" This reverts commit 1a1df72.
1 parent b76ce74 commit 2730fec

File tree

1 file changed

+63
-15
lines changed

1 file changed

+63
-15
lines changed

src/Oxpecker.Solid.FablePlugin/Library.fs

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,36 @@ open Fable.AST
66
open Fable.AST.Fable
77

88
[<assembly: ScanForPlugins>]
9-
do ()
9+
do () // Prompts fable to utilise this plugin
1010

1111
module internal rec AST =
12+
/// <summary>
13+
/// AST Representation for a JSX Attribute/property. Tuple of name and value
14+
/// </summary>
1215
type PropInfo = string * Expr
16+
/// <summary>
17+
/// List of AST property name value pairs
18+
/// </summary>
1319
type Props = PropInfo list
1420

1521
type TagSource =
1622
| AutoImport of tagName: string
1723
| 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>
1928
type TagInfo =
2029
| WithChildren of tagName: TagSource * propsAndChildren: CallInfo * range: SourceLocation option
2130
| NoChildren of tagName: TagSource * props: Expr list * range: SourceLocation option
2231
| Combined of tagName: TagSource * props: Expr list * propsAndChildren: CallInfo * range: SourceLocation option
2332

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>
2539
let (|CallTag|_|) condition =
2640
function
2741
| Call(Import(importInfo, LambdaType(_, DeclaredType(typ, _)), _), callInfo, _, range) when condition importInfo ->
@@ -43,13 +57,19 @@ module internal rec AST =
4357
AutoImport finalTagName
4458
Some(tagImport, callInfo, range)
4559
| _ -> None
46-
60+
/// <summary>
61+
/// Pattern matches expressions to Tags calls without children
62+
/// </summary>
63+
/// <returns><c>TagInfo.NoChildren</c></returns>
4764
let (|TagNoChildren|_|) (expr: Expr) =
4865
let condition = _.Selector.EndsWith("_$ctor")
4966
match expr with
5067
| CallTag condition (tagName, _, range) -> Some(tagName, range)
5168
| _ -> None
52-
69+
/// <summary>
70+
/// Pattern matches expressions to Tag calls with children
71+
/// </summary>
72+
/// <returns><c>TagInfo.WithChildren</c></returns>
5373
let (|TagWithChildren|_|) (expr: Expr) =
5474
let condition =
5575
fun importInfo ->
@@ -58,22 +78,34 @@ module internal rec AST =
5878
match expr with
5979
| CallTag condition tagCallInfo -> Some tagCallInfo
6080
| _ -> 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>
6285
let (|LetElement|_|) =
6386
function
6487
| Let({ Name = name }, _, _) when name.StartsWith("element") -> Some()
6588
| _ -> None
66-
89+
/// <summary>
90+
/// Pattern matches <c>let</c> bindings for Tags with children
91+
/// </summary>
92+
/// <returns><c>TagInfo.WithChildren</c></returns>
6793
let (|LetTagWithChildren|_|) =
6894
function
6995
| Let(_, TagWithChildren(tagName, callInfo, range), _) -> TagInfo.WithChildren(tagName, callInfo, range) |> Some
7096
| _ -> 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>
72101
let (|LetTagNoChildrenWithProps|_|) =
73102
function
74103
| Let(_, TagNoChildren(tagName, range), Sequential exprs) -> TagInfo.NoChildren(tagName, exprs, range) |> Some
75104
| _ -> 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>
77109
let (|CallTagNoChildrenWithHandler|_|) (expr: Expr) =
78110
match expr with
79111
| Call(Import(importInfo, _, _),
@@ -98,25 +130,36 @@ module internal rec AST =
98130
range) when importInfo.Selector.StartsWith("HtmlElementExtensions_") -> // on, attr, data, ref
99131
TagInfo.NoChildren(tagName, expr :: props, range) |> Some
100132
| _ -> 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>
102137
let (|LetTagNoChildrenNoProps|_|) =
103138
function
104139
| Let(_, TagNoChildren(tagName, range), _) -> TagInfo.NoChildren(tagName, [], range) |> Some
105140
| _ -> 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>
107145
let (|TextNoSiblings|_|) =
108146
function
109147
| Lambda({ Name = cont }, TypeCast(textBody, Unit), None) when cont.StartsWith("cont") -> Some textBody
110148
| _ -> 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>
112153
let (|LibraryTagImport|_|) (expr: Expr) =
113154
match expr with
114155
| Call(Import({ Kind = UserImport false }, Any, _) as imp, { Tags = [ "new" ] }, DeclaredType(typ, []), range) when
115156
typ.FullName.StartsWith("Oxpecker.Solid")
116157
->
117158
Some(imp, range)
118159
| _ -> None
119-
160+
/// <summary>
161+
/// Plugin type declaration for JSX Element
162+
/// </summary>
120163
let jsxElementType =
121164
Type.DeclaredType(
122165
ref = {
@@ -125,7 +168,9 @@ module internal rec AST =
125168
},
126169
genericArgs = []
127170
)
128-
171+
/// <summary>
172+
/// Plugin import declaration for JSX <c>create</c>
173+
/// </summary>
129174
let importJsxCreate =
130175
Import(
131176
info = {
@@ -453,7 +498,10 @@ module internal rec AST =
453498
range = range
454499
)
455500

456-
501+
/// <summary>
502+
/// Registers a function as a SolidComponent for transformation by
503+
/// the <c>Oxpecker.Solid.FablePlugin</c>
504+
/// </summary>
457505
type SolidComponentAttribute() =
458506
inherit MemberDeclarationPluginAttribute()
459507

0 commit comments

Comments
 (0)