Skip to content

Commit

Permalink
Less_Parser: Improve parseDirective() docs, minor toCSS sync
Browse files Browse the repository at this point in the history
* Follows-up 6edad32 (Ibe33cc358f). It seems return null/void
  and empty array have the same effect in the toCSS visitor for
  Directive nodes. Upstream does void, so let's do the same.

* Make it clear that parseDirective can return Import and Media
  nodes as well.

Change-Id: Ida803aaaf86b88012c72eb546e1c6b074c1198a8
  • Loading branch information
Krinkle committed Apr 29, 2024
1 parent 9c38475 commit 1f5fcc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions lib/Less/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2281,12 +2281,12 @@ private function parseMedia() {
}
}

//
// A CSS Directive
//
// @charset "utf-8";
//
// @see less-2.5.3.js#parsers.directive
/**
* A CSS Directive like `@charset "utf-8";`
*
* @return Less_Tree_Import|Less_Tree_Media|Less_Tree_Directive|null
* @see less-2.5.3.js#parsers.directive
*/
private function parseDirective() {
if ( !$this->peekChar( '@' ) ) {
return;
Expand Down
5 changes: 2 additions & 3 deletions lib/Less/Visitor/toCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function visitMedia( $mediaNode, &$visitDeeper ) {

public function visitDirective( $directiveNode, &$visitDeeper ) {
if ( $directiveNode->name === '@charset' ) {

if ( !$directiveNode->getIsReferenced() ) {
return;
}
Expand All @@ -69,7 +68,7 @@ public function visitDirective( $directiveNode, &$visitDeeper ) {
// return $this->visit($comment);
//}

return [];
return;
}
$this->charset = true;
}
Expand All @@ -86,7 +85,7 @@ public function visitDirective( $directiveNode, &$visitDeeper ) {
}

if ( !$directiveNode->rules ) {
return [];
return;
}
if ( $this->hasVisibleChild( $directiveNode ) ) {
// marking as referenced in case the directive is stored inside another directive
Expand Down

0 comments on commit 1f5fcc8

Please sign in to comment.