@@ -630,9 +630,19 @@ module StructuredText =
630
630
let removeLabels ( xs : Choice < FieldLike , Type > list ) =
631
631
xs |> List.map ( function Choice2Of2 t -> Choice2Of2 t | Choice1Of2 fl -> Choice2Of2 fl.value)
632
632
633
- let emitComments ( comments : Comment list ) : text list =
634
- // TODO
635
- []
633
+ let emitComments ( floating : bool ) ( comments : Comment list ) : text list =
634
+ if List.isEmpty comments then []
635
+ else
636
+ let escape =
637
+ String.replace " /*" " / *"
638
+ >> String.replace " */" " * /"
639
+ let emit ( c : Comment ) =
640
+ match c with
641
+ | Description lines
642
+ | Summary lines -> lines |> List.map escape |> strLines
643
+ | c -> c.ToJsDoc() |> escape |> str
644
+ let body = comments |> List.map emit |> concat newline
645
+ if floating then [ comment body] else [ docComment body]
636
646
637
647
let inline binding ( f : ( string -> string ) -> CurrentScope -> Binding ) : StructuredTextItem list =
638
648
[ Binding ( fun renamer scope -> f ( renamer.Rename " value" ) scope)]
@@ -688,7 +698,7 @@ let extValue flags overrideFunc ctx (t: Type) =
688
698
let rec emitMembers flags overrideFunc ctx ( selfTy : Type ) ( isExportDefaultClass : bool ) ( ma : MemberAttribute ) m =
689
699
let emitType_ = emitTypeImpl flags overrideFunc
690
700
691
- let comments = emitComments ma.comments
701
+ let comments = emitComments false ma.comments
692
702
693
703
let inline extFunc ft = extFunc flags overrideFunc ctx ft
694
704
let inline extValue t = extValue flags overrideFunc ctx t
@@ -845,11 +855,13 @@ let rec emitMembers flags overrideFunc ctx (selfTy: Type) (isExportDefaultClass:
845
855
emitMembers flags overrideFunc ctx selfTy isExportDefaultClass ma ( Indexer ( ft, WriteOnly))
846
856
]
847
857
| SymbolIndexer ( symbol, ft, _) ->
858
+ let comments = emitComments true ma.comments
848
859
let c =
849
860
let ft = func ft
850
861
tprintf " external [Symbol.%s ]: " symbol + ft + tprintf " = \" [Symbol.%s ]\" " symbol
851
862
binding ( fun _ _ -> Binding.unknown comments ( Some c))
852
863
| UnknownMember msgo ->
864
+ let comments = emitComments true ma.comments
853
865
binding ( fun _ _ -> Binding.unknown comments ( msgo |> Option.map str))
854
866
855
867
let emitTypeAliasesImpl
@@ -1053,7 +1065,7 @@ let rec emitClass flags overrideFunc (ctx: Context) (current: StructuredText) (c
1053
1065
| ClassKind.NormalClass _ -> forceScope |> Option.defaultValue Scope.Default
1054
1066
| _ -> Scope.Ignore
1055
1067
1056
- let comments = c.comments |> emitComments
1068
+ let comments = c.comments |> emitComments false
1057
1069
1058
1070
let tagsDefinition =
1059
1071
if useTags && innerCtx.options.inheritWithTags.HasProvide then
@@ -1105,7 +1117,7 @@ let rec emitClass flags overrideFunc (ctx: Context) (current: StructuredText) (c
1105
1117
1106
1118
emitTypeAliasesImpl " t" flags overrideFunc innerCtx c.loc c.typeParams selfTyText.ty ( fun x ->
1107
1119
if not x.isOverload then
1108
- [ TypeDefText.Create( x.name, x.tyargs, x.target, isRec= selfTyText.isRec, comments= emitComments c.comments)]
1120
+ [ TypeDefText.Create( x.name, x.tyargs, x.target, isRec= selfTyText.isRec, comments= emitComments false c.comments)]
1109
1121
else
1110
1122
[ TypeAliasText ( Statement.typeAlias false x.name ( x.tyargs |> List.map snd) x.target)]
1111
1123
)
@@ -1246,9 +1258,9 @@ let emitEnum (ctx: Context) (current: StructuredText) (e: Enum) =
1246
1258
for key, value in distinctCases do
1247
1259
yield emitConstructor key [ Attr.as_ ( Term.literal value)] [] |> indent
1248
1260
]
1249
- let item = TypeDefText.Create( " t" , [], Some casesText, shouldAssert= true , comments= emitComments e.comments)
1261
+ let item = TypeDefText.Create( " t" , [], Some casesText, shouldAssert= true , comments= emitComments false e.comments)
1250
1262
let items = item :: List.map childNode e.cases
1251
- let comments = e.comments |> emitComments
1263
+ let comments = e.comments |> emitComments false
1252
1264
{| StructuredTextNode.empty with items = items; comments = comments |}
1253
1265
1254
1266
let exports = getExportFromStatement ctx e.name Kind.OfEnum " enum" ( Enum e)
@@ -1260,7 +1272,7 @@ let emitEnum (ctx: Context) (current: StructuredText) (e: Enum) =
1260
1272
let emitTypeAlias flags overrideFunc ( ctx : Context ) ( current : StructuredText ) ( ta : TypeAlias ) : StructuredText =
1261
1273
let emitType = emitTypeImpl flags overrideFunc
1262
1274
1263
- let comments = ( ta :> ICommented<_>) .getComments() |> emitComments
1275
+ let comments = ( ta :> ICommented<_>) .getComments() |> emitComments false
1264
1276
let knownTypes = Statement.getKnownTypes ctx [ TypeAlias ta]
1265
1277
1266
1278
let items =
@@ -1272,7 +1284,7 @@ let emitTypeAlias flags overrideFunc (ctx: Context) (current: StructuredText) (t
1272
1284
[ TypeDefText.Create (
1273
1285
x.name, x.tyargs, x.target,
1274
1286
isRec= isRec, attrs= attrs, shouldAssert= shouldAssert,
1275
- comments= emitComments ta.comments
1287
+ comments= emitComments false ta.comments
1276
1288
)]
1277
1289
else
1278
1290
[ TypeAliasText ( Statement.typeAlias false x.name ( x.tyargs |> List.map snd) x.target)]
@@ -1380,7 +1392,7 @@ let rec emitFunction flags overrideFunc ctx (f: Function) =
1380
1392
let inline extFunc ft = extFunc flags overrideFunc ctx ft
1381
1393
let ty , attr = extFunc f.typ
1382
1394
let attr = attr |> impossibleNone ( fun () -> " emitFunction" )
1383
- let comments = emitComments f.comments
1395
+ let comments = emitComments false f.comments
1384
1396
binding ( fun rename s -> createExternalForValue ctx rename s ( Attr.External.val_ :: attr) comments f.name ty)
1385
1397
1386
1398
and emitVariable flags overrideFunc ctx ( v : Variable ) =
@@ -1393,7 +1405,7 @@ and emitVariable flags overrideFunc ctx (v: Variable) =
1393
1405
let emitType = emitTypeImpl flags
1394
1406
let emitType_ = emitType overrideFunc
1395
1407
let ty , attr = emitType_ ctx v.typ, [ Attr.External.val_]
1396
- let comments = emitComments v.comments
1408
+ let comments = emitComments false v.comments
1397
1409
binding ( fun rename s -> createExternalForValue ctx rename s attr comments v.name ty)
1398
1410
1399
1411
let emitImport ( ctx : Context ) ( i : Import ) : StructuredTextItem list =
@@ -1452,7 +1464,7 @@ let emitImport (ctx: Context) (i: Import) : StructuredTextItem list =
1452
1464
|> Option.defaultValue []
1453
1465
| NamespaceImport _ | ES6DefaultImport _ | ES6Import _ -> []
1454
1466
1455
- [ yield ! emitComments i.comments |> List.map ImportText
1467
+ [ yield ! emitComments true i.comments |> List.map ImportText
1456
1468
yield commentStr i.origText |> ImportText
1457
1469
for c in i.clauses do
1458
1470
yield ! emitImportClause c]
@@ -1481,7 +1493,7 @@ let createStructuredText (rootCtx: Context) (stmts: Statement list) : Structured
1481
1493
comments = memberAttr.comments; loc = memberAttr.loc }
1482
1494
emitFunction flags overrideFunc ctx f
1483
1495
[ for ma, m in moduleIntf.members do
1484
- let comments = emitComments ma.comments
1496
+ let comments = emitComments false ma.comments
1485
1497
match m with
1486
1498
| Field ( fl, mt) ->
1487
1499
yield ! emitAsVariable fl.name fl.value ( mt = ReadOnly) ma
@@ -1527,7 +1539,7 @@ let createStructuredText (rootCtx: Context) (stmts: Statement list) : Structured
1527
1539
| SymbolIndexer _ | UnknownMember None -> () ]
1528
1540
1529
1541
let rec folder ctx ( current : StructuredText ) ( s : Statement ) : StructuredText =
1530
- let comments = ( s :> ICommented<_>) .getComments() |> emitComments
1542
+ let comments = ( s :> ICommented<_>) .getComments() |> emitComments false
1531
1543
1532
1544
let knownTypes () = Statement.getKnownTypes ctx [ s]
1533
1545
let addExport name kind kindString current =
@@ -1667,7 +1679,7 @@ let createStructuredText (rootCtx: Context) (stmts: Statement list) : Structured
1667
1679
| Some s -> commentStr s | None -> commentStr " unknown statement"
1668
1680
current |> set {| StructuredTextNode.empty with items = [ Comment cmt] |}
1669
1681
| FloatingComment c ->
1670
- let cmt = c.comments |> emitComments |> List.map Comment
1682
+ let cmt = c.comments |> emitComments true |> List.map Comment
1671
1683
current |> set {| StructuredTextNode.empty with items = Comment empty :: cmt |}
1672
1684
1673
1685
stmts |> List.fold ( folder rootCtx) Trie.empty
@@ -1751,7 +1763,7 @@ let rec emitModule (dt: DependencyTrie<string>) flags (ctx: Context) st =
1751
1763
yield Statement.open_ moduleName
1752
1764
yield str " type nonrec t = t"
1753
1765
]
1754
- let m content = {| name = moduleName; origName = e.name; content = content; comments = emitComments e.comments |}
1766
+ let m content = {| name = moduleName; origName = e.name; content = content; comments = emitComments false e.comments |}
1755
1767
{| types = types
1756
1768
intf = Statement.moduleSig ( m intf)
1757
1769
impl = Statement.moduleVal ( m ( if isLinear then intf else impl))
0 commit comments