Skip to content

Commit 47fe36d

Browse files
authored
Merge pull request #652 from Cerdic/Issue/leafo/620
Fix for #620
2 parents 0af1a8d + 1271d1b commit 47fe36d

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

src/Compiler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,11 @@ protected function reduce($value, $inExp = false)
22712271
case Type::T_FUNCTION_CALL:
22722272
return $this->fncall($value[1], $value[2]);
22732273

2274+
case Type::T_SELF:
2275+
$selfSelector = $this->multiplySelectors($this->env);
2276+
$selfSelector = $this->collapseSelectors($selfSelector);
2277+
return [Type::T_STRING, '', [$selfSelector]];
2278+
22742279
default:
22752280
return $value;
22762281
}

src/Parser.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,11 @@ protected function value(&$out)
14021402
}
14031403
}
14041404

1405+
if ($this->matchChar('&', true)) {
1406+
$out = [Type::T_SELF];
1407+
return true;
1408+
}
1409+
14051410
if ($char === '$' && $this->variable($out)) {
14061411
return true;
14071412
}
@@ -1991,28 +1996,18 @@ protected function interpolation(&$out, $lookWhite = true)
19911996
$s = $this->count;
19921997

19931998
if ($this->literal('#{', 2) && $this->valueList($value) && $this->matchChar('}', false)) {
1994-
if ($lookWhite) {
1995-
$left = preg_match('/\s/', $this->buffer[$s - 1]) ? ' ' : '';
1996-
$right = preg_match('/\s/', $this->buffer[$this->count]) ? ' ': '';
1999+
if ($value === [Type::T_SELF]) {
2000+
$out = $value;
19972001
} else {
1998-
$left = $right = false;
1999-
}
2000-
2001-
$out = [Type::T_INTERPOLATE, $value, $left, $right];
2002-
$this->eatWhiteDefault = $oldWhite;
2002+
if ($lookWhite) {
2003+
$left = preg_match('/\s/', $this->buffer[$s - 1]) ? ' ' : '';
2004+
$right = preg_match('/\s/', $this->buffer[$this->count]) ? ' ': '';
2005+
} else {
2006+
$left = $right = false;
2007+
}
20032008

2004-
if ($this->eatWhiteDefault) {
2005-
$this->whitespace();
2009+
$out = [Type::T_INTERPOLATE, $value, $left, $right];
20062010
}
2007-
2008-
return true;
2009-
}
2010-
2011-
$this->seek($s);
2012-
2013-
if ($this->literal('#{', 2) && $this->selectorSingle($sel) && $this->matchChar('}', false)) {
2014-
$out = $sel[0];
2015-
20162011
$this->eatWhiteDefault = $oldWhite;
20172012

20182013
if ($this->eatWhiteDefault) {
@@ -2023,6 +2018,7 @@ protected function interpolation(&$out, $lookWhite = true)
20232018
}
20242019

20252020
$this->seek($s);
2021+
20262022
$this->eatWhiteDefault = $oldWhite;
20272023

20282024
return false;

tests/inputs/values.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ multiline string.";
4141
d: +foo(12px);
4242
}
4343

44+
#self {
45+
$self1: #{&};
46+
$self2: &;
47+
content:'#{$self2}';
48+
}

tests/outputs/values.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ multiline string.";
3232
b: 0.5em;
3333
c: -foo(12px);
3434
d: +foo(12px); }
35+
36+
#self {
37+
content: "#self"; }

tests/outputs_numbered/values.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ multiline string.";
3333
b: 0.5em;
3434
c: -foo(12px);
3535
d: +foo(12px); }
36+
/* line 44, inputs/values.scss */
37+
#self {
38+
content: "#self"; }

0 commit comments

Comments
 (0)