fail on duplicate key in map declaration
This commit is contained in:
parent
24176bb1f0
commit
04e9b99b09
@ -56,14 +56,16 @@ impl SassMap {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, key: Value, value: Value) {
|
/// Returns true if the key already exists
|
||||||
for &mut (ref k, ref mut v) in &mut self.0 {
|
pub fn insert(&mut self, key: Value, value: Value) -> bool {
|
||||||
|
for (ref k, ref mut v) in &mut self.0 {
|
||||||
if k == &key {
|
if k == &key {
|
||||||
*v = value;
|
*v = value;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.0.push((key, value));
|
self.0.push((key, value));
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +325,9 @@ impl Value {
|
|||||||
super_selector,
|
super_selector,
|
||||||
)?;
|
)?;
|
||||||
devour_whitespace(paren_toks);
|
devour_whitespace(paren_toks);
|
||||||
map.insert(key, val);
|
if map.insert(key, val) {
|
||||||
|
return Err("Duplicate key.".into());
|
||||||
|
}
|
||||||
if paren_toks.peek().is_none() {
|
if paren_toks.peek().is_none() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -129,3 +129,7 @@ test!(
|
|||||||
"a {\n color: inspect(map-remove((\"foo\": 1, \"bar\": 2, \"baz\": 3), \"bar\", \"baz\"));\n}\n",
|
"a {\n color: inspect(map-remove((\"foo\": 1, \"bar\": 2, \"baz\": 3), \"bar\", \"baz\"));\n}\n",
|
||||||
"a {\n color: (\"foo\": 1);\n}\n"
|
"a {\n color: (\"foo\": 1);\n}\n"
|
||||||
);
|
);
|
||||||
|
error!(
|
||||||
|
duplicate_key_in_declaration,
|
||||||
|
"a {\n $a: (foo: a, foo: b);;\n}\n", "Error: Duplicate key."
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user