Skip to content

Commit 423f6c2

Browse files
committed
remember source parser for compile time error
1 parent cbdfbc6 commit 423f6c2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

scss.inc.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ protected function compileImport($rawPath, $out) {
506506
// return a value to halt execution
507507
protected function compileChild($child, $out) {
508508
$this->sourcePos = isset($child[-1]) ? $child[-1] : -1;
509+
$this->sourceParser = isset($child[-2]) ? $child[-2] : $this->parser;
509510

510511
switch ($child[0]) {
511512
case "import":
@@ -1430,7 +1431,7 @@ protected function importFile($path, $out) {
14301431
$tree = $this->importCache[$realPath];
14311432
} else {
14321433
$code = file_get_contents($path);
1433-
$parser = new scss_parser($path);
1434+
$parser = new scss_parser($path, false);
14341435
$tree = $parser->parse($code);
14351436
$this->parsedFiles[] = $path;
14361437

@@ -2262,8 +2263,8 @@ protected function throwError($msg = null) {
22622263
$msg = call_user_func_array("sprintf", func_get_args());
22632264
}
22642265

2265-
if ($this->sourcePos >= 0 && isset($this->parser)) {
2266-
$this->parser->throwParseError($msg, $this->sourcePos);
2266+
if ($this->sourcePos >= 0 && isset($this->sourceParser)) {
2267+
$this->sourceParser->throwParseError($msg, $this->sourcePos);
22672268
}
22682269

22692270
throw new Exception($msg);
@@ -2456,8 +2457,9 @@ class scss_parser {
24562457
static protected $commentMultiLeft = "/*";
24572458
static protected $commentMultiRight = "*/";
24582459

2459-
function __construct($sourceName = null) {
2460+
function __construct($sourceName = null, $rootParser = true) {
24602461
$this->sourceName = $sourceName;
2462+
$this->rootParser = $rootParser;
24612463

24622464
if (empty(self::$operatorStr)) {
24632465
self::$operatorStr = $this->makeOperatorStr(self::$operators);
@@ -2854,7 +2856,10 @@ protected function popBlock() {
28542856
}
28552857

28562858
protected function append($statement, $pos=null) {
2857-
if ($pos !== null) $statement[-1] = $pos;
2859+
if ($pos !== null) {
2860+
$statement[-1] = $pos;
2861+
if (!$this->rootParser) $statement[-2] = $this;
2862+
}
28582863
$this->env->children[] = $statement;
28592864
}
28602865

0 commit comments

Comments
 (0)