44
55import 'package:analyzer/dart/ast/ast.dart' ;
66import 'package:analyzer/dart/ast/visitor.dart' ;
7- import 'package:analyzer/dart/element/element .dart' ;
7+ import 'package:analyzer/dart/element/element2 .dart' ;
88import 'package:analyzer/dart/element/nullability_suffix.dart' ;
99import 'package:analyzer/dart/element/type.dart' ;
1010// ignore: implementation_imports
@@ -38,16 +38,16 @@ const Set<String> _sdkWebLibraries = {
3838bool _isJsInteropType (DartType type, _InteropTypeKind kind) {
3939 if (type is TypeParameterType ) return _isJsInteropType (type.bound, kind);
4040 if (type is InterfaceType ) {
41- var element = type.element ;
41+ var element = type.element3 ;
4242 var dartJsInteropTypeKind = kind == _InteropTypeKind .dartJsInteropType ||
4343 kind == _InteropTypeKind .any;
4444 var userJsInteropTypeKind = kind == _InteropTypeKind .userJsInteropType ||
4545 kind == _InteropTypeKind .any;
46- if (element is ExtensionTypeElement ) {
46+ if (element is ExtensionTypeElement2 ) {
4747 if (dartJsInteropTypeKind && element.isFromLibrary (_dartJsInteropUri)) {
4848 return true ;
4949 } else if (userJsInteropTypeKind) {
50- var representationType = element.representation .type;
50+ var representationType = element.representation2 .type;
5151 return _isJsInteropType (
5252 representationType, _InteropTypeKind .dartJsInteropType) ||
5353 _isJsInteropType (
@@ -74,10 +74,10 @@ bool _isWasmIncompatibleJsInterop(DartType type) {
7474 return _isWasmIncompatibleJsInterop (type.bound);
7575 }
7676 if (type is ! InterfaceType ) return false ;
77- var element = type.element ;
77+ var element = type.element3 ;
7878 // `hasJS` only checks for the `dart:_js_annotations` definition, which is
7979 // what we want here.
80- if (element.hasJS) return true ;
80+ if (element.metadata2. hasJS) return true ;
8181 return _sdkWebLibraries.any ((uri) => element.isFromLibrary (uri)) ||
8282 // While a type test with types from this library is very rare, we should
8383 // still ignore it for consistency.
@@ -93,28 +93,28 @@ bool _isWasmIncompatibleJsInterop(DartType type) {
9393///
9494/// Returns null if `type` is not a `dart:js_interop` `@staticInterop` class.
9595DartType ? _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 ;
9999 var hasJS = false ;
100100 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 &&
105105 annotationElement.isFromLibrary (_dartJsInteropUri) &&
106- annotationElement.enclosingElement3.name == 'JS' ) {
106+ annotationElement.enclosingElement2.name3 == 'JS' ) {
107107 hasJS = true ;
108- dartJsInterop = annotationElement.library ;
109- } else if (annotationElement is PropertyAccessorElement &&
108+ dartJsInterop = annotationElement.library2 ;
109+ } else if (annotationElement is GetterElement &&
110110 annotationElement.isFromLibrary (_dartJsAnnotationsUri) &&
111- annotationElement.name == 'staticInterop' ) {
111+ annotationElement.name3 == 'staticInterop' ) {
112112 hasStaticInterop = true ;
113113 }
114114 }
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' )
118118 // Nullability is ignored in this lint, so just return `thisType`.
119119 .thisType
120120 : null ;
@@ -144,7 +144,7 @@ class EraseNonJSInteropTypes extends ExtensionTypeErasure {
144144 : _isJsInteropType (type, _InteropTypeKind .dartJsInteropType)) {
145145 // Nullability and generics on interop types are ignored for this lint. In
146146 // order to just compare the interfaces themselves, we use `thisType`.
147- return type.element .thisType;
147+ return type.element3 .thisType;
148148 } else {
149149 return _jsTypeForStaticInterop (type) ?? super .visitInterfaceType (type);
150150 }
@@ -398,9 +398,7 @@ class _Visitor extends SimpleAstVisitor<void> {
398398 }
399399}
400400
401- extension on Element {
401+ extension on Element2 {
402402 /// 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;
406404}
0 commit comments