Skip to content

Commit 48f93d7

Browse files
author
Anna Gringauze
authored
Migrate dwds/web directory to null safety (#1648)
* Migrate web directory to null safety * Ignore false positive analyzer warning * Fixed analyzer warning * Addressed CR comments
1 parent 36561ff commit 48f93d7

File tree

8 files changed

+30
-37
lines changed

8 files changed

+30
-37
lines changed

dwds/lib/src/utilities/sdk_configuration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class SdkConfiguration {
120120
class DefaultSdkConfigurationProvider extends SdkConfigurationProvider {
121121
DefaultSdkConfigurationProvider();
122122

123-
late SdkConfiguration _configuration = _create();
123+
late final SdkConfiguration _configuration = _create();
124124

125125
/// Create and validate configuration matching the default SDK layout.
126126
@override

dwds/web/client.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@JS()
86
library hot_reload_client;
97

@@ -38,7 +36,7 @@ const _batchDelayMilliseconds = 1000;
3836

3937
// GENERATE:
4038
// pub run build_runner build web
41-
Future<void> main() {
39+
Future<void>? main() {
4240
return runZonedGuarded(() async {
4341
// Set the unique id for this instance of the app.
4442
// Test apps may already have this set.
@@ -221,13 +219,13 @@ String _fixProtocol(String url) {
221219
external String get dartAppId;
222220

223221
@JS(r'$dartAppInstanceId')
224-
external String get dartAppInstanceId;
222+
external String? get dartAppInstanceId;
225223

226224
@JS(r'$dwdsDevHandlerPath')
227225
external String get dwdsDevHandlerPath;
228226

229227
@JS(r'$dartAppInstanceId')
230-
external set dartAppInstanceId(String id);
228+
external set dartAppInstanceId(String? id);
231229

232230
@JS(r'$dartModuleStrategy')
233231
external String get dartModuleStrategy;

dwds/web/promise.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@JS()
86
library webdev.web.promise;
97

@@ -49,7 +47,7 @@ Future<T> toFuture<T>(Promise<T> promise) {
4947
final completer = Completer<T>();
5048
promise.then(
5149
allowInterop(completer.complete),
52-
allowInterop(completer.completeError),
50+
allowInterop((e) => completer.completeError(e)),
5351
);
5452
return completer.future;
5553
}

dwds/web/reloader/legacy_restarter.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'dart:async';
86
import 'dart:html';
97
import 'dart:js';
@@ -12,7 +10,7 @@ import 'restarter.dart';
1210

1311
class LegacyRestarter implements Restarter {
1412
@override
15-
Future<bool> restart({String runId}) async {
13+
Future<bool> restart({String? runId}) async {
1614
final dartLibrary = context['dart_library'] as JsObject;
1715
if (runId == null) {
1816
dartLibrary.callMethod('reload');
@@ -22,16 +20,17 @@ class LegacyRestarter implements Restarter {
2220
]);
2321
}
2422
final reloadCompleter = Completer<bool>();
25-
StreamSubscription sub;
26-
sub = window.onMessage.listen((event) {
23+
final sub = window.onMessage.listen((event) {
2724
final message = event.data;
2825
if (message is Map &&
2926
message['type'] == 'DDC_STATE_CHANGE' &&
3027
message['state'] == 'restart_end') {
3128
reloadCompleter.complete(true);
32-
sub.cancel();
3329
}
3430
});
35-
return reloadCompleter.future;
31+
return reloadCompleter.future.then((value) {
32+
sub.cancel();
33+
return value;
34+
});
3635
}
3736
}

dwds/web/reloader/manager.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'dart:async';
86
import 'dart:convert';
97
import 'dart:html';
@@ -28,7 +26,7 @@ class ReloadingManager {
2826
/// - called hotRestart with the same runId
2927
///
3028
/// The apps are restarted at the same time on the first call.
31-
Future<bool> hotRestart({String runId}) async {
29+
Future<bool> hotRestart({String? runId}) async {
3230
_beforeRestart();
3331
final result = await _restarter.restart(runId: runId);
3432
_afterRestart(result);

dwds/web/reloader/require_restarter.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@JS()
86
library require_reloading_manager;
97

@@ -23,7 +21,8 @@ import 'restarter.dart';
2321
/// The last known digests of all the modules in the application.
2422
///
2523
/// This is updated in place during calls to hotRestart.
26-
Map<String, String> _lastKnownDigests;
24+
/// TODO(annagrin): can this be a private field in RequireRestarter?
25+
late Map<String, String> _lastKnownDigests;
2726

2827
@JS(r'$requireLoader')
2928
external RequireLoader get requireLoader;
@@ -90,8 +89,8 @@ abstract class JsMap<K, V> {
9089
/// Handles hot restart reloading for use with the require module system.
9190
class RequireRestarter implements Restarter {
9291
final _moduleOrdering = HashMap<String, int>();
93-
SplayTreeSet<String> _dirtyModules;
94-
var _running = Completer<bool>()..complete();
92+
late SplayTreeSet<String> _dirtyModules;
93+
var _running = Completer<bool>()..complete(true);
9594

9695
var count = 0;
9796

@@ -100,7 +99,7 @@ class RequireRestarter implements Restarter {
10099
}
101100

102101
@override
103-
Future<bool> restart({String runId}) async {
102+
Future<bool> restart({String? runId}) async {
104103
final developer = getProperty(require('dart_sdk'), 'developer');
105104
if (callMethod(getProperty(developer, '_extensions'), 'containsKey',
106105
['ext.flutter.disassemble']) as bool) {
@@ -117,7 +116,7 @@ class RequireRestarter implements Restarter {
117116
'Unable to find an existing digest for module: $moduleId.');
118117
_reloadPage();
119118
} else if (_lastKnownDigests[moduleId] != newDigests[moduleId]) {
120-
_lastKnownDigests[moduleId] = newDigests[moduleId];
119+
_lastKnownDigests[moduleId] = newDigests[moduleId]!;
121120
modulesToLoad.add(moduleId);
122121
}
123122
}
@@ -145,7 +144,7 @@ class RequireRestarter implements Restarter {
145144
}
146145

147146
List<String> _moduleParents(String module) =>
148-
requireLoader.moduleParentsGraph.get(module)?.cast() ?? [];
147+
requireLoader.moduleParentsGraph.get(module).cast();
149148

150149
int _moduleTopologicalCompare(String module1, String module2) {
151150
var topological = 0;
@@ -159,8 +158,8 @@ class RequireRestarter implements Restarter {
159158
'Unable to fetch ordering info for module: $missing');
160159
}
161160

162-
topological =
163-
Comparable.compare(_moduleOrdering[module2], _moduleOrdering[module1]);
161+
topological = Comparable.compare(
162+
_moduleOrdering[module2]!, _moduleOrdering[module1]!);
164163

165164
if (topological == 0) {
166165
// If modules are in cycle (same strongly connected component) compare
@@ -183,13 +182,13 @@ class RequireRestarter implements Restarter {
183182
var reloadedModules = 0;
184183
try {
185184
_dirtyModules.addAll(modules);
186-
String previousModuleId;
185+
String? previousModuleId;
187186
while (_dirtyModules.isNotEmpty) {
188187
final moduleId = _dirtyModules.first;
189188
_dirtyModules.remove(moduleId);
190189
final parentIds = _moduleParents(moduleId);
191190
// Check if this is the root / bootstrap module.
192-
if (parentIds == null || parentIds.isEmpty) {
191+
if (parentIds.isEmpty) {
193192
// The bootstrap module is not reloaded but we need to update the
194193
// $dartRunMain reference to the newly loaded child module.
195194
final childModule = callMethod(

dwds/web/reloader/restarter.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
abstract class Restarter {
86
/// Attemps to perform a hot restart and returns whether it was successful or
97
/// not.
10-
Future<bool> restart({String runId});
8+
Future<bool> restart({String? runId});
119
}

dwds/web/run_main.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// @dart = 2.9
1+
// Copyright (c) 2019, 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+
25
import 'dart:html';
36

47
/// Creates a script that will run properly when strict CSP is enforced.
@@ -15,7 +18,7 @@ final ScriptElement Function() _createScript = (() {
1518
final _noncePattern = RegExp('^[\\w+/_-]+[=]{0,2}\$');
1619

1720
/// Returns CSP nonce, if set for any script tag.
18-
String _findNonce() {
21+
String? _findNonce() {
1922
final elements = window.document.querySelectorAll('script');
2023
for (final element in elements) {
2124
final nonceValue =
@@ -33,6 +36,6 @@ String _findNonce() {
3336
/// handling zone.
3437
void runMain() {
3538
final scriptElement = _createScript()..innerHtml = r'window.$dartRunMain();';
36-
document.body.append(scriptElement);
39+
document.body!.append(scriptElement);
3740
Future.microtask(scriptElement.remove);
3841
}

0 commit comments

Comments
 (0)