Skip to content

Conversation

thomasetter
Copy link
Contributor

This fixes the issue that two enums with the same name cause the "second" one to overwrite the "first" one.

Currently, looking at the output of target/wasm32-unknown-unknown/wbg-tmp-wasm-<some-hex-characters>.wasm/wasm-bindgen-test.js generated with

WASM_BINDGEN_SPLIT_LINKED_MODULES=1 cargo test --target wasm32-unknown-unknown

the part with the enums (was at line 4849 for me) looks like this:

**
*/
module.exports.Color = Object.freeze({ Green:0,"0":"Green",Yellow:1,"1":"Yellow",Red:2,"2":"Red", });
/**
*/
module.exports.JsRenamedEnum = Object.freeze({ A:10,"10":"A",B:20,"20":"B", });
/**
*/
module.exports.EnumArrayElement = Object.freeze({ Unit:0,"0":"Unit", });
/**
* annotated enum type
*/
module.exports.AnnotatedEnum = Object.freeze({
/**
* annotated enum variant 1
*/
Variant1:0,"0":"Variant1",
/**
* annotated enum variant 2
*/
Variant2:1,"1":"Variant2", });
/**
*/
module.exports.Color = Object.freeze({ Green:0,"0":"Green",Yellow:1,"1":"Yellow",Red:2,"2":"Red", });
/**
*/
module.exports.ColorWithCustomValues = Object.freeze({ Green:21,"21":"Green",Yellow:34,"34":"Yellow",Red:2,"2":"Red", });
/**
*/
module.exports.MyEnum = Object.freeze({ One:1,"1":"One",Two:2,"2":"Two", });

The second assignment module.exports.Color = overwrites the first one, causing the first one to have no effect.

The reason this was not captured by the tests is that the two enums were identical in shape (same unit keys/values).

Copy link
Contributor

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

LGTM!
Could you add a note in the changelog as well?

@thomasetter
Copy link
Contributor Author

Thanks for the quick review, added a note in the changelog under Changed.

@daxpedda daxpedda merged commit 54f22ee into wasm-bindgen:main Oct 26, 2023
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