Skip to content

Commit 2eef52a

Browse files
committed
Fix duplicate key handling for maps
Deferred check from parser to evaluation Fixes #1187
1 parent 8ca8816 commit 2eef52a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

eval.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,13 @@ namespace Sass {
398398
for (auto key : m->keys()) {
399399
*mm << std::make_pair(key->perform(this), m->at(key)->perform(this));
400400
}
401+
402+
// check for duplicate keys
403+
if (mm->has_duplicate_key()) {
404+
To_String to_string(&ctx);
405+
error("Duplicate key \"" + mm->get_duplicate_key()->perform(&to_string) + "\" in map " + m->perform(&to_string) + ".", m->pstate());
406+
}
407+
401408
mm->is_expanded(true);
402409
return mm;
403410
}

parser.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ namespace Sass {
10141014

10151015
Expression* Parser::parse_map()
10161016
{
1017-
To_String to_string(&ctx);
1017+
ParserState opstate = pstate;
10181018
Expression* key = parse_list();
10191019
if (String_Quoted* str = dynamic_cast<String_Quoted*>(key)) {
10201020
if (!str->quote_mark() && !str->is_delayed()) {
@@ -1035,7 +1035,7 @@ namespace Sass {
10351035

10361036
Expression* value = parse_space_list();
10371037

1038-
Map* map = new (ctx.mem) Map(pstate, 1);
1038+
Map* map = new (ctx.mem) Map(opstate, 1);
10391039
(*map) << make_pair(key, value);
10401040

10411041
while (lex_css< exactly<','> >())
@@ -1064,8 +1064,15 @@ namespace Sass {
10641064
(*map) << make_pair(key, value);
10651065
}
10661066

1067-
if (map->has_duplicate_key())
1068-
{ error("Duplicate key \"" + map->get_duplicate_key()->perform(&to_string) + "\" in map " + map->perform(&to_string) + ".", pstate); }
1067+
// Check was moved to eval step
1068+
// if (map->has_duplicate_key()) {
1069+
// To_String to_string(&ctx);
1070+
// error("Duplicate key \"" + map->get_duplicate_key()->perform(&to_string) + "\" in map " + map->perform(&to_string) + ".", pstate);
1071+
// }
1072+
1073+
ParserState ps = map->pstate();
1074+
ps.offset = pstate - ps + pstate.offset;
1075+
map->pstate(ps);
10691076

10701077
return map;
10711078
}

0 commit comments

Comments
 (0)