@@ -43,7 +43,7 @@ pub struct ExportedClass {
43
43
}
44
44
45
45
struct ClassField {
46
- comments : String ,
46
+ comments : Vec < String > ,
47
47
name : String ,
48
48
readonly : bool ,
49
49
}
@@ -55,7 +55,6 @@ pub struct SubContext<'a, 'b: 'a> {
55
55
56
56
impl < ' a > Context < ' a > {
57
57
fn export ( & mut self , name : & str , contents : & str , comments : Option < String > ) {
58
- let contents = contents;
59
58
let contents = contents. trim ( ) ;
60
59
if let Some ( ref c) = comments {
61
60
self . globals . push_str ( c) ;
@@ -596,14 +595,14 @@ impl<'a> Context<'a> {
596
595
) ) ;
597
596
cx. finish ( "" , & format ! ( "wasm.{}" , wasm_setter) ) . 0
598
597
} ;
599
- let ( get, _ts) = Js2Rust :: new ( & field. name , self )
598
+ let ( get, _ts, js_doc ) = Js2Rust :: new ( & field. name , self )
600
599
. method ( true , false )
601
600
. ret ( & Some ( descriptor) ) ?
602
601
. finish ( "" , & format ! ( "wasm.{}" , wasm_getter) ) ;
603
602
if !dst. ends_with ( "\n " ) {
604
603
dst. push_str ( "\n " ) ;
605
604
}
606
- dst. push_str ( & field. comments ) ;
605
+ dst. push_str ( & format_doc_comments ( & field. comments , Some ( js_doc ) ) ) ;
607
606
dst. push_str ( "get " ) ;
608
607
dst. push_str ( & field. name ) ;
609
608
dst. push_str ( & get) ;
@@ -1653,11 +1652,11 @@ impl<'a, 'b> SubContext<'a, 'b> {
1653
1652
. exported_classes
1654
1653
. entry ( s. name . clone ( ) )
1655
1654
. or_insert_with ( Default :: default) ;
1656
- class. comments = format_doc_comments ( & s. comments ) ;
1655
+ class. comments = format_doc_comments ( & s. comments , None ) ;
1657
1656
class. fields . extend ( s. fields . iter ( ) . map ( |f| ClassField {
1658
1657
name : f. name . clone ( ) ,
1659
1658
readonly : f. readonly ,
1660
- comments : format_doc_comments ( & f. comments ) ,
1659
+ comments : f. comments . clone ( ) ,
1661
1660
} ) ) ;
1662
1661
}
1663
1662
@@ -1674,13 +1673,13 @@ impl<'a, 'b> SubContext<'a, 'b> {
1674
1673
Some ( d) => d,
1675
1674
} ;
1676
1675
1677
- let ( js, ts) = Js2Rust :: new ( & export. function . name , self . cx )
1676
+ let ( js, ts, js_doc ) = Js2Rust :: new ( & export. function . name , self . cx )
1678
1677
. process ( descriptor. unwrap_function ( ) ) ?
1679
1678
. finish ( "function" , & format ! ( "wasm.{}" , export. function. name) ) ;
1680
1679
self . cx . export (
1681
1680
& export. function . name ,
1682
1681
& js,
1683
- Some ( format_doc_comments ( & export. comments ) ) ,
1682
+ Some ( format_doc_comments ( & export. comments , Some ( js_doc ) ) ) ,
1684
1683
) ;
1685
1684
self . cx . globals . push_str ( "\n " ) ;
1686
1685
self . cx . typescript . push_str ( "export " ) ;
@@ -1701,18 +1700,19 @@ impl<'a, 'b> SubContext<'a, 'b> {
1701
1700
Some ( d) => d,
1702
1701
} ;
1703
1702
1704
- let ( js, ts) = Js2Rust :: new ( & export. function . name , self . cx )
1703
+ let ( js, ts, js_doc ) = Js2Rust :: new ( & export. function . name , self . cx )
1705
1704
. method ( export. method , export. consumed )
1706
1705
. process ( descriptor. unwrap_function ( ) ) ?
1707
1706
. finish ( "" , & format ! ( "wasm.{}" , wasm_name) ) ;
1707
+
1708
1708
let class = self
1709
1709
. cx
1710
1710
. exported_classes
1711
1711
. entry ( class_name. to_string ( ) )
1712
1712
. or_insert ( ExportedClass :: default ( ) ) ;
1713
1713
class
1714
1714
. contents
1715
- . push_str ( & format_doc_comments ( & export. comments ) ) ;
1715
+ . push_str ( & format_doc_comments ( & export. comments , Some ( js_doc ) ) ) ;
1716
1716
if !export. method {
1717
1717
class. contents . push_str ( "static " ) ;
1718
1718
class. typescript . push_str ( "static " ) ;
@@ -1960,7 +1960,7 @@ impl<'a, 'b> SubContext<'a, 'b> {
1960
1960
self . cx . export (
1961
1961
& enum_. name ,
1962
1962
& format ! ( "Object.freeze({{ {} }})" , variants) ,
1963
- Some ( format_doc_comments ( & enum_. comments ) ) ,
1963
+ Some ( format_doc_comments ( & enum_. comments , None ) ) ,
1964
1964
) ;
1965
1965
self . cx
1966
1966
. typescript
@@ -2011,10 +2011,17 @@ impl<'a, 'b> SubContext<'a, 'b> {
2011
2011
}
2012
2012
}
2013
2013
2014
- fn format_doc_comments ( comments : & Vec < String > ) -> String {
2014
+ fn format_doc_comments ( comments : & Vec < String > , js_doc_comments : Option < String > ) -> String {
2015
2015
let body: String = comments
2016
2016
. iter ( )
2017
2017
. map ( |c| format ! ( "*{}\n " , c. trim_matches( '"' ) ) )
2018
2018
. collect ( ) ;
2019
- format ! ( "/**\n {}*/\n " , body)
2019
+ let doc = if let Some ( docs) = js_doc_comments {
2020
+ docs. lines ( )
2021
+ . map ( |l| format ! ( "* {} \n " , l) )
2022
+ . collect ( )
2023
+ } else {
2024
+ String :: new ( )
2025
+ } ;
2026
+ format ! ( "/**\n {}{}*/\n " , body, doc)
2020
2027
}
0 commit comments