Skip to content

Commit

Permalink
Less_Tree_Color: Preserve color keywords and short hex notation as-is
Browse files Browse the repository at this point in the history
Bug: T352866
Change-Id: I0e6fa0fa88b4ab8dc41c55524661fdb9675e9393
  • Loading branch information
Hannah Okwelum authored and Krinkle committed Jan 4, 2024
1 parent b01ecdd commit 79ae252
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 83 deletions.
2 changes: 1 addition & 1 deletion lib/Less/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ private function parseEntitiesVariableCurly() {
*/
private function parseEntitiesColor() {
if ( $this->PeekChar( '#' ) && ( $rgb = $this->MatchReg( '/\\G#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/' ) ) ) {
return new Less_Tree_Color( $rgb[1] );
return new Less_Tree_Color( $rgb[1], 1, null, $rgb[0] );
}
}

Expand Down
9 changes: 7 additions & 2 deletions lib/Less/Tree/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ class Less_Tree_Color extends Less_Tree {
public $isTransparentKeyword;
public $value;

public function __construct( $rgb, $a = 1, $isTransparentKeyword = null ) {
public function __construct( $rgb, $a = 1, $isTransparentKeyword = null, $originalForm = null ) {
if ( $isTransparentKeyword ) {
$this->rgb = $rgb;
$this->alpha = $a;
$this->isTransparentKeyword = true;
return;
}
if ( isset( $originalForm ) ) {
$this->value = $originalForm;
}

$this->rgb = [];
if ( is_array( $rgb ) ) {
Expand Down Expand Up @@ -53,7 +56,9 @@ public function genCSS( $output ) {
public function toCSS( $doNotCompress = false ) {
$compress = Less_Parser::$options['compress'] && !$doNotCompress;
$alpha = Less_Functions::fround( $this->alpha );

if ( $this->value ) {
return $this->value;
}
//
// If we have some transparency, the only way to represent it
// is via `rgba`. Otherwise, we use the hex representation,
Expand Down
2 changes: 1 addition & 1 deletion test/Fixtures/bootstrap3-sourcemap/expected/bootstrap.map

Large diffs are not rendered by default.

Loading

0 comments on commit 79ae252

Please sign in to comment.