Improve errors for alpha() with the wrong number of arguments

Closes #700
This commit is contained in:
Natalie Weizenbaum 2019-07-02 15:13:36 -07:00
parent ed06a41afc
commit 9838caff6f
2 changed files with 16 additions and 7 deletions

View File

@ -4,6 +4,9 @@
function is now `$amount`, to match the name in LibSass and originally in Ruby
Sass.
* The `alpha()` function now produces clearer error messages when the wrong
number of arguments are passed.
## 1.22.2
### JavaScript API

View File

@ -171,17 +171,23 @@ final global = UnmodifiableListView([
return SassNumber(color.alpha);
},
r"$args...": (arguments) {
if (arguments[0].asList.every((argument) =>
argument is SassString &&
!argument.hasQuotes &&
argument.text.contains(_microsoftFilterStart))) {
var argList = arguments[0].asList;
if (argList.isNotEmpty &&
argList.every((argument) =>
argument is SassString &&
!argument.hasQuotes &&
argument.text.contains(_microsoftFilterStart))) {
// Suport the proprietary Microsoft alpha() function.
return _functionString("alpha", arguments);
}
assert(arguments.length != 1);
throw SassScriptException(
"Only 1 argument allowed, but ${arguments.length} were passed.");
assert(argList.length != 1);
if (argList.isEmpty) {
throw SassScriptException("Missing argument \$color.");
} else {
throw SassScriptException(
"Only 1 argument allowed, but ${argList.length} were passed.");
}
}
}),