forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tsgen] Make commonjs module output compatible with tsc.
This enables commonjs modules to be imported into TypeScript using the same syntax as ESM modules e.g. `import moduleFactory from './embind_tsgen.js';`
- Loading branch information
1 parent
76ad476
commit 033cd49
Showing
3 changed files
with
42 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,36 @@ | ||
// Example TS program that consumes the emscripten-generated module to to | ||
// illustrate how the type definitions are used and test they are workings as | ||
// expected. | ||
import moduleFactory from './embind_tsgen.mjs'; | ||
import moduleFactory from './embind_tsgen.js'; | ||
|
||
const module = await moduleFactory(); | ||
// Async IIFE is required for TSC with commonjs modules. This is noted needed | ||
// for ESM top level await can be used. | ||
(async function() { | ||
|
||
// Test a few variations of passing value_objects with strings. | ||
module.setValObj({ | ||
bar: module.Bar.valueOne, | ||
string: "ABCD", | ||
callback: () => {} | ||
}); | ||
const module = await moduleFactory(); | ||
|
||
module.setValObj({ | ||
bar: module.Bar.valueOne, | ||
string: new Int8Array([65, 66, 67, 68]), | ||
callback: () => {} | ||
}); | ||
// Test a few variations of passing value_objects with strings. | ||
module.setValObj({ | ||
bar: module.Bar.valueOne, | ||
string: "ABCD", | ||
callback: () => {} | ||
}); | ||
|
||
const valObj = module.getValObj(); | ||
// TODO: remove the cast below when better definitions are generated for value | ||
// objects. | ||
const valString : string = valObj.string as string; | ||
module.setValObj({ | ||
bar: module.Bar.valueOne, | ||
string: new Int8Array([65, 66, 67, 68]), | ||
callback: () => {} | ||
}); | ||
|
||
// Ensure nonnull pointers do no need a cast or nullptr check to use. | ||
const obj = module.getNonnullPointer(); | ||
obj.delete(); | ||
const valObj = module.getValObj(); | ||
// TODO: remove the cast below when better definitions are generated for value | ||
// objects. | ||
const valString : string = valObj.string as string; | ||
|
||
console.log('ts ran'); | ||
// Ensure nonnull pointers do no need a cast or nullptr check to use. | ||
const obj = module.getNonnullPointer(); | ||
obj.delete(); | ||
|
||
console.log('ts ran'); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters