Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions LibTest/js_interop/staticInterop_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 `staticInterop` enables the JS annotated class to be treated as
/// a "static" interop class.
///
/// These classes allow interop with native types, like the ones in `dart:html`.
/// These classes should not contain any instance members, inherited or
/// otherwise, and should instead use static extension members.
///
/// @description Checks it is a compile-time error if a class is annotated with
/// `@staticInterop` but has no `@JS()` annotation.
/// @author sgrekhov22@gmail.com

import 'dart:js_interop';

@staticInterop
class C {
// ^
// [analyzer] unspecified
// [web] unspecified
}

main() {
print(C);
}
38 changes: 38 additions & 0 deletions LibTest/js_interop/staticInterop_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 `staticInterop` enables the JS annotated class to be treated as
/// a "static" interop class.
///
/// These classes allow interop with native types, like the ones in `dart:html`.
/// These classes should not contain any instance members, inherited or
/// otherwise, and should instead use static extension members.
///
/// @description Checks it is a compile-time error if an enum is annotated with
/// `@staticInterop`.
/// @author sgrekhov22@gmail.com

import 'dart:js_interop';

@staticInterop
enum E1 {
// ^^
// [analyzer] unspecified
// [web] unspecified
e0;
}

@staticInterop
@JS()
enum E2 {
// ^^
// [analyzer] unspecified
// [web] unspecified
e0;
}

main() {
print(E1);
print(E2);
}
34 changes: 34 additions & 0 deletions LibTest/js_interop/staticInterop_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 `staticInterop` enables the JS annotated class to be treated as
/// a "static" interop class.
///
/// These classes allow interop with native types, like the ones in `dart:html`.
/// These classes should not contain any instance members, inherited or
/// otherwise, and should instead use static extension members.
///
/// @description Checks that it is a compile-time error if an extension is
/// annotated with `@staticInterop`.
/// @author sgrekhov22@gmail.com
/// @issue 61119, 61124

import 'dart:js_interop';

class C {}

@staticInterop
@JS()
extension Ext on C {
// ^^^
// [analyzer] unspecified
// [web] unspecified
external String getString();
external int getNumber();
external bool getBool();
}

main() {
print(C);
}
37 changes: 37 additions & 0 deletions LibTest/js_interop/staticInterop_A01_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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 `staticInterop` enables the JS annotated class to be treated as
/// a "static" interop class.
///
/// These classes allow interop with native types, like the ones in `dart:html`.
/// These classes should not contain any instance members, inherited or
/// otherwise, and should instead use static extension members.
///
/// @description Checks that it is a warning if a mixin is annotated with
/// `@staticInterop`.
/// @author sgrekhov22@gmail.com
/// @issue 61124

import 'dart:js_interop';

@staticInterop
mixin M1 {
// ^^
// [analyzer] unspecified
// [web] unspecified
}

@staticInterop
@JS()
mixin M2 {
// ^^
// [analyzer] unspecified
// [web] unspecified
}

main() {
print(M1);
print(M2);
}
50 changes: 50 additions & 0 deletions LibTest/js_interop/staticInterop_A01_t05.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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 `staticInterop` enables the JS annotated class to be treated as
/// a "static" interop class.
///
/// These classes allow interop with native types, like the ones in `dart:html`.
/// These classes should not contain any instance members, inherited or
/// otherwise, and should instead use static extension members.
///
/// @description Checks that it is a warning if an extension type is annotated
/// with `@staticInterop`.
/// @author sgrekhov22@gmail.com
/// @issue 61124

import 'dart:js_interop';

@staticInterop
extension type ET1(JSObject o) {}
// ^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
@JS()
extension type ET2(JSObject o) {}
// ^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
extension type ET3(JSObject o) implements JSObject {}
// ^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
@JS()
extension type ET4(JSObject o) implements JSObject {}
// ^^^
// [analyzer] unspecified
// [web] unspecified

main() {
print(ET1);
print(ET2);
print(ET3);
print(ET4);
}
48 changes: 48 additions & 0 deletions LibTest/js_interop/staticInterop_A01_t06.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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 `staticInterop` enables the JS annotated class to be treated as
/// a "static" interop class.
///
/// These classes allow interop with native types, like the ones in `dart:html`.
/// These classes should not contain any instance members, inherited or
/// otherwise, and should instead use static extension members.
///
/// @description Checks that it is a warning if a declaration that isn't a JS
/// interop class is annotated with `@staticInterop`.
/// @author sgrekhov22@gmail.com
/// @issue 61124

import 'dart:js_interop';

@staticInterop
int variable = 42;
// ^^^^^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
String get getter => "getter";
// ^^^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
String func() => "function";
// ^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
void set setter(String _) {}
// ^^^^^^
// [analyzer] unspecified
// [web] unspecified

main() {
print(variable);
print(getter);
print(func);
setter = "";
}
31 changes: 31 additions & 0 deletions LibTest/js_interop/staticInterop_A01_t07.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 `staticInterop` enables the JS annotated class to be treated as
/// a "static" interop class.
///
/// These classes allow interop with native types, like the ones in `dart:html`.
/// These classes should not contain any instance members, inherited or
/// otherwise, and should instead use static extension members.
///
/// @description Checks that it is a warning if a local declaration is annotated
/// with `@staticInterop`.
/// @author sgrekhov22@gmail.com
/// @issue 61124

import 'dart:js_interop';

main() {
@staticInterop
int variable = 42;
// ^^^^^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
String func() => "function";
// ^^^^
// [analyzer] unspecified
// [web] unspecified
}
83 changes: 83 additions & 0 deletions LibTest/js_interop/staticInterop_A01_t08.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 `staticInterop` enables the JS annotated class to be treated as
/// a "static" interop class.
///
/// These classes allow interop with native types, like the ones in `dart:html`.
/// These classes should not contain any instance members, inherited or
/// otherwise, and should instead use static extension members.
///
/// @description Checks that it is a warning if a class member is annotated with
/// `@staticInterop`.
/// @author sgrekhov22@gmail.com
/// @issue 61124

import 'dart:js_interop';

class C {
@staticInterop
C();
//^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
factory C.f() = C;
// ^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
int instanceVariable = 42;
// ^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
String get instanceGetter => "instanceGetter";
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
String instanceMethod() => "instanceMethod";
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
void set instanceSetter(String _) {}
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
static int staticVariable = 42;
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
static String get staticGetter => "staticGetter";
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
static String staticMethod() => "staticMethod";
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [web] unspecified

@staticInterop
static void set staticSetter(String _) {}
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [web] unspecified
}

main() {
print(C);
}
Loading