Skip to content

Commit 69fd5c5

Browse files
author
Jonah Williams
authored
[flutter_tools] null assertions off by default for web (flutter#64186)
Like Android/iOS, only enable --null-assertions if asked. Previously this was enabled by default for web, but in general this has proved to be too breaking to enable by default. flutter#61042
1 parent ae4b3ba commit 69fd5c5

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

dev/bots/test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,8 @@ Future<void> _runWebDebugTest(String target, {
866866
...<String>[
867867
'--enable-experiment',
868868
'non-nullable',
869-
'--no-sound-null-safety'
869+
'--no-sound-null-safety',
870+
'--null-assertions',
870871
],
871872
'-d',
872873
'chrome',

packages/flutter_tools/lib/src/build_runner/devfs_web.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ class WebDevFS implements DevFS {
636636
@required this.entrypoint,
637637
@required this.expressionCompiler,
638638
@required this.chromiumLauncher,
639+
@required this.nullAssertions,
639640
this.testMode = false,
640641
});
641642

@@ -651,6 +652,7 @@ class WebDevFS implements DevFS {
651652
final bool testMode;
652653
final ExpressionCompiler expressionCompiler;
653654
final ChromiumLauncher chromiumLauncher;
655+
final bool nullAssertions;
654656

655657
WebAssetServer webAssetServer;
656658

@@ -791,8 +793,7 @@ class WebDevFS implements DevFS {
791793
'main_module.bootstrap.js',
792794
generateMainModule(
793795
entrypoint: entrypoint,
794-
nullSafety: buildInfo.extraFrontEndOptions
795-
?.contains('--enable-experiment=non-nullable') ?? false,
796+
nullAssertions: nullAssertions,
796797
),
797798
);
798799
// TODO(jonahwilliams): refactor the asset code in this and the regular devfs to

packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
469469
entrypoint: globals.fs.file(target).uri,
470470
expressionCompiler: expressionCompiler,
471471
chromiumLauncher: _chromiumLauncher,
472+
nullAssertions: debuggingOptions.nullAssertions,
472473
);
473474
final Uri url = await device.devFS.create();
474475
if (debuggingOptions.buildInfo.isDebug) {

packages/flutter_tools/lib/src/web/bootstrap.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ document.head.appendChild(requireEl);
5050
/// this object is the module.
5151
String generateMainModule({
5252
@required String entrypoint,
53-
@required bool nullSafety,
53+
@required bool nullAssertions,
5454
}) {
5555
return '''/* ENTRYPOINT_EXTENTION_MARKER */
5656
// Create the main module loaded below.
5757
define("main_module.bootstrap", ["$entrypoint", "dart_sdk"], function(app, dart_sdk) {
5858
dart_sdk.dart.setStartAsyncSynchronously(true);
5959
dart_sdk._debugger.registerDevtoolsFormatter();
60-
if ($nullSafety) {
60+
if ($nullAssertions) {
6161
dart_sdk.dart.nonNullAsserts(true);
6262
}
6363

packages/flutter_tools/test/general.shard/web/bootstrap_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void main() {
2323
test('generateMainModule embeds urls correctly', () {
2424
final String result = generateMainModule(
2525
entrypoint: 'foo/bar/main.js',
26-
nullSafety: false,
26+
nullAssertions: false,
2727
);
2828
// bootstrap main module has correct defined module.
2929
expect(result, contains('define("main_module.bootstrap", ["foo/bar/main.js", "dart_sdk"], '
@@ -33,7 +33,7 @@ void main() {
3333
test('generateMainModule includes null safety switches', () {
3434
final String result = generateMainModule(
3535
entrypoint: 'foo/bar/main.js',
36-
nullSafety: true,
36+
nullAssertions: true,
3737
);
3838

3939
expect(result, contains(

packages/flutter_tools/test/general.shard/web/devfs_web_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ void main() {
462462
urlTunneller: null,
463463
useSseForDebugProxy: true,
464464
useSseForDebugBackend: true,
465+
nullAssertions: true,
465466
buildInfo: const BuildInfo(
466467
BuildMode.debug,
467468
'',
@@ -574,6 +575,7 @@ void main() {
574575
urlTunneller: null,
575576
useSseForDebugProxy: true,
576577
useSseForDebugBackend: true,
578+
nullAssertions: true,
577579
buildInfo: const BuildInfo(
578580
BuildMode.debug,
579581
'',
@@ -689,6 +691,7 @@ void main() {
689691
testMode: true,
690692
expressionCompiler: null,
691693
chromiumLauncher: null,
694+
nullAssertions: true,
692695
);
693696
webDevFS.requireJS.createSync(recursive: true);
694697
webDevFS.stackTraceMapper.createSync(recursive: true);
@@ -725,6 +728,7 @@ void main() {
725728
urlTunneller: null,
726729
useSseForDebugProxy: true,
727730
useSseForDebugBackend: true,
731+
nullAssertions: true,
728732
buildInfo: const BuildInfo(
729733
BuildMode.debug,
730734
'',

0 commit comments

Comments
 (0)