@@ -220,9 +220,9 @@ let DumpCallBackFunctions flavor =
220
220
|> Array.iter DumpCallBackFunction
221
221
222
222
let DumpEnums () =
223
- let DumpEnum ( e : Browser.Enum ) =
223
+ let dumpEnum ( e : Browser.Enum ) =
224
224
Pt.printl " declare var %s : string;" e.Name
225
- browser.Enums |> Array.iter DumpEnum
225
+ browser.Enums |> Array.iter dumpEnum
226
226
227
227
/// Dump the properties and methods of a given interface
228
228
let DumpMembers flavor prefix ( dumpScope : DumpScope ) ( i : Browser.Interface ) =
@@ -244,7 +244,7 @@ let DumpMembers flavor prefix (dumpScope: DumpScope) (i:Browser.Interface) =
244
244
| _ -> DomTypeToTsType p.Type
245
245
Pt.printl " %s%s : %s ;" prefix p.Name pType
246
246
247
- if dumpScope <> DumpScope. StaticOnly then
247
+ if dumpScope <> StaticOnly then
248
248
match i.Properties with
249
249
| Some ps ->
250
250
ps.Properties
@@ -490,52 +490,85 @@ let DumpInterface flavor (i:Browser.Interface) =
490
490
Pt.printl " "
491
491
492
492
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
496
500
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 ()
501
505
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
512
509
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 " "
517
521
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 ()
521
526
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()
526
558
527
559
let DumpNonCallbackInterfaces flavor =
528
560
GetNonCallbackInterfacesByFlavor flavor
529
561
|> 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)
539
572
540
573
let DumpDictionaries flavor =
541
574
let DumpDictionary ( dict : Browser.Dictionary ) =
0 commit comments