@@ -175,7 +175,7 @@ module InputJson =
175
175
176
176
let getItemByName ( allItems : InputJsonType.Root []) ( itemName : string ) ( kind : ItemKind ) otherFilter =
177
177
let filter ( item : InputJsonType.Root ) =
178
- OptionCheckValue itemName item.Name &&
178
+ ( OptionCheckValue itemName item.Name || OptionCheckValue ( sprintf " %s ? " itemName ) item.Name ) &&
179
179
item.Kind.ToLower() = kind.ToString() &&
180
180
otherFilter item
181
181
allItems |> Array.tryFind filter
@@ -779,6 +779,10 @@ module Emit =
779
779
( DomTypeToNullableTsType m.Type m.Nullable.IsSome) = expectedMType &&
780
780
m.Params.Length = 1 &&
781
781
( DomTypeToTsType m.Params.[ 0 ]. Type) = expectedParamType
782
+ let processInterfaceType iName =
783
+ match getOverriddenItems ItemKind.Interface Flavor.All |> Array.tryFind ( matchInterface iName) with
784
+ | Some it -> iName + " <" + ( it.TypeParameters |> String.concat " , " ) + " >"
785
+ | _ -> iName
782
786
783
787
/// Emit overloads for the createElement method
784
788
let EmitCreateElementOverloads ( m : Browser.Method ) =
@@ -789,45 +793,47 @@ module Emit =
789
793
/// Emit overloads for the getElementsByTagName method
790
794
let EmitGetElementsByTagNameOverloads ( m : Browser.Method ) =
791
795
if matchSingleParamMethodSignature m " getElementsByTagName" " NodeList" " string" then
792
- Pt.Printl " getElementsByTagName<K extends keyof ElementListTagNameMap>(%s : K): ElementListTagNameMap[K];" m.Params.[ 0 ]. Name
796
+ Pt.Printl " getElementsByTagName<K extends keyof HTMLElementTagNameMap>(%s : K): NodeListOf<HTMLElementTagNameMap[K]>;" m.Params.[ 0 ]. Name
797
+ Pt.Printl " getElementsByTagName<K extends keyof SVGElementTagNameMap>(%s : K): NodeListOf<SVGElementTagNameMap[K]>;" m.Params.[ 0 ]. Name
793
798
Pt.Printl " getElementsByTagName(%s : string): NodeListOf<Element>;" m.Params.[ 0 ]. Name
794
799
795
800
/// Emit overloads for the querySelector method
796
801
let EmitQuerySelectorOverloads ( m : Browser.Method ) =
797
802
if matchSingleParamMethodSignature m " querySelector" " Element" " string" then
798
- Pt.Printl " querySelector<K extends keyof ElementTagNameMap>(selectors: K): ElementTagNameMap[K] | null;"
803
+ Pt.Printl " querySelector<K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null;"
804
+ Pt.Printl " querySelector<K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K] | null;"
799
805
Pt.Printl " querySelector<E extends Element = Element>(selectors: string): E | null;"
800
806
801
807
/// Emit overloads for the querySelectorAll method
802
808
let EmitQuerySelectorAllOverloads ( m : Browser.Method ) =
803
809
if matchSingleParamMethodSignature m " querySelectorAll" " NodeList" " string" then
804
- Pt.Printl " querySelectorAll<K extends keyof ElementListTagNameMap>(selectors: K): ElementListTagNameMap[K];"
810
+ Pt.Printl " querySelectorAll<K extends keyof HTMLElementTagNameMap>(selectors: K): NodeListOf<HTMLElementTagNameMap[K]>;"
811
+ Pt.Printl " querySelectorAll<K extends keyof SVGElementTagNameMap>(selectors: K): NodeListOf<SVGElementTagNameMap[K]>;"
805
812
Pt.Printl " querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;"
806
813
807
814
let EmitHTMLElementTagNameMap () =
808
815
Pt.Printl " interface HTMLElementTagNameMap {"
809
816
Pt.IncreaseIndent()
810
817
for e in tagNameToEleName do
811
- if iNameToIDependList.ContainsKey e.Value && Seq.contains " HTMLElement " iNameToIDependList.[ e.Value] then
818
+ if iNameToIDependList.ContainsKey e.Value && not ( Seq.contains " SVGElement " iNameToIDependList.[ e.Value]) then
812
819
Pt.Printl " \" %s \" : %s ;" ( e.Key.ToLower()) e.Value
813
820
Pt.DecreaseIndent()
814
821
Pt.Printl " }"
815
822
Pt.Printl " "
816
823
817
- let EmitElementTagNameMap () =
818
- Pt.Printl " interface ElementTagNameMap extends HTMLElementTagNameMap {"
824
+ let EmitSVGElementTagNameMap () =
825
+ Pt.Printl " interface SVGElementTagNameMap {"
819
826
Pt.IncreaseIndent()
820
827
for e in tagNameToEleName do
821
- if iNameToIDependList.ContainsKey e.Value && not ( Seq.contains " HTMLElement " iNameToIDependList.[ e.Value]) then
828
+ if iNameToIDependList.ContainsKey e.Value && Seq.contains " SVGElement " iNameToIDependList.[ e.Value] then
822
829
Pt.Printl " \" %s \" : %s ;" ( e.Key.ToLower()) e.Value
823
830
Pt.DecreaseIndent()
824
831
Pt.Printl " }"
825
832
Pt.Printl " "
826
833
827
- let EmitElementListTagNameMap () =
828
- Pt.Printl " type ElementListTagNameMap = {"
829
- Pt.PrintWithAddedIndent " [key in keyof ElementTagNameMap]: NodeListOf<ElementTagNameMap[key]>"
830
- Pt.Printl " };"
834
+ let EmitElementTagNameMap () =
835
+ Pt.Printl " /** @deprecated Directly use HTMLElementTagNameMap or SVGElementTagNameMap as appropriate, instead. */"
836
+ Pt.Printl " interface ElementTagNameMap extends HTMLElementTagNameMap, SVGElementTagNameMap { }"
831
837
Pt.Printl " "
832
838
833
839
/// Emit overloads for the createEvent method
@@ -978,7 +984,12 @@ module Emit =
978
984
// Otherwise, this is EventTarget.addEventListener, we want to keep that.
979
985
let mFilter ( m : Browser.Method ) =
980
986
matchScope emitScope m &&
981
- not ( prefix <> " " && OptionCheckValue " addEventListener" m.Name)
987
+ not (
988
+ prefix <> " " && (
989
+ ( OptionCheckValue " addEventListener" m.Name) ||
990
+ ( OptionCheckValue " removeEventListener" m.Name)
991
+ )
992
+ )
982
993
983
994
let emitMethod flavor prefix ( i : Browser.Interface ) ( m : Browser.Method ) =
984
995
let printLine content =
@@ -1061,30 +1072,43 @@ module Emit =
1061
1072
| _ -> ()
1062
1073
1063
1074
let EmitEventHandlers ( flavor : Flavor ) ( prefix : string ) ( i : Browser.Interface ) =
1075
+ let getOptionsType ( addOrRemove : string ) =
1076
+ if addOrRemove = " add" then " AddEventListenerOptions" else " EventListenerOptions"
1077
+
1064
1078
let fPrefix =
1065
1079
if prefix.StartsWith " declare var" then " declare function " else " "
1066
1080
1067
- let emitEventHandler prefix ( iParent : Browser.Interface ) =
1081
+ let emitTypedEventHandler ( prefix : string ) ( addOrRemove : string ) ( iParent : Browser.Interface ) =
1082
+ Pt.Printl
1083
+ " %s%s EventListener<K extends keyof %s EventMap>(type: K, listener: (this: %s , ev: %s EventMap[K]) => any, options?: boolean | %s ): void;"
1084
+ prefix addOrRemove iParent.Name i.Name iParent.Name ( getOptionsType addOrRemove)
1085
+
1086
+ let emitStringEventHandler ( addOrRemove : string ) =
1068
1087
Pt.Printl
1069
- " %s addEventListener<K extends keyof %s EventMap> (type: K , listener: (this: %s , ev: %s EventMap[K]) => any, useCapture ?: boolean): void;"
1070
- prefix iParent.Name i.Name iParent.Name
1088
+ " %s%s EventListener (type: string , listener: EventListenerOrEventListenerObject, options ?: boolean | %s ): void;"
1089
+ fPrefix addOrRemove ( getOptionsType addOrRemove )
1071
1090
1072
- let shouldEmitStringEventHandler =
1091
+ let tryEmitTypedEventHandlerForInterface ( addOrRemove : string ) =
1073
1092
if iNameToEhList.ContainsKey i.Name && not iNameToEhList.[ i.Name]. IsEmpty then
1074
- emitEventHandler fPrefix i
1093
+ emitTypedEventHandler fPrefix addOrRemove i
1075
1094
true
1076
1095
elif iNameToEhParents.ContainsKey i.Name && not iNameToEhParents.[ i.Name]. IsEmpty then
1077
1096
iNameToEhParents.[ i.Name]
1078
1097
|> List.sortBy ( fun i -> i.Name)
1079
- |> List.iter ( emitEventHandler fPrefix)
1098
+ |> List.iter ( emitTypedEventHandler fPrefix addOrRemove )
1080
1099
true
1081
1100
else
1082
1101
false
1083
1102
1084
- if shouldEmitStringEventHandler then
1085
- Pt.Printl
1086
- " %s addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;"
1087
- fPrefix
1103
+ let emitEventHandler ( addOrRemove : string ) =
1104
+ if tryEmitTypedEventHandlerForInterface addOrRemove then
1105
+ // only emit the string event handler if we just emited a typed handler
1106
+ emitStringEventHandler addOrRemove
1107
+
1108
+
1109
+ emitEventHandler " add"
1110
+ emitEventHandler " remove"
1111
+
1088
1112
1089
1113
let EmitConstructorSignature flavor ( i : Browser.Interface ) =
1090
1114
let emitConstructorSigFromJson ( c : InputJsonType.Root ) =
@@ -1142,9 +1166,9 @@ module Emit =
1142
1166
1143
1167
let processedIName = processIName i.Name
1144
1168
if processedIName <> i.Name then
1145
- Pt.PrintlToStack " interface %s extends %s {" i.Name processedIName
1169
+ Pt.PrintlToStack " interface %s extends %s {" ( processInterfaceType i.Name) processedIName
1146
1170
1147
- Pt.Printl " interface %s " processedIName
1171
+ Pt.Printl " interface %s " ( processInterfaceType processedIName)
1148
1172
let finalExtends =
1149
1173
let overridenExtendsFromJson =
1150
1174
InputJson.getOverriddenItemsByInterfaceName ItemKind.Extends Flavor.All i.Name
@@ -1369,13 +1393,18 @@ module Emit =
1369
1393
EmitConstructor flavor i
1370
1394
1371
1395
let EmitDictionaries flavor =
1396
+
1372
1397
let emitDictionary ( dict : Browser.Dictionary ) =
1373
1398
match dict.Extends with
1374
- | " Object" -> Pt.Printl " interface %s {" dict.Name
1375
- | _ -> Pt.Printl " interface %s extends %s {" dict.Name dict.Extends
1399
+ | " Object" -> Pt.Printl " interface %s {" ( processInterfaceType dict.Name)
1400
+ | _ -> Pt.Printl " interface %s extends %s {" ( processInterfaceType dict.Name) dict.Extends
1376
1401
1377
1402
let emitJsonProperty ( p : InputJsonType.Root ) =
1378
- Pt.Printl " %s : %s ;" p.Name.Value p.Type.Value
1403
+ let readOnlyModifier =
1404
+ match p.Readonly with
1405
+ | Some( true ) -> " readonly "
1406
+ | _ -> " "
1407
+ Pt.Printl " %s%s : %s ;" readOnlyModifier p.Name.Value p.Type.Value
1379
1408
1380
1409
let removedPropNames =
1381
1410
getRemovedItems ItemKind.Property flavor
@@ -1489,8 +1518,8 @@ module Emit =
1489
1518
1490
1519
if flavor <> Worker then
1491
1520
EmitHTMLElementTagNameMap()
1521
+ EmitSVGElementTagNameMap()
1492
1522
EmitElementTagNameMap()
1493
- EmitElementListTagNameMap()
1494
1523
EmitNamedConstructors()
1495
1524
1496
1525
match GetGlobalPollutor flavor with
0 commit comments