Add support for extending selector lists (#455)

Closes #452
This commit is contained in:
Natalie Weizenbaum 2018-08-17 13:32:10 -07:00 committed by GitHub
parent 677d781c52
commit 997e068499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 33 deletions

View File

@ -1,4 +1,8 @@
## 1.12.1 ## 1.13.0
* Allow `@extend` to be used with multiple comma-separated simple selectors.
This is already supported by other implementations, but fell through the
cracks for Dart Sass until now.
* Don't crash when a media rule contains another media rule followed by a style * Don't crash when a media rule contains another media rule followed by a style
rule. rule.

View File

@ -580,29 +580,33 @@ class _EvaluateVisitor
var targetText = var targetText =
await _interpolationToValue(node.selector, warnForColor: true); await _interpolationToValue(node.selector, warnForColor: true);
var target = _adjustParseError(targetText.span, () { var list = _adjustParseError(
try { targetText.span,
return new SimpleSelector.parse(targetText.value.trim(), () => new SelectorList.parse(targetText.value.trim(),
logger: _logger, allowParent: false); logger: _logger, allowParent: false));
} on SassFormatException catch (error) {
CompoundSelector compound;
try {
compound = new CompoundSelector.parse(targetText.value.trim(),
logger: _logger, allowParent: false);
} on SassFormatException {
throw error;
}
for (var complex in list.components) {
if (complex.components.length != 1 ||
complex.components.first is! CompoundSelector) {
// If the selector was a compound selector but not a simple // If the selector was a compound selector but not a simple
// selector, emit a more explicit error. // selector, emit a more explicit error.
throw new SassFormatException(
"complex selectors may not be extended.", targetText.span);
}
var compound = complex.components.first as CompoundSelector;
if (compound.components.length != 1) {
throw new SassFormatException( throw new SassFormatException(
"compound selectors may longer be extended.\n" "compound selectors may longer be extended.\n"
"Consider `@extend ${compound.components.join(', ')}` instead.\n" "Consider `@extend ${compound.components.join(', ')}` instead.\n"
"See http://bit.ly/ExtendCompound for details.\n", "See http://bit.ly/ExtendCompound for details.\n",
error.span); targetText.span);
} }
});
_extender.addExtension(_styleRule.selector, target, node, _mediaQueries); _extender.addExtension(
_styleRule.selector, compound.components.first, node, _mediaQueries);
}
return null; return null;
} }

View File

@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart. // DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/synchronize.dart for details. // See tool/synchronize.dart for details.
// //
// Checksum: 2bf89d853d3acfa3d7215dc7a6d43aefe0397519 // Checksum: 11e77e1df658d69b4ecab6447225f79c358db535
import 'async_evaluate.dart' show EvaluateResult; import 'async_evaluate.dart' show EvaluateResult;
export 'async_evaluate.dart' show EvaluateResult; export 'async_evaluate.dart' show EvaluateResult;
@ -581,29 +581,33 @@ class _EvaluateVisitor
var targetText = _interpolationToValue(node.selector, warnForColor: true); var targetText = _interpolationToValue(node.selector, warnForColor: true);
var target = _adjustParseError(targetText.span, () { var list = _adjustParseError(
try { targetText.span,
return new SimpleSelector.parse(targetText.value.trim(), () => new SelectorList.parse(targetText.value.trim(),
logger: _logger, allowParent: false); logger: _logger, allowParent: false));
} on SassFormatException catch (error) {
CompoundSelector compound;
try {
compound = new CompoundSelector.parse(targetText.value.trim(),
logger: _logger, allowParent: false);
} on SassFormatException {
throw error;
}
for (var complex in list.components) {
if (complex.components.length != 1 ||
complex.components.first is! CompoundSelector) {
// If the selector was a compound selector but not a simple // If the selector was a compound selector but not a simple
// selector, emit a more explicit error. // selector, emit a more explicit error.
throw new SassFormatException(
"complex selectors may not be extended.", targetText.span);
}
var compound = complex.components.first as CompoundSelector;
if (compound.components.length != 1) {
throw new SassFormatException( throw new SassFormatException(
"compound selectors may longer be extended.\n" "compound selectors may longer be extended.\n"
"Consider `@extend ${compound.components.join(', ')}` instead.\n" "Consider `@extend ${compound.components.join(', ')}` instead.\n"
"See http://bit.ly/ExtendCompound for details.\n", "See http://bit.ly/ExtendCompound for details.\n",
error.span); targetText.span);
} }
});
_extender.addExtension(_styleRule.selector, target, node, _mediaQueries); _extender.addExtension(
_styleRule.selector, compound.components.first, node, _mediaQueries);
}
return null; return null;
} }

View File

@ -1,5 +1,5 @@
name: sass name: sass
version: 1.12.1-dev version: 1.13.0
description: A Sass implementation in Dart. description: A Sass implementation in Dart.
author: Dart Team <misc@dartlang.org> author: Dart Team <misc@dartlang.org>
homepage: https://github.com/sass/dart-sass homepage: https://github.com/sass/dart-sass