@@ -438,23 +438,19 @@ export class TSDBuilder extends ExportsWalker {
438
438
}
439
439
440
440
visitFunction ( name : string , element : Function ) : void {
441
- if ( element . isAny ( CommonFlags . PRIVATE | CommonFlags . SET ) ) return ;
441
+ if ( element . isAny ( CommonFlags . PRIVATE ) ) return ;
442
442
var sb = this . sb ;
443
443
var signature = element . signature ;
444
444
indent ( sb , this . indentLevel ) ;
445
- if ( element . is ( CommonFlags . PROTECTED ) ) sb . push ( "protected " ) ;
446
- if ( element . is ( CommonFlags . STATIC ) ) sb . push ( "static " ) ;
447
- if ( element . is ( CommonFlags . GET ) ) {
448
- sb . push ( "get " ) ;
449
- sb . push ( name ) ; // 'get:funcName' internally
450
- sb . push ( "(): " ) ;
451
- sb . push ( this . typeToString ( signature . returnType ) ) ;
452
- sb . push ( ";\n" ) ;
453
- return ;
445
+ if ( ! element . isAny ( CommonFlags . STATIC | CommonFlags . INSTANCE ) ) {
446
+ sb . push ( "export function " ) ;
454
447
} else {
455
- if ( ! element . isAny ( CommonFlags . STATIC | CommonFlags . INSTANCE ) ) sb . push ( "export function " ) ;
456
- sb . push ( name ) ;
448
+ if ( element . is ( CommonFlags . PROTECTED ) ) sb . push ( "protected " ) ;
449
+ if ( element . is ( CommonFlags . STATIC ) ) sb . push ( "static " ) ;
450
+ if ( element . is ( CommonFlags . GET ) ) sb . push ( "get " ) ;
451
+ else if ( element . is ( CommonFlags . SET ) ) sb . push ( "set " ) ;
457
452
}
453
+ sb . push ( name ) ;
458
454
sb . push ( "(" ) ;
459
455
var parameters = signature . parameterTypes ;
460
456
var numParameters = parameters . length ;
@@ -604,12 +600,12 @@ export class TSDBuilder extends ExportsWalker {
604
600
605
601
build ( ) : string {
606
602
var sb = this . sb ;
607
- var isWasm64 = this . program . options . isWasm64 ;
603
+ var options = this . program . options ;
608
604
sb . push ( "type i8 = number;\n" ) ;
609
605
sb . push ( "type i16 = number;\n" ) ;
610
606
sb . push ( "type i32 = number;\n" ) ;
611
607
sb . push ( "type i64 = bigint;\n" ) ;
612
- if ( isWasm64 ) {
608
+ if ( options . isWasm64 ) {
613
609
sb . push ( "type isize = bigint;\n" ) ;
614
610
} else {
615
611
sb . push ( "type isize = number;\n" ) ;
@@ -618,7 +614,7 @@ export class TSDBuilder extends ExportsWalker {
618
614
sb . push ( "type u16 = number;\n" ) ;
619
615
sb . push ( "type u32 = number;\n" ) ;
620
616
sb . push ( "type u64 = bigint;\n" ) ;
621
- if ( isWasm64 ) {
617
+ if ( options . isWasm64 ) {
622
618
sb . push ( "type usize = bigint;\n" ) ;
623
619
} else {
624
620
sb . push ( "type usize = number;\n" ) ;
@@ -627,6 +623,23 @@ export class TSDBuilder extends ExportsWalker {
627
623
sb . push ( "type f64 = number;\n" ) ;
628
624
sb . push ( "type bool = boolean | number;\n" ) ;
629
625
this . walk ( ) ;
626
+ if ( options . exportMemory ) {
627
+ sb . push ( "export const memory: WebAssembly.Memory;\n" ) ;
628
+ }
629
+ if ( options . exportTable ) {
630
+ sb . push ( "export const table: WebAssembly.Table;\n" ) ;
631
+ }
632
+ if ( options . explicitStart ) {
633
+ sb . push ( "export function _start(): void;\n" ) ;
634
+ }
635
+ if ( options . exportRuntime ) {
636
+ sb . push ( "export function __new(size: usize, id: u32): usize;\n" ) ;
637
+ sb . push ( "export function __pin(ptr: usize): usize;\n" ) ;
638
+ sb . push ( "export function __unpin(ptr: usize): void;\n" ) ;
639
+ sb . push ( "export function __collect(): void;\n" ) ;
640
+ sb . push ( "export const __rtti_base: usize;\n" ) ;
641
+ }
642
+ sb . push ( "export const __setArgumentsLength: ((n: i32) => void) | undefined;\n" ) ;
630
643
return this . sb . join ( "" ) ;
631
644
}
632
645
}
0 commit comments