Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually merge maps instead of just concatenating #578

Merged
merged 1 commit into from Jul 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Compiler.php
Expand Up @@ -4985,7 +4985,17 @@ protected function libMapMerge($args)
$map1 = $this->assertMap($args[0]);
$map2 = $this->assertMap($args[1]);

return [Type::T_MAP, array_merge($map1[1], $map2[1]), array_merge($map1[2], $map2[2])];
foreach ($map2[1] as $i2 => $key2) {
foreach ($map1[1] as $i1 => $key1) {
if ($this->compileStringContent($this->coerceString($key1)) === $this->compileStringContent($this->coerceString($key2))) {
$map1[2][$i1] = $map2[2][$i2];
continue 2;
}
}
$map1[1][] = $map2[1][$i2];
$map1[2][] = $map2[2][$i2];
}
return $map1;
}

protected static $libKeywords = ['args'];
Expand Down
5 changes: 3 additions & 2 deletions tests/inputs/map.scss
Expand Up @@ -25,9 +25,10 @@ div {
bar: nth(nth($map, 1), 1);
}

$color: ("black" : #000000);
$color: ("black" : #000000, "grey" : #777777);
$color2: ("grey" : #888888, "white" : #ffffff);

@each $color_name, $color_value in $color {
@each $color_name, $color_value in map_merge( $color, $color2 ) {
.#{$color_name} {
background-color: $color_value !important;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/outputs/map.css
Expand Up @@ -12,6 +12,10 @@ div {
bar: color; }
.black {
background-color: #000 !important; }
.grey {
background-color: #888 !important; }
.white {
background-color: #fff !important; }

div {
a: 1;
Expand Down
10 changes: 8 additions & 2 deletions tests/outputs_numbered/map.css
Expand Up @@ -11,10 +11,16 @@ div {
div {
foo: color black;
bar: color; }
/* line 31, inputs/map.scss */
/* line 32, inputs/map.scss */
.black {
background-color: #000 !important; }
/* line 52, inputs/map.scss */
/* line 32, inputs/map.scss */
.grey {
background-color: #888 !important; }
/* line 32, inputs/map.scss */
.white {
background-color: #fff !important; }
/* line 53, inputs/map.scss */
div {
a: 1;
b: 2;
Expand Down