Reject unknown named parameters.

This commit is contained in:
Natalie Weizenbaum 2017-01-26 20:09:45 -08:00
parent 45cfed063f
commit c26615386b
2 changed files with 7 additions and 3 deletions

View File

@ -59,6 +59,8 @@
* Support slash-separated numbers in arguments to plain CSS functions.
* Error out if a function is passed an unknown named parameter.
## 1.0.0-alpha.8
* Add the `content-exists()` function.

View File

@ -1351,6 +1351,7 @@ class _PerformVisitor
/// when applied to [arguments].
void _verifyArguments(int positional, Map<String, dynamic> named,
ArgumentDeclaration arguments, FileSpan span) {
var namedUsed = 0;
for (var i = 0; i < arguments.arguments.length; i++) {
var argument = arguments.arguments[i];
if (i < positional) {
@ -1360,8 +1361,9 @@ class _PerformVisitor
"name.",
span);
}
} else if (argument.defaultValue == null &&
!named.containsKey(argument.name)) {
} else if (named.containsKey(argument.name)) {
namedUsed++;
} else if (argument.defaultValue == null) {
throw _exception("Missing argument \$${argument.name}.", span);
}
}
@ -1377,7 +1379,7 @@ class _PerformVisitor
span);
}
if (arguments.arguments.length - positional < named.length) {
if (namedUsed < named.length) {
var unknownNames = normalizedSet(named.keys)
..removeAll(arguments.arguments.map((argument) => argument.name));
throw _exception(