Skip to content

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

Closed
@mkustermann

Description

@mkustermann

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart2wasmIssues for the dart2wasm compiler.type-performanceIssue relates to performance or code sizeweb-js-interopIssues that impact all js interop

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions