File tree Expand file tree Collapse file tree 5 files changed +56
-8
lines changed
Expand file tree Collapse file tree 5 files changed +56
-8
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88- Ts2ocaml now emits builder function ` [@js.builder] ` for POJO interfaces.
99
1010## [ 1.4.0-beta.3] - 2022-01-17
11- - Add option ` --human- readable-anonymous-interface- names ` (or ` --readable-names ` ) to try to use more readable names instead of ` AnonymousInterfaceN ` .
11+ - Add an option ` --readable-names ` to try to use more readable names instead of ` AnonymousInterfaceN ` .
1212
1313## [ 1.4.0-beta.2] - 2022-01-17
1414- Fix a bug which prevented ts2ocaml from generating anonymous interfaces when used with --simplify=named-interface-value
Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ module Test =
143143 " safe" , !! " node_modules/@types/yargs-parser/index.d.ts" , [];
144144 " safe" , !! " node_modules/@types/yargs/index.d.ts" , [ " --rec-module=off" ];
145145
146- " minimal" , !! " node_modules/@types/vscode/index.d.ts" , [ " --safe-arity=full " ];
146+ " minimal" , !! " node_modules/@types/vscode/index.d.ts" , [ " --safe-arity=full" ; " --readable-names " ];
147147 ]
148148
149149 for preset, package, additionalOptions in packages do
Original file line number Diff line number Diff line change @@ -918,3 +918,52 @@ let _ = Foo.someMethod (foo ()) 42.0
918918```
919919
920920A notable example is the ` document ` variable in DOM (https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts ).
921+
922+
923+ ## ` --try-readable-names `
924+
925+ Try to use more readable names instead of ` AnonymousInterfaceN ` .
926+
927+ * If the anonymous interface is an argument of a function, the name of the argument will be used.
928+ ``` typescript
929+ declare function foo(person : { name: string ; age: number }) : void ;
930+ ```
931+
932+ ``` ocaml
933+ module PersonN : sig
934+ type t
935+ val get_name: t -> string
936+ val set_name: t -> string -> unit
937+ val get_age: t -> float
938+ val set_age: t -> float -> unit
939+
940+ val create: name:string -> age:float -> unit -> t
941+ end
942+
943+ val foo: person:PersonN.t -> unit
944+ ```
945+
946+ * If the anonymous interface is the type of a field or the return type of a function, the name of the field/function will be used.
947+ ``` typescript
948+ declare const foo: { name: string };
949+
950+ declare function bar(age : number ) : { age: number };
951+ ```
952+
953+ ``` ocaml
954+ module FooN : sig
955+ type t
956+ val get_name: t -> string
957+ ...
958+ end
959+
960+ val get_foo: unit -> FooN.t
961+
962+ module BarN : sig
963+ type t
964+ val get_age: t -> float
965+ ...
966+ end
967+
968+ val bar: float -> BarN.t
969+ ```
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ type Options =
103103 abstract recModule: RecModule with get, set
104104 abstract safeArity: FeatureFlag with get, set
105105 abstract simplify: Simplify list with get, set
106- abstract humanReadableAnonymousInterfaceNames : bool with get, set
106+ abstract readableNames : bool with get, set
107107
108108module Options =
109109 open Fable.Core .JsInterop
@@ -247,11 +247,10 @@ module Options =
247247 sprintf " Turn on simplification features. Available features: %s "
248248 ( Simplify.Values |> Array.map string |> String.concat " , " ))
249249 .addFlag(
250- " human- readable-anonymous-interface -names" ,
251- ( fun ( o : Options ) -> o.humanReadableAnonymousInterfaceNames ),
250+ " readable-names" ,
251+ ( fun ( o : Options ) -> o.readableNames ),
252252 descr= " Try to use more readable names instead of AnonymousInterfaceN." ,
253- defaultValue = false ,
254- alias= " readable-names"
253+ defaultValue = false
255254 )
256255
257256 .middleware(! ^validate )
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ let literalToIdentifier (ctx: Context) (l: Literal) : text =
8888
8989let anonymousInterfaceModuleName ( ctx : Context ) ( info : AnonymousInterfaceInfo ) =
9090 match info.origin.valueName, info.origin.argName with
91- | _, Some s | Some s, None when ctx.options.humanReadableAnonymousInterfaceNames ->
91+ | _, Some s | Some s, None when ctx.options.readableNames ->
9292 sprintf " %s%d " ( Naming.toCase Naming.PascalCase s) info.id
9393 | _, _ ->
9494 sprintf " AnonymousInterface%d " info.id
You can’t perform that action at this time.
0 commit comments