diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index 012c0da04..3766b1090 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -28,20 +28,21 @@ class Configuration { final Map _values; /// Creates an implicit configuration with the given [values]. - Configuration.implicit(this._values); + Configuration.implicit(this._values, {String? opaqueId}) + : this.opaqueId = opaqueId ?? Xid.string(); /// Uniquely identifying ID for a configuration lasting across the execution /// context. /// /// Implicit configurations will always have different IDs. - int get opaqueId => Xid.string().hashCode; + final String opaqueId; /// The empty configuration, which indicates that the module has not been /// configured. /// /// Empty configurations are always considered implicit, since they are /// ignored if the module has already been loaded. - const Configuration.empty() : _values = const {}; + factory Configuration.empty() => Configuration.implicit({}); bool get isEmpty => values.isEmpty; @@ -52,7 +53,7 @@ class Configuration { /// Creates a new configuration from this one based on a `@forward` rule. Configuration throughForward(ForwardRule forward) { - if (isEmpty) return const Configuration.empty(); + if (isEmpty) return Configuration.empty(); var newValues = _values; // Only allow variables that are visible through the `@forward` to be @@ -69,12 +70,13 @@ class Configuration { } else if (hiddenVariables != null && hiddenVariables.isNotEmpty) { newValues = LimitedMapView.blocklist(newValues, hiddenVariables); } - return _withValues(newValues); + return _withValues(newValues, opaqueId: opaqueId); } /// Returns a copy of [this] with the given [values] map. - Configuration _withValues(Map values) => - Configuration.implicit(values); + Configuration _withValues(Map values, + {String? opaqueId}) => + Configuration.implicit(values, opaqueId: opaqueId); String toString() => "(" + @@ -95,15 +97,13 @@ class ExplicitConfiguration extends Configuration { /// The node whose span indicates where the configuration was declared. final AstNode nodeWithSpan; - ExplicitConfiguration(Map values, this.nodeWithSpan) - : super.implicit(values); - - /// ID for a [configuration] created with an explicit `@use ... with` uniquely - /// identified by its [nodeWithSpan] property. - @override - int get opaqueId => nodeWithSpan.span.toString().hashCode; + ExplicitConfiguration(Map values, this.nodeWithSpan, + {String? opaqueId}) + : super.implicit(values, opaqueId: opaqueId); /// Returns a copy of [this] with the given [values] map. - Configuration _withValues(Map values) => - ExplicitConfiguration(values, nodeWithSpan); + @override + Configuration _withValues(Map values, + {String? opaqueId}) => + ExplicitConfiguration(values, nodeWithSpan, opaqueId: opaqueId); } diff --git a/lib/src/visitor/async_evaluate.dart b/lib/src/visitor/async_evaluate.dart index f2bcfa8da..a4ed7d21e 100644 --- a/lib/src/visitor/async_evaluate.dart +++ b/lib/src/visitor/async_evaluate.dart @@ -141,8 +141,8 @@ class _EvaluateVisitor /// All modules that have been loaded and evaluated so far. final _modules = {}; - /// Configuration ids seen by a module by URI. - final _moduleConfigurationIds = {}; + /// Configuration seen by a module URI. + final _moduleConfigurations = {}; /// A map from canonical module URLs to the nodes whose spans indicate where /// those modules were originally loaded. @@ -305,7 +305,7 @@ class _EvaluateVisitor /// The configuration for the current module. /// /// If this is empty, that indicates that the current module is not configured. - var _configuration = const Configuration.empty(); + var _configuration = Configuration.empty(); /// Creates a new visitor. /// @@ -470,7 +470,7 @@ class _EvaluateVisitor var withMap = arguments[1].realNull?.assertMap("with").contents; var callableNode = _callableNode!; - var configuration = const Configuration.empty(); + var configuration = Configuration.empty(); if (withMap != null) { var values = {}; var span = callableNode.span; @@ -673,7 +673,8 @@ class _EvaluateVisitor var alreadyLoaded = _modules[url]; if (alreadyLoaded != null) { var currentConfiguration = configuration ?? _configuration; - if (_moduleConfigurationIds[url] != currentConfiguration.opaqueId && + if (_moduleConfigurations[url]!.opaqueId != + currentConfiguration.opaqueId && currentConfiguration is ExplicitConfiguration) { var message = namesInErrors ? "${p.prettyUri(url)} was already loaded, so it can't be " @@ -755,7 +756,7 @@ class _EvaluateVisitor var module = environment.toModule(css, extensionStore); if (url != null) { _modules[url] = module; - _moduleConfigurationIds[url] = _configuration.opaqueId; + _moduleConfigurations[url] = _configuration; if (nodeWithSpan != null) _moduleNodes[url] = nodeWithSpan; } @@ -2090,7 +2091,7 @@ class _EvaluateVisitor } Future visitUseRule(UseRule node) async { - var configuration = const Configuration.empty(); + var configuration = Configuration.empty(); if (node.configuration.isNotEmpty) { var values = {}; for (var variable in node.configuration) { diff --git a/lib/src/visitor/evaluate.dart b/lib/src/visitor/evaluate.dart index 5047f3305..b18b708ea 100644 --- a/lib/src/visitor/evaluate.dart +++ b/lib/src/visitor/evaluate.dart @@ -5,7 +5,7 @@ // DO NOT EDIT. This file was generated from async_evaluate.dart. // See tool/grind/synchronize.dart for details. // -// Checksum: 6e3090c0d46489113c7a3751a37bfbf202285bc2 +// Checksum: 9064ba88b38e5cfcc31fd345b185d2c334b490a6 // // ignore_for_file: unused_import @@ -149,8 +149,8 @@ class _EvaluateVisitor /// All modules that have been loaded and evaluated so far. final _modules = >{}; - /// Configuration ids seen by a module by URI. - final _moduleConfigurationIds = {}; + /// Configuration seen by a module URI. + final _moduleConfigurations = {}; /// A map from canonical module URLs to the nodes whose spans indicate where /// those modules were originally loaded. @@ -313,7 +313,7 @@ class _EvaluateVisitor /// The configuration for the current module. /// /// If this is empty, that indicates that the current module is not configured. - var _configuration = const Configuration.empty(); + var _configuration = Configuration.empty(); /// Creates a new visitor. /// @@ -475,7 +475,7 @@ class _EvaluateVisitor var withMap = arguments[1].realNull?.assertMap("with").contents; var callableNode = _callableNode!; - var configuration = const Configuration.empty(); + var configuration = Configuration.empty(); if (withMap != null) { var values = {}; var span = callableNode.span; @@ -678,7 +678,8 @@ class _EvaluateVisitor var alreadyLoaded = _modules[url]; if (alreadyLoaded != null) { var currentConfiguration = configuration ?? _configuration; - if (_moduleConfigurationIds[url] != currentConfiguration.opaqueId && + if (_moduleConfigurations[url]!.opaqueId != + currentConfiguration.opaqueId && currentConfiguration is ExplicitConfiguration) { var message = namesInErrors ? "${p.prettyUri(url)} was already loaded, so it can't be " @@ -760,7 +761,7 @@ class _EvaluateVisitor var module = environment.toModule(css, extensionStore); if (url != null) { _modules[url] = module; - _moduleConfigurationIds[url] = _configuration.opaqueId; + _moduleConfigurations[url] = _configuration; if (nodeWithSpan != null) _moduleNodes[url] = nodeWithSpan; } @@ -2082,7 +2083,7 @@ class _EvaluateVisitor } Value? visitUseRule(UseRule node) { - var configuration = const Configuration.empty(); + var configuration = Configuration.empty(); if (node.configuration.isNotEmpty) { var values = {}; for (var variable in node.configuration) {