Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions TS.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,6 @@ module Emit =
| "DOMString" -> "string"
| "DOMTimeStamp" -> "number"
| "EndOfStreamError" -> "number"
| "EventListener" -> "EventListenerOrEventListenerObject"
| "double" | "float" -> "number"
| "object" -> "any"
| "ReadyState" -> "string"
Expand Down Expand Up @@ -838,11 +837,14 @@ module Emit =
(if p.Variadic then "[]" else "")
String.Join(", ", (List.map paramToString ps))

let EmitCallBackInterface (i:Browser.Interface) =
Pt.Printl "interface %s {" i.Name
Pt.PrintWithAddedIndent "(evt: Event): void;"
Pt.Printl "}"
Pt.Printl ""
let EmitCallBackInterface flavor (i:Browser.Interface) =
if ShouldKeep flavor i then
let m = i.Methods.Value.Methods.[0]
let overload = (GetOverloads (Function.Method m) false).[0]
let paramsString = ParamsToString overload.ParamCombinations
let returnType = DomTypeToTsType m.Type
Pt.Printl "type %s = (%s) => %s | { %s(%s): %s; };" i.Name paramsString returnType m.Name.Value paramsString returnType
Pt.Printl ""

let EmitCallBackFunctions flavor =
let emitCallbackFunctionsFromJson (cb: InputJson.InputJsonType.Root) =
Expand Down Expand Up @@ -1064,7 +1066,7 @@ module Emit =

let emitStringEventHandler (addOrRemove: string) =
Pt.Printl
"%s%sEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | %s): void;"
"%s%sEventListener(type: string, listener: EventListener, options?: boolean | %s): void;"
fPrefix addOrRemove (getOptionsType addOrRemove)

let tryEmitTypedEventHandlerForInterface (addOrRemove: string) =
Expand Down Expand Up @@ -1484,15 +1486,12 @@ module Emit =
Pt.Printl ""

EmitDictionaries flavor
browser.CallbackInterfaces.Interfaces |> Array.iter EmitCallBackInterface
browser.CallbackInterfaces.Interfaces |> Array.iter (EmitCallBackInterface flavor)
EmitNonCallbackInterfaces flavor

// Add missed interface definition from the spec
InputJson.getAddedItems InputJson.Interface flavor |> Array.iter EmitAddedInterface

Pt.Printl "declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject;"
Pt.Printl ""

EmitCallBackFunctions flavor

if flavor <> Worker then
Expand Down
Loading