Skip to content

Commit bf65bf2

Browse files
committed
Merge branch '3.x' into 4.x
* 3.x: Fix wrong array index (again) fix: update extension references in docs to use backticks [Doc] Fix `code-block` in html_cva [Docs] Replace `=` by `:` in code examples fix: deprecated documentation Use `:` instead of `=` for named argument in the docs use EmptyNode instead of an Nodes instance without children Fix `ModuleNode` instanciation when `$embeddedTemplates` is null merge the Nodes and Node sections reduce the number of deprecations being triggered
2 parents 2310b63 + 3c7c97e commit bf65bf2

File tree

6 files changed

+43
-39
lines changed

6 files changed

+43
-39
lines changed

doc/api.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -325,23 +325,23 @@ extension via the ``addExtension()`` method::
325325

326326
Twig comes bundled with the following extensions:
327327

328-
* *Twig\Extension\CoreExtension*: Defines all the core features of Twig.
328+
* ``\Twig\Extension\CoreExtension``: Defines all the core features of Twig.
329329

330-
* *Twig\Extension\DebugExtension*: Defines the ``dump`` function to help debug
330+
* ``\Twig\Extension\DebugExtension``: Defines the ``dump`` function to help debug
331331
template variables.
332332

333-
* *Twig\Extension\EscaperExtension*: Adds automatic output-escaping and the
333+
* ``\Twig\Extension\EscaperExtension``: Adds automatic output-escaping and the
334334
possibility to escape/unescape blocks of code.
335335

336-
* *Twig\Extension\SandboxExtension*: Adds a sandbox mode to the default Twig
336+
* ``\Twig\Extension\SandboxExtension``: Adds a sandbox mode to the default Twig
337337
environment, making it safe to evaluate untrusted code.
338338

339-
* *Twig\Extension\ProfilerExtension*: Enables the built-in Twig profiler.
339+
* ``\Twig\Extension\ProfilerExtension``: Enables the built-in Twig profiler.
340340

341-
* *Twig\Extension\OptimizerExtension*: Optimizes the node tree before
341+
* ``\Twig\Extension\OptimizerExtension``: Optimizes the node tree before
342342
compilation.
343343

344-
* *Twig\Extension\StringLoaderExtension*: Defines the ``template_from_string``
344+
* ``\Twig\Extension\StringLoaderExtension``: Defines the ``template_from_string``
345345
function to allow loading templates from string in a template.
346346

347347
The Core, Escaper, and Optimizer extensions are registered by default.

doc/filters/format_number.rst

+17-17
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,37 @@ The list of supported options:
2222
* ``grouping_used``: Specifies whether to use grouping separator for thousands::
2323

