@@ -438,23 +438,19 @@ export class TSDBuilder extends ExportsWalker {
438438 }
439439
440440 visitFunction ( name : string , element : Function ) : void {
441- if ( element . isAny ( CommonFlags . PRIVATE | CommonFlags . SET ) ) return ;
441+ if ( element . isAny ( CommonFlags . PRIVATE ) ) return ;
442442 var sb = this . sb ;
443443 var signature = element . signature ;
444444 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 " ) ;
454447 } 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 " ) ;
457452 }
453+ sb . push ( name ) ;
458454 sb . push ( "(" ) ;
459455 var parameters = signature . parameterTypes ;
460456 var numParameters = parameters . length ;
@@ -604,12 +600,12 @@ export class TSDBuilder extends ExportsWalker {
604600
605601 build ( ) : string {
606602 var sb = this . sb ;
607- var isWasm64 = this . program . options . isWasm64 ;
603+ var options = this . program . options ;
608604 sb . push ( "type i8 = number;\n" ) ;
609605 sb . push ( "type i16 = number;\n" ) ;
610606 sb . push ( "type i32 = number;\n" ) ;
611607 sb . push ( "type i64 = bigint;\n" ) ;
612- if ( isWasm64 ) {
608+ if ( options . isWasm64 ) {
613609 sb . push ( "type isize = bigint;\n" ) ;
614610 } else {
615611 sb . push ( "type isize = number;\n" ) ;
@@ -618,7 +614,7 @@ export class TSDBuilder extends ExportsWalker {
618614 sb . push ( "type u16 = number;\n" ) ;
619615 sb . push ( "type u32 = number;\n" ) ;
620616 sb . push ( "type u64 = bigint;\n" ) ;
621- if ( isWasm64 ) {
617+ if ( options . isWasm64 ) {
622618 sb . push ( "type usize = bigint;\n" ) ;
623619 } else {
624620 sb . push ( "type usize = number;\n" ) ;
@@ -627,6 +623,23 @@ export class TSDBuilder extends ExportsWalker {
627623 sb . push ( "type f64 = number;\n" ) ;
628624 sb . push ( "type bool = boolean | number;\n" ) ;
629625 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" ) ;
630643 return this . sb . join ( "" ) ;
631644 }
632645}
0 commit comments