mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-65761 lib: Update scssphp to 0.8.3
This commit is contained in:
parent
f7e108438f
commit
358d571156
@ -62,4 +62,9 @@ class Block
|
||||
* @var array
|
||||
*/
|
||||
public $children;
|
||||
|
||||
/**
|
||||
* @var \Leafo\ScssPhp\Block
|
||||
*/
|
||||
public $selfParent;
|
||||
}
|
||||
|
239
lib/scssphp/Cache.php
Normal file
239
lib/scssphp/Cache.php
Normal file
@ -0,0 +1,239 @@
|
||||
<?php
|
||||
/**
|
||||
* SCSSPHP
|
||||
*
|
||||
* @copyright 2012-2018 Leaf Corcoran
|
||||
*
|
||||
* @license http://opensource.org/licenses/MIT MIT
|
||||
*
|
||||
* @link http://leafo.github.io/scssphp
|
||||
*/
|
||||
|
||||
namespace Leafo\ScssPhp;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* The scss cache manager.
|
||||
*
|
||||
* In short:
|
||||
*
|
||||
* allow to put in cache/get from cache a generic result from a known operation on a generic dataset,
|
||||
* taking in account options that affects the result
|
||||
*
|
||||
* The cache manager is agnostic about data format and only the operation is expected to be described by string
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* SCSS cache
|
||||
*
|
||||
* @author Cedric Morin
|
||||
*/
|
||||
class Cache
|
||||
{
|
||||
const CACHE_VERSION = 0;
|
||||
|
||||
// directory used for storing data
|
||||
public static $cacheDir = false;
|
||||
|
||||
// prefix for the storing data
|
||||
public static $prefix = 'scssphp_';
|
||||
|
||||
// force a refresh : 'once' for refreshing the first hit on a cache only, true to never use the cache in this hit
|
||||
public static $forceFefresh = false;
|
||||
|
||||
// specifies the number of seconds after which data cached will be seen as 'garbage' and potentially cleaned up
|
||||
public static $gcLifetime = 604800;
|
||||
|
||||
// array of already refreshed cache if $forceFefresh==='once'
|
||||
protected static $refreshed = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
// check $cacheDir
|
||||
if (isset($options['cache_dir'])) {
|
||||
self::$cacheDir = $options['cache_dir'];
|
||||
}
|
||||
|
||||
if (empty(self::$cacheDir)) {
|
||||
throw new Exception('cache_dir not set');
|
||||
}
|
||||
|
||||
if (isset($options['prefix'])) {
|
||||
self::$prefix = $options['prefix'];
|
||||
}
|
||||
|
||||
if (empty(self::$prefix)) {
|
||||
throw new Exception('prefix not set');
|
||||
}
|
||||
|
||||
if (isset($options['forceRefresh'])) {
|
||||
self::$forceFefresh = $options['force_refresh'];
|
||||
}
|
||||
|
||||
self::checkCacheDir();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cached result of $operation on $what,
|
||||
* which is known as dependant from the content of $options
|
||||
*
|
||||
* @param string $operation parse, compile...
|
||||
* @param mixed $what content key (e.g., filename to be treated)
|
||||
* @param array $options any option that affect the operation result on the content
|
||||
* @param integer $lastModified last modified timestamp
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getCache($operation, $what, $options = [], $lastModified = null)
|
||||
{
|
||||
$fileCache = self::$cacheDir . self::cacheName($operation, $what, $options);
|
||||
|
||||
if ((! self::$forceRefresh || (self::$forceRefresh === 'once' && isset(self::$refreshed[$fileCache])))
|
||||
&& file_exists($fileCache)
|
||||
) {
|
||||
$cacheTime = filemtime($fileCache);
|
||||
|
||||
if ((is_null($lastModified) || $cacheTime > $lastModified)
|
||||
&& $cacheTime + self::$gcLifetime > time()
|
||||
) {
|
||||
$c = file_get_contents($fileCache);
|
||||
$c = unserialize($c);
|
||||
|
||||
if (is_array($c) && isset($c['value'])) {
|
||||
return $c['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in cache the result of $operation on $what,
|
||||
* which is known as dependant from the content of $options
|
||||
*
|
||||
* @param string $operation
|
||||
* @param mixed $what
|
||||
* @param mixed $value
|
||||
* @param array $options
|
||||
*/
|
||||
public function setCache($operation, $what, $value, $options = [])
|
||||
{
|
||||
$fileCache = self::$cacheDir . self::cacheName($operation, $what, $options);
|
||||
|
||||
$c = ['value' => $value];
|
||||
$c = serialize($c);
|
||||
file_put_contents($fileCache, $c);
|
||||
|
||||
if (self::$forceRefresh === 'once') {
|
||||
self::$refreshed[$fileCache] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache name for the caching of $operation on $what,
|
||||
* which is known as dependant from the content of $options
|
||||
*
|
||||
* @param string $operation
|
||||
* @param mixed $what
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function cacheName($operation, $what, $options = [])
|
||||
{
|
||||
$t = [
|
||||
'version' => self::CACHE_VERSION,
|
||||
'operation' => $operation,
|
||||
'what' => $what,
|
||||
'options' => $options
|
||||
];
|
||||
|
||||
$t = self::$prefix
|
||||
. sha1(json_encode($t))
|
||||
. ".$operation"
|
||||
. ".scsscache";
|
||||
|
||||
return $t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the cache dir exists and is writeable
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function checkCacheDir()
|
||||
{
|
||||
self::$cacheDir = str_replace('\\', '/', self::$cacheDir);
|
||||
self::$cacheDir = rtrim(self::$cacheDir, '/') . '/';
|
||||
|
||||
if (! file_exists(self::$cacheDir)) {
|
||||
if (! mkdir(self::$cacheDir)) {
|
||||
throw new Exception('Cache directory couldn\'t be created: ' . self::$cacheDir);
|
||||
}
|
||||
} elseif (! is_dir(self::$cacheDir)) {
|
||||
throw new Exception('Cache directory doesn\'t exist: ' . self::$cacheDir);
|
||||
} elseif (! is_writable(self::$cacheDir)) {
|
||||
throw new Exception('Cache directory isn\'t writable: ' . self::$cacheDir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete unused cached files
|
||||
*/
|
||||
public static function cleanCache()
|
||||
{
|
||||
static $clean = false;
|
||||
|
||||
if ($clean || empty(self::$cacheDir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$clean = true;
|
||||
|
||||
// only remove files with extensions created by SCSSPHP Cache
|
||||
// css files removed based on the list files
|
||||
$removeTypes = ['scsscache' => 1];
|
||||
|
||||
$files = scandir(self::$cacheDir);
|
||||
|
||||
if (! $files) {
|
||||
return;
|
||||
}
|
||||
|
||||
$checkTime = time() - self::$gcLifetime;
|
||||
|
||||
foreach ($files as $file) {
|
||||
// don't delete if the file wasn't created with SCSSPHP Cache
|
||||
if (strpos($file, self::$prefix) !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$parts = explode('.', $file);
|
||||
$type = array_pop($parts);
|
||||
|
||||
if (! isset($removeTypes[$type])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fullPath = self::$cacheDir . $file;
|
||||
$mtime = filemtime($fullPath);
|
||||
|
||||
// don't delete if it's a relatively new file
|
||||
if ($mtime > $checkTime) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unlink($fullPath);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -33,6 +33,11 @@ class Environment
|
||||
*/
|
||||
public $store;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $storeUnreduced;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
|
@ -256,7 +256,8 @@ abstract class Formatter
|
||||
$this->currentLine,
|
||||
$this->currentColumn,
|
||||
$this->currentBlock->sourceLine,
|
||||
$this->currentBlock->sourceColumn - 1, //columns from parser are off by one
|
||||
//columns from parser are off by one
|
||||
$this->currentBlock->sourceColumn > 0 ? $this->currentBlock->sourceColumn - 1 : 0,
|
||||
$this->currentBlock->sourceName
|
||||
);
|
||||
|
||||
|
@ -59,4 +59,23 @@ class Compressed extends Formatter
|
||||
$this->write($this->break);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output block selectors
|
||||
*
|
||||
* @param \Leafo\ScssPhp\Formatter\OutputBlock $block
|
||||
*/
|
||||
protected function blockSelectors(OutputBlock $block)
|
||||
{
|
||||
$inner = $this->indentStr();
|
||||
|
||||
$this->write(
|
||||
$inner
|
||||
. implode(
|
||||
$this->tagSeparator,
|
||||
str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
|
||||
)
|
||||
. $this->open . $this->break
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -57,4 +57,23 @@ class Crunched extends Formatter
|
||||
$this->write($this->break);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output block selectors
|
||||
*
|
||||
* @param \Leafo\ScssPhp\Formatter\OutputBlock $block
|
||||
*/
|
||||
protected function blockSelectors(OutputBlock $block)
|
||||
{
|
||||
$inner = $this->indentStr();
|
||||
|
||||
$this->write(
|
||||
$inner
|
||||
. implode(
|
||||
$this->tagSeparator,
|
||||
str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
|
||||
)
|
||||
. $this->open . $this->break
|
||||
);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
184
lib/scssphp/SourceMap/Base64.php
Normal file
184
lib/scssphp/SourceMap/Base64.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* SCSSPHP
|
||||
*
|
||||
* @copyright 2012-2015 Leaf Corcoran
|
||||
*
|
||||
* @license http://opensource.org/licenses/MIT MIT
|
||||
*
|
||||
* @link http://leafo.github.io/scssphp
|
||||
*/
|
||||
|
||||
namespace Leafo\ScssPhp\SourceMap;
|
||||
|
||||
/**
|
||||
* Base 64 Encode/Decode
|
||||
*
|
||||
* @author Anthon Pang <anthon.pang@gmail.com>
|
||||
*/
|
||||
class Base64
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $encodingMap = [
|
||||
0 => 'A',
|
||||
1 => 'B',
|
||||
2 => 'C',
|
||||
3 => 'D',
|
||||
4 => 'E',
|
||||
5 => 'F',
|
||||
6 => 'G',
|
||||
7 => 'H',
|
||||
8 => 'I',
|
||||
9 => 'J',
|
||||
10 => 'K',
|
||||
11 => 'L',
|
||||
12 => 'M',
|
||||
13 => 'N',
|
||||
14 => 'O',
|
||||
15 => 'P',
|
||||
16 => 'Q',
|
||||
17 => 'R',
|
||||
18 => 'S',
|
||||
19 => 'T',
|
||||
20 => 'U',
|
||||
21 => 'V',
|
||||
22 => 'W',
|
||||
23 => 'X',
|
||||
24 => 'Y',
|
||||
25 => 'Z',
|
||||
26 => 'a',
|
||||
27 => 'b',
|
||||
28 => 'c',
|
||||
29 => 'd',
|
||||
30 => 'e',
|
||||
31 => 'f',
|
||||
32 => 'g',
|
||||
33 => 'h',
|
||||
34 => 'i',
|
||||
35 => 'j',
|
||||
36 => 'k',
|
||||
37 => 'l',
|
||||
38 => 'm',
|
||||
39 => 'n',
|
||||
40 => 'o',
|
||||
41 => 'p',
|
||||
42 => 'q',
|
||||
43 => 'r',
|
||||
44 => 's',
|
||||
45 => 't',
|
||||
46 => 'u',
|
||||
47 => 'v',
|
||||
48 => 'w',
|
||||
49 => 'x',
|
||||
50 => 'y',
|
||||
51 => 'z',
|
||||
52 => '0',
|
||||
53 => '1',
|
||||
54 => '2',
|
||||
55 => '3',
|
||||
56 => '4',
|
||||
57 => '5',
|
||||
58 => '6',
|
||||
59 => '7',
|
||||
60 => '8',
|
||||
61 => '9',
|
||||
62 => '+',
|
||||
63 => '/',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $decodingMap = [
|
||||
'A' => 0,
|
||||
'B' => 1,
|
||||
'C' => 2,
|
||||
'D' => 3,
|
||||
'E' => 4,
|
||||
'F' => 5,
|
||||
'G' => 6,
|
||||
'H' => 7,
|
||||
'I' => 8,
|
||||
'J' => 9,
|
||||
'K' => 10,
|
||||
'L' => 11,
|
||||
'M' => 12,
|
||||
'N' => 13,
|
||||
'O' => 14,
|
||||
'P' => 15,
|
||||
'Q' => 16,
|
||||
'R' => 17,
|
||||
'S' => 18,
|
||||
'T' => 19,
|
||||
'U' => 20,
|
||||
'V' => 21,
|
||||
'W' => 22,
|
||||
'X' => 23,
|
||||
'Y' => 24,
|
||||
'Z' => 25,
|
||||
'a' => 26,
|
||||
'b' => 27,
|
||||
'c' => 28,
|
||||
'd' => 29,
|
||||
'e' => 30,
|
||||
'f' => 31,
|
||||
'g' => 32,
|
||||
'h' => 33,
|
||||
'i' => 34,
|
||||
'j' => 35,
|
||||
'k' => 36,
|
||||
'l' => 37,
|
||||
'm' => 38,
|
||||
'n' => 39,
|
||||
'o' => 40,
|
||||
'p' => 41,
|
||||
'q' => 42,
|
||||
'r' => 43,
|
||||
's' => 44,
|
||||
't' => 45,
|
||||
'u' => 46,
|
||||
'v' => 47,
|
||||
'w' => 48,
|
||||
'x' => 49,
|
||||
'y' => 50,
|
||||
'z' => 51,
|
||||
0 => 52,
|
||||
1 => 53,
|
||||
2 => 54,
|
||||
3 => 55,
|
||||
4 => 56,
|
||||
5 => 57,
|
||||
6 => 58,
|
||||
7 => 59,
|
||||
8 => 60,
|
||||
9 => 61,
|
||||
'+' => 62,
|
||||
'/' => 63,
|
||||
];
|
||||
|
||||
/**
|
||||
* Convert to base64
|
||||
*
|
||||
* @param integer $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode($value)
|
||||
{
|
||||
return self::$encodingMap[$value];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from base64
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function decode($value)
|
||||
{
|
||||
return self::$decodingMap[$value];
|
||||
}
|
||||
}
|
137
lib/scssphp/SourceMap/Base64VLQ.php
Normal file
137
lib/scssphp/SourceMap/Base64VLQ.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* SCSSPHP
|
||||
*
|
||||
* @copyright 2012-2015 Leaf Corcoran
|
||||
*
|
||||
* @license http://opensource.org/licenses/MIT MIT
|
||||
*
|
||||
* @link http://leafo.github.io/scssphp
|
||||
*/
|
||||
|
||||
namespace Leafo\ScssPhp\SourceMap;
|
||||
|
||||
use Leafo\ScssPhp\SourceMap\Base64;
|
||||
|
||||
/**
|
||||
* Base 64 VLQ
|
||||
*
|
||||
* Based on the Base 64 VLQ implementation in Closure Compiler:
|
||||
* https://github.com/google/closure-compiler/blob/master/src/com/google/debugging/sourcemap/Base64VLQ.java
|
||||
*
|
||||
* Copyright 2011 The Closure Compiler Authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @author John Lenz <johnlenz@google.com>
|
||||
* @author Anthon Pang <anthon.pang@gmail.com>
|
||||
*/
|
||||
class Base64VLQ
|
||||
{
|
||||
// A Base64 VLQ digit can represent 5 bits, so it is base-32.
|
||||
const VLQ_BASE_SHIFT = 5;
|
||||
|
||||
// A mask of bits for a VLQ digit (11111), 31 decimal.
|
||||
const VLQ_BASE_MASK = 31;
|
||||
|
||||
// The continuation bit is the 6th bit.
|
||||
const VLQ_CONTINUATION_BIT = 32;
|
||||
|
||||
/**
|
||||
* Returns the VLQ encoded value.
|
||||
*
|
||||
* @param integer $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode($value)
|
||||
{
|
||||
$encoded = '';
|
||||
$vlq = self::toVLQSigned($value);
|
||||
|
||||
do {
|
||||
$digit = $vlq & self::VLQ_BASE_MASK;
|
||||
$vlq >>= self::VLQ_BASE_SHIFT;
|
||||
|
||||
if ($vlq > 0) {
|
||||
$digit |= self::VLQ_CONTINUATION_BIT;
|
||||
}
|
||||
|
||||
$encoded .= Base64::encode($digit);
|
||||
} while ($vlq > 0);
|
||||
|
||||
return $encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes VLQValue.
|
||||
*
|
||||
* @param string $str
|
||||
* @param integer $index
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function decode($str, &$index)
|
||||
{
|
||||
$result = 0;
|
||||
$shift = 0;
|
||||
|
||||
do {
|
||||
$c = $str[$index++];
|
||||
$digit = Base64::decode($c);
|
||||
$continuation = ($digit & self::VLQ_CONTINUATION_BIT) != 0;
|
||||
$digit &= self::VLQ_BASE_MASK;
|
||||
$result = $result + ($digit << $shift);
|
||||
$shift = $shift + self::VLQ_BASE_SHIFT;
|
||||
} while ($continuation);
|
||||
|
||||
return self::fromVLQSigned($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from a two-complement value to a value where the sign bit is
|
||||
* is placed in the least significant bit. For example, as decimals:
|
||||
* 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
|
||||
* 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
|
||||
*
|
||||
* @param integer $value
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
private static function toVLQSigned($value)
|
||||
{
|
||||
if ($value < 0) {
|
||||
return ((-$value) << 1) + 1;
|
||||
}
|
||||
|
||||
return ($value << 1) + 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to a two-complement value from a value where the sign bit is
|
||||
* is placed in the least significant bit. For example, as decimals:
|
||||
* 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
|
||||
* 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
|
||||
*
|
||||
* @param integer $value
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
private static function fromVLQSigned($value)
|
||||
{
|
||||
$negate = ($value & 1) === 1;
|
||||
$value = $value >> 1;
|
||||
|
||||
return $negate ? -$value : $value;
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@ class Base64VLQEncoder
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $charToIntMap = array(
|
||||
private $charToIntMap = [
|
||||
'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7,
|
||||
'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15,
|
||||
'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23,
|
||||
@ -56,14 +56,14 @@ class Base64VLQEncoder
|
||||
'o' => 40, 'p' => 41, 'q' => 42, 'r' => 43, 's' => 44, 't' => 45, 'u' => 46, 'v' => 47,
|
||||
'w' => 48, 'x' => 49, 'y' => 50, 'z' => 51, 0 => 52, 1 => 53, 2 => 54, 3 => 55,
|
||||
4 => 56, 5 => 57, 6 => 58, 7 => 59, 8 => 60, 9 => 61, '+' => 62, '/' => 63,
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Integer to char map
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $intToCharMap = array(
|
||||
private $intToCharMap = [
|
||||
0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H',
|
||||
8 => 'I', 9 => 'J', 10 => 'K', 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P',
|
||||
16 => 'Q', 17 => 'R', 18 => 'S', 19 => 'T', 20 => 'U', 21 => 'V', 22 => 'W', 23 => 'X',
|
||||
@ -72,7 +72,7 @@ class Base64VLQEncoder
|
||||
40 => 'o', 41 => 'p', 42 => 'q', 43 => 'r', 44 => 's', 45 => 't', 46 => 'u', 47 => 'v',
|
||||
48 => 'w', 49 => 'x', 50 => 'y', 51 => 'z', 52 => '0', 53 => '1', 54 => '2', 55 => '3',
|
||||
56 => '4', 57 => '5', 58 => '6', 59 => '7', 60 => '8', 61 => '9', 62 => '+', 63 => '/',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -33,7 +33,7 @@ class SourceMapGenerator
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
protected $defaultOptions = [
|
||||
// an optional source root, useful for relocating source files
|
||||
// on a server or removing repeated values in the 'sources' entry.
|
||||
// This value is prepended to the individual entries in the 'source' field.
|
||||
@ -56,12 +56,12 @@ class SourceMapGenerator
|
||||
|
||||
// base path for filename normalization
|
||||
'sourceMapBasepath' => ''
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* The base64 VLQ encoder
|
||||
*
|
||||
* @var \Leafo\ScssPhp\SourceMap\Base64VLQEncoder
|
||||
* @var \Leafo\ScssPhp\SourceMap\Base64VLQ
|
||||
*/
|
||||
protected $encoder;
|
||||
|
||||
@ -70,22 +70,22 @@ class SourceMapGenerator
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $mappings = array();
|
||||
protected $mappings = [];
|
||||
|
||||
/**
|
||||
* Array of contents map
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $contentsMap = array();
|
||||
protected $contentsMap = [];
|
||||
|
||||
/**
|
||||
* File to content map
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $sources = array();
|
||||
protected $source_keys = array();
|
||||
protected $sources = [];
|
||||
protected $sourceKeys = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
@ -95,7 +95,7 @@ class SourceMapGenerator
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$this->options = array_merge($this->defaultOptions, $options);
|
||||
$this->encoder = new Base64VLQEncoder();
|
||||
$this->encoder = new Base64VLQ();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,13 +109,13 @@ class SourceMapGenerator
|
||||
*/
|
||||
public function addMapping($generatedLine, $generatedColumn, $originalLine, $originalColumn, $sourceFile)
|
||||
{
|
||||
$this->mappings[] = array(
|
||||
'generated_line' => $generatedLine,
|
||||
$this->mappings[] = [
|
||||
'generated_line' => $generatedLine,
|
||||
'generated_column' => $generatedColumn,
|
||||
'original_line' => $originalLine,
|
||||
'original_column' => $originalColumn,
|
||||
'source_file' => $sourceFile
|
||||
);
|
||||
'original_line' => $originalLine,
|
||||
'original_column' => $originalColumn,
|
||||
'source_file' => $sourceFile
|
||||
];
|
||||
|
||||
$this->sources[$sourceFile] = $sourceFile;
|
||||
}
|
||||
@ -123,9 +123,10 @@ class SourceMapGenerator
|
||||
/**
|
||||
* Saves the source map to a file
|
||||
*
|
||||
* @param string $file The absolute path to a file
|
||||
* @param string $content The content to write
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \Leafo\ScssPhp\Exception\CompilerException If the file could not be saved
|
||||
*/
|
||||
public function saveMap($content)
|
||||
@ -136,7 +137,9 @@ class SourceMapGenerator
|
||||
// directory does not exist
|
||||
if (! is_dir($dir)) {
|
||||
// FIXME: create the dir automatically?
|
||||
throw new CompilerException(sprintf('The directory "%s" does not exist. Cannot save the source map.', $dir));
|
||||
throw new CompilerException(
|
||||
sprintf('The directory "%s" does not exist. Cannot save the source map.', $dir)
|
||||
);
|
||||
}
|
||||
|
||||
// FIXME: proper saving, with dir write check!
|
||||
@ -156,7 +159,7 @@ class SourceMapGenerator
|
||||
*/
|
||||
public function generateJson()
|
||||
{
|
||||
$sourceMap = array();
|
||||
$sourceMap = [];
|
||||
$mappings = $this->generateMappings();
|
||||
|
||||
// File version (always the first entry in the object) and must be a positive integer.
|
||||
@ -178,14 +181,14 @@ class SourceMapGenerator
|
||||
}
|
||||
|
||||
// A list of original sources used by the 'mappings' entry.
|
||||
$sourceMap['sources'] = array();
|
||||
$sourceMap['sources'] = [];
|
||||
|
||||
foreach ($this->sources as $source_uri => $source_filename) {
|
||||
$sourceMap['sources'][] = $this->normalizeFilename($source_filename);
|
||||
foreach ($this->sources as $sourceUri => $sourceFilename) {
|
||||
$sourceMap['sources'][] = $this->normalizeFilename($sourceFilename);
|
||||
}
|
||||
|
||||
// A list of symbol names used by the 'mappings' entry.
|
||||
$sourceMap['names'] = array();
|
||||
$sourceMap['names'] = [];
|
||||
|
||||
// A string with the encoded mapping data.
|
||||
$sourceMap['mappings'] = $mappings;
|
||||
@ -202,7 +205,7 @@ class SourceMapGenerator
|
||||
unset($sourceMap['sourceRoot']);
|
||||
}
|
||||
|
||||
return json_encode($sourceMap);
|
||||
return json_encode($sourceMap, JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,7 +219,7 @@ class SourceMapGenerator
|
||||
return null;
|
||||
}
|
||||
|
||||
$content = array();
|
||||
$content = [];
|
||||
|
||||
foreach ($this->sources as $sourceFile) {
|
||||
$content[] = file_get_contents($sourceFile);
|
||||
@ -236,10 +239,10 @@ class SourceMapGenerator
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->source_keys = array_flip(array_keys($this->sources));
|
||||
$this->sourceKeys = array_flip(array_keys($this->sources));
|
||||
|
||||
// group mappings by generated line number.
|
||||
$groupedMap = $groupedMapEncoded = array();
|
||||
$groupedMap = $groupedMapEncoded = [];
|
||||
|
||||
foreach ($this->mappings as $m) {
|
||||
$groupedMap[$m['generated_line']][] = $m;
|
||||
@ -248,15 +251,15 @@ class SourceMapGenerator
|
||||
ksort($groupedMap);
|
||||
$lastGeneratedLine = $lastOriginalIndex = $lastOriginalLine = $lastOriginalColumn = 0;
|
||||
|
||||
foreach ($groupedMap as $lineNumber => $line_map) {
|
||||
foreach ($groupedMap as $lineNumber => $lineMap) {
|
||||
while (++$lastGeneratedLine < $lineNumber) {
|
||||
$groupedMapEncoded[] = ';';
|
||||
}
|
||||
|
||||
$lineMapEncoded = array();
|
||||
$lineMapEncoded = [];
|
||||
$lastGeneratedColumn = 0;
|
||||
|
||||
foreach ($line_map as $m) {
|
||||
foreach ($lineMap as $m) {
|
||||
$mapEncoded = $this->encoder->encode($m['generated_column'] - $lastGeneratedColumn);
|
||||
$lastGeneratedColumn = $m['generated_column'];
|
||||
|
||||
@ -293,9 +296,16 @@ class SourceMapGenerator
|
||||
*/
|
||||
protected function findFileIndex($filename)
|
||||
{
|
||||
return $this->source_keys[$filename];
|
||||
return $this->sourceKeys[$filename];
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize filename
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function normalizeFilename($filename)
|
||||
{
|
||||
$filename = $this->fixWindowsPath($filename);
|
||||
@ -303,7 +313,7 @@ class SourceMapGenerator
|
||||
$basePath = $this->options['sourceMapBasepath'];
|
||||
|
||||
// "Trim" the 'sourceMapBasepath' from the output filename.
|
||||
if (strpos($filename, $basePath) === 0) {
|
||||
if (strlen($basePath) && strpos($filename, $basePath) === 0) {
|
||||
$filename = substr($filename, strlen($basePath));
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ class Util
|
||||
*/
|
||||
public static function encodeURIComponent($string)
|
||||
{
|
||||
$revert = array('%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')');
|
||||
$revert = ['%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')'];
|
||||
|
||||
return strtr(rawurlencode($string), $revert);
|
||||
}
|
||||
|
@ -18,5 +18,5 @@ namespace Leafo\ScssPhp;
|
||||
*/
|
||||
class Version
|
||||
{
|
||||
const VERSION = 'v0.7.5';
|
||||
const VERSION = 'v0.8.3';
|
||||
}
|
||||
|
@ -222,7 +222,7 @@
|
||||
<location>scssphp</location>
|
||||
<name>scssphp</name>
|
||||
<license>MIT</license>
|
||||
<version>0.7.5</version>
|
||||
<version>0.8.3</version>
|
||||
</library>
|
||||
<library>
|
||||
<location>spout</location>
|
||||
|
Loading…
x
Reference in New Issue
Block a user