Open jodinathan opened 1 year ago
Yeah, the complication is that we have two contradictory semantics here:
Create an object literal using the invocation. This is the way @anonymous
constructors work today - all they do is take the invocation and translate it to a JS object literal. Any arguments that are not passed are not included and default values are ignored. This is more efficient than jsify
and doesn't undergo any conversions.
Create an object literal using the declaration. This is more of what you want. This always creates an object literal with every single parameter as a key, but it's up to the invocation to determine whether each key will have the default value or a custom value.
In order to support 2, users need an option that says "don't ignore the defaults". It could be a variant of @anonymous
, for example. The same also applies for whatever annotation we use for inline classes. Currently, such a way doesn't exist, so the best option is what you wrote above, which obviously is very verbose. I think such an option is worth adding though, and I'm leaning towards exploring it after some of the work is done for Dart 3.
@srujzs could you please point the files commonly used by the SDK to compile an anonymous item. I am curious to take a soft look on how it works
Sure, here are the links for each backend:
The js_bindings uses a
factory
constructor replacement for anonymous classes when the class has enum values.The problem is that we can't send
null
as argument in some cases. For example, theRequestInit
can't receive anull
value for thecache
argument, justundefined
.I made it work by doing some checks, however, it generates a verbose JS code.
Is there anything I could do to make this simpler?
The dart interface
The dart call:
The generated output:
The
A.KA
function: