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

[js_interop/dart2wasm] Canonicalize and move <constant-or-literal>.toJS at compile-time to mjs file #56046

Open
mkustermann opened this issue Jun 19, 2024 · 0 comments
Labels
area-dart2wasm Issues for the dart2wasm compiler. web-js-interop Issues that impact all js interop

Comments

@mkustermann
Copy link
Member

We should evaluate whether it makes sense for dart2wasm recognize <constant-or-literal>.toJS expressions and canonicalize & move those objects at compile-time to JS (by emitting them into the ...mjs file and importing those external references) instead of lazily at runtime.

It may be very common to have code such as

@JS()
external JSObject foo(JSString value);

main() {
  foo('foo'.toJS);
}

Currently one may be tempted to cache such manually at the top-level via

@JS()
external JSObject foo(JSString value);

final jsFooArg = 'foo'.toJS;
main() {
  foo(jsFooArg);
}

but this compiles to worse code in dart2js (see #56045)

/cc @srujzs

@mkustermann mkustermann added the area-dart2wasm Issues for the dart2wasm compiler. label Jun 19, 2024
@srujzs srujzs added the web-js-interop Issues that impact all js interop label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart2wasm Issues for the dart2wasm compiler. web-js-interop Issues that impact all js interop
Projects
Status: No status
Development

No branches or pull requests

2 participants