Skip to content

Commit 97a6549

Browse files
committed
Fix a bug when emitting exports for enum types
1 parent 4cf4f13 commit 97a6549

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

src/Targets/ReScript/Writer.fs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ let emitEnum flags overrideFunc (ctx: Context) (current: StructuredText) (e: Enu
13161316
|> List.map fst
13171317
let casesText =
13181318
if (cases |> List.sumBy (fun s -> s.Length)) > 80 then
1319-
concat newline [
1319+
newline + concat newline [
13201320
for case in cases do
13211321
yield indent (tprintf "| %s" case)
13221322
]
@@ -1354,10 +1354,12 @@ let emitEnum flags overrideFunc (ctx: Context) (current: StructuredText) (e: Enu
13541354
]
13551355
let items = items @ List.map child e.cases
13561356
let comments = e.comments |> emitComments
1357-
let exports = getExportFromStatement ctx e.name Kind.OfEnum "enum" (Enum e)
1358-
{| StructuredTextNode.empty with items = items; comments = comments; exports = Option.toList exports |}
1357+
{| StructuredTextNode.empty with items = items; comments = comments |}
13591358

1360-
current |> add [e.name] parentNode
1359+
let exports = getExportFromStatement ctx e.name Kind.OfEnum "enum" (Enum e)
1360+
current
1361+
|> add [e.name] parentNode
1362+
|> set {| StructuredTextNode.empty with exports = Option.toList exports |}
13611363

13621364
let private createExternalForValue (ctx: Context) (rename: string -> string) (s: CurrentScope) attr comments name ty =
13631365
let fallback () =
@@ -1776,10 +1778,12 @@ let rec emitModule (flags: EmitModuleFlags) (ctx: Context) (st: StructuredText)
17761778
let ctx = ctx |> Context.ofChildNamespace k
17771779
let result = emitModule flags ctx v
17781780
let openTypesModule =
1779-
let hasTypeDefinitions = result.types |> List.isEmpty |> not
1780-
v.value
1781-
|> Option.map (fun v -> hasTypeDefinitions && v.openTypesModule)
1782-
|> Option.defaultValue hasTypeDefinitions
1781+
if flags.isReservedModule then false
1782+
else
1783+
let hasTypeDefinitions = result.types |> List.isEmpty |> not
1784+
v.value
1785+
|> Option.map (fun v -> hasTypeDefinitions && v.openTypesModule)
1786+
|> Option.defaultValue hasTypeDefinitions
17831787
{| name = name; origName = k |}, openTypesModule, result)
17841788

17851789
let items =
@@ -1856,7 +1860,7 @@ let rec emitModule (flags: EmitModuleFlags) (ctx: Context) (st: StructuredText)
18561860
| Choice3Of5 b -> yield! Binding.emitForInterface b
18571861
| Choice5Of5 c -> yield c
18581862
| _ -> ()
1859-
// yield! exports.intf
1863+
yield! exports.intf
18601864
]
18611865

18621866
let impl =
@@ -1885,7 +1889,7 @@ let rec emitModule (flags: EmitModuleFlags) (ctx: Context) (st: StructuredText)
18851889
| Choice3Of5 b -> yield! Binding.emitForImplementation b
18861890
| Choice5Of5 c -> yield c
18871891
| _ -> ()
1888-
// yield! exports.impl
1892+
yield! exports.impl
18891893
]
18901894

18911895
let comments =
@@ -1894,13 +1898,6 @@ let rec emitModule (flags: EmitModuleFlags) (ctx: Context) (st: StructuredText)
18941898
{| imports = imports; types = types; intf = intf; impl = impl; comments = comments |}
18951899

18961900
and emitExportModule (ctx: Context) (exports: ExportItem list) : EmitModuleResult =
1897-
let emitComment comments origText = [
1898-
let hasDocComment = not (List.isEmpty comments)
1899-
yield commentStr origText |> TypeDefText
1900-
if hasDocComment then
1901-
yield comments |> emitComments |> concat newline |> comment |> TypeDefText
1902-
]
1903-
19041901
let emitModuleAlias name (i: Ident) =
19051902
if i.kind |> Option.map Kind.generatesReScriptModule |> Option.defaultValue false then
19061903
[ Statement.moduleAlias
@@ -1931,18 +1928,9 @@ and emitExportModule (ctx: Context) (exports: ExportItem list) : EmitModuleResul
19311928
| ES6Export e :: rest ->
19321929
let name = e.renameAs |> Option.defaultValue (e.target.name |> List.last)
19331930
go' (acc |> setItems ["Export"] (emitModuleAlias name e.target)) rest
1934-
let acc =
1935-
let generatesExportModule =
1936-
clauses |> List.exists (function ES6Export _ | ES6DefaultExport _ -> true | _ -> false)
1937-
if generatesExportModule then
1938-
acc |> setItems ["Export"] (emitComment export.comments export.origText)
1939-
else
1940-
acc |> addItems (emitComment export.comments export.origText)
19411931
go false (go' acc clauses) rest
19421932
| ExportItem.ReExport export :: rest ->
19431933
// TODO
1944-
let acc =
1945-
acc |> setItems ["Export"] (emitComment export.comments export.origText)
19461934
go isFirst acc rest
19471935

19481936
let st = go true Trie.empty exports

0 commit comments

Comments
 (0)