emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.39k stars 3.26k forks source link

--emit-tsd does not output function argument names #22001

Open jdarpinian opened 1 month ago

jdarpinian commented 1 month ago

When using --emit-tsd, all of the function arguments in the resulting .d.ts file are named _0, _1, etc. They have correct types, but the real argument names are important to me. Am I missing a compiler flag that would enable outputting argument names, or is this not yet implemented?

jdarpinian commented 1 month ago

I guess I see the problem. Embind gets the argument types by template metaprogramming, but getting the argument names would require C++ reflection which is not standardized yet. Besides waiting for that (hopefully within our lifetimes?) I guess other options would be writing a clang plugin, or parsing DWARF information (when present).

jdarpinian commented 1 month ago

I see that Embind actually has an undocumented feature for this! If you include a parenthesized argument list in the name string passed to embind::function, it will be used to supply argument names in the .d.ts file. However it doesn't handle types in the argument list, it has to be a list of names without types. I'll try making a PR to accept types in this list too, and check that the types match the real types.