Skip to content

Commit 0b94ebc

Browse files
committed
Actually merge maps instead of just concatenating
1 parent 585f6ae commit 0b94ebc

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

src/Compiler.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4985,7 +4985,17 @@ protected function libMapMerge($args)
49854985
$map1 = $this->assertMap($args[0]);
49864986
$map2 = $this->assertMap($args[1]);
49874987

4988-
return [Type::T_MAP, array_merge($map1[1], $map2[1]), array_merge($map1[2], $map2[2])];
4988+
foreach ($map2[1] as $i2 => $key2) {
4989+
foreach ($map1[1] as $i1 => $key1) {
4990+
if ($this->compileStringContent($this->coerceString($key1)) === $this->compileStringContent($this->coerceString($key2))) {
4991+
$map1[2][$i1] = $map2[2][$i2];
4992+
continue 2;
4993+
}
4994+
}
4995+
$map1[1][] = $map2[1][$i2];
4996+
$map1[2][] = $map2[2][$i2];
4997+
}
4998+
return $map1;
49894999
}
49905000

49915001
protected static $libKeywords = ['args'];

tests/inputs/map.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ div {
2525
bar: nth(nth($map, 1), 1);
2626
}
2727

28-
$color: ("black" : #000000);
28+
$color: ("black" : #000000, "grey" : #777777);
29+
$color2: ("grey" : #888888, "white" : #ffffff);
2930

30-
@each $color_name, $color_value in $color {
31+
@each $color_name, $color_value in map_merge( $color, $color2 ) {
3132
.#{$color_name} {
3233
background-color: $color_value !important;
3334
}

tests/outputs/map.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ div {
1212
bar: color; }
1313
.black {
1414
background-color: #000 !important; }
15+
.grey {
16+
background-color: #888 !important; }
17+
.white {
18+
background-color: #fff !important; }
1519

1620
div {
1721
a: 1;

tests/outputs_numbered/map.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ div {
1111
div {
1212
foo: color black;
1313
bar: color; }
14-
/* line 31, inputs/map.scss */
14+
/* line 32, inputs/map.scss */
1515
.black {
1616
background-color: #000 !important; }
17-
/* line 52, inputs/map.scss */
17+
/* line 32, inputs/map.scss */
18+
.grey {
19+
background-color: #888 !important; }
20+
/* line 32, inputs/map.scss */
21+
.white {
22+
background-color: #fff !important; }
23+
/* line 53, inputs/map.scss */
1824
div {
1925
a: 1;
2026
b: 2;

0 commit comments

Comments
 (0)