Skip to content

Commit

Permalink
Improve ES6 support in TypeScript definitions generation (#21460)
Browse files Browse the repository at this point in the history
Users building with --emit-tsd and the EXPORT_ES6 setting should get
TypeScript definitions accounting for the fact that ES6 modules
include a default export that is a functor to instantiate and access
the wasm module in question

When generating TS definitions, query the EXPORT_ES6 setting and,
if present, add the appropriate exports to the output

Include options param in default functor export for `--emit-tsd`.
This serves as a starting point for incluing all options such as
`locateFile` (and the slew of others), without requiring manually
iterating through them

Update tests to include factory function
  • Loading branch information
jnickg authored Mar 5, 2024
1 parent 53f661c commit c8a1890
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/other/embind_tsgen_ignore_2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ interface EmbindModule {
wstring_test(_0: string): string;
}
export type MainModule = WasmModule & EmbindModule;
export default function MainModuleFactory (options?: unknown): Promise<MainModule>;
2 changes: 2 additions & 0 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ def create_tsd(metadata, embind_tsd):
if embind_tsd:
export_interfaces += ' & EmbindModule'
out += f'export type MainModule = {export_interfaces};\n'
if settings.EXPORT_ES6 and settings.MODULARIZE:
out += 'export default function MainModuleFactory (options?: unknown): Promise<MainModule>;\n'
return out


Expand Down

0 comments on commit c8a1890

Please sign in to comment.