Skip to content

Commit 1908da1

Browse files
committed
feat: add support for UnknownKeyword
[converter][web]
1 parent c2714b9 commit 1908da1

File tree

11 files changed

+55
-1
lines changed

11 files changed

+55
-1
lines changed

src/Glutinum.Converter/FsharpAST.fs

+1
Original file line numberDiff line numberDiff line change
@@ -372,5 +372,6 @@ type FSharpType =
372372
| ThisType of typeName: string
373373
| Function of FSharpFunctionType
374374
| Class of FSharpClass
375+
| Object
375376

376377
type FSharpOutFile = { Name: string; Opens: string list }

src/Glutinum.Converter/GlueAST.fs

+3-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ type GlueType =
210210
| IntersectionType of GlueMember list
211211
| TypeLiteral of GlueTypeLiteral
212212
| OptionalType of GlueType
213+
| Unknown
213214

214215
member this.Name =
215216
match this with
@@ -245,4 +246,5 @@ type GlueType =
245246
| FunctionType _
246247
| TupleType _
247248
| OptionalType _ // TODO: Should we take the name of the underlying type and add option to it?
248-
| Discard -> "obj"
249+
| Discard
250+
| Unknown -> "obj"

src/Glutinum.Converter/Printer.fs

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ let private printAttributes
164164

165165
let rec private printType (fsharpType: FSharpType) =
166166
match fsharpType with
167+
| FSharpType.Object -> "obj"
167168
| FSharpType.Mapped info -> info.Name
168169
| FSharpType.Union info ->
169170
let cases =
@@ -733,6 +734,7 @@ let rec print (printer: Printer) (fsharpTypes: FSharpType list) =
733734

734735
| FSharpType.Mapped _
735736
| FSharpType.Primitive _
737+
| FSharpType.Object
736738
| FSharpType.TypeReference _
737739
| FSharpType.Option _
738740
| FSharpType.ResizeArray _

src/Glutinum.Converter/Reader/TypeNode.fs

+2
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ let readTypeNode
318318

319319
reader.ReadTypeOperatorNode typeOperatorNode
320320

321+
| Ts.SyntaxKind.UnknownKeyword -> GlueType.Unknown
322+
321323
| _ ->
322324
generateReaderError
323325
"type node"

src/Glutinum.Converter/Transform.fs

+15
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ let rec private transformType
123123
: FSharpType
124124
=
125125
match glueType with
126+
| GlueType.Unknown -> FSharpType.Object
127+
126128
| GlueType.Primitive primitiveInfo ->
127129
transformPrimitive primitiveInfo |> FSharpType.Primitive
128130

@@ -1258,6 +1260,18 @@ let private transformTypeAliasDeclaration
12581260
}
12591261
|> FSharpType.Interface
12601262

1263+
| GlueType.Unknown ->
1264+
({
1265+
Name = typeAliasName
1266+
Type = FSharpType.Object
1267+
TypeParameters =
1268+
transformTypeParameters
1269+
context
1270+
glueTypeAliasDeclaration.TypeParameters
1271+
}
1272+
: FSharpTypeAlias)
1273+
|> FSharpType.TypeAlias
1274+
12611275
| GlueType.ClassDeclaration _
12621276
| GlueType.Enum _
12631277
| GlueType.Interface _
@@ -1350,6 +1364,7 @@ let rec private transformToFsharp
13501364
| GlueType.Literal _
13511365
| GlueType.Variable _
13521366
| GlueType.Primitive _
1367+
| GlueType.Unknown
13531368
| GlueType.KeyOf _
13541369
| GlueType.Discard
13551370
| GlueType.TupleType _

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

+2
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ type FSharpASTViewer =
299299
(context: NodeContext<'Msg>)
300300
=
301301
match fsharpType with
302+
| FSharpType.Object -> ASTViewer.renderValueOnly "Object" context
303+
302304
| FSharpType.Interface interfaceInfo ->
303305
ASTViewer.renderNode
304306
"Interface"

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

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ type GlueASTViewer =
155155
(context: NodeContext<'Msg>)
156156
=
157157
match glueType with
158+
| GlueType.Unknown -> ASTViewer.renderValueOnly "Unknown" context
159+
158160
| GlueType.Variable variableInfo ->
159161
ASTViewer.renderNode
160162
"Variable"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type MyType = unknown
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module rec Glutinum
2+
3+
open Fable.Core
4+
open Fable.Core.JsInterop
5+
open System
6+
7+
type MyType =
8+
obj
9+
10+
(***)
11+
#r "nuget: Fable.Core"
12+
(***)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const version : unknown;
+14
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("version", "module")>]
10+
static member inline version: obj = nativeOnly
11+
12+
(***)
13+
#r "nuget: Fable.Core"
14+
(***)

0 commit comments

Comments
 (0)