Skip to content

Commit 153bca0

Browse files
committed
fix for static interfaces with non-static methods
1 parent 23e64e1 commit 153bca0

File tree

1 file changed

+73
-40
lines changed

1 file changed

+73
-40
lines changed

TS.fs

Lines changed: 73 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ let DumpCallBackFunctions flavor =
220220
|> Array.iter DumpCallBackFunction
221221

222222
let DumpEnums () =
223-
let DumpEnum (e: Browser.Enum) =
223+
let dumpEnum (e: Browser.Enum) =
224224
Pt.printl "declare var %s: string;" e.Name
225-
browser.Enums |> Array.iter DumpEnum
225+
browser.Enums |> Array.iter dumpEnum
226226

227227
/// Dump the properties and methods of a given interface
228228
let DumpMembers flavor prefix (dumpScope: DumpScope) (i:Browser.Interface) =
@@ -244,7 +244,7 @@ let DumpMembers flavor prefix (dumpScope: DumpScope) (i:Browser.Interface) =
244244
| _ -> DomTypeToTsType p.Type
245245
Pt.printl "%s%s: %s;" prefix p.Name pType
246246

247-
if dumpScope <> DumpScope.StaticOnly then
247+
if dumpScope <> StaticOnly then
248248
match i.Properties with
249249
| Some ps ->
250250
ps.Properties
@@ -490,52 +490,85 @@ let DumpInterface flavor (i:Browser.Interface) =
490490
Pt.printl ""
491491

492492
let DumpStaticInterface flavor (i:Browser.Interface) =
493-
Pt.resetIndent()
494-
DumpInterfaceDeclaration i
495-
Pt.increaseIndent ()
493+
// Some types are static types with non-static members. For example,
494+
// NodeFilter is a static method itself, however it has an "acceptNode" method
495+
// that expects the user to implement.
496+
let hasNonStaticMember =
497+
match i.Methods with
498+
| Some ms -> ms.Methods |> Array.exists (fun m -> m.Static.IsNone)
499+
| _ -> false
496500

497-
let prefix = ""
498-
DumpMembers flavor prefix DumpScope.StaticOnly i
499-
DumpConstants i
500-
DumpEventHandlers prefix i
501+
let dumpStaticInterfaceWithNSMembers () =
502+
Pt.resetIndent()
503+
DumpInterfaceDeclaration i
504+
Pt.increaseIndent ()
501505

502-
let dumpIndexers (ms:Browser.Method []) =
503-
ms
504-
|> Array.filter (fun m -> m.Getter.IsSome)
505-
|> Array.iter
506-
(fun m ->
507-
let indexer = m.Params.[0]
508-
Pt.printl "[%s: %s]: %s;"
509-
indexer.Name
510-
(DomTypeToTsType indexer.Type)
511-
(DomTypeToTsType indexer.Type))
506+
let prefix = ""
507+
DumpMembers flavor prefix DumpScope.InstanceOnly i
508+
DumpEventHandlers prefix i
512509

513-
// The indices could be within either Methods or Anonymous Methods
514-
match i.Methods with
515-
| Some ms -> ms.Methods |> dumpIndexers
516-
| None -> ()
510+
Pt.decreaseIndent()
511+
Pt.printl "}"
512+
Pt.printl ""
513+
Pt.printl "declare var %s: {" i.Name
514+
Pt.increaseIndent()
515+
Pt.printl "prototype: %s;" i.Name
516+
DumpConstants i
517+
DumpMembers flavor prefix DumpScope.StaticOnly i
518+
Pt.decreaseIndent()
519+
Pt.printl "}"
520+
Pt.printl ""
517521

518-
match i.AnonymousMethods with
519-
| Some ms -> ms.Methods |> dumpIndexers
520-
| None -> ()
522+
let dumpPureStaticInterface () =
523+
Pt.resetIndent()
524+
DumpInterfaceDeclaration i
525+
Pt.increaseIndent ()
521526

522-
Pt.decreaseIndent()
523-
Pt.printl "}"
524-
Pt.printl "declare var %s: %s;" i.Name i.Name
525-
Pt.printl ""
527+
let prefix = ""
528+
DumpMembers flavor prefix DumpScope.StaticOnly i
529+
DumpConstants i
530+
DumpEventHandlers prefix i
531+
532+
let dumpIndexers (ms:Browser.Method []) =
533+
ms
534+
|> Array.filter (fun m -> m.Getter.IsSome)
535+
|> Array.iter
536+
(fun m ->
537+
let indexer = m.Params.[0]
538+
Pt.printl "[%s: %s]: %s;"
539+
indexer.Name
540+
(DomTypeToTsType indexer.Type)
541+
(DomTypeToTsType indexer.Type))
542+
543+
// The indices could be within either Methods or Anonymous Methods
544+
match i.Methods with
545+
| Some ms -> ms.Methods |> dumpIndexers
546+
| None -> ()
547+
548+
match i.AnonymousMethods with
549+
| Some ms -> ms.Methods |> dumpIndexers
550+
| None -> ()
551+
552+
Pt.decreaseIndent()
553+
Pt.printl "}"
554+
Pt.printl "declare var %s: %s;" i.Name i.Name
555+
Pt.printl ""
556+
557+
if hasNonStaticMember then dumpStaticInterfaceWithNSMembers() else dumpPureStaticInterface()
526558

527559
let DumpNonCallbackInterfaces flavor =
528560
GetNonCallbackInterfacesByFlavor flavor
529561
|> Array.iter
530-
(fun i -> match i with
531-
// Static attribute means singleton object
532-
| i when i.Static.IsSome ->
533-
DumpStaticInterface flavor i
534-
| i when i.NoInterfaceObject.IsSome ->
535-
DumpInterface flavor i
536-
| _ ->
537-
DumpInterface flavor i
538-
DumpConstructor flavor i)
562+
(fun i ->
563+
match i with
564+
// Static attribute the type doesn't have a constructor function
565+
| i when i.Static.IsSome ->
566+
DumpStaticInterface flavor i
567+
| i when i.NoInterfaceObject.IsSome ->
568+
DumpInterface flavor i
569+
| _ ->
570+
DumpInterface flavor i
571+
DumpConstructor flavor i)
539572

540573
let DumpDictionaries flavor =
541574
let DumpDictionary (dict:Browser.Dictionary) =

0 commit comments

Comments
 (0)