Skip to content

Commit 1a8b16a

Browse files
authored
Merge pull request leafo#442 from mahagr/master
Fix mixin and variable scopes (leafo#440)
2 parents b42b2e2 + 1270b5c commit 1a8b16a

File tree

7 files changed

+89
-0
lines changed

7 files changed

+89
-0
lines changed

src/Compiler.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,9 @@ protected function compileChild($child, OutputBlock $out)
16961696
$this->pushEnv();
16971697
$this->env->depth--;
16981698

1699+
$storeEnv = $this->storeEnv;
1700+
$this->storeEnv = $this->env;
1701+
16991702
if (isset($content)) {
17001703
$content->scope = $callingScope;
17011704

@@ -1710,6 +1713,8 @@ protected function compileChild($child, OutputBlock $out)
17101713

17111714
$this->compileChildrenNoReturn($mixin->children, $out);
17121715

1716+
$this->storeEnv = $storeEnv;
1717+
17131718
$this->popEnv();
17141719
break;
17151720

@@ -3346,6 +3351,9 @@ protected function callScssFunction($name, $argValues, &$returnValue)
33463351

33473352
$this->pushEnv();
33483353

3354+
$storeEnv = $this->storeEnv;
3355+
$this->storeEnv = $this->env;
3356+
33493357
// set the args
33503358
if (isset($func->args)) {
33513359
$this->applyArguments($func->args, $argValues);
@@ -3360,6 +3368,8 @@ protected function callScssFunction($name, $argValues, &$returnValue)
33603368

33613369
$ret = $this->compileChildren($func->children, $tmp);
33623370

3371+
$this->storeEnv = $storeEnv;
3372+
33633373
$this->popEnv();
33643374

33653375
$returnValue = ! isset($ret) ? self::$defaultValue : $ret;

tests/inputs/functions.scss

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,41 @@ $str: 'global';
128128
l4: inspect((a: 1, b: 2));
129129
l5: inspect($value: (a: 1, b: 2));
130130
}
131+
132+
@function contains($list, $values...) {
133+
@each $value in $values {
134+
@if type-of(index($list, $value)) != "number" {
135+
@return false;
136+
}
137+
}
138+
139+
@return true;
140+
}
141+
142+
@function mapping($items) {
143+
$src: ();
144+
$map: (
145+
one: 1px 1px,
146+
two: 2px 2px,
147+
);
148+
149+
@each $key, $values in $map {
150+
@if contains($items, $key) {
151+
$value1: nth($values, 1);
152+
$value2: nth($values, 2);
153+
154+
$src: append($src, $value1 $value2, space);
155+
}
156+
}
157+
158+
@return $src;
159+
}
160+
161+
@mixin test() {
162+
padding: mapping(one two);
163+
}
164+
165+
div {
166+
margin: mapping(one two);
167+
@include test();
168+
}

tests/inputs/mixins.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,21 @@ div.parameter-name-scope {
190190
.test{
191191
@include test-mixin();
192192
}
193+
194+
@mixin inner($value) {}
195+
196+
@mixin outer($value) {
197+
#{$value} {
198+
content: "#{$value}";
199+
@content;
200+
content: "#{$value}";
201+
}
202+
}
203+
204+
@include outer(div) {
205+
@include inner('break');
206+
@include outer(p) {
207+
@include inner('break');
208+
}
209+
}
210+

tests/outputs/functions.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ p {
4545
l3: 5, 6;
4646
l4: (a: 1, b: 2);
4747
l5: (a: 1, b: 2); }
48+
49+
div {
50+
margin: 1px 1px 2px 2px;
51+
padding: 1px 1px 2px 2px; }

tests/outputs/mixins.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,10 @@ div.parameter-name-scope {
9595
@media screen and (min-width:0\0) {
9696
.test {
9797
color: #000; } }
98+
99+
div {
100+
content: "div";
101+
content: "div"; }
102+
div p {
103+
content: "p";
104+
content: "p"; }

tests/outputs_numbered/functions.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ p {
4747
l3: 5, 6;
4848
l4: (a: 1, b: 2);
4949
l5: (a: 1, b: 2); }
50+
/* line 165, inputs/functions.scss */
51+
div {
52+
margin: 1px 1px 2px 2px;
53+
padding: 1px 1px 2px 2px; }

tests/outputs_numbered/mixins.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,11 @@ div.parameter-name-scope {
108108
@media screen and (min-width:0\0) {
109109
.test {
110110
color: #000; } }
111+
/* line 197, inputs/mixins.scss */
112+
div {
113+
content: "div";
114+
content: "div"; }
115+
/* line 197, inputs/mixins.scss */
116+
div p {
117+
content: "p";
118+
content: "p"; }

0 commit comments

Comments
 (0)