Skip to content

Commit b5ad858

Browse files
srujzsCommit Queue
authored andcommitted
[_js_interop_checks] Update min SDK version to 3.7.0-0 and format
Uses the latest formatter changes. PS2 fixes some string wrapping to adapt to the new changes. PS3 removes an unnecessary null assertions with the latest SDK. Change-Id: I33387c89395a52a2bc5bc261f29a20a7c9b5fd09 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400722 Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Mayank Patke <[email protected]> Auto-Submit: Srujan Gaddam <[email protected]>
1 parent 789c266 commit b5ad858

File tree

8 files changed

+1225
-726
lines changed

8 files changed

+1225
-726
lines changed

pkg/_js_interop_checks/lib/js_interop_checks.dart

Lines changed: 313 additions & 161 deletions
Large diffs are not rendered by default.

pkg/_js_interop_checks/lib/src/js_interop.dart

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ final _jsInterop = Uri.parse('dart:js_interop');
118118
///
119119
/// If [interopLibraries] is null, we check `package:js`,
120120
/// `dart:_js_annotations`, and `dart:js_interop`.
121-
bool _isInteropAnnotation(Expression value, String annotationClassName,
122-
{Set<Uri>? interopLibraries}) {
121+
bool _isInteropAnnotation(
122+
Expression value,
123+
String annotationClassName, {
124+
Set<Uri>? interopLibraries,
125+
}) {
123126
interopLibraries ??= {_packageJs, _jsAnnotations, _jsInterop};
124127
var c = annotationClass(value);
125128
if (c == null || c.name != annotationClassName) return false;
@@ -130,9 +133,11 @@ bool _isInteropAnnotation(Expression value, String annotationClassName,
130133
bool _isJSInteropAnnotation(Expression value) =>
131134
_isInteropAnnotation(value, 'JS');
132135

133-
bool _isPackageJSAnnotation(Expression value) =>
134-
_isInteropAnnotation(value, 'JS',
135-
interopLibraries: {_packageJs, _jsAnnotations});
136+
bool _isPackageJSAnnotation(Expression value) => _isInteropAnnotation(
137+
value,
138+
'JS',
139+
interopLibraries: {_packageJs, _jsAnnotations},
140+
);
136141

137142
bool _isDartJSInteropAnnotation(Expression value) =>
138143
_isInteropAnnotation(value, 'JS', interopLibraries: {_jsInterop});
@@ -211,15 +216,19 @@ List<String> stringAnnotationValues(Expression node) {
211216
var value = constant.fieldValues.values.elementAt(0);
212217
if (value is StringConstant) values.addAll(value.value.split(','));
213218
} else if (argLength > 1) {
214-
throw ArgumentError('Method expects annotation with at most one '
215-
'positional argument: $node.');
219+
throw ArgumentError(
220+
'Method expects annotation with at most one positional argument: '
221+
'$node.',
222+
);
216223
}
217224
}
218225
} else if (node is ConstructorInvocation) {
219226
var argLength = node.arguments.positional.length;
220227
if (argLength > 1 || node.arguments.named.isNotEmpty) {
221-
throw ArgumentError('Method expects annotation with at most one '
222-
'positional argument: $node.');
228+
throw ArgumentError(
229+
'Method expects annotation with at most one positional argument: '
230+
'$node.',
231+
);
223232
} else if (argLength == 1) {
224233
var value = node.arguments.positional[0];
225234
if (value is StringLiteral) {
@@ -267,17 +276,21 @@ Library? _findJsInteropLibrary(Component component, Uri interopUri) {
267276
/// `calculateTransitiveImportsOfDartFfiIfUsed` in
268277
/// pkg/vm/lib/transformations/ffi/common.dart.
269278
Set<Library> calculateTransitiveImportsOfJsInteropIfUsed(
270-
Component component, Uri interopUri) {
279+
Component component,
280+
Uri interopUri,
281+
) {
271282
// Check for the presence of [jsInteropLibrary] as a dependency of any of the
272283
// libraries in [component]. We use this to bypass the expensive
273284
// [calculateTransitiveDependenciesOf] call for cases where js interop is
274285
// not used, otherwise we could just use the index of the library instead.
275286
Library? jsInteropLibrary = _findJsInteropLibrary(component, interopUri);
276287
if (jsInteropLibrary == null) return const <Library>{};
277288

278-
kernel_graph.LibraryGraph graph =
279-
kernel_graph.LibraryGraph(component.libraries);
280-
Set<Library> result =
281-
kernel_graph.calculateTransitiveDependenciesOf(graph, {jsInteropLibrary});
289+
kernel_graph.LibraryGraph graph = kernel_graph.LibraryGraph(
290+
component.libraries,
291+
);
292+
Set<Library> result = kernel_graph.calculateTransitiveDependenciesOf(graph, {
293+
jsInteropLibrary,
294+
});
282295
return result;
283296
}

pkg/_js_interop_checks/lib/src/transformations/export_checker.dart

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ import 'package:_js_interop_checks/js_interop_checks.dart'
1515
import 'package:_js_interop_checks/src/js_interop.dart' as js_interop;
1616
import 'package:kernel/ast.dart';
1717

18-
enum ExportStatus {
19-
exportError,
20-
exportable,
21-
nonExportable,
22-
}
18+
enum ExportStatus { exportError, exportable, nonExportable }
2319

2420
class ExportChecker {
2521
final JsInteropDiagnosticReporter _diagnosticReporter;
@@ -85,7 +81,7 @@ class ExportChecker {
8581
var demangledCls = cls.isMixinApplication ? cls.mixin : cls;
8682
for (var member in [
8783
...demangledCls.procedures.where((proc) => proc.exportable),
88-
...demangledCls.fields.where((field) => field.exportable)
84+
...demangledCls.fields.where((field) => field.exportable),
8985
]) {
9086
var memberName = member.name.text;
9187
if (member is Procedure && member.isSetter) {
@@ -122,23 +118,25 @@ class ExportChecker {
122118

123119
if (classHasJSExport && js_interop.getJSExportName(cls).isNotEmpty) {
124120
_diagnosticReporter.report(
125-
templateJsInteropExportDartInterfaceHasNonEmptyJSExportValue
126-
.withArguments(cls.name),
127-
cls.fileOffset,
128-
cls.name.length,
129-
cls.location?.file);
121+
templateJsInteropExportDartInterfaceHasNonEmptyJSExportValue
122+
.withArguments(cls.name),
123+
cls.fileOffset,
124+
cls.name.length,
125+
cls.location?.file,
126+
);
130127
exportStatus[cls.reference] = ExportStatus.exportError;
131128
}
132129

133130
_collectOverrides(cls);
134131

135132
var allExportableMembers = _overrideMap[cls.reference]!.values.where(
136-
(member) =>
137-
// Only members that qualify are those that are exportable, and
138-
// either their class has the annotation or they have it themselves.
139-
member.exportable &&
140-
(js_interop.hasJSExportAnnotation(member) ||
141-
js_interop.hasJSExportAnnotation(member.enclosingClass!)));
133+
(member) =>
134+
// Only members that qualify are those that are exportable, and
135+
// either their class has the annotation or they have it themselves.
136+
member.exportable &&
137+
(js_interop.hasJSExportAnnotation(member) ||
138+
js_interop.hasJSExportAnnotation(member.enclosingClass!)),
139+
);
142140
var exports = <String, Set<Member>>{};
143141

144142
// Store the exportable members.
@@ -183,20 +181,24 @@ class ExportChecker {
183181
var sortedExistingMembers =
184182
existingMembers.map((member) => member.toString()).toList()..sort();
185183
_diagnosticReporter.report(
186-
templateJsInteropExportMemberCollision.withArguments(
187-
exportName, sortedExistingMembers.join(', ')),
188-
cls.fileOffset,
189-
cls.name.length,
190-
cls.location?.file);
184+
templateJsInteropExportMemberCollision.withArguments(
185+
exportName,
186+
sortedExistingMembers.join(', '),
187+
),
188+
cls.fileOffset,
189+
cls.name.length,
190+
cls.location?.file,
191+
);
191192
exportStatus[cls.reference] = ExportStatus.exportError;
192193
}
193194

194195
if (exports.isEmpty) {
195196
_diagnosticReporter.report(
196-
templateJsInteropExportNoExportableMembers.withArguments(cls.name),
197-
cls.fileOffset,
198-
cls.name.length,
199-
cls.location?.file);
197+
templateJsInteropExportNoExportableMembers.withArguments(cls.name),
198+
cls.fileOffset,
199+
cls.name.length,
200+
cls.location?.file,
201+
);
200202
exportStatus[cls.reference] = ExportStatus.exportError;
201203
}
202204

@@ -212,11 +214,13 @@ class ExportChecker {
212214
if (memberHasJSExportAnnotation) {
213215
if (!member.exportable) {
214216
_diagnosticReporter.report(
215-
templateJsInteropExportDisallowedMember
216-
.withArguments(member.name.text),
217-
member.fileOffset,
218-
member.name.text.length,
219-
member.location?.file);
217+
templateJsInteropExportDisallowedMember.withArguments(
218+
member.name.text,
219+
),
220+
member.fileOffset,
221+
member.name.text.length,
222+
member.location?.file,
223+
);
220224
if (cls != null) {
221225
exportStatus[cls.reference] = ExportStatus.exportError;
222226
}

0 commit comments

Comments
 (0)