diff --git a/LibTest/js_interop/anonymous_A01_t01.dart b/LibTest/js_interop/anonymous_A01_t01.dart index 556619c82d..1eeac2dd25 100644 --- a/LibTest/js_interop/anonymous_A01_t01.dart +++ b/LibTest/js_interop/anonymous_A01_t01.dart @@ -5,10 +5,23 @@ /// @assertion An annotation that indicates a JS annotated class is structural /// and does not have a known JavaScript prototype. /// -/// A class marked with [anonymous] must have an unnamed factory constructor -/// with no positional arguments, only named arguments. Invoking the constructor -/// desugars to creating a JavaScript object literal with name-value pairs -/// corresponding to the parameter names and values. +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. /// /// @description Checks that invoking the constructor desugars to creating a /// JavaScript object literal with name-value pairs corresponding to the diff --git a/LibTest/js_interop/anonymous_A01_t02.dart b/LibTest/js_interop/anonymous_A01_t02.dart index bbdcdd40ff..eb42d18fac 100644 --- a/LibTest/js_interop/anonymous_A01_t02.dart +++ b/LibTest/js_interop/anonymous_A01_t02.dart @@ -5,10 +5,23 @@ /// @assertion An annotation that indicates a JS annotated class is structural /// and does not have a known JavaScript prototype. /// -/// A class marked with [anonymous] must have an unnamed factory constructor -/// with no positional arguments, only named arguments. Invoking the constructor -/// desugars to creating a JavaScript object literal with name-value pairs -/// corresponding to the parameter names and values. +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. /// /// @description Checks that invoking the constructor desugars to creating a /// JavaScript object literal with name-value pairs corresponding to the diff --git a/LibTest/js_interop/anonymous_A02_t01.dart b/LibTest/js_interop/anonymous_A02_t01.dart index 8da886e7f2..ae7112cafa 100644 --- a/LibTest/js_interop/anonymous_A02_t01.dart +++ b/LibTest/js_interop/anonymous_A02_t01.dart @@ -5,10 +5,23 @@ /// @assertion An annotation that indicates a JS annotated class is structural /// and does not have a known JavaScript prototype. /// -/// A class marked with [anonymous] must have an unnamed factory constructor -/// with no positional arguments, only named arguments. Invoking the constructor -/// desugars to creating a JavaScript object literal with name-value pairs -/// corresponding to the parameter names and values. +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. /// /// @description Checks that it is not an error if a class annotated with /// [anonymous] has no unnamed factory constructor. Creating an instance creates diff --git a/LibTest/js_interop/anonymous_A03_t01.dart b/LibTest/js_interop/anonymous_A03_t01.dart index 761e83fde1..2945f467fa 100644 --- a/LibTest/js_interop/anonymous_A03_t01.dart +++ b/LibTest/js_interop/anonymous_A03_t01.dart @@ -5,10 +5,23 @@ /// @assertion An annotation that indicates a JS annotated class is structural /// and does not have a known JavaScript prototype. /// -/// A class marked with [anonymous] must have an unnamed factory constructor -/// with no positional arguments, only named arguments. Invoking the constructor -/// desugars to creating a JavaScript object literal with name-value pairs -/// corresponding to the parameter names and values. +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. /// /// @description Checks that it is a warning if an extension type is annotated /// with [anonymous]. diff --git a/LibTest/js_interop/anonymous_A03_t02.dart b/LibTest/js_interop/anonymous_A03_t02.dart index 9f9a94bd21..5d5609c434 100644 --- a/LibTest/js_interop/anonymous_A03_t02.dart +++ b/LibTest/js_interop/anonymous_A03_t02.dart @@ -5,10 +5,23 @@ /// @assertion An annotation that indicates a JS annotated class is structural /// and does not have a known JavaScript prototype. /// -/// A class marked with [anonymous] must have an unnamed factory constructor -/// with no positional arguments, only named arguments. Invoking the constructor -/// desugars to creating a JavaScript object literal with name-value pairs -/// corresponding to the parameter names and values. +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. /// /// @description Checks that it is a compile-time error if an enum is annotated /// with [anonymous]. diff --git a/LibTest/js_interop/anonymous_A03_t03.dart b/LibTest/js_interop/anonymous_A03_t03.dart index decf4cfd4c..3fc97acc9e 100644 --- a/LibTest/js_interop/anonymous_A03_t03.dart +++ b/LibTest/js_interop/anonymous_A03_t03.dart @@ -5,10 +5,23 @@ /// @assertion An annotation that indicates a JS annotated class is structural /// and does not have a known JavaScript prototype. /// -/// A class marked with [anonymous] must have an unnamed factory constructor -/// with no positional arguments, only named arguments. Invoking the constructor -/// desugars to creating a JavaScript object literal with name-value pairs -/// corresponding to the parameter names and values. +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. /// /// @description Checks that it is a compile-time error if a mixin is annotated /// with [anonymous]. diff --git a/LibTest/js_interop/anonymous_A03_t04.dart b/LibTest/js_interop/anonymous_A03_t04.dart index 55ced9f92f..a7fdf11cb4 100644 --- a/LibTest/js_interop/anonymous_A03_t04.dart +++ b/LibTest/js_interop/anonymous_A03_t04.dart @@ -5,10 +5,23 @@ /// @assertion An annotation that indicates a JS annotated class is structural /// and does not have a known JavaScript prototype. /// -/// A class marked with [anonymous] must have an unnamed factory constructor -/// with no positional arguments, only named arguments. Invoking the constructor -/// desugars to creating a JavaScript object literal with name-value pairs -/// corresponding to the parameter names and values. +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. /// /// @description Checks that it is a compile-time error if an extension /// is annotated with `@anonymous`. diff --git a/LibTest/js_interop/anonymous_A03_t05.dart b/LibTest/js_interop/anonymous_A03_t05.dart index 9d54ecb27e..221c3cf38b 100644 --- a/LibTest/js_interop/anonymous_A03_t05.dart +++ b/LibTest/js_interop/anonymous_A03_t05.dart @@ -5,10 +5,23 @@ /// @assertion An annotation that indicates a JS annotated class is structural /// and does not have a known JavaScript prototype. /// -/// A class marked with [anonymous] must have an unnamed factory constructor -/// with no positional arguments, only named arguments. Invoking the constructor -/// desugars to creating a JavaScript object literal with name-value pairs -/// corresponding to the parameter names and values. +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. /// /// @description Checks that it is a compile-time error if a non-type is marked /// with [anonymous]. diff --git a/LibTest/js_interop/anonymous_A04_t01.dart b/LibTest/js_interop/anonymous_A04_t01.dart new file mode 100644 index 0000000000..9bf77ce70c --- /dev/null +++ b/LibTest/js_interop/anonymous_A04_t01.dart @@ -0,0 +1,56 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion An annotation that indicates a JS annotated class is structural +/// and does not have a known JavaScript prototype. +/// +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. +/// +/// @description Checks that it is a compile-time error if an external factory +/// constructor of a class annotated with [anonymous] contains any positional +/// parameters. +/// @author sgrekhov22@gmail.com + +import 'dart:js_interop'; + +@anonymous +@staticInterop +@JS() +class C1 { + external factory C1(String s0, {String s, int n, bool b}); +// ^^ +// [analyzer] unspecified +// [web] unspecified +} + +@anonymous +@staticInterop +@JS() +class C2 { + external factory C2.f(int n); +// ^ +// [analyzer] unspecified +// [web] unspecified +} + +main() { + print(C1); + print(C2); +} diff --git a/LibTest/js_interop/anonymous_A05_t01.dart b/LibTest/js_interop/anonymous_A05_t01.dart new file mode 100644 index 0000000000..1a67923c18 --- /dev/null +++ b/LibTest/js_interop/anonymous_A05_t01.dart @@ -0,0 +1,66 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion An annotation that indicates a JS annotated class is structural +/// and does not have a known JavaScript prototype. +/// +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. +/// +/// @description Checks that it is a compile-time error if a class annotated +/// with [anonymous] contains any generative constructors. +/// @author sgrekhov22@gmail.com + +import 'dart:js_interop'; + +@anonymous +@staticInterop +@JS() +class C1 { + external C1({String s, int n, bool b}); +// ^^ +// [analyzer] unspecified +// [web] unspecified +} + +@anonymous +@staticInterop +@JS() +class C2 { + C2.f({String s = "", int n = 0, bool b = false}); +//^^^^ +// [analyzer] unspecified +// [web] unspecified +} + +@anonymous +@staticInterop +@JS() +class C3 { + C3({required String s}); +//^^ +// [analyzer] unspecified +// [web] unspecified +} + +main() { + print(C1); + print(C2); + print(C3); +} diff --git a/LibTest/js_interop/anonymous_A06_t01.dart b/LibTest/js_interop/anonymous_A06_t01.dart new file mode 100644 index 0000000000..4d270fa565 --- /dev/null +++ b/LibTest/js_interop/anonymous_A06_t01.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion An annotation that indicates a JS annotated class is structural +/// and does not have a known JavaScript prototype. +/// +/// A class marked with [anonymous] allows external factories with named +/// parameters. Invoking these factories creates a JavaScript object literal +/// with name-value pairs corresponding to any named parameters and their +/// values. If there are no named parameters, an empty JavaScript object is +/// created. +/// [anonymous] classes have the following restrictions: +/// - They must contain a [JS] annotation, either from this library or from +/// `dart:js_interop`. If the latter, the class must also contain +/// [staticInterop]. +/// - They cannot contain any non-external members unless it's a +/// [staticInterop] class, in which case it can also contain non-external +/// factories and static methods. +/// - They cannot contain any external generative constructors. +/// - Any external factory must not contain any positional parameters. +/// - They cannot extend or be extended by a non-[JS] annotated class. +/// - The annotation should only be applied to non-mixin classes and no other +/// declarations. +/// +/// @description Checks that it is not an error if a class annotated with +/// [anonymous] declares static members. +/// @author sgrekhov22@gmail.com + +import 'dart:js_interop'; + +@anonymous +@staticInterop +@JS() +class C { + static String v = "v"; + static String get g => "g"; + static String m() => "m"; + static void set s(String s) {} +} + +main() { + print(C); +}