Detect import loops.

This commit is contained in:
Natalie Weizenbaum 2017-01-15 15:05:28 -08:00
parent 6a4eafe915
commit 0000c4a7e9
2 changed files with 13 additions and 0 deletions

View File

@ -16,6 +16,8 @@
* Don't emit loud comments in functions.
* Detect import loops.
* Fix `@import` with a `supports()` clause.
* Forbid functions named "and", "or", and "not".

View File

@ -121,6 +121,8 @@ class _PerformVisitor
/// multiple times.
final _importedFiles = <String, Stylesheet>{};
final _activeImports = new Set<Uri>();
/// The extender that handles extensions for this perform run.
final _extender = new Extender();
@ -182,6 +184,7 @@ class _PerformVisitor
}
CssStylesheet run(Stylesheet node) {
_activeImports.add(node.span.sourceUrl);
visitStylesheet(node);
return _root;
}
@ -553,6 +556,13 @@ class _PerformVisitor
/// Adds the stylesheet imported by [import] to the current document.
void _visitDynamicImport(DynamicImport import) {
var stylesheet = _loadImport(import);
var url = stylesheet.span.sourceUrl;
if (_activeImports.contains(url)) {
throw _exception("This file is already being imported.", import.span);
}
_activeImports.add(url);
_withStackFrame("@import", import.span, () {
_withEnvironment(_environment.global(), () {
for (var statement in stylesheet.children) {
@ -560,6 +570,7 @@ class _PerformVisitor
}
});
});
_activeImports.remove(url);
}
/// Loads the [Stylesheet] imported by [import], or throws a