@@ -48,82 +48,77 @@ impl Config {
48
48
}
49
49
}
50
50
51
- impl Output {
52
- pub fn typescript ( & self ) -> String {
53
- let mut exports = format ! ( "/* tslint:disable */\n " ) ;
54
-
55
- if let Some ( i) = self . module . export_section ( ) {
56
- let imported_functions = self
57
- . module
58
- . import_section ( )
59
- . map ( |m| m. functions ( ) as u32 )
60
- . unwrap_or ( 0 ) ;
61
- for entry in i. entries ( ) {
62
- let idx = match * entry. internal ( ) {
63
- Internal :: Function ( i) => i - imported_functions,
64
- Internal :: Memory ( _) => {
65
- exports. push_str ( & format ! (
66
- "
67
- export const {}: WebAssembly.Memory;
68
- " ,
69
- entry. field( )
70
- ) ) ;
71
- continue ;
72
- }
73
- Internal :: Table ( _) => {
74
- exports. push_str ( & format ! (
75
- "
76
- export const {}: WebAssembly.Table;
77
- " ,
78
- entry. field( )
79
- ) ) ;
80
- continue ;
81
- }
82
- Internal :: Global ( _) => continue ,
83
- } ;
84
-
85
- let functions = self
86
- . module
87
- . function_section ( )
88
- . expect ( "failed to find function section" ) ;
89
- let idx = functions. entries ( ) [ idx as usize ] . type_ref ( ) ;
90
-
91
- let types = self
92
- . module
93
- . type_section ( )
94
- . expect ( "failed to find type section" ) ;
95
- let ty = match types. types ( ) [ idx as usize ] {
96
- Type :: Function ( ref f) => f,
97
- } ;
98
- let mut args = String :: new ( ) ;
99
- for ( i, _) in ty. params ( ) . iter ( ) . enumerate ( ) {
100
- if i > 0 {
101
- args. push_str ( ", " ) ;
102
- }
103
- args. push ( ( b'a' + ( i as u8 ) ) as char ) ;
104
- args. push_str ( ": number" ) ;
51
+ pub fn typescript ( module : & Module ) -> String {
52
+ let mut exports = format ! ( "/* tslint:disable */\n " ) ;
53
+
54
+ if let Some ( i) = module. export_section ( ) {
55
+ let imported_functions = module
56
+ . import_section ( )
57
+ . map ( |m| m. functions ( ) as u32 )
58
+ . unwrap_or ( 0 ) ;
59
+ for entry in i. entries ( ) {
60
+ let idx = match * entry. internal ( ) {
61
+ Internal :: Function ( i) => i - imported_functions,
62
+ Internal :: Memory ( _) => {
63
+ exports. push_str ( & format ! (
64
+ "export const {}: WebAssembly.Memory;\n " ,
65
+ entry. field( )
66
+ ) ) ;
67
+ continue ;
105
68
}
106
-
107
- exports. push_str ( & format ! (
108
- "
109
- export function {name}({args}): {ret};
110
- " ,
111
- name = entry. field( ) ,
112
- args = args,
113
- ret = if ty. return_type( ) . is_some( ) {
114
- "number"
115
- } else {
116
- "void"
117
- } ,
118
- ) ) ;
69
+ Internal :: Table ( _) => {
70
+ exports. push_str ( & format ! (
71
+ "export const {}: WebAssembly.Table;\n " ,
72
+ entry. field( )
73
+ ) ) ;
74
+ continue ;
75
+ }
76
+ Internal :: Global ( _) => continue ,
77
+ } ;
78
+
79
+ let functions = module
80
+ . function_section ( )
81
+ . expect ( "failed to find function section" ) ;
82
+ let idx = functions. entries ( ) [ idx as usize ] . type_ref ( ) ;
83
+
84
+ let types = module
85
+ . type_section ( )
86
+ . expect ( "failed to find type section" ) ;
87
+ let ty = match types. types ( ) [ idx as usize ] {
88
+ Type :: Function ( ref f) => f,
89
+ } ;
90
+ let mut args = String :: new ( ) ;
91
+ for ( i, _) in ty. params ( ) . iter ( ) . enumerate ( ) {
92
+ if i > 0 {
93
+ args. push_str ( ", " ) ;
94
+ }
95
+ args. push ( ( b'a' + ( i as u8 ) ) as char ) ;
96
+ args. push_str ( ": number" ) ;
119
97
}
98
+
99
+ exports. push_str ( & format ! (
100
+ "export function {name}({args}): {ret};\n " ,
101
+ name = entry. field( ) ,
102
+ args = args,
103
+ ret = if ty. return_type( ) . is_some( ) {
104
+ "number"
105
+ } else {
106
+ "void"
107
+ } ,
108
+ ) ) ;
120
109
}
110
+ }
121
111
112
+ return exports;
113
+ }
114
+
115
+ impl Output {
116
+ pub fn typescript ( & self ) -> String {
117
+ let mut ts = typescript ( & self . module ) ;
122
118
if self . base64 {
123
- exports . push_str ( "export const booted: Promise<boolean>;" ) ;
119
+ ts . push_str ( "export const booted: Promise<boolean>;\n " ) ;
124
120
}
125
-
126
- return exports;
121
+ return ts
127
122
}
128
123
129
124
pub fn js ( self ) -> Result < String , Error > {
0 commit comments