Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/86616
Change subject: lessphp: don't re-order or deduplicate comments
......................................................................
lessphp: don't re-order or deduplicate comments
Before I submit this upstream, I'd like to test this a bit more.
Once this is merged upstream, I'll update the patch to reference the current
commit in the file header, and we'll merge it then.
Bug: 54673
Change-Id: Ib6bc76736d460081dc8f48aee09ca32066dae296
---
M includes/libs/lessc.inc.php
1 file changed, 55 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/16/86616/1
diff --git a/includes/libs/lessc.inc.php b/includes/libs/lessc.inc.php
index 7b1c27b..99a1576 100644
--- a/includes/libs/lessc.inc.php
+++ b/includes/libs/lessc.inc.php
@@ -67,8 +67,9 @@
*/
class lessc {
static public $VERSION = "v0.4.0";
- static protected $TRUE = array("keyword", "true");
- static protected $FALSE = array("keyword", "false");
+
+ static public $TRUE = array("keyword", "true");
+ static public $FALSE = array("keyword", "false");
protected $libFunctions = array();
protected $registeredVars = array();
@@ -310,33 +311,68 @@
$this->compileProp($prop, $block, $out);
}
- $out->lines = array_values(array_unique($out->lines));
+ $out->lines = array_values($this->deduplicate($out->lines));
+ }
+
+ /**
+ * Deduplicate lines in a block. Comments are not deduplicated. If a
+ * duplicate rule is detected, the comments immediately preceding each
+ * occurence are consolidated.
+ */
+ protected function deduplicate($lines) {
+ $unique = array();
+ $comments = array();
+
+ foreach($lines as $line) {
+ if (strpos($line, '/*') === 0) {
+ $comments[] = $line;
+ continue;
+ }
+ if (!in_array($line, $unique)) {
+ $unique[] = $line;
+ }
+ array_splice($unique, array_search($line, $unique), 0,
$comments);
+ $comments = array();
+ }
+ return array_merge($unique, $comments);
}
protected function sortProps($props, $split = false) {
$vars = array();
$imports = array();
$other = array();
+ $stack = array();
foreach ($props as $prop) {
switch ($prop[0]) {
+ case "comment":
+ $stack[] = $prop;
+ break;
case "assign":
+ $stack[] = $prop;
if (isset($prop[1][0]) && $prop[1][0] ==
$this->vPrefix) {
- $vars[] = $prop;
+ $vars = array_merge($vars, $stack);
} else {
- $other[] = $prop;
+ $other = array_merge($other, $stack);
}
+ $stack = array();
break;
case "import":
$id = self::$nextImportId++;
$prop[] = $id;
- $imports[] = $prop;
+ $stack[] = $prop;
+ $imports = array_merge($imports, $stack);
$other[] = array("import_mixin", $id);
+ $stack = array();
break;
default:
- $other[] = $prop;
+ $stack[] = $prop;
+ $other = array_merge($other, $stack);
+ $stack = array();
+ break;
}
}
+ $other = array_merge($other, $stack);
if ($split) {
return array(array_merge($vars, $imports), $other);
@@ -1058,7 +1094,7 @@
* Helper function to get arguments for color manipulation functions.
* takes a list that contains a color like thing and a percentage
*/
- protected function colorArgs($args) {
+ public function colorArgs($args) {
if ($args[0] != 'list' || count($args[2]) < 2) {
return array(array('color', 0, 0, 0), 0);
}
@@ -1217,18 +1253,18 @@
return $lightColor;
}
- protected function assertColor($value, $error = "expected color value")
{
+ public function assertColor($value, $error = "expected color value") {
$color = $this->coerceColor($value);
if (is_null($color)) $this->throwError($error);
return $color;
}
- protected function assertNumber($value, $error = "expecting number") {
+ public function assertNumber($value, $error = "expecting number") {
if ($value[0] == "number") return $value[1];
$this->throwError($error);
}
- protected function assertArgs($value, $expectedArgs, $name="") {
+ public function assertArgs($value, $expectedArgs, $name="") {
if ($expectedArgs == 1) {
return $value;
} else {
@@ -1548,7 +1584,7 @@
return $value;
}
- protected function toBool($a) {
+ public function toBool($a) {
if ($a) return self::$TRUE;
else return self::$FALSE;
}
@@ -2031,7 +2067,7 @@
/**
* Uses the current value of $this->count to show line and line number
*/
- protected function throwError($msg = null) {
+ public function throwError($msg = null) {
if ($this->sourceLoc >= 0) {
$this->sourceParser->throwError($msg, $this->sourceLoc);
}
@@ -2350,6 +2386,10 @@
if (empty($this->buffer)) return false;
$s = $this->seek();
+ if ($this->whitespace()) {
+ return true;
+ }
+
// setting a property
if ($this->keyword($key) && $this->assign() &&
$this->propertyValue($value, $key) && $this->end())
@@ -2430,7 +2470,7 @@
}
// opening a simple block
- if ($this->tags($tags) && $this->literal('{')) {
+ if ($this->tags($tags) && $this->literal('{', false)) {
$tags = $this->fixTags($tags);
$this->pushBlock($tags);
return true;
@@ -3293,7 +3333,7 @@
// consume an end of statement delimiter
protected function end() {
- if ($this->literal(';')) {
+ if ($this->literal(';', false)) {
return true;
} elseif ($this->count == strlen($this->buffer) ||
$this->buffer[$this->count] == '}') {
// if there is end of file or a closing block next then
we don't need a ;
--
To view, visit https://gerrit.wikimedia.org/r/86616
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib6bc76736d460081dc8f48aee09ca32066dae296
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits