Skip to content

Commit 79f6252

Browse files
authored
Merge pull request #578 from s7eph4n/map_merge
Actually merge maps instead of just concatenating
2 parents 3d3fd50 + 0b94ebc commit 79f6252

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
@@ -5003,7 +5003,17 @@ protected function libMapMerge($args)
50035003
$map1 = $this->assertMap($args[0]);
50045004
$map2 = $this->assertMap($args[1]);
50055005

5006-
return [Type::T_MAP, array_merge($map1[1], $map2[1]), array_merge($map1[2], $map2[2])];
5006+
foreach ($map2[1] as $i2 => $key2) {
5007+
foreach ($map1[1] as $i1 => $key1) {
5008+
if ($this->compileStringContent($this->coerceString($key1)) === $this->compileStringContent($this->coerceString($key2))) {
5009+
$map1[2][$i1] = $map2[2][$i2];
5010+
continue 2;
5011+
}
5012+
}
5013+
$map1[1][] = $map2[1][$i2];
5014+
$map1[2][] = $map2[2][$i2];
5015+
}
5016+
return $map1;
50075017
}
50085018

50095019
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)