Skip to content

Conversation

@brendandahl
Copy link
Collaborator

In the new TS file we can add tests for things where just checking if the definition file compiles is not enough. This will help catch issues like #22569.

struct ValObj {
Foo foo;
Bar bar;
std::string string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to be a more realistic use of a ValueObject.

# Test that the output compiles with a TS file that uses the defintions.
cmd = shared.get_npm_cmd('tsc') + ['embind_tsgen.d.ts', '--noEmit']
shutil.copyfile(test_file('other/embind_tsgen.ts'), 'main.ts')
# A package file with type=module is needed to allow top level await in TS.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you instead use the .mjs extension?

shutil.copyfile(test_file('other/embind_tsgen.ts'), 'main.ts')
# A package file with type=module is needed to allow top level await in TS.
shutil.copyfile(test_file('other/embind_tsgen_package.json'), 'package.json')
cmd = shared.get_npm_cmd('tsc') + ['embind_tsgen.d.ts', 'main.ts', '--module', 'NodeNext', '--moduleResolution', 'nodenext']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't tsc generate a file called .mjs here I wonder?

Is the package.json file here needed for running tsc or for running the output?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't tsc generate a file called .mjs here I wonder?

They prefer the package approach. IIRC the different extension was somewhat controversial.

Is the package.json file here needed for running tsc or for running the output?

It's also needed for node to run it as an ES module. I've updated the comment.

In the new TS file we can add tests for things where just checking if the
definition file compiles is not enough. This will help catch issues like
@@ -0,0 +1,168 @@
// TypeScript bindings for emscripten-generated code. Automatically generated at compile time.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should say "Automatically generated by emcc" instead here.


actual = read_file('embind_tsgen.d.ts')
self.assertFileContents(test_file('other/embind_tsgen.d.ts'), actual)
self.assertFileContents(test_file('other/embind_tsgen_module.d.ts'), actual)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have both embind_tsgen.d.ts and embind_tsgen_module.d.ts checked into source control?

Should these two lines move up to 3391 right after the file is first generated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other/embind_tsgen.d.ts is used by a two other tests, it's the version of the output built without modularize & es6. I could alternatively rename it for the other tests.

@brendandahl brendandahl merged commit 76ad476 into emscripten-core:main Nov 20, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants