Skip to content

Commit 3a6b887

Browse files
committed
Convert strict comparisons
1 parent 94491e3 commit 3a6b887

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/Utils/TwigBuilder.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ public function createVariable($name, $assignment)
2929

3030
public function createIf(string $condition)
3131
{
32+
$condition = $this->refactorCondition($condition);
33+
3234
return $this->createBlock('if '.$condition);
3335
}
3436

3537
public function createElseIf(string $condition)
3638
{
39+
$condition = $this->refactorCondition($condition);
40+
3741
return $this->createBlock('elseif '.$condition);
3842
}
3943

@@ -87,7 +91,7 @@ public function createMultilineComment(array $comments)
8791

8892
public function createBlock($content)
8993
{
90-
return $this->options['tag_block'][self::OPEN].' '.$content.' '.$this->options['tag_block'][self::CLOSE];
94+
return "\n".$this->options['tag_block'][self::OPEN].' '.$content.' '.$this->options['tag_block'][self::CLOSE];
9195
}
9296

9397
/**
@@ -109,4 +113,12 @@ public function createIncludePartial(string $partialPath, array $variables = [])
109113

110114
return $this->createBlock('include "'.$partialPath.'" with { '.implode(', ', $props).' }');
111115
}
116+
117+
public function refactorCondition(string $condition): string
118+
{
119+
$condition = str_replace('===', '==', $condition);
120+
$condition = str_replace('!==', '!=', $condition);
121+
122+
return $condition;
123+
}
112124
}

tests/AbstractTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ protected function createDocumentWithHtml(string $html): DOMDocument
4545
protected function normalizeHtml($html): string
4646
{
4747
$html = preg_replace('/(\s)+/s', '\\1', $html);
48+
$html = str_replace("\n", '', $html);
4849

4950
// Trim node text
5051
$html = preg_replace('/\>[^\S ]+/s', ">", $html);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
{% if a == 1 %}
3+
<div>Text</div>
4+
{% endif %}
5+
</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
<div v-if="a === 1">Text</div>
4+
</div>
5+
</template>

0 commit comments

Comments
 (0)