4 * Parser output with source map
9 class Less_Output_Mapped
extends Less_Output
{
12 * The source map generator
14 * @var Less_SourceMap_Generator
23 protected $lineNumber = 0;
30 protected $column = 0;
33 * Array of contents map (file and its content)
37 protected $contentsMap = array();
42 * @param array $contentsMap Array of filename to contents map
43 * @param Less_SourceMap_Generator $generator
45 public function __construct(array $contentsMap, $generator){
46 $this->contentsMap
= $contentsMap;
47 $this->generator
= $generator;
51 * Adds a chunk to the stack
52 * The $index for less.php may be different from less.js since less.php does not chunkify inputs
54 * @param string $chunk
55 * @param string $fileInfo
56 * @param integer $index
57 * @param mixed $mapLines
59 public function add($chunk, $fileInfo = null, $index = 0, $mapLines = null){
61 //ignore adding empty strings
67 $sourceLines = array();
73 $url = $fileInfo['currentUri'];
75 if( isset($this->contentsMap
[$url]) ){
76 $inputSource = substr($this->contentsMap
[$url], 0, $index);
77 $sourceLines = explode("\n", $inputSource);
78 $sourceColumns = end($sourceLines);
80 throw new Exception('Filename '.$url.' not in contentsMap');
85 $lines = explode("\n", $chunk);
86 $columns = end($lines);
91 $this->generator
->addMapping(
92 $this->lineNumber +
1, // generated_line
93 $this->column
, // generated_column
94 count($sourceLines), // original_line
95 strlen($sourceColumns), // original_column
99 for($i = 0, $count = count($lines); $i < $count; $i++
){
100 $this->generator
->addMapping(
101 $this->lineNumber +
$i +
1, // generated_line
102 $i === 0 ?
$this->column
: 0, // generated_column
103 count($sourceLines) +
$i, // original_line
104 $i === 0 ?
strlen($sourceColumns) : 0, // original_column
111 if(count($lines) === 1){
112 $this->column +
= strlen($columns);
114 $this->lineNumber +
= count($lines) - 1;
115 $this->column
= strlen($columns);