Skip to content

Commit fa1ddd2

Browse files
committed
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.
1 parent 77a58b3 commit fa1ddd2

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

lib/src/async_environment.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,20 @@ class AsyncEnvironment {
810810
forwarded: _forwardedModules);
811811
}
812812

813+
/// Returns a module with the same members and upstream modules as [this], but
814+
/// an empty stylesheet and extender.
815+
///
816+
/// This is used when resolving imports, since they need to inject forwarded
817+
/// members into the current scope. It's the only situation in which a nested
818+
/// environment can become a module.
819+
Module toDummyModule() {
820+
return _EnvironmentModule(
821+
this,
822+
CssStylesheet(const [], SourceFile.decoded(const []).span(0)),
823+
Extender.empty,
824+
forwarded: _forwardedModules);
825+
}
826+
813827
/// Returns the module with the given [namespace], or throws a
814828
/// [SassScriptException] if none exists.
815829
Module _getModule(String namespace) {

lib/src/environment.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DO NOT EDIT. This file was generated from async_environment.dart.
66
// See tool/grind/synchronize.dart for details.
77
//
8-
// Checksum: 76e7c2e929fc7d19390987069ff3a8c4b3fadfc5
8+
// Checksum: b5212ffc7c50a8e7e436b25c7c16eb2996da2def
99
//
1010
// ignore_for_file: unused_import
1111

@@ -815,6 +815,20 @@ class Environment {
815815
forwarded: _forwardedModules);
816816
}
817817

818+
/// Returns a module with the same members and upstream modules as [this], but
819+
/// an empty stylesheet and extender.
820+
///
821+
/// This is used when resolving imports, since they need to inject forwarded
822+
/// members into the current scope. It's the only situation in which a nested
823+
/// environment can become a module.
824+
Module<Callable> toDummyModule() {
825+
return _EnvironmentModule(
826+
this,
827+
CssStylesheet(const [], SourceFile.decoded(const []).span(0)),
828+
Extender.empty,
829+
forwarded: _forwardedModules);
830+
}
831+
818832
/// Returns the module with the given [namespace], or throws a
819833
/// [SassScriptException] if none exists.
820834
Module<Callable> _getModule(String namespace) {

lib/src/visitor/async_evaluate.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,8 +1420,7 @@ class _EvaluateVisitor
14201420
// Create a dummy module with empty CSS and no extensions to make forwarded
14211421
// members available in the current import context and to combine all the
14221422
// CSS from modules used by [stylesheet].
1423-
var module = environment.toModule(
1424-
CssStylesheet(const [], stylesheet.span), Extender.empty);
1423+
var module = environment.toDummyModule();
14251424
_environment.importForwards(module);
14261425

14271426
if (module.transitivelyContainsCss) {

lib/src/visitor/evaluate.dart

Lines changed: 2 additions & 3 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: f6a7ece88049e365d88091c14cc8143335a06d75
8+
// Checksum: 0ad7cedc5ee1d05297c4a8d321d492854742e8ab
99
//
1010
// ignore_for_file: unused_import
1111

@@ -1417,8 +1417,7 @@ class _EvaluateVisitor
14171417
// Create a dummy module with empty CSS and no extensions to make forwarded
14181418
// members available in the current import context and to combine all the
14191419
// CSS from modules used by [stylesheet].
1420-
var module = environment.toModule(
1421-
CssStylesheet(const [], stylesheet.span), Extender.empty);
1420+
var module = environment.toDummyModule();
14221421
_environment.importForwards(module);
14231422

14241423
if (module.transitivelyContainsCss) {

0 commit comments

Comments
 (0)