File tree Expand file tree Collapse file tree 3 files changed +56
-3
lines changed
pkg/_js_interop_checks/lib Expand file tree Collapse file tree 3 files changed +56
-3
lines changed Original file line number Diff line number Diff line change @@ -894,8 +894,8 @@ class JsInteropChecks extends RecursiveVisitor {
894
894
/// - inside a JS interop class
895
895
/// - inside an extension on a JS interop or @Native annotatable
896
896
/// - inside a JS interop inline class
897
- /// - a top level member that is JS interop annotated or in a JS interop
898
- /// library
897
+ /// - a top level member that is JS interop annotated or in a package:js JS
898
+ /// interop library
899
899
bool _isJSInteropMember (Member member) {
900
900
if (member.isExternal) {
901
901
if (_classHasJSAnnotation) return true ;
@@ -906,7 +906,13 @@ class JsInteropChecks extends RecursiveVisitor {
906
906
return _inlineExtensionIndex.getInlineClass (member) != null ;
907
907
}
908
908
if (member.enclosingClass == null ) {
909
- return hasJSInteropAnnotation (member) || _libraryHasJSAnnotation;
909
+ // dart:js_interop requires top-levels to be @JS-annotated. package:js
910
+ // historically does not have this restriction. We add this restriction
911
+ // to refuse confusion on what an external member does now that we can
912
+ // have dart:ffi and dart:js_interop in the same code via dart2wasm.
913
+ final libraryHasPkgJSAnnotation =
914
+ _libraryHasJSAnnotation && ! _libraryHasDartJSInteropAnnotation;
915
+ return hasJSInteropAnnotation (member) || libraryHasPkgJSAnnotation;
910
916
}
911
917
}
912
918
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2
+ // for details. All rights reserved. Use of this source code is governed by a
3
+ // BSD-style license that can be found in the LICENSE file.
4
+
5
+ // Test that top-level external members need an @JS annotation even if the
6
+ // library has one when using dart:js_interop.
7
+
8
+ @JS ()
9
+ library top_level_member_annotation_static_test;
10
+
11
+ import 'dart:js_interop' ;
12
+
13
+ external int field;
14
+ // ^
15
+ // [web] Only JS interop members may be 'external'.
16
+
17
+ external int finalField;
18
+ // ^
19
+ // [web] Only JS interop members may be 'external'.
20
+
21
+ external int get getter;
22
+ // ^
23
+ // [web] Only JS interop members may be 'external'.
24
+
25
+ external set setter (_);
26
+ // ^
27
+ // [web] Only JS interop members may be 'external'.
28
+
29
+ external int method ();
30
+ // ^
31
+ // [web] Only JS interop members may be 'external'.
32
+
33
+ @JS ()
34
+ external int annotatedField;
35
+
36
+ @JS ()
37
+ external int annotatedFinalField;
38
+
39
+ @JS ()
40
+ external int get annotatedGetter;
41
+
42
+ @JS ()
43
+ external set annotatedSetter (_);
44
+
45
+ @JS ()
46
+ external int annotatedMethod ();
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ js/(?!export|static_interop_test)*: SkipByDesign
17
17
js/static_interop_test/external_static_member_lowerings_trusttypes_test: SkipByDesign # Tests @trustTypes, which is unsupported on dart2wasm.
18
18
js/static_interop_test/inline_class/non_interop_inline_class_static_test: SkipByDesign # Some external checks are not run on dart2wasm.
19
19
js/static_interop_test/static_external_extension_members_static_test: SkipByDesign # dart:html not supported on dart2wasm.
20
+ js/static_interop_test/top_level_member_annotation_static_test: SkipByDesign # Some external checks are not run on dart2wasm.
20
21
mirrors/*: SkipByDesign
21
22
web/*: SkipByDesign
22
23
You can’t perform that action at this time.
0 commit comments