Skip to content

Commit dfd89b4

Browse files
committed
Fix logical operator “!” and “!==“ for twig
1 parent c00a044 commit dfd89b4

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/Compiler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ protected function sanitizeCondition(string $condition)
398398
{
399399
$condition = str_replace('&&', 'and', $condition);
400400
$condition = str_replace('||', 'or', $condition);
401+
$condition = str_replace('!==', '!=', $condition);
402+
$condition = preg_replace('/!([^=])/', 'not $1', $condition);
401403

402404
foreach (Replacements::getConstants() as $constant => $value) {
403405
$condition = str_replace($value, Replacements::getSanitizedConstant($constant), $condition);

tests/fixtures/vue-if/simple-if-2.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
{% if someVar %}
33
<div>Text</div>
44
{% endif %}
5+
{% if not someVar and mobile != true %}
6+
<div>Mobile</div>
7+
{% endif %}
58
</div>

tests/fixtures/vue-if/simple-if-2.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<div>
33
<div v-if="someVar">Text</div>
4+
<div v-if="!someVar && mobile !== true">Mobile</div>
45
</div>
56
</template>

0 commit comments

Comments
 (0)