Open lexaknyazev opened 6 years ago
I think this blanket is not supported, since @JS()
is supposed to be a direct mapping to JS-code, which obviously won't have Dart-specific default values (in fact they might have there own based on undefined
, which this would break).
We should probably cover this in stuff that @jmesserly wants to specify for JS interop if so.
in fact they might have there own based on
undefined
, which this would break
Fair point. But defining non-external factories should be safe, right? This example shows the same result as the one above.
@JS()
@anonymous
class MyClass {
external factory MyClass({String foo, String bar});
factory MyClass.defaultFoo({String foo = 'fooValue', String bar}) =>
new MyClass(foo: foo, bar: bar);
}
@JS('console.log')
external void log(v);
void main() {
log(new MyClass.defaultFoo(bar: 'barValue'));
}
I don't think JS interop officially supports Dart-only code on JS members (it might work).
Could the compilers fail on default arguments in this context since they're not going to work as one would expected?
It looks like this is proposed in https://github.com/dart-lang/sdk/issues/41375.
Dart SDK 2.0.0-dev.60.0
Compiled with DDC (fragment):
Compiled with Dart2JS (fragment):