Skip to content

Commit 1d5efab

Browse files
committed
feat: add @deprecated supports
[converter][web]
1 parent 31fe4e0 commit 1d5efab

File tree

11 files changed

+109
-18
lines changed

11 files changed

+109
-18
lines changed

src/Glutinum.Converter/FsharpAST.fs

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ type FSharpAttribute =
179179
| ImportAll of moduleName: string
180180
| Erase
181181
| AllowNullLiteral
182+
| Obsolete of string option
182183
| StringEnum of Fable.Core.CaseRules
183184
| CompiledName of string
184185
| RequireQualifiedAccess

src/Glutinum.Converter/GlueAST.fs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type GlueComment =
1919
| Summary of string list
2020
| Returns of string
2121
| Param of GlueCommentParam
22+
| Deprecated of string option
2223
| Remarks of string
2324

2425
type GlueParameter =

src/Glutinum.Converter/Printer.fs

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ let private attributeToText (fsharpAttribute: FSharpAttribute) =
109109
| FSharpAttribute.EmitSelf -> "[<Emit(\"$0\")>]"
110110
| FSharpAttribute.ParamArray -> "[<ParamArray>]"
111111
| FSharpAttribute.Interface -> "[<Interface>]"
112+
| FSharpAttribute.Obsolete message ->
113+
match message with
114+
| Some message -> $"[<Obsolete(\"%s{message}\")>]"
115+
| None -> "[<Obsolete>]"
112116

113117
let private printInlineAttribute
114118
(printer: Printer)

src/Glutinum.Converter/Reader/FunctionDeclaration.fs

+10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ let readFunctionDeclaration
7474
|> GlueComment.Param
7575
|> Some
7676

77+
| Ts.SyntaxKind.JSDocDeprecatedTag ->
78+
match tag.comment with
79+
| Some comment ->
80+
ts.getTextOfJSDocComment comment
81+
|> GlueComment.Deprecated
82+
|> Some
83+
// We want to keep the deprecated tag even if there is no comment
84+
// as it is still useful information
85+
| None -> GlueComment.Deprecated None |> Some
86+
7787
| Ts.SyntaxKind.JSDocTag ->
7888
match tag.tagName.getText () with
7989
| "remarks" ->

src/Glutinum.Converter/Transform.fs

+49-18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module rec Glutinum.Converter.Transform
33
open Fable.Core
44
open Glutinum.Converter.FSharpAST
55
open Glutinum.Converter.GlueAST
6+
open System
67

78
// Not really proud of this implementation, but I was not able to make it in a
89
// pure functional way, using a Tree structure or something similar
@@ -88,23 +89,47 @@ let private sanitizeNameAndPushScope
8889
(name, context)
8990

9091
let private transformComment (comment: GlueAST.GlueComment list) =
91-
comment
92-
|> List.map (fun comment ->
93-
match comment with
94-
| GlueComment.Summary summary -> FSharpXmlDoc.Summary summary
95-
| GlueComment.Returns returns -> FSharpXmlDoc.Returns returns
96-
| GlueComment.Param param ->
97-
let content =
98-
param.Content
99-
|> Option.map (fun content ->
100-
content.TrimStart().TrimStart('-').TrimStart()
101-
)
102-
|> Option.defaultValue ""
92+
let deprecated, others =
93+
comment
94+
|> List.partition (
95+
function
96+
| GlueComment.Deprecated _ -> true
97+
| _ -> false
10398

104-
({ Name = param.Name; Content = content }: FSharpCommentParam)
105-
|> FSharpXmlDoc.Param
106-
| GlueComment.Remarks remarks -> FSharpXmlDoc.Remarks remarks
107-
)
99+
)
100+
101+
let obsoleteAttributes =
102+
deprecated
103+
|> List.map (
104+
function
105+
| GlueComment.Deprecated content -> FSharpAttribute.Obsolete content
106+
| _ -> failwith "Should not happen"
107+
)
108+
109+
let others =
110+
others
111+
|> List.map (fun comment ->
112+
match comment with
113+
| GlueComment.Deprecated _ -> failwith "Should not happen"
114+
| GlueComment.Summary summary -> FSharpXmlDoc.Summary summary
115+
| GlueComment.Returns returns -> FSharpXmlDoc.Returns returns
116+
| GlueComment.Param param ->
117+
let content =
118+
param.Content
119+
|> Option.map (fun content ->
120+
content.TrimStart().TrimStart('-').TrimStart()
121+
)
122+
|> Option.defaultValue ""
123+
124+
({ Name = param.Name; Content = content }: FSharpCommentParam)
125+
|> FSharpXmlDoc.Param
126+
| GlueComment.Remarks remarks -> FSharpXmlDoc.Remarks remarks
127+
)
128+
129+
{|
130+
ObsoleteAttributes = obsoleteAttributes
131+
Others = others
132+
|}
108133

