Skip to content

Commit

Permalink
dont pass an explicit --native-null-assertion option if none was prov…
Browse files Browse the repository at this point in the history
…ided (#3458)
  • Loading branch information
jakemac53 committed Feb 17, 2023
1 parent 1f0608c commit 3aecb69
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
5 changes: 5 additions & 0 deletions build_web_compilers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.0.2

- Allow the compiler to choose the default for the native null assertions
option when one is not explicitly provided.

## 4.0.1

- Add support for `dart:js_interop`.
Expand Down
7 changes: 4 additions & 3 deletions build_web_compilers/lib/src/dart2js_bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import 'web_entrypoint_builder.dart';
Future<void> bootstrapDart2Js(
BuildStep buildStep,
List<String> dart2JsArgs, {
required bool nativeNullAssertions,
required bool? nativeNullAssertions,
}) =>
_resourcePool.withResource(() => _bootstrapDart2Js(buildStep, dart2JsArgs,
nativeNullAssertions: nativeNullAssertions));

Future<void> _bootstrapDart2Js(
BuildStep buildStep,
List<String> dart2JsArgs, {
required bool nativeNullAssertions,
required bool? nativeNullAssertions,
}) async {
var dartEntrypointId = buildStep.inputId;
var moduleId =
Expand Down Expand Up @@ -85,7 +85,8 @@ https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-ski
'--multi-root=${scratchSpace.tempDir.uri.toFilePath()}',
for (var experiment in enabledExperiments)
'--enable-experiment=$experiment',
'--${nativeNullAssertions ? '' : 'no-'}native-null-assertions',
if (nativeNullAssertions != null)
'--${nativeNullAssertions ? '' : 'no-'}native-null-assertions',
'-o$jsOutputPath',
'$dartUri',
]);
Expand Down
14 changes: 9 additions & 5 deletions build_web_compilers/lib/src/dev_compiler_bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Future<void> bootstrapDdc(
BuildStep buildStep, {
DartPlatform? platform,
Iterable<AssetId> requiredAssets = const [],
required bool nativeNullAssertions,
required bool? nativeNullAssertions,
}) async {
platform = ddcPlatform;
// Ensures that the sdk resources are built and available.
Expand Down Expand Up @@ -193,12 +193,15 @@ String _appBootstrap({
required String moduleScope,
required String entrypointLibraryName,
required String oldModuleScope,
required bool nativeNullAssertions,
}) =>
'''
required bool? nativeNullAssertions,
}) {
var nativeAssertsCode = nativeNullAssertions == null
? ''
: 'dart_sdk.dart.nativeNonNullAsserts($nativeNullAssertions);';
return '''
define("$bootstrapModuleName", ["$moduleName", "dart_sdk"], function(app, dart_sdk) {
dart_sdk.dart.setStartAsyncSynchronously(true);
dart_sdk.dart.nativeNonNullAsserts($nativeNullAssertions);
$nativeAssertsCode
dart_sdk._isolate_helper.startRootIsolate(() => {}, []);
$_initializeTools
$_mainExtensionMarker
Expand Down Expand Up @@ -231,6 +234,7 @@ define("$bootstrapModuleName", ["$moduleName", "dart_sdk"], function(app, dart_s
});
})();
''';
}

/// The actual entrypoint JS file which injects all the necessary scripts to
/// run the app.
Expand Down
7 changes: 5 additions & 2 deletions build_web_compilers/lib/src/web_entrypoint_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ class WebEntrypointBuilder implements Builder {

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

const WebEntrypointBuilder(
this.webCompiler, {
Expand Down Expand Up @@ -97,7 +100,7 @@ class WebEntrypointBuilder implements Builder {
return WebEntrypointBuilder(compiler,
dart2JsArgs: dart2JsArgs,
nativeNullAssertions:
options.config[_nativeNullAssertionsOption] as bool? ?? true);
options.config[_nativeNullAssertionsOption] as bool?);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion build_web_compilers/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build_web_compilers
version: 4.0.1
version: 4.0.2
description: Builder implementations wrapping the dart2js and DDC compilers.
repository: https://github.com/dart-lang/build/tree/master/build_web_compilers

Expand Down

0 comments on commit 3aecb69

Please sign in to comment.