Skip to content

Commit f8aeb9f

Browse files
committed
Add --no-types-module option
1 parent fe0623c commit f8aeb9f

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/Targets/ReScript/Common.fs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ type Options =
7272
// output options
7373
abstract outputDir: string option with get
7474
abstract resi: bool with get
75-
// code generator options
75+
// typer options
7676
abstract numberAsInt: bool with get, set
7777
abstract subtyping: Subtyping list with get, set
7878
abstract inheritWithTags: FeatureFlag with get, set
79+
// code generator options
7980
abstract simplify: Simplify list with get, set
8081
abstract readableNames: bool with get, set
82+
abstract noTypesModule: bool with get, set
8183

8284
module Options =
8385
open Fable.Core.JsInterop
@@ -203,7 +205,8 @@ module Options =
203205
.group(
204206
!^ResizeArray[
205207
"simplify";
206-
"human-readable-anonymous-interface-names";
208+
"readable-names";
209+
"no-types-module"
207210
],
208211
"Code Generator Options:")
209212
.addCommaSeparatedStringSet(
@@ -219,6 +222,12 @@ module Options =
219222
descr="Try to use more readable names instead of AnonymousInterfaceN.",
220223
defaultValue = false
221224
)
225+
.addFlag(
226+
"no-types-module",
227+
(fun (o: Options) -> o.noTypesModule),
228+
descr="Unsafe. Do not emit Types module even if there are recursive modules.",
229+
defaultValue = false
230+
)
222231

223232
.middleware(!^validate)
224233

@@ -231,4 +240,4 @@ type Output = {
231240
res: text
232241
}
233242

234-
let [<ImportDefault("../../../dist_rescript/src/ts2ocaml.res?raw")>] stdlib: string = jsNative
243+
let [<ImportDefault("../../../dist_rescript/src/ts2ocaml.res?raw")>] stdlib: string = jsNative

src/Targets/ReScript/Writer.fs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -929,11 +929,9 @@ let rec emitClass flags overrideFunc (ctx: Context) (current: StructuredText) (c
929929
| InheritingType.Other t -> [t])
930930
|> List.map (getKnownTypes innerCtx)
931931

932-
// We only need the anonymous interfaces that appear in the members
933932
yield
934933
c.members
935934
|> Seq.collect (snd >> findTypesInClassMember (knownTypeFinder innerCtx) ())
936-
// |> Seq.filter (function KnownType.AnonymousInterface _ -> true | _ -> false)
937935
|> Set.ofSeq
938936

939937
yield!
@@ -1617,8 +1615,8 @@ module EmitModuleResult =
16171615
let empty : EmitModuleResult =
16181616
{| imports = []; types = []; impl = []; intf = []; comments = [] |}
16191617

1620-
let rec emitModule (dt: DependencyTrie<string>) flags ctx st =
1621-
let isLinear = DependencyTrie.isLinear dt // compute only once
1618+
let rec emitModule (dt: DependencyTrie<string>) flags (ctx: Context) st =
1619+
let isLinear = ctx.options.noTypesModule || DependencyTrie.isLinear dt // compute only once
16221620
let rec go (flags: EmitModuleFlags) (ctx: Context) (st: StructuredText) : EmitModuleResult =
16231621
let renamer = new OverloadRenamer()
16241622
let children =
@@ -1750,6 +1748,20 @@ let rec emitModule (dt: DependencyTrie<string>) flags ctx st =
17501748
]
17511749

17521750
let impl =
1751+
let fixmeRecursiveModules (ms: TextModule list) =
1752+
match ms with
1753+
| [] -> []
1754+
| [m] -> [Statement.moduleVal m]
1755+
| _ when ctx.options.noTypesModule ->
1756+
[ yield
1757+
commentStr (
1758+
sprintf "FIXME: start of recursive definitions (%s)"
1759+
(ms |> List.map (fun m -> m.name) |> String.concat ", ")
1760+
)
1761+
yield! Statement.moduleValMany ms
1762+
yield commentStr "FIXME: end of recursive definitions" ]
1763+
| _ -> Statement.moduleValMany ms
1764+
17531765
let children =
17541766
children
17551767
|> List.filter (fun (_, _, c) -> c.impl |> List.isEmpty |> not)
@@ -1760,7 +1772,7 @@ let rec emitModule (dt: DependencyTrie<string>) flags ctx st =
17601772
else
17611773
c.imports @ c.impl
17621774
{| k with content = content; comments = c.comments |})
1763-
|> Statement.moduleSCC dt Statement.moduleValMany Statement.moduleValMany ctx
1775+
|> Statement.moduleSCC dt fixmeRecursiveModules Statement.moduleValMany ctx
17641776
let typeDefs =
17651777
items |> List.choose (function
17661778
| TypeAliasText t -> Some t

0 commit comments

Comments
 (0)