ocsigen / ts2ocaml

Generate OCaml bindings from TypeScript definitions via the TypeScript compiler API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Merge definitions

tmattio opened this issue · comments

When multiple definitions exist for the same module. they should be merged.
For instance:

export interface Disposable {
    /**
     * Dispose this object.
     */
    dispose(): void;
}
export declare namespace Disposable {
    function create(func: () => void): Disposable;
}

currently generates:

module[@js.scope "Disposable"] Disposable : sig
  type t = _Disposable
  val t_to_js: t -> Ojs.t
  val t_of_js: Ojs.t -> t
  type t_0 = t
  val t_0_to_js: t_0 -> Ojs.t
  val t_0_of_js: Ojs.t -> t_0
  val dispose: t -> unit [@@js.call "dispose"]
end
module[@js.scope "Disposable"] Disposable : sig
  val create_: func:(unit -> unit) -> _Disposable [@@js.global "create"]
end

when it should generate:

module Disposable : sig
  type t = _Disposable

  val t_to_js : t -> Ojs.t

  val t_of_js : Ojs.t -> t

  val dispose : t -> unit [@@js.call "dispose"]

  val create_ : func:(unit -> unit) -> _Disposable [@@js.global "create"]
end
[@@js.scope "Disposable"]

I think it at least generates these modules with different names e.g.:

module[@js.scope "Disposable"] Disposable : sig
  type t = _Disposable
  val t_to_js: t -> Ojs.t
  val t_of_js: Ojs.t -> t
  type t_0 = t
  val t_0_to_js: t_0 -> Ojs.t
  val t_0_of_js: Ojs.t -> t_0
  val dispose: t -> unit [@@js.call "dispose"]
end
module[@js.scope "Disposable"] Disposable' : sig
  val create_: func:(unit -> unit) -> _Disposable [@@js.global "create"]
end

I'm still working for the complete fix (merging both to one module), but I'll finish it after LexiFi/gen_js_api#153 is merged (which will allow us a massive refactoring to the Writer module).

Now we have the complete fix for this since f615799