From fa1ddd28ad36301c6ee39f8c61ac656a341b3d4a Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 6 Feb 2020 02:11:15 -0800 Subject: [PATCH] Add a separate Environment method to create dummy import modules This avoids triggering `assert(!atRoot)` for nested environments, while still having that precaution for normal `toModule()` calls. --- lib/src/async_environment.dart | 14 ++++++++++++++ lib/src/environment.dart | 16 +++++++++++++++- lib/src/visitor/async_evaluate.dart | 3 +-- lib/src/visitor/evaluate.dart | 5 ++--- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/src/async_environment.dart b/lib/src/async_environment.dart index 4f19ef8c..e19a14a5 100644 --- a/lib/src/async_environment.dart +++ b/lib/src/async_environment.dart @@ -810,6 +810,20 @@ class AsyncEnvironment { forwarded: _forwardedModules); } + /// Returns a module with the same members and upstream modules as [this], but + /// an empty stylesheet and extender. + /// + /// This is used when resolving imports, since they need to inject forwarded + /// members into the current scope. It's the only situation in which a nested + /// environment can become a module. + Module toDummyModule() { + return _EnvironmentModule( + this, + CssStylesheet(const [], SourceFile.decoded(const []).span(0)), + Extender.empty, + forwarded: _forwardedModules); + } + /// Returns the module with the given [namespace], or throws a /// [SassScriptException] if none exists. Module _getModule(String namespace) { diff --git a/lib/src/environment.dart b/lib/src/environment.dart index 331be0a7..7c8c9356 100644 --- a/lib/src/environment.dart +++ b/lib/src/environment.dart @@ -5,7 +5,7 @@ // DO NOT EDIT. This file was generated from async_environment.dart. // See tool/grind/synchronize.dart for details. // -// Checksum: 76e7c2e929fc7d19390987069ff3a8c4b3fadfc5 +// Checksum: b5212ffc7c50a8e7e436b25c7c16eb2996da2def // // ignore_for_file: unused_import @@ -815,6 +815,20 @@ class Environment { forwarded: _forwardedModules); } + /// Returns a module with the same members and upstream modules as [this], but + /// an empty stylesheet and extender. + /// + /// This is used when resolving imports, since they need to inject forwarded + /// members into the current scope. It's the only situation in which a nested + /// environment can become a module. + Module toDummyModule() { + return _EnvironmentModule( + this, + CssStylesheet(const [], SourceFile.decoded(const []).span(0)), + Extender.empty, + forwarded: _forwardedModules); + } + /// Returns the module with the given [namespace], or throws a /// [SassScriptException] if none exists. Module _getModule(String namespace) { diff --git a/lib/src/visitor/async_evaluate.dart b/lib/src/visitor/async_evaluate.dart index 48440b27..dc0f7681 100644 --- a/lib/src/visitor/async_evaluate.dart +++ b/lib/src/visitor/async_evaluate.dart @@ -1420,8 +1420,7 @@ class _EvaluateVisitor // Create a dummy module with empty CSS and no extensions to make forwarded // members available in the current import context and to combine all the // CSS from modules used by [stylesheet]. - var module = environment.toModule( - CssStylesheet(const [], stylesheet.span), Extender.empty); + var module = environment.toDummyModule(); _environment.importForwards(module); if (module.transitivelyContainsCss) { diff --git a/lib/src/visitor/evaluate.dart b/lib/src/visitor/evaluate.dart index d14d9880..d143858f 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: f6a7ece88049e365d88091c14cc8143335a06d75 +// Checksum: 0ad7cedc5ee1d05297c4a8d321d492854742e8ab // // ignore_for_file: unused_import @@ -1417,8 +1417,7 @@ class _EvaluateVisitor // Create a dummy module with empty CSS and no extensions to make forwarded // members available in the current import context and to combine all the // CSS from modules used by [stylesheet]. - var module = environment.toModule( - CssStylesheet(const [], stylesheet.span), Extender.empty); + var module = environment.toDummyModule(); _environment.importForwards(module); if (module.transitivelyContainsCss) {