Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getter macro inconsistent behavior in Release/Debug builds #3912

Closed
dt665m opened this issue Apr 4, 2024 · 3 comments
Closed

getter macro inconsistent behavior in Release/Debug builds #3912

dt665m opened this issue Apr 4, 2024 · 3 comments
Labels

Comments

@dt665m
Copy link

dt665m commented Apr 4, 2024

Describe the Bug

I have a rust struct that is using #[wasm_bindgen] tooling with #[wasm_bindgen(getter)] functions. I'm seeing inconsistent behavior when building my project in Release and Debug mode.

In Debug Mode, accessing the getter in javascript land resolves to the returned object of the getter method.
In Release Mode, accessing the getter in javascript land resolves to a function/method. This happens with both the #[wasm_bindgen(getter)] proc macro for functions and the #[wasm_bindgen(getter_with_clone)] proc macro for the struct.

Steps to Reproduce

  • wasm-bindgen 0.2.92
  • I'm using OSX Sonoma on Apple Silicon and Chrome 123.x
  • clone this minimal repro
  • install trunk cargo install --locked trunk
  • serve with trunk serve
  • open browser at localhost:8080. Observe console log of "hello world"
  • serve with trunk serve --release
  • open browser at localhost:8080. Observe console log of "function...."

Expected Behavior

Debug and Release should be the same

Actual Behavior

Differing results in Debug and Release

@dt665m dt665m added the bug label Apr 4, 2024
@Liamolucko
Copy link
Collaborator

This seems to be a bug with Trunk's minifier (https://github.com/wilsonzlin/minify-js): passing --no-minification fixes the issue. (Minification seems to be disabled by default in debug builds.)

It seems like it simply deletes the get keyword; this JS:

class A {
    get b() {
        return 5;
    }
}

gets minified into

class a{b(){return 5}}

This is with v0.5, the version Trunk's using; I haven't checked if it's still an issue in v0.6.

@dt665m
Copy link
Author

dt665m commented Apr 7, 2024

Thanks for tracking this... I'll move this issue to trunk. Should we close here?

@daxpedda
Copy link
Collaborator

Thanks for tracking this... I'll move this issue to trunk. Should we close here?

Yes, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants