@@ -96,6 +96,12 @@ impl<'a> CodeGenerator<'a> {
96
96
code_gen. package
97
97
) ;
98
98
99
+ // this should only be called once and not per file
100
+ // if cfg!(feature = "use-wasm-bindgen") {
101
+ code_gen. buf
102
+ . push_str ( "use wasm_bindgen::prelude::*;\n \n " ) ;
103
+ // }
104
+
99
105
code_gen. path . push ( 4 ) ;
100
106
for ( idx, message) in file. message_type . into_iter ( ) . enumerate ( ) {
101
107
code_gen. path . push ( idx as i32 ) ;
@@ -188,6 +194,11 @@ impl<'a> CodeGenerator<'a> {
188
194
self . append_doc ( ) ;
189
195
self . append_type_attributes ( & fq_message_name) ;
190
196
self . push_indent ( ) ;
197
+ // if cfg!(feature = "use-wasm-bindgen") {
198
+ self . buf
199
+ . push_str ( "#[wasm_bindgen]\n " ) ;
200
+ self . push_indent ( ) ;
201
+ // }
191
202
self . buf
192
203
. push_str ( "#[derive(Clone, PartialEq, ::prost::Message)]\n " ) ;
193
204
self . push_indent ( ) ;
@@ -388,7 +399,13 @@ impl<'a> CodeGenerator<'a> {
388
399
self . buf . push_str ( "\" )]\n " ) ;
389
400
self . append_field_attributes ( msg_name, field. name ( ) ) ;
390
401
self . push_indent ( ) ;
391
- self . buf . push_str ( "pub " ) ;
402
+ // see https://github.com/rustwasm/wasm-bindgen/issues/439
403
+ // pub not working in structs for vectors
404
+ if !repeated
405
+ // && cfg!(feature = "use-wasm-bindgen")
406
+ {
407
+ self . buf . push_str ( "pub " ) ;
408
+ }
392
409
self . buf . push_str ( & to_snake ( field. name ( ) ) ) ;
393
410
self . buf . push_str ( ": " ) ;
394
411
if repeated {
@@ -508,6 +525,12 @@ impl<'a> CodeGenerator<'a> {
508
525
509
526
let oneof_name = format ! ( "{}.{}" , msg_name, oneof. name( ) ) ;
510
527
self . append_type_attributes ( & oneof_name) ;
528
+ // wasm-bindgen does not support enums holding data
529
+ // this might need a lot more changes to work
530
+
531
+ // self.push_indent();
532
+ // self.buf
533
+ // .push_str("#[wasm_bindgen]\n");
511
534
self . push_indent ( ) ;
512
535
self . buf
513
536
. push_str ( "#[derive(Clone, PartialEq, ::prost::Oneof)]\n " ) ;
@@ -593,6 +616,11 @@ impl<'a> CodeGenerator<'a> {
593
616
self . append_doc ( ) ;
594
617
self . append_type_attributes ( & fq_enum_name) ;
595
618
self . push_indent ( ) ;
619
+ // if cfg!(feature = "use-wasm-bindgen") {
620
+ self . buf
621
+ . push_str ( "#[wasm_bindgen]\n " ) ;
622
+ self . push_indent ( ) ;
623
+ // }
596
624
self . buf . push_str (
597
625
"#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]\n " ,
598
626
) ;
@@ -726,6 +754,12 @@ impl<'a> CodeGenerator<'a> {
726
754
self . package . push_str ( module) ;
727
755
728
756
self . depth += 1 ;
757
+
758
+ // if cfg!(feature = "use-wasm-bindgen") {
759
+ self . push_indent ( ) ;
760
+ self . buf
761
+ . push_str ( "use wasm_bindgen::prelude::*;\n \n " ) ;
762
+ // }
729
763
}
730
764
731
765
fn pop_mod ( & mut self ) {
0 commit comments