109134
let private transformLiteral (glueLiteral: GlueLiteral) : FSharpLiteral =
110135
match glueLiteral with
@@ -351,8 +376,14 @@ let private transformExports
351376
| GlueType.FunctionDeclaration info ->
352377
let name, context = sanitizeNameAndPushScope info.Name context
353378

379+
let xmlDocInfo = transformComment info.Documentation
380+
354381
{
355-
Attributes = [ FSharpAttribute.Import(info.Name, "module") ]
382+
Attributes =
383+
[
384+
FSharpAttribute.Import(info.Name, "module")
385+
yield! xmlDocInfo.ObsoleteAttributes
386+
]
356387
Name = name
357388
OriginalName = info.Name
358389
Parameters =
@@ -364,7 +395,7 @@ let private transformExports
364395
IsStatic = true
365396
Accessor = None
366397
Accessibility = FSharpAccessibility.Public
367-
XmlDoc = transformComment info.Documentation
398+
XmlDoc = xmlDocInfo.Others
368399
}
369400
|> FSharpMember.Method
370401
|> List.singleton

src/Glutinum.Web/Pages/Editors.FSharpAST.FSharpASTViewer.fs

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ type FSharpASTViewer =
8585

8686
| FSharpAttribute.Interface -> ASTViewer.renderValueOnly "Interface"
8787

88+
| FSharpAttribute.Obsolete message ->
89+
ASTViewer.renderNode "Obsolete" [
90+
ASTViewer.renderKeyValueOption "Message" id message
91+
]
92+
8893
static member private Attributes(attributes: FSharpAttribute list) =
8994
attributes
9095
|> List.map FSharpASTViewer.FSharpAttribute

src/Glutinum.Web/Pages/Editors.GlueAST.GlueASTViewer.fs

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ type GlueASTViewer =
9191
| GlueComment.Remarks content ->
9292
[ ASTViewer.renderValueOnly content ]
9393
|> ASTViewer.renderNode "Remarks"
94+
95+
| GlueComment.Deprecated content ->
96+
ASTViewer.renderKeyValueOption "Deprecated" id content
9497
)
9598
|> ASTViewer.renderNode "Documentation"
9699

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* @deprecated
3+
*/
4+
declare function isInlineTag(tagName: string): boolean;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module rec Glutinum
2+
3+
open Fable.Core
4+
open Fable.Core.JsInterop
5+
open System
6+
7+
[<Erase>]
8+
type Exports =
9+
[<Import("isInlineTag", "module"); Obsolete>]
10+
static member isInlineTag (tagName: string) : bool = nativeOnly
11+
12+
(***)
13+
#r "nuget: Fable.Core"
14+
(***)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* @deprecated Use the new base class instead.
3+
*/
4+
declare function isInlineTag(tagName: string): boolean;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module rec Glutinum
2+
3+
open Fable.Core
4+
open Fable.Core.JsInterop
5+
open System
6+
7+
[<Erase>]
8+
type Exports =
9+
[<Import("isInlineTag", "module"); Obsolete("Use the new base class instead.")>]
10+
static member isInlineTag (tagName: string) : bool = nativeOnly
11+
12+
(***)
13+
#r "nuget: Fable.Core"
14+
(***)

0 commit comments

Comments
 (0)