From ba3eb47dad79c739624193c609a9245eb457da25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Israel=20Ortiz=20Garc=C3=ADa?= Date: Tue, 19 Jul 2022 18:16:20 -0700 Subject: [PATCH] explicit configs now also used xid and forwardRules inherit the opaqueId from the original config --- lib/src/configuration.dart | 32 ++++++++++++++--------------- lib/src/visitor/async_evaluate.dart | 15 +++++++------- lib/src/visitor/evaluate.dart | 17 +++++++-------- 3 files changed, 33 insertions(+), 31 deletions(-) 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 37c401d3b..fa127e508 100644 --- a/lib/src/visitor/async_evaluate.dart +++ b/lib/src/visitor/async_evaluate.dart @@ -140,8 +140,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. @@ -304,7 +304,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. /// @@ -469,7 +469,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; @@ -672,7 +672,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 " @@ -754,7 +755,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; } @@ -2031,7 +2032,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 67ee873df..fa5194b2d 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: 954b44d16887e3792990684e25ac3abf32113371 +// Checksum: 2fc96fb16a1003ef73f3d5189f5b73334c23c324 // // ignore_for_file: unused_import @@ -148,8 +148,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. @@ -312,7 +312,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. /// @@ -474,7 +474,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; @@ -677,7 +677,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 " @@ -759,7 +760,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; } @@ -2023,7 +2024,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) {