2424
{# 1,234,567.89 #}
25-
{{ 1234567.89|format_number({grouping_used:true}, locale='en') }}
25+
{{ 1234567.89|format_number({grouping_used:true}, locale: 'en') }}
2626

2727
* ``decimal_always_shown``: Specifies whether to always show the decimal part, even if it's zero::
2828

2929
{# 123. #}
30-
{{ 123|format_number({decimal_always_shown:true}, locale='en') }}
30+
{{ 123|format_number({decimal_always_shown:true}, locale: 'en') }}
3131

3232
* ``max_integer_digit``:
3333
* ``min_integer_digit``:
3434
* ``integer_digit``: Define constraints on the integer part::
3535

3636
{# 345.679 #}
37-
{{ 12345.6789|format_number({max_integer_digit:3, min_integer_digit:2}, locale='en') }}
37+
{{ 12345.6789|format_number({max_integer_digit:3, min_integer_digit:2}, locale: 'en') }}
3838

3939
* ``max_fraction_digit``:
4040
* ``min_fraction_digit``:
4141
* ``fraction_digit``: Define constraints on the fraction part::
4242

4343
{# 123.46 #}
44-
{{ 123.456789|format_number({max_fraction_digit:2, min_fraction_digit:1}, locale='en') }}
44+
{{ 123.456789|format_number({max_fraction_digit:2, min_fraction_digit:1}, locale: 'en') }}
4545

4646
* ``multiplier``: Multiplies the value before formatting::
4747

4848
{# 123,000 #}
49-
{{ 123|format_number({multiplier:1000}, locale='en') }}
49+
{{ 123|format_number({multiplier:1000}, locale: 'en') }}
5050

5151
* ``grouping_size``:
5252
* ``secondary_grouping_size``: Set the size of the primary and secondary grouping separators::
5353

5454
{# 1,23,45,678 #}
55-
{{ 12345678|format_number({grouping_size:3, secondary_grouping_size:2}, locale='en') }}
55+
{{ 12345678|format_number({grouping_size:3, secondary_grouping_size:2}, locale: 'en') }}
5656

5757
* ``rounding_mode``:
5858
* ``rounding_increment``: Control rounding behavior, here is a list of all rounding_mode available:
@@ -67,7 +67,7 @@ The list of supported options:
6767
.. code-block:: twig
6868
6969
{# 123.5 #}
70-
{{ 123.456|format_number({rounding_mode:'ceiling', rounding_increment:0.05}, locale='en') }}
70+
{{ 123.456|format_number({rounding_mode:'ceiling', rounding_increment:0.05}, locale: 'en') }}
7171
7272
* ``format_width``:
7373
* ``padding_position``: Set width and padding for the formatted number, here is a list of all padding_position available:
@@ -79,19 +79,19 @@ The list of supported options:
7979
.. code-block:: twig
8080
8181
{# 123 #}
82-
{{ 123|format_number({format_width:10, padding_position:'before_suffix'}, locale='en') }}
82+
{{ 123|format_number({format_width:10, padding_position:'before_suffix'}, locale: 'en') }}
8383
8484
* ``significant_digits_used``:
8585
* ``min_significant_digits_used``:
8686
* ``max_significant_digits_used``: Control significant digits in formatting::
8787

8888
{# 123.4568 #}
89-
{{ 123.456789|format_number({significant_digits_used:true, min_significant_digits_used:4, max_significant_digits_used:7}, locale='en') }}
89+
{{ 123.456789|format_number({significant_digits_used:true, min_significant_digits_used:4, max_significant_digits_used:7}, locale: 'en') }}
9090

9191
* ``lenient_parse``: If true, allows lenient parsing of the input::
9292

9393
{# 123 #}
94-
{{ 123|format_number({lenient_parse:true}, locale='en') }}
94+
{{ 123|format_number({lenient_parse:true}, locale: 'en') }}
9595

9696
Besides plain numbers, the filter can also format numbers in various styles::
9797

@@ -109,37 +109,37 @@ The list of supported styles:
109109
* ``decimal``::
110110

111111
{# 1,234.568 #}
112-
{{ 1234.56789 | format_number(style='decimal', locale='en') }}
112+
{{ 1234.56789 | format_number(style: 'decimal', locale: 'en') }}
113113

114114
* ``currency``::
115115

116116
{# $1,234.56 #}
117-
{{ 1234.56 | format_number(style='currency', locale='en') }}
117+
{{ 1234.56 | format_number(style: 'currency', locale: 'en') }}
118118

119119
* ``percent``::
120120

121121
{# 12% #}
122-
{{ 0.1234 | format_number(style='percent', locale='en') }}
122+
{{ 0.1234 | format_number(style: 'percent', locale: 'en') }}
123123

124124
* ``scientific``::
125125

126126
{# 1.23456789e+3 #}
127-
{{ 1234.56789 | format_number(style='scientific', locale='en') }}
127+
{{ 1234.56789 | format_number(style: 'scientific', locale: 'en') }}
128128

129129
* ``spellout``::
130130

131131
{# one thousand two hundred thirty-four point five six seven eight nine #}
132-
{{ 1234.56789 | format_number(style='spellout', locale='en') }}
132+
{{ 1234.56789 | format_number(style: 'spellout', locale: 'en') }}
133133

134134
* ``ordinal``::
135135

136136
{# 1st #}
137-
{{ 1 | format_number(style='ordinal', locale='en') }}
137+
{{ 1 | format_number(style: 'ordinal', locale: 'en') }}
138138

139139
* ``duration``::
140140

141141
{# 2:30:00 #}
142-
{{ 9000 | format_number(style='duration', locale='en') }}
142+
{{ 9000 | format_number(style: 'duration', locale: 'en') }}
143143

144144
As a shortcut, you can use the ``format_*_number`` filters by replacing ``*``
145145
with a style::

doc/functions/html_cva.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ To "merge" conflicting classes together and keep only the ones you need, use the
5656
``tailwind_merge()`` filter from `tales-from-a-dev/twig-tailwind-extra`_
5757
with the ``html_cva()`` function:
5858

59-
.. code-block:: terminal
59+
.. code-block:: bash
6060
6161
$ composer require tales-from-a-dev/twig-tailwind-extra
6262

doc/functions/include.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ You can disable access to the context by setting ``with_context`` to
2727
.. code-block:: twig
2828
2929
{# only the name variable will be accessible #}
30-
{{ include('template.html.twig', {name: 'Fabien'}, with_context = false) }}
30+
{{ include('template.html.twig', {name: 'Fabien'}, with_context: false) }}
3131
3232
.. code-block:: twig
3333
3434
{# no variables will be accessible #}
35-
{{ include('template.html.twig', with_context = false) }}
35+
{{ include('template.html.twig', with_context: false) }}
3636
3737
And if the expression evaluates to a ``\Twig\Template`` or a
3838
``\Twig\TemplateWrapper`` instance, Twig will use it directly::
@@ -48,7 +48,7 @@ the template does not exist:
4848

4949
.. code-block:: twig
5050
51-
{{ include('sidebar.html.twig', ignore_missing = true) }}
51+
{{ include('sidebar.html.twig', ignore_missing: true) }}
5252
5353
You can also provide a list of templates that are checked for existence before
5454
inclusion. The first template that exists will be rendered:

src/Node/Expression/ArrayExpression.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,32 @@ public function compile(Compiler $compiler): void
7979
}
8080

8181
$compiler->raw('[');
82-
$first = true;
83-
$nextIndex = 0;
84-
foreach ($this->getKeyValuePairs() as $pair) {
85-
if (!$first) {
82+
$isSequence = true;
83+
foreach ($this->getKeyValuePairs() as $i => $pair) {
84+
if (0 !== $i) {
8685
$compiler->raw(', ');
8786
}
88-
$first = false;
8987

9088
$key = null;
9189
if ($pair['key'] instanceof ContextVariable) {
9290
$pair['key'] = new StringCastUnary($pair['key'], $pair['key']->getTemplateLine());
93-
}
94-
if ($pair['key'] instanceof LocalVariable) {
91+
} elseif ($pair['key'] instanceof LocalVariable) {
9592
$key = $pair['key']->getAttribute('name');
9693
$pair['key'] = new ConstantExpression($key, $pair['key']->getTemplateLine());
97-
}
98-
if ($pair['key'] instanceof ConstantExpression) {
94+
} elseif ($pair['key'] instanceof ConstantExpression) {
9995
$key = $pair['key']->getAttribute('value');
10096
}
10197

102-
if ($nextIndex !== $key && !$pair['value'] instanceof SpreadUnary) {
98+
if ($key !== $i) {
99+
$isSequence = false;
100+
}
101+
102+
if (!$isSequence && !$pair['value'] instanceof SpreadUnary) {
103103
$compiler
104104
->subcompile($pair['key'])
105105
->raw(' => ')
106106
;
107107
}
108-
++$nextIndex;
109108

110109
$compiler->subcompile($pair['value']);
111110
}

tests/Fixtures/expressions/array.test

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Twig supports array notation
5555
{% set trad = {194:'ABC',141:'DEF',100:'GHI',170:'JKL',110:'MNO',111:'PQR'} %}
5656
{% set trad2 = {'194':'ABC','141':'DEF','100':'GHI','170':'JKL','110':'MNO','111':'PQR'} %}
5757
{{ trad == trad2 ? 'OK' : 'KO' }}
58+
{% set trad = {11: 'ABC', 2: 'DEF', 4: 'GHI', 3: 'JKL'} %}
59+
{% set trad2 = {'11': 'ABC', '2': 'DEF', '4': 'GHI', '3': 'JKL'} %}
60+
{{ trad == trad2 ? 'OK' : 'KO' }}
5861

5962
{# indexes are kept #}
6063
{{ { 1: "first", 0: "second" } == { '1': "first", '0': "second" } ? 'OK' : 'KO' }}
@@ -104,6 +107,7 @@ ok
104107
ok
105108
ok
106109

110+
OK
107111
OK
108112

109113
OK
@@ -151,6 +155,7 @@ ok
151155
ok
152156
ok
153157

158+
OK
154159
OK
155160

156161
OK

0 commit comments

Comments
 (0)