Skip to content

Commit 3aecb69

Browse files
authored
dont pass an explicit --native-null-assertion option if none was provided (#3458)
1 parent 1f0608c commit 3aecb69

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

build_web_compilers/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 4.0.2
2+
3+
- Allow the compiler to choose the default for the native null assertions
4+
option when one is not explicitly provided.
5+
16
## 4.0.1
27

38
- Add support for `dart:js_interop`.

build_web_compilers/lib/src/dart2js_bootstrap.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ import 'web_entrypoint_builder.dart';
2424
Future<void> bootstrapDart2Js(
2525
BuildStep buildStep,
2626
List<String> dart2JsArgs, {
27-
required bool nativeNullAssertions,
27+
required bool? nativeNullAssertions,
2828
}) =>
2929
_resourcePool.withResource(() => _bootstrapDart2Js(buildStep, dart2JsArgs,
3030
nativeNullAssertions: nativeNullAssertions));
3131

3232
Future<void> _bootstrapDart2Js(
3333
BuildStep buildStep,
3434
List<String> dart2JsArgs, {
35-
required bool nativeNullAssertions,
35+
required bool? nativeNullAssertions,
3636
}) async {
3737
var dartEntrypointId = buildStep.inputId;
3838
var moduleId =
@@ -85,7 +85,8 @@ https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-ski
8585
'--multi-root=${scratchSpace.tempDir.uri.toFilePath()}',
8686
for (var experiment in enabledExperiments)
8787
'--enable-experiment=$experiment',
88-
'--${nativeNullAssertions ? '' : 'no-'}native-null-assertions',
88+
if (nativeNullAssertions != null)
89+
'--${nativeNullAssertions ? '' : 'no-'}native-null-assertions',
8990
'-o$jsOutputPath',
9091
'$dartUri',
9192
]);

build_web_compilers/lib/src/dev_compiler_bootstrap.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Future<void> bootstrapDdc(
3131
BuildStep buildStep, {
3232
DartPlatform? platform,
3333
Iterable<AssetId> requiredAssets = const [],
34-
required bool nativeNullAssertions,
34+
required bool? nativeNullAssertions,
3535
}) async {
3636
platform = ddcPlatform;
3737
// Ensures that the sdk resources are built and available.
@@ -193,12 +193,15 @@ String _appBootstrap({
193193
required String moduleScope,
194194
required String entrypointLibraryName,
195195
required String oldModuleScope,
196-
required bool nativeNullAssertions,
197-
}) =>
198-
'''
196+
required bool? nativeNullAssertions,
197+
}) {
198+
var nativeAssertsCode = nativeNullAssertions == null
199+
? ''
200+
: 'dart_sdk.dart.nativeNonNullAsserts($nativeNullAssertions);';
201+
return '''
199202
define("$bootstrapModuleName", ["$moduleName", "dart_sdk"], function(app, dart_sdk) {
200203
dart_sdk.dart.setStartAsyncSynchronously(true);
201-
dart_sdk.dart.nativeNonNullAsserts($nativeNullAssertions);
204+
$nativeAssertsCode
202205
dart_sdk._isolate_helper.startRootIsolate(() => {}, []);
203206
$_initializeTools
204207
$_mainExtensionMarker
@@ -231,6 +234,7 @@ define("$bootstrapModuleName", ["$moduleName", "dart_sdk"], function(app, dart_s
231234
});
232235
})();
233236
''';
237+
}
234238

235239
/// The actual entrypoint JS file which injects all the necessary scripts to
236240
/// run the app.

build_web_compilers/lib/src/web_entrypoint_builder.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ class WebEntrypointBuilder implements Builder {
5555

5656
/// Whether or not to enable runtime non-null assertions for values returned
5757
/// from browser apis.
58-
final bool nativeNullAssertions;
58+
///
59+
/// If `null` then no flag will be provided to the compiler, and the default
60+
/// will be used.
61+
final bool? nativeNullAssertions;
5962

6063
const WebEntrypointBuilder(
6164
this.webCompiler, {
@@ -97,7 +100,7 @@ class WebEntrypointBuilder implements Builder {
97100
return WebEntrypointBuilder(compiler,
98101
dart2JsArgs: dart2JsArgs,
99102
nativeNullAssertions:
100-
options.config[_nativeNullAssertionsOption] as bool? ?? true);
103+
options.config[_nativeNullAssertionsOption] as bool?);
101104
}
102105

103106
@override

build_web_compilers/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_web_compilers
2-
version: 4.0.1
2+
version: 4.0.2
33
description: Builder implementations wrapping the dart2js and DDC compilers.
44
repository: https://github.com/dart-lang/build/tree/master/build_web_compilers
55

0 commit comments

Comments
 (0)