4
4
5
5
import 'package:analyzer/dart/ast/ast.dart' ;
6
6
import 'package:analyzer/dart/ast/visitor.dart' ;
7
- import 'package:analyzer/dart/element/element .dart' ;
7
+ import 'package:analyzer/dart/element/element2 .dart' ;
8
8
import 'package:analyzer/dart/element/nullability_suffix.dart' ;
9
9
import 'package:analyzer/dart/element/type.dart' ;
10
10
// ignore: implementation_imports
@@ -38,16 +38,16 @@ const Set<String> _sdkWebLibraries = {
38
38
bool _isJsInteropType (DartType type, _InteropTypeKind kind) {
39
39
if (type is TypeParameterType ) return _isJsInteropType (type.bound, kind);
40
40
if (type is InterfaceType ) {
41
- var element = type.element ;
41
+ var element = type.element3 ;
42
42
var dartJsInteropTypeKind = kind == _InteropTypeKind .dartJsInteropType ||
43
43
kind == _InteropTypeKind .any;
44
44
var userJsInteropTypeKind = kind == _InteropTypeKind .userJsInteropType ||
45
45
kind == _InteropTypeKind .any;
46
- if (element is ExtensionTypeElement ) {
46
+ if (element is ExtensionTypeElement2 ) {
47
47
if (dartJsInteropTypeKind && element.isFromLibrary (_dartJsInteropUri)) {
48
48
return true ;
49
49
} else if (userJsInteropTypeKind) {
50
- var representationType = element.representation .type;
50
+ var representationType = element.representation2 .type;
51
51
return _isJsInteropType (
52
52
representationType, _InteropTypeKind .dartJsInteropType) ||
53
53
_isJsInteropType (
@@ -74,10 +74,10 @@ bool _isWasmIncompatibleJsInterop(DartType type) {
74
74
return _isWasmIncompatibleJsInterop (type.bound);
75
75
}
76
76
if (type is ! InterfaceType ) return false ;
77
- var element = type.element ;
77
+ var element = type.element3 ;
78
78
// `hasJS` only checks for the `dart:_js_annotations` definition, which is
79
79
// what we want here.
80
- if (element.hasJS) return true ;
80
+ if (element.metadata2. hasJS) return true ;
81
81
return _sdkWebLibraries.any ((uri) => element.isFromLibrary (uri)) ||
82
82
// While a type test with types from this library is very rare, we should
83
83
// still ignore it for consistency.
@@ -93,28 +93,28 @@ bool _isWasmIncompatibleJsInterop(DartType type) {
93
93
///
94
94
/// Returns null if `type` is not a `dart:js_interop` `@staticInterop` class.
95
95
DartType ? _jsTypeForStaticInterop (InterfaceType type) {
96
- var element = type.element ;
97
- if (element is ! ClassElement ) return null ;
98
- var metadata = element.metadata ;
96
+ var element = type.element3 ;
97
+ if (element is ! ClassElement2 ) return null ;
98
+ var metadata = element.metadata2 ;
99
99
var hasJS = false ;
100
100
var hasStaticInterop = false ;
101
- late LibraryElement dartJsInterop;
102
- for (var annotation in metadata) {
103
- var annotationElement = annotation.element ;
104
- if (annotationElement is ConstructorElement &&
101
+ LibraryElement2 ? dartJsInterop;
102
+ for (var annotation in metadata.annotations ) {
103
+ var annotationElement = annotation.element2 ;
104
+ if (annotationElement is ConstructorElement2 &&
105
105
annotationElement.isFromLibrary (_dartJsInteropUri) &&
106
- annotationElement.enclosingElement3.name == 'JS' ) {
106
+ annotationElement.enclosingElement2.name3 == 'JS' ) {
107
107
hasJS = true ;
108
- dartJsInterop = annotationElement.library ;
109
- } else if (annotationElement is PropertyAccessorElement &&
108
+ dartJsInterop = annotationElement.library2 ;
109
+ } else if (annotationElement is GetterElement &&
110
110
annotationElement.isFromLibrary (_dartJsAnnotationsUri) &&
111
- annotationElement.name == 'staticInterop' ) {
111
+ annotationElement.name3 == 'staticInterop' ) {
112
112
hasStaticInterop = true ;
113
113
}
114
114
}
115
- return (hasJS && hasStaticInterop)
116
- ? dartJsInterop.units.single. extensionTypes
117
- .singleWhere ((extType) => extType.name == 'JSObject' )
115
+ return (hasJS && hasStaticInterop && dartJsInterop != null )
116
+ ? dartJsInterop.extensionTypes
117
+ .singleWhere ((extType) => extType.name3 == 'JSObject' )
118
118
// Nullability is ignored in this lint, so just return `thisType`.
119
119
.thisType
120
120
: null ;
@@ -144,7 +144,7 @@ class EraseNonJSInteropTypes extends ExtensionTypeErasure {
144
144
: _isJsInteropType (type, _InteropTypeKind .dartJsInteropType)) {
145
145
// Nullability and generics on interop types are ignored for this lint. In
146
146
// order to just compare the interfaces themselves, we use `thisType`.
147
- return type.element .thisType;
147
+ return type.element3 .thisType;
148
148
} else {
149
149
return _jsTypeForStaticInterop (type) ?? super .visitInterfaceType (type);
150
150
}
@@ -398,9 +398,7 @@ class _Visitor extends SimpleAstVisitor<void> {
398
398
}
399
399
}
400
400
401
- extension on Element {
401
+ extension on Element2 {
402
402
/// Returns whether this is from the Dart library at [uri] .
403
- bool isFromLibrary (String uri) =>
404
- library? .definingCompilationUnit.source ==
405
- context.sourceFactory.forUri (uri);
403
+ bool isFromLibrary (String uri) => library2? .uri.toString () == uri;
406
404
}
0 commit comments