Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
"psr-4": { "Leafo\\ScssPhp\\": "src/" }
},
"autoload-dev": {
"psr-4": { "Leafo\\ScssPhp\\Test\\": "tests/" }
"psr-4": { "Leafo\\ScssPhp\\Test\\": "tests/" },
"classmap": [
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add classmap here?

"src/"
]
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "~2.5",
"phpunit/phpunit": "~4.6"
"phpunit/phpunit": "^7"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe phpunit7 requires php^7.1, but scssphp only requires php>=5.4.0

},
"bin": ["bin/pscss"],
"archive": {
Expand Down
8 changes: 8 additions & 0 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ class Block
* @var array
*/
public $children;
/**
* @var \Leafo\ScssPhp\Block
*/
public $atrootParent;
/**
* @var array
*/
public $atrootParentSelectors;
}
21 changes: 19 additions & 2 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ protected function compileAtRoot(Block $block)

$this->env = $this->filterWithout($envs, $without);
$newBlock = $this->spliceTree($envs, $block, $without);
if (isset($block->atrootParent))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this projects coding standard, but I'm pretty sure using {} is prefered even on single line considitionals.

$newBlock[1]->atrootParent = $block->atrootParent;

$saveScope = $this->scope;
$this->scope = $this->rootBlock;
Expand Down Expand Up @@ -1293,6 +1295,9 @@ protected function hasSelectorPlaceholder($selector)

foreach ($selector as $parts) {
foreach ($parts as $part) {
if (is_array($part)) {
return false;
}
if (strlen($part) && '%' === $part[0]) {
return true;
}
Expand Down Expand Up @@ -1878,7 +1883,11 @@ protected function compileChild($child, OutputBlock $out)
if (isset($mixin->args)) {
$this->applyArguments($mixin->args, $argValues);
}

foreach ($mixin->children as $stm) {
if ($stm[0] == Type::T_AT_ROOT) {
$stm[1]->atrootParentSelectors = $callingScope->selectors;
}
}
$this->env->marker = 'mixin';

$this->compileChildrenNoReturn($mixin->children, $out);
Expand Down Expand Up @@ -2912,8 +2921,16 @@ protected function multiplySelectors(Environment $env)
if (empty($env->selectors)) {
continue;
}

if ($env->block->type == Type::T_AT_ROOT) {
break;
}
$selectors = [];
if (!empty($env->block->parent->atrootParent) && !empty($env->block->parent->atrootParent->selectors)) {
$parentSelectors = $env->block->parent->atrootParent->selectors;
}
if (!empty($env->parent->parent->block->atrootParentSelectors)) {
$parentSelectors = $env->parent->parent->block->atrootParentSelectors;
}

foreach ($env->selectors as $selector) {
foreach ($parentSelectors as $parent) {
Expand Down
31 changes: 28 additions & 3 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ protected function pushBlock($selectors, $pos = 0)
$b->selectors = $selectors;
$b->comments = [];
$b->parent = $this->env;
$b->atrootParent = $this->env;

if (! $this->env) {
$b->children = [];
Expand Down Expand Up @@ -762,7 +763,9 @@ protected function popBlock()
if (empty($block->parent)) {
$this->throwParseError('unexpected }');
}

// if ($block->type == Type::T_AT_ROOT || $block->type == Type::T_MIXIN || $block->type == Type::T_INCLUDE) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this commented code should just not be included, if its not in use.

// $block->atrootParent = $block->parent;
// }
$this->env = $block->parent;
unset($block->parent);

Expand Down Expand Up @@ -1897,18 +1900,35 @@ protected function interpolation(&$out, $lookWhite = true)
{
$oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = true;
$selector = false;

$s = $this->seek();

if ($this->literal('#{') && $this->valueList($value) && $this->literal('}', false)) {

if ($lookWhite) {
$left = preg_match('/\s/', $this->buffer[$s - 1]) ? ' ' : '';
$right = preg_match('/\s/', $this->buffer[$this->count]) ? ' ': '';
$right = preg_match('/\s/', $this->buffer[$this->count]) ? ' ' : '';
} else {
$left = $right = false;
}

$out = [Type::T_INTERPOLATE, $value, $left, $right];

$this->eatWhiteDefault = $oldWhite;

if ($this->eatWhiteDefault) {
$this->whitespace();
}

return true;
}

$this->seek($s);

if ($this->literal('#{') && $selector = $this->selectorSingle($sel) && $this->literal('}', false)) {

$out = $sel[0];

$this->eatWhiteDefault = $oldWhite;

if ($this->eatWhiteDefault) {
Expand Down Expand Up @@ -2095,6 +2115,11 @@ protected function selectorSingle(&$out)
$parts[] = Compiler::$selfSelector;
continue;
}
// self
// if ($this->literal('#{&}', true)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assume unused commented code should just be removed

// $parts[] = Compiler::$selfSelector;
// continue;
// }

if ($this->literal('.', false)) {
$parts[] = '.';
Expand Down
2 changes: 1 addition & 1 deletion tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
class ApiTest extends \PHPUnit_Framework_TestCase
class ApiTest extends \PHPUnit\Framework\TestCase
{
public function setUp()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Base64VLQTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/
class Base64VLQTest extends \PHPUnit_Framework_TestCase
class Base64VLQTest extends \PHPUnit\Framework\TestCase
{
/**
* Test encode
Expand Down
2 changes: 1 addition & 1 deletion tests/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
class ExceptionTest extends \PHPUnit_Framework_TestCase
class ExceptionTest extends \PHPUnit\Framework\TestCase
{
public function setUp()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/FailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/
class FailingTest extends \PHPUnit_Framework_TestCase
class FailingTest extends \PHPUnit\Framework\TestCase
{
public function setUp()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function _quote($str)
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
class InputTest extends \PHPUnit_Framework_TestCase
class InputTest extends \PHPUnit\Framework\TestCase
{
protected static $inputDir = 'inputs';
protected static $outputDir = 'outputs';
Expand Down
2 changes: 1 addition & 1 deletion tests/ScssTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
class ScssTest extends \PHPUnit_Framework_TestCase
class ScssTest extends \PHPUnit\Framework\TestCase
{
/**
* @param string $name
Expand Down
2 changes: 1 addition & 1 deletion tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Zimzat <zimzat@zimzat.com>
*/
class ServerTest extends \PHPUnit_Framework_TestCase
class ServerTest extends \PHPUnit\Framework\TestCase
{
public function testCheckedCachedCompile()
{
Expand Down