@@ -135,84 +135,61 @@ let DumpCreateEventOverloads (m: Browser.Method) =
135
135
Pt.printl " createEvent(eventInterface: string): Event;"
136
136
137
137
let ParamsToString ( ps : Param list ) =
138
- let ParamToString ( p : Param ) =
138
+ let paramToString ( p : Param ) =
139
139
( if p.Variadic then " ..." else " " ) +
140
140
( AdjustParamName p.Name) +
141
141
( if not p.Variadic && p.Optional then " ?: " else " : " ) +
142
142
( DomTypeToTsType p.Type) +
143
143
( if p.Variadic then " []" else " " )
144
- String.Join( " , " , ( List.map ParamToString ps))
144
+ String.Join( " , " , ( List.map paramToString ps))
145
145
146
146
let DumpMethod flavor prefix ( i : Browser.Interface ) ( m : Browser.Method ) =
147
+ // print comment
147
148
if m.Name.IsSome then
148
149
match GetCommentForMethod i.Name m.Name.Value with
149
150
| Some comment -> Pt.printl " %s " comment
150
151
| _ -> ()
151
152
152
- match i.Name, m.Name with
153
- | _, Some " createElement" ->
154
- DumpCreateElementOverloads m
155
- | _, Some " createEvent" ->
156
- DumpCreateEventOverloads m
157
- | _, Some " getElementsByTagName" ->
158
- DumpGetElementsByTagNameOverloads m
159
- | _, Some " getElementsByTagNameNS" ->
160
- Pt.printl " getElementsByTagNameNS(namespaceURI: string, localName: string): NodeListOf<Element>;"
161
- | _, Some " getElementsByClassName" ->
162
- // Issue 4401:
163
- // in the spec "getElementsByClassName" is defined in both Document and HTMLElement, actually
164
- // it should be in Element instead of HTMLElement. So suppress it here if the i.Name equals HTMLElement
165
- if i.Name <> " HTMLElement" then
166
- Pt.printl " getElementsByClassName(classNames: string): NodeListOf<Element>;"
167
- | _, Some " getElementsByName" ->
168
- Pt.printl " getElementsByName(elementName: string): NodeListOf<Element>;"
169
- | " NodeSelector" , Some " querySelectorAll" ->
170
- Pt.printl " querySelectorAll(selectors: string): NodeListOf<Element>;"
171
- | " Document" , Some " getElementById" ->
172
- Pt.printl " getElementById(elementId: string): HTMLElement;"
173
- | " Document" , Some " open" ->
174
- Pt.printl " open(url?: string, name?: string, features?: string, replace?: boolean): Document;"
175
- | _, Some " alert" ->
176
- Pt.printl " %s alert(message?: any): void;" prefix
177
- // Todo: hack for issue #2984
178
- | " HTMLCanvasElement" , Some " getContext" ->
179
- Pt.printl " %s getContext(contextId: \" 2d\" ): CanvasRenderingContext2D;" prefix
180
- Pt.printl " %s getContext(contextId: \" experimental-webgl\" ): WebGLRenderingContext;" prefix
181
- Pt.printl " %s getContext(contextId: string, ...args: any[]): CanvasRenderingContext2D | WebGLRenderingContext;" prefix
182
- // Todo: hack for issue #3002
183
- | " XMLHttpRequest" , Some " send" ->
184
- if flavor <> Flavor.Worker then
185
- Pt.printl " %s send(data?: Document): void;" prefix
186
- Pt.printl " %s send(data?: string): void;" prefix
187
- Pt.printl " %s send(data?: any): void;" prefix
188
- // Todo: hack for issue #3344
189
- | " WebGLRenderingContext" , Some " texImage2D" ->
190
- Pt.printl " %s texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void;" prefix
191
- Pt.printl " %s texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void;" prefix
192
- Pt.printl " %s texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void;" prefix
193
- Pt.printl " %s texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void;" prefix
194
- Pt.printl " %s texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void;" prefix
195
- | " WebGLRenderingContext" , Some " texSubImage2D" ->
196
- Pt.printl " %s texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void;" prefix
197
- Pt.printl " %s texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void;" prefix
198
- Pt.printl " %s texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void;" prefix
199
- Pt.printl " %s texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void;" prefix
200
- Pt.printl " %s texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void;" prefix
201
- | _ ->
202
- let consoleMethodsNeedToReplaceStringWithAny = [| " dir" ; " dirxml" ; " error" ; " info" ; " log" ; " warn" |]
203
- GetOverloads ( Method m) false
204
- |> List.iter
205
- ( fun { ParamCombinations = pCombList ; ReturnTypes = rTypes } ->
206
- let paramsString =
207
- // Some console methods should accept "any" instead of "string" for convenience, although
208
- // it is said to be string in the spec
209
- if i.Name = " Console" && m.Name.IsSome && Array.contains m.Name.Value consoleMethodsNeedToReplaceStringWithAny then
210
- ( ParamsToString pCombList) .Replace( " string" , " any" )
211
- else
212
- ParamsToString pCombList
213
- let returnString = rTypes |> List.map DomTypeToTsType |> String.concat " | "
214
- Pt.printl " %s%s (%s ): %s ;" prefix ( if m.Name.IsSome then m.Name.Value else " " ) paramsString returnString
215
- )
153
+ // find if there are overriding signatures in the external json file
154
+ let removedType =
155
+ match m.Name with
156
+ | Some mName -> findRemovedType mName i.Name MemberKind.Method
157
+ | None -> None
158
+
159
+ let overridenType =
160
+ match m.Name with
161
+ | Some mName -> findOverridingType mName i.Name MemberKind.Method
162
+ | None -> None
163
+
164
+ match removedType with
165
+ | Some r -> ()
166
+ | None ->
167
+ match overridenType with
168
+ | Some t ->
169
+ match flavor with
170
+ | Windows | Web -> t.WebOnlySignatures |> Array.iter ( Pt.printl " %s%s ;" prefix)
171
+ | _ -> ()
172
+ t.Signatures |> Array.iter ( Pt.printl " %s%s ;" prefix)
173
+ | None ->
174
+ match i.Name, m.Name with
175
+ | _, Some " createElement" -> DumpCreateElementOverloads m
176
+ | _, Some " createEvent" -> DumpCreateEventOverloads m
177
+ | _, Some " getElementsByTagName" -> DumpGetElementsByTagNameOverloads m
178
+ | _ ->
179
+ let consoleMethodsNeedToReplaceStringWithAny = [| " dir" ; " dirxml" ; " error" ; " info" ; " log" ; " warn" |]
180
+ GetOverloads ( Method m) false
181
+ |> List.iter
182
+ ( fun { ParamCombinations = pCombList ; ReturnTypes = rTypes } ->
183
+ let paramsString =
184
+ // Some console methods should accept "any" instead of "string" for convenience, although
185
+ // it is said to be string in the spec
186
+ if i.Name = " Console" && m.Name.IsSome && Array.contains m.Name.Value consoleMethodsNeedToReplaceStringWithAny then
187
+ ( ParamsToString pCombList) .Replace( " string" , " any" )
188
+ else
189
+ ParamsToString pCombList
190
+ let returnString = rTypes |> List.map DomTypeToTsType |> String.concat " | "
191
+ Pt.printl " %s%s (%s ): %s ;" prefix ( if m.Name.IsSome then m.Name.Value else " " ) paramsString returnString
192
+ )
216
193
217
194
let DumpCallBackInterface ( i : Browser.Interface ) =
218
195
Pt.printl " interface %s {" i.Name
@@ -251,50 +228,33 @@ let DumpEnums () =
251
228
let DumpMembers flavor prefix ( dumpScope : DumpScope ) ( i : Browser.Interface ) =
252
229
// -------- Dump properties --------
253
230
// Note: the schema file shows the property doesn't have static attribute
231
+ let dumpProperty ( p : Browser.Property ) =
232
+ match GetCommentForProperty i.Name p.Name with
233
+ | Some comment -> Pt.printl " %s " comment
234
+ | _ -> ()
235
+
236
+ match findRemovedType p.Name i.Name MemberKind.Property with
237
+ | Some _ -> ()
238
+ | None ->
239
+ match findOverridingType p.Name i.Name MemberKind.Property with
240
+ | Some t -> Pt.printl " %s%s : %s ;" prefix t.Name t.Type.Value
241
+ | None ->
242
+ let pType = match p.Type with
243
+ | " EventHandler" -> String.Format( " (ev: {0}) => any" , ehNameToEType.[ p.Name])
244
+ | _ -> DomTypeToTsType p.Type
245
+ Pt.printl " %s%s : %s ;" prefix p.Name pType
246
+
254
247
if dumpScope <> DumpScope.StaticOnly then
255
248
match i.Properties with
256
249
| Some ps ->
257
250
ps.Properties
258
251
|> Array.filter ( ShouldKeep flavor)
259
- |> Array.iter ( fun p ->
260
- match GetCommentForProperty i.Name p.Name with
261
- | Some comment -> Pt.printl " %s " comment
262
- | _ -> ()
263
-
264
- let pType =
265
- match i.Name, p.Name, p.Type with
266
- | _, _, " EventHandler" ->
267
- String.Format( " (ev: {0}) => any" , ehNameToEType.[ p.Name])
268
- // There are type conflicts between
269
- | " BeforeUnloadEvent" , " returnValue" , _ -> " any"
270
- | " HTMLEmbedElement" , " hidden" , _ -> " any"
271
- | _ -> DomTypeToTsType p.Type
272
- match p.Name, pType with
273
- // HOTFIX: although technically the type of documentElement should be "Element",
274
- // but in most cases typescript would be dealing with HTML document, therefore it
275
- // would be more convenient (and more backward compatible) to assume "HTMLElement"
276
- | " documentElement" , _ -> Pt.printl " %s documentElement: HTMLElement;" prefix
277
- // HOTFIX: move the className and id property from HTMLElement to Element
278
- | " id" , _ when i.Name = " HTMLElement" -> ()
279
- | " className" , _ when i.Name = " HTMLElement" -> ()
280
- | " className" , _ when i.Name = " SVGStylable" ->
281
- Pt.printl " %s className: any;" prefix
282
- // HOTFIX: explicitly denote the type of SVGElement.className property to "any", and making it
283
- // appear after "id"
284
- | " id" , _ when i.Name = " SVGElement" ->
285
- Pt.printl " %s%s : %s ;" prefix p.Name pType
286
- Pt.printl " %s className: any;" prefix
287
- // HOTFIX: Issue 3884
288
- | " orientation" , _ when i.Name = " Window" ->
289
- Pt.printl " %s orientation: string | number;" prefix
290
- | _ -> Pt.printl " %s%s : %s ;" prefix p.Name pType)
252
+ |> Array.iter dumpProperty
291
253
| None -> ()
292
- // Hack to add the URL property to window
293
- if i.Name = " Window" then
294
- Pt.printl " %s URL: URL;" prefix
295
- if i.Name = " Element" then
296
- Pt.printl " %s id: string;" prefix
297
- Pt.printl " %s className: string;" prefix
254
+
255
+ addedTypes
256
+ |> Array.filter ( fun t -> t.Interface.IsNone || t.Interface.Value = i.Name)
257
+ |> Array.iter ( fun t -> Pt.printl " %s%s : %s ;" prefix t.Name t.Type.Value)
298
258
299
259
// -------- Dump methods --------
300
260
// Note: two cases:
0 commit comments