Skip to content

Commit 6c8e0f3

Browse files
authored
Merge pull request #74 from tronsha/bugfix/#73
Fixed #73 add error handling for scss compiler
2 parents 835ea0b + 77b3a9a commit 6c8e0f3

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/Utils/StyleBuilder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DOMElement;
88
use Exception;
99
use ScssPhp\ScssPhp\Compiler as ScssCompiler;
10+
use ScssPhp\ScssPhp\Exception\CompilerException;
1011

1112
class StyleBuilder
1213
{
@@ -83,7 +84,11 @@ public function compile(?DOMElement $styleElement): ?string
8384
if ($this->scssCompiler === null) {
8485
$this->scssCompiler = new ScssCompiler();
8586
}
86-
$style = $this->scssCompiler->compile($this->scssData . ' ' . $style);
87+
try {
88+
$style = $this->scssCompiler->compile($this->scssData . ' ' . $style);
89+
} catch (CompilerException $e) {
90+
$style = "\n/* Warning: " . $e->getMessage() . " */\n";
91+
}
8792
}
8893

8994
if ($styleElement->hasAttribute('scoped')) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<style>/* Warning: `./file` file not found for @import: line: 2, column: 1 */</style>
2+
<div class="{{ class|default('') }}" style="{{ style|default('') }}">
3+
<div class="foo">
4+
foo
5+
</div>
6+
</div>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<div>
3+
<div class="foo">
4+
foo
5+
</div>
6+
</div>
7+
</template>
8+
9+
<style lang="scss">
10+
@import "./file";
11+
12+
.foo {
13+
color: red;
14+
&__bar {
15+
color: blue;
16+
}
17+
&__baz {
18+
color: $color;
19+
}
20+
}
21+
</style>
22+
23+
<script>
24+
export default {
25+
}
26+
</script>

0 commit comments

Comments
 (0)