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.
This commit is contained in:
Natalie Weizenbaum 2020-02-06 02:11:15 -08:00
parent 77a58b34b6
commit fa1ddd28ad
4 changed files with 32 additions and 6 deletions

View File

@ -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) {

View File

@ -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<Callable> 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<Callable> _getModule(String namespace) {

View File

@ -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) {

View File

@ -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) {