Skip to content

Commit

Permalink
Reset the forwarded config to empty for @use and meta.load-module() (#…
Browse files Browse the repository at this point in the history
…855)

In #827 I made configuration never be null, but this turns out to be
overkill: we still need a way for _loadModule() and _execute() to
distinguish between "use the existing configuration" (for @forward)
and "use no configuration" (for an unconfigured @use or
meta.load-module()). We now use null as a sentinel value there, while
still ensuring that _configuration is non-nullable.

Closes #854
  • Loading branch information
nex3 committed Oct 22, 2019
1 parent 73de08b commit 1b17ab7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,9 @@
* Fix a bug preventing built-in modules from being loaded within a configured
module.

* Fix a bug preventing an unconfigured module from being loaded from within two
different configured modules.

* Fix a bug when `meta.load-css()` was used to load some files that included
media queries.

Expand Down
20 changes: 10 additions & 10 deletions lib/src/visitor/async_evaluate.dart
Expand Up @@ -413,9 +413,9 @@ class _EvaluateVisitor
var url = Uri.parse(arguments[0].assertString("module").text);
var withMap = arguments[1].realNull?.assertMap("with")?.contents;

Map<String, _ConfiguredValue> configuration;
var configuration = const <String, _ConfiguredValue>{};
if (withMap != null) {
configuration = <String, _ConfiguredValue>{};
configuration = {};
var span = _callableNode.span;
withMap.forEach((variable, value) {
var name =
Expand Down Expand Up @@ -525,11 +525,9 @@ class _EvaluateVisitor
{Uri baseUrl,
Map<String, _ConfiguredValue> configuration,
bool namesInErrors = false}) async {
configuration ??= const {};

var builtInModule = _builtInModules[url];
if (builtInModule != null) {
if (configuration.isNotEmpty) {
if (configuration != null && configuration.isNotEmpty) {
throw _exception(
namesInErrors
? "Built-in module $url can't be configured."
Expand Down Expand Up @@ -589,12 +587,11 @@ class _EvaluateVisitor
Future<Module> _execute(AsyncImporter importer, Stylesheet stylesheet,
{Map<String, _ConfiguredValue> configuration,
bool namesInErrors = false}) async {
configuration ??= const {};
var url = stylesheet.span.sourceUrl;

var alreadyLoaded = _modules[url];
if (alreadyLoaded != null) {
if (configuration.isNotEmpty || _configuration.isNotEmpty) {
if ((configuration ?? _configuration).isNotEmpty) {
throw _exception(namesInErrors
? "${p.prettyUri(url)} was already loaded, so it can't be "
"configured using \"with\"."
Expand Down Expand Up @@ -637,7 +634,10 @@ class _EvaluateVisitor
_atRootExcludingStyleRule = false;
_inKeyframes = false;

if (configuration.isNotEmpty) _configuration = Map.of(configuration);
if (configuration != null) {
_configuration =
configuration.isEmpty ? const {} : Map.of(configuration);
}

await visitStylesheet(stylesheet);
css = _outOfOrderImports == null
Expand All @@ -658,7 +658,7 @@ class _EvaluateVisitor
_atRootExcludingStyleRule = oldAtRootExcludingStyleRule;
_inKeyframes = oldInKeyframes;

if (configuration.isNotEmpty && _configuration.isNotEmpty) {
if (configuration != null && _configuration.isNotEmpty) {
throw _exception(
namesInErrors
? "\$${_configuration.keys.first} was not declared with "
Expand Down Expand Up @@ -1780,7 +1780,7 @@ class _EvaluateVisitor
_environment.addModule(module, namespace: node.namespace);
},
configuration: node.configuration.isEmpty
? null
? const {}
: {
for (var entry in node.configuration.entries)
entry.key: _ConfiguredValue(
Expand Down
22 changes: 11 additions & 11 deletions lib/src/visitor/evaluate.dart
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 9083313a65eb24875e7292b859202fd574daf46b
// Checksum: 8abca72a6d671844aa9eb075aef56f58fd71ddf7
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -419,9 +419,9 @@ class _EvaluateVisitor
var url = Uri.parse(arguments[0].assertString("module").text);
var withMap = arguments[1].realNull?.assertMap("with")?.contents;

Map<String, _ConfiguredValue> configuration;
var configuration = const <String, _ConfiguredValue>{};
if (withMap != null) {
configuration = <String, _ConfiguredValue>{};
configuration = {};
var span = _callableNode.span;
withMap.forEach((variable, value) {
var name =
Expand Down Expand Up @@ -531,11 +531,9 @@ class _EvaluateVisitor
{Uri baseUrl,
Map<String, _ConfiguredValue> configuration,
bool namesInErrors = false}) {
configuration ??= const {};

var builtInModule = _builtInModules[url];
if (builtInModule != null) {
if (configuration.isNotEmpty) {
if (configuration != null && configuration.isNotEmpty) {
throw _exception(
namesInErrors
? "Built-in module $url can't be configured."
Expand Down Expand Up @@ -595,12 +593,11 @@ class _EvaluateVisitor
Module<Callable> _execute(Importer importer, Stylesheet stylesheet,
{Map<String, _ConfiguredValue> configuration,
bool namesInErrors = false}) {
configuration ??= const {};
var url = stylesheet.span.sourceUrl;

var alreadyLoaded = _modules[url];
if (alreadyLoaded != null) {
if (configuration.isNotEmpty || _configuration.isNotEmpty) {
if ((configuration ?? _configuration).isNotEmpty) {
throw _exception(namesInErrors
? "${p.prettyUri(url)} was already loaded, so it can't be "
"configured using \"with\"."
Expand Down Expand Up @@ -643,7 +640,10 @@ class _EvaluateVisitor
_atRootExcludingStyleRule = false;
_inKeyframes = false;

if (configuration.isNotEmpty) _configuration = Map.of(configuration);
if (configuration != null) {
_configuration =
configuration.isEmpty ? const {} : Map.of(configuration);
}

visitStylesheet(stylesheet);
css = _outOfOrderImports == null
Expand All @@ -664,7 +664,7 @@ class _EvaluateVisitor
_atRootExcludingStyleRule = oldAtRootExcludingStyleRule;
_inKeyframes = oldInKeyframes;

if (configuration.isNotEmpty && _configuration.isNotEmpty) {
if (configuration != null && _configuration.isNotEmpty) {
throw _exception(
namesInErrors
? "\$${_configuration.keys.first} was not declared with "
Expand Down Expand Up @@ -1774,7 +1774,7 @@ class _EvaluateVisitor
_environment.addModule(module, namespace: node.namespace);
},
configuration: node.configuration.isEmpty
? null
? const {}
: {
for (var entry in node.configuration.entries)
entry.key: _ConfiguredValue(
Expand Down

0 comments on commit 1b17ab7

Please sign in to comment.