Skip to content

Commit

Permalink
Minimal support for TypeQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime committed Dec 4, 2023
1 parent f1cbc09 commit eebef14
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Glutinum.Converter/Read.fs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,20 @@ let private readTypeNode
}
|> GlueType.FunctionType

| Ts.SyntaxKind.TypeQuery ->
let typeNodeQuery = typeNode :?> Ts.TypeQueryNode

let typ = checker.getTypeAtLocation typeNodeQuery

if TypeFlags.hasFlag typ.flags Ts.TypeFlags.Object then
{
Name = typ.symbol.name
Constructors = []
Members = []
}
|> GlueType.ClassDeclaration
else
GlueType.Primitive GluePrimitive.Any

| _ -> failwith $"readTypeNode: Unsupported kind {typeNode.kind}"
| None -> GlueType.Primitive GluePrimitive.Unit
Expand Down
9 changes: 8 additions & 1 deletion src/Glutinum.Converter/Transform.fs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ let rec private transformType (glueType: GlueType) : FSharpType =
| GlueType.Array glueType ->
transformType glueType |> FSharpType.ResizeArray

| GlueType.ClassDeclaration _
| GlueType.ClassDeclaration classDeclaration ->
({
Name = classDeclaration.Name
FullName = classDeclaration.Name
}
: FSharpTypeReference)
|> FSharpType.TypeReference

| GlueType.ModuleDeclaration _
| GlueType.IndexedAccessType _
| GlueType.Literal _
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/typeQuery/class.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class DayJs {
constructor()
}

export type PluginFunc = (c: typeof DayJs) => void
22 changes: 22 additions & 0 deletions tests/specs/typeQuery/class.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module rec Glutinum

(***)
#r "nuget: Fable.Core"
(***)

open Fable.Core
open System

[<Erase>]
type Exports =
[<Import("DayJs", "module"); EmitConstructor>]
static member DayJs () : DayJs = nativeOnly

[<AllowNullLiteral>]
type DayJs =
interface end

[<AllowNullLiteral>]
type PluginFunc =
[<Emit("$0($1...)")>]
abstract member Invoke: c: DayJs -> unit

0 comments on commit eebef14

Please sign in to comment.