Skip to content

Commit 1b17ab7

Browse files
authored
Reset the forwarded config to empty for @use and meta.load-module() (#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
1 parent 73de08b commit 1b17ab7

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Fix a bug preventing built-in modules from being loaded within a configured
44
module.
55

6+
* Fix a bug preventing an unconfigured module from being loaded from within two
7+
different configured modules.
8+
69
* Fix a bug when `meta.load-css()` was used to load some files that included
710
media queries.
811

lib/src/visitor/async_evaluate.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ class _EvaluateVisitor
413413
var url = Uri.parse(arguments[0].assertString("module").text);
414414
var withMap = arguments[1].realNull?.assertMap("with")?.contents;
415415

416-
Map<String, _ConfiguredValue> configuration;
416+
var configuration = const <String, _ConfiguredValue>{};
417417
if (withMap != null) {
418-
configuration = <String, _ConfiguredValue>{};
418+
configuration = {};
419419
var span = _callableNode.span;
420420
withMap.forEach((variable, value) {
421421
var name =
@@ -525,11 +525,9 @@ class _EvaluateVisitor
525525
{Uri baseUrl,
526526
Map<String, _ConfiguredValue> configuration,
527527
bool namesInErrors = false}) async {
528-
configuration ??= const {};
529-
530528
var builtInModule = _builtInModules[url];
531529
if (builtInModule != null) {
532-
if (configuration.isNotEmpty) {
530+
if (configuration != null && configuration.isNotEmpty) {
533531
throw _exception(
534532
namesInErrors
535533
? "Built-in module $url can't be configured."
@@ -589,12 +587,11 @@ class _EvaluateVisitor
589587
Future<Module> _execute(AsyncImporter importer, Stylesheet stylesheet,
590588
{Map<String, _ConfiguredValue> configuration,
591589
bool namesInErrors = false}) async {
592-
configuration ??= const {};
593590
var url = stylesheet.span.sourceUrl;
594591

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

640-
if (configuration.isNotEmpty) _configuration = Map.of(configuration);
637+
if (configuration != null) {
638+
_configuration =
639+
configuration.isEmpty ? const {} : Map.of(configuration);
640+
}
641641

642642
await visitStylesheet(stylesheet);
643643
css = _outOfOrderImports == null
@@ -658,7 +658,7 @@ class _EvaluateVisitor
658658
_atRootExcludingStyleRule = oldAtRootExcludingStyleRule;
659659
_inKeyframes = oldInKeyframes;
660660

661-
if (configuration.isNotEmpty && _configuration.isNotEmpty) {
661+
if (configuration != null && _configuration.isNotEmpty) {
662662
throw _exception(
663663
namesInErrors
664664
? "\$${_configuration.keys.first} was not declared with "
@@ -1780,7 +1780,7 @@ class _EvaluateVisitor
17801780
_environment.addModule(module, namespace: node.namespace);
17811781
},
17821782
configuration: node.configuration.isEmpty
1783-
? null
1783+
? const {}
17841784
: {
17851785
for (var entry in node.configuration.entries)
17861786
entry.key: _ConfiguredValue(

lib/src/visitor/evaluate.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DO NOT EDIT. This file was generated from async_evaluate.dart.
66
// See tool/grind/synchronize.dart for details.
77
//
8-
// Checksum: 9083313a65eb24875e7292b859202fd574daf46b
8+
// Checksum: 8abca72a6d671844aa9eb075aef56f58fd71ddf7
99
//
1010
// ignore_for_file: unused_import
1111

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

422-
Map<String, _ConfiguredValue> configuration;
422+
var configuration = const <String, _ConfiguredValue>{};
423423
if (withMap != null) {
424-
configuration = <String, _ConfiguredValue>{};
424+
configuration = {};
425425
var span = _callableNode.span;
426426
withMap.forEach((variable, value) {
427427
var name =
@@ -531,11 +531,9 @@ class _EvaluateVisitor
531531
{Uri baseUrl,
532532
Map<String, _ConfiguredValue> configuration,
533533
bool namesInErrors = false}) {
534-
configuration ??= const {};
535-
536534
var builtInModule = _builtInModules[url];
537535
if (builtInModule != null) {
538-
if (configuration.isNotEmpty) {
536+
if (configuration != null && configuration.isNotEmpty) {
539537
throw _exception(
540538
namesInErrors
541539
? "Built-in module $url can't be configured."
@@ -595,12 +593,11 @@ class _EvaluateVisitor
595593
Module<Callable> _execute(Importer importer, Stylesheet stylesheet,
596594
{Map<String, _ConfiguredValue> configuration,
597595
bool namesInErrors = false}) {
598-
configuration ??= const {};
599596
var url = stylesheet.span.sourceUrl;
600597

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

646-
if (configuration.isNotEmpty) _configuration = Map.of(configuration);
643+
if (configuration != null) {
644+
_configuration =
645+
configuration.isEmpty ? const {} : Map.of(configuration);
646+
}
647647

648648
visitStylesheet(stylesheet);
649649
css = _outOfOrderImports == null
@@ -664,7 +664,7 @@ class _EvaluateVisitor
664664
_atRootExcludingStyleRule = oldAtRootExcludingStyleRule;
665665
_inKeyframes = oldInKeyframes;
666666

667-
if (configuration.isNotEmpty && _configuration.isNotEmpty) {
667+
if (configuration != null && _configuration.isNotEmpty) {
668668
throw _exception(
669669
namesInErrors
670670
? "\$${_configuration.keys.first} was not declared with "
@@ -1774,7 +1774,7 @@ class _EvaluateVisitor
17741774
_environment.addModule(module, namespace: node.namespace);
17751775
},
17761776
configuration: node.configuration.isEmpty
1777-
? null
1777+
? const {}
17781778
: {
17791779
for (var entry in node.configuration.entries)
17801780
entry.key: _ConfiguredValue(

0 commit comments

Comments
 (0)