@@ -33,18 +33,49 @@ class _StaticInterop {
3333/// An annotation that indicates a [JS] annotated class is structural and does
3434/// not have a known JavaScript prototype.
3535///
36- /// A class marked with [anonymous] must have an unnamed factory constructor
37- /// with no positional arguments, only named arguments. Invoking the constructor
38- /// desugars to creating a JavaScript object literal with name-value pairs
39- /// corresponding to the parameter names and values.
36+ /// A class marked with [anonymous] allows external factories with named
37+ /// parameters. Invoking these factories creates JavaScript object literals with
38+ /// name-value pairs corresponding to any named parameters and their values. If
39+ /// there are no named parameters, an empty JavaScript object is created.
40+ ///
41+ /// [anonymous] classes have the following restrictions:
42+ /// - They must contain a [JS] annotation, either from this library or from
43+ /// `dart:js_interop`. If the latter, the class must also contain
44+ /// [staticInterop].
45+ /// - They cannot contain any non-external members unless it's a
46+ /// [staticInterop] class, in which case it can also contain non-external
47+ /// factories and static methods.
48+ /// - They cannot contain any external generative constructors.
49+ /// - Any external factory must not contain any positional parameters.
50+ /// - They cannot extend or be extended by a non-[JS] annotated class.
51+ /// - The annotation should only be applied to non-mixin classes and no other
52+ /// declarations.
4053const _Anonymous anonymous = _Anonymous ();
4154
4255/// [staticInterop] enables the [JS] annotated class to be treated as a "static"
4356/// interop class.
4457///
4558/// These classes allow interop with native types, like the ones in `dart:html` .
46- /// These classes should not contain any instance members, inherited or
47- /// otherwise, and should instead use static extension members.
59+ /// These classes implicitly all erase to the internal interceptor
60+ /// `JavaScriptObject` , so they can be freely casted to and from other
61+ /// [staticInterop] types, `dart:html` types, and `JSObject` from
62+ /// `dart:js_interop` . Non-[staticInterop] `package:js` types can be casted to
63+ /// [staticInterop] types, but the reverse can fail if the underlying value is a
64+ /// `@Native` -reserved type (like `dart:html` types).
65+ ///
66+ /// [staticInterop] classes have the following restrictions:
67+ /// - They must contain a [JS] annotation, either from this library or from
68+ /// `dart:js_interop`.
69+ /// - They should not contain any instance members, inherited or otherwise, and
70+ /// should instead use static extension members, which can be external or
71+ /// non-external.
72+ /// - They can only contain factories and `static` members. They can be
73+ /// combined with [anonymous] to make external factories create new
74+ /// JavaScript object literals instead.
75+ /// - They should not implement, extend, or mixin non-[staticInterop] classes
76+ /// and vice-versa.
77+ /// - The annotation should only be applied to non-mixin classes and no other
78+ /// declarations.
4879const _StaticInterop staticInterop = _StaticInterop ();
4980
5081/// NOTE: [trustTypes] is an experimental annotation that may disappear at any
0 commit comments