Skip to content

Commit d252b24

Browse files
committed
Fix style block support
1 parent 417f7d6 commit d252b24

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

src/Compiler.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ public function convert(): string
190190
}
191191

192192
$html = $this->addVariableBlocks($html);
193-
$html = $this->replaceScopedPlaceholders($html);
194193
$html = $this->replacePlaceholders($html);
194+
$html = $this->replaceScopedPlaceholders($html);
195195

196196
$html = preg_replace('/<template>\s*(.*)\s*<\/template>/ism', '$1', $html);
197197
$html = preg_replace('/<\/?template[^>]*?>/i', '', $html);
@@ -367,15 +367,15 @@ private function preparePropertiesForInclude(array $variables): array
367367
} elseif (strpos($name, 'dataV') === 0 && strlen($name) === 37) {
368368
unset($variables[$key]);
369369
$variables[] = new Property(
370-
'scoped',
370+
'dataScopedStyleAttribute',
371371
'"data-v-' . strtolower(substr($name, 5)) . '"',
372372
false
373373
);
374-
} elseif ($name === '__SCOPED_DEFAULT__') {
374+
} elseif ($name === '__DATA_SCOPED_STYLE_ATTRIBUTE__') {
375375
unset($variables[$key]);
376376
$variables[] = new Property(
377-
'scoped',
378-
'scoped|default(\'\')',
377+
'dataScopedStyleAttribute',
378+
'dataScopedStyleAttribute|default(\'\')',
379379
false
380380
);
381381
}
@@ -1252,13 +1252,13 @@ private function addScopedAttribute(DOMElement $node, int $level): void
12521252
}
12531253

12541254
if ($this->styleBuilder->getOutputType() & StyleBuilder::STYLE_SCOPED) {
1255-
$node->setAttributeNode(new DOMAttr('__SCOPED_DEFAULT__', ''));
1255+
$node->setAttributeNode(new DOMAttr('__DATA_SCOPED_STYLE_ATTRIBUTE__', ''));
12561256
}
12571257
}
12581258

12591259
private function replaceScopedPlaceholders(string $html): string
12601260
{
1261-
$html = str_replace('__SCOPED_DEFAULT__=""', '{{ scoped|default(\'\') }}', $html);
1261+
$html = str_replace('__DATA_SCOPED_STYLE_ATTRIBUTE__=""', '{{ dataScopedStyleAttribute|default(\'\') }}', $html);
12621262
$html = preg_replace('/(data-v-[0-9a-f]{32})=""/', '$1', $html);
12631263

12641264
return $html;

tests/fixtures/style-block-scoped/style-block-scoped-with-child-binding.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
color: red;
44
}
55
</style>
6-
<div class="root {{ class|default('') }}" data-v-a2116698cabca27b45a4db453446b8d2 {{ scoped|default('') }} style="{{ style|default('') }}">
6+
<div class="root {{ class|default('') }}" data-v-a2116698cabca27b45a4db453446b8d2 {{ dataScopedStyleAttribute|default('') }} style="{{ style|default('') }}">
77
<div class="foo" data-v-a2116698cabca27b45a4db453446b8d2>
8-
{% include "/templates/ChildComponent.twig" with { 'scoped': "data-v-a2116698cabca27b45a4db453446b8d2", 'class': "", 'style': "" } %}
8+
{% include "/templates/ChildComponent.twig" with { 'dataScopedStyleAttribute': "data-v-a2116698cabca27b45a4db453446b8d2", 'class': "", 'style': "" } %}
99
</div>
1010
</div>

tests/fixtures/style-block-scoped/style-block-scoped.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
text-decoration: underline;
1414
}
1515
</style>
16-
<div class="root {{ class|default('') }}" data-v-6737f06d5bb113335593e128322855f1 {{ scoped|default('') }} style="{{ style|default('') }}">
16+
<div class="root {{ class|default('') }}" data-v-6737f06d5bb113335593e128322855f1 {{ dataScopedStyleAttribute|default('') }} style="{{ style|default('') }}">
1717
<div class="foo" data-v-6737f06d5bb113335593e128322855f1>
1818
foo
1919
</div>

tests/fixtures/style-block-scoped/style-block-scss-scoped.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<style>.foo[data-v-eb50964453fb1d39d2d2f020c6639c00] { color: red; } .foo__bar[data-v-eb50964453fb1d39d2d2f020c6639c00] { color: blue; } .foo__baz[data-v-eb50964453fb1d39d2d2f020c6639c00] { color: #00FF00; }</style>
2-
<div data-v-eb50964453fb1d39d2d2f020c6639c00 {{ scoped|default('') }} class="{{ class|default('') }}" style="{{ style|default('') }}">
2+
<div data-v-eb50964453fb1d39d2d2f020c6639c00 {{ dataScopedStyleAttribute|default('') }} class="{{ class|default('') }}" style="{{ style|default('') }}">
33
<div class="foo__bar" data-v-eb50964453fb1d39d2d2f020c6639c00>
44
baz
55
</div>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<style> .foo { color: red; }</style>
2-
<div {{ scoped|default('') }} class="{{ class|default('') }}" style="{{ style|default('') }}">
3-
<div class="foo" {{ scoped|default('') }}>
2+
<div {{ dataScopedStyleAttribute|default('') }} class="{{ class|default('') }}" style="{{ style|default('') }}">
3+
<div class="foo" {{ dataScopedStyleAttribute|default('') }}>
44
foo
55
</div>
66
</div>

tests/fixtures/style-block-scoped/style-blocks.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<style> .foo { color: red; }</style>
22
<style> .bar[data-v-9d8ac5d70d06b0f0d2a21f893932dffe] { color: blue; }</style>
33
<style>.baz { color: #00FF00; }</style>
4-
<div data-v-9d8ac5d70d06b0f0d2a21f893932dffe {{ scoped|default('') }} class="{{ class|default('') }}" style="{{ style|default('') }}">
4+
<div data-v-9d8ac5d70d06b0f0d2a21f893932dffe {{ dataScopedStyleAttribute|default('') }} class="{{ class|default('') }}" style="{{ style|default('') }}">
55
<div class="foo bar baz" data-v-9d8ac5d70d06b0f0d2a21f893932dffe>
66
42
77
</div>

0 commit comments

Comments
 (0)