From 69221190e72ae1aaf46a1f1deb18dd5d3b3ff4e5 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Fri, 12 Aug 2016 17:51:17 -0700 Subject: [PATCH] Enable @extend. Still tons of runtime errors. --- lib/src/extend/extender.dart | 8 +++++--- lib/src/parser.dart | 6 ++++++ lib/src/visitor/sass/statement/perform.dart | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/src/extend/extender.dart b/lib/src/extend/extender.dart index e29db37a..7f583305 100644 --- a/lib/src/extend/extender.dart +++ b/lib/src/extend/extender.dart @@ -89,7 +89,7 @@ class Extender { return new SelectorList(newList.where((complex) => complex != null)); } - List _extendComplex(ComplexSelector complex, + Iterable _extendComplex(ComplexSelector complex, Map> extensions) { // This could be written more simply using [List.map], but we want to avoid // any allocations in the common case where no extends apply. @@ -104,8 +104,10 @@ class Extender { if (changed) extendedNotExpanded.add([[component]]); } else { if (!changed) { - extendedNotExpanded = - complex.components.take(i).map((component) => [[component]]); + extendedNotExpanded = complex.components + .take(i) + .map((component) => [[component]]) + .toList(); } changed = true; extendedNotExpanded.add(extended); diff --git a/lib/src/parser.dart b/lib/src/parser.dart index ef97514f..bd6bf2ba 100644 --- a/lib/src/parser.dart +++ b/lib/src/parser.dart @@ -69,6 +69,12 @@ class Parser { return selector; } + SimpleSelector parseSimpleSelector() { + var simple = _simpleSelector(); + _scanner.expectDone(); + return simple; + } + VariableDeclaration _variableDeclaration() { if (!_scanner.scanChar($dollar)) return null; diff --git a/lib/src/visitor/sass/statement/perform.dart b/lib/src/visitor/sass/statement/perform.dart index f7874f9e..aa6bfa69 100644 --- a/lib/src/visitor/sass/statement/perform.dart +++ b/lib/src/visitor/sass/statement/perform.dart @@ -66,6 +66,14 @@ class PerformVisitor extends StatementVisitor { _parent.addChild(new CssDeclaration(name, cssValue, span: node.span)); } + void visitExtendRule(ExtendRule node) { + var targetText = _performInterpolation(node.selector); + + // TODO: recontextualize parse errors. + var simple = new Parser(targetText.value).parseSimpleSelector(); + _extender.addExtension(_selector.value, simple); + } + void visitAtRule(AtRule node) { var value = node.value == null ? null