Skip to content

Commit 23c04c0

Browse files
author
Alexander Bachmann
committed
add to resolve scoped imports with scssphp
1 parent fb28b01 commit 23c04c0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Compiler.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ class Compiler
6666
*/
6767
protected $styleBuilder;
6868

69+
/**
70+
* @var string|null
71+
*/
72+
protected $stylePath = null;
73+
6974
/**
7075
* @var NodeHelper
7176
*/
@@ -133,6 +138,7 @@ public function __construct(DOMDocument $document, LoggerInterface $logger)
133138
{
134139
$this->builder = new TwigBuilder();
135140
$this->styleBuilder = new StyleBuilder();
141+
$this->stylePath = null;
136142
$this->nodeHelper = new NodeHelper();
137143
$this->document = $document;
138144
$this->logger = $logger;
@@ -159,6 +165,14 @@ public function setBanner($strings): void
159165
$this->banner = $strings;
160166
}
161167

168+
/**
169+
* @param string $path
170+
*/
171+
public function setStylePath(string $path): void
172+
{
173+
$this->stylePath = $path;
174+
}
175+
162176
/**
163177
* @throws ReflectionException
164178
* @throws Exception
@@ -216,7 +230,7 @@ public function convert(): string
216230
}
217231
foreach ($styleBlocks as $styleBlock) {
218232
/* @var DOMElement $styleBlock */
219-
$this->rawBlocks[] = $this->styleBuilder->compile($styleBlock);
233+
$this->rawBlocks[] = $this->styleBuilder->compile($styleBlock, $this->stylePath);
220234
}
221235
}
222236

src/Utils/StyleBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function setScssData(string $data): void
7070
$this->scssData = $data;
7171
}
7272

73-
public function compile(?DOMElement $styleElement): ?string
73+
public function compile(?DOMElement $styleElement, $path = null): ?string
7474
{
7575
if (!$styleElement instanceof DOMElement
7676
|| ($styleElement->hasAttribute('scoped') && !($this->outputType & self::STYLE_SCOPED))
@@ -85,7 +85,7 @@ public function compile(?DOMElement $styleElement): ?string
8585
$this->scssCompiler = new ScssCompiler();
8686
}
8787
try {
88-
$style = $this->scssCompiler->compile($this->scssData . ' ' . $style);
88+
$style = $this->scssCompiler->compile($this->scssData . ' ' . $style, $path);
8989
} catch (CompilerException $e) {
9090
$style = "\n/* Warning: " . $e->getMessage() . " */\n";
9191
}

0 commit comments

Comments
 (0)