[tsgen] Quote non-identifier enum value names in module entry.#26814
Open
soilSpoon wants to merge 3 commits intoemscripten-core:mainfrom
Open
[tsgen] Quote non-identifier enum value names in module entry.#26814soilSpoon wants to merge 3 commits intoemscripten-core:mainfrom
soilSpoon wants to merge 3 commits intoemscripten-core:mainfrom
Conversation
7acd724 to
b282d9a
Compare
`enum_value_type::string` (added in emscripten-core#25257) accepts arbitrary JS-facing names via `.value("name", ...)`. The type union path quotes these as string literals, but `printModuleEntry` emits them as bare object keys, producing invalid TypeScript when the name is not a valid JS identifier (e.g. hyphenated names). The same bare-key shape exists in all three `valueType` branches. The convention in `object`/`number` modes is to use C++ identifiers so the bug isn't reachable there in practice, but the fix applies to all three for symmetry with `print`, which already handles non-identifier names via string-literal quoting.
b282d9a to
ba193ad
Compare
Collaborator
|
You'll want to run |
…num.
The previous commit added a hyphenated enum to embind_tsgen.cpp to
exercise the printModuleEntry quoting fix, and updated the
embind_tsgen.d.ts baseline. The same .cpp is also compiled by
test_embind_tsgen_ignore_{1,2,3,7} and the embind_tsgen_module test, so
their baselines need the matching HyphenatedEnum entries.
Regenerated via:
test/runner.py "other.test_embind_tsgen*" --rebaseline
Author
|
@brendandahl Done in e3630d3. The new
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
enum_value_type::string(added in #25257) accepts arbitrary JS-facing names via.value("name", ...). The type union path quotes these correctly as string literals, butprintModuleEntryemits them as bare object keys, producing invalid TypeScript when the name is not a valid JS identifier.Before:
After:
The same bare-key shape exists in all three
valueTypebranches ofprintModuleEntry. The convention inobject/numbermodes is to use C++ identifiers so the bug isn't reachable there in practice, but the fix applies to all three for symmetry withprint, which already handles non-identifier names via string-literal quoting.