Skip to content

Commit

Permalink
Deprecate the range function
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Oct 24, 2024
1 parent b0017ad commit 4ee1d06
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 3.15.0 (2024-XX-XX)

* Deprecate the `range` function, use the `..` operator
* Deprecate `TempNameExpression` in favor of `LocalVariable`
* Deprecate `NameExpression` in favor of `ContextVariable`
* Deprecate `AssignNameExpression` in favor of `AssignContextVariable`
Expand Down
3 changes: 3 additions & 0 deletions doc/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Functions
Note that it won't be removed in 4.0 to allow a smoother upgrade path.

* The ``range`` function is deprecated as of Twig 3.15, use the ``..`` operator
instead.

Extensions
----------

Expand Down
5 changes: 5 additions & 0 deletions doc/functions/range.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
``range``
=========

.. warning::

The ``attribute`` filter is deprecated as of Twig 3.15. Use the ``..``
operator instead.

Returns a list containing an arithmetic progression of integers:

.. code-block:: twig
Expand Down
2 changes: 1 addition & 1 deletion src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function getFunctions(): array
new TwigFunction('attribute', null, ['parser_callable' => [self::class, 'parseAttributeFunction']]),
new TwigFunction('max', 'max'),
new TwigFunction('min', 'min'),
new TwigFunction('range', 'range'),
new TwigFunction('range', 'range', ['deprecation_info' => new DeprecatedCallableInfo('twig/twig', '3.15')]),
new TwigFunction('constant', [self::class, 'constant']),
new TwigFunction('cycle', [self::class, 'cycle']),
new TwigFunction('random', [self::class, 'random'], ['needs_charset' => true]),
Expand Down
1 change: 1 addition & 0 deletions src/NodeVisitor/SandboxNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function enterNode(Node $node, Environment $env): Node
}

// the .. operator is equivalent to the range() function
// To be removed in 4.0
if ($node instanceof RangeBinary && !isset($this->functions['range'])) {
$this->functions['range'] = $node->getTemplateLine();
}
Expand Down
8 changes: 0 additions & 8 deletions tests/Fixtures/functions/range.test

This file was deleted.

4 changes: 2 additions & 2 deletions tests/Fixtures/whitespace/trim_block.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Whitespace trimming on tags.
--TEMPLATE--
Trim on control tag:
{% for i in range(1, 9) -%}
{% for i in 1..9 -%}
{{ i }}
{%- endfor %}


Trim on output tag:
{% for i in range(1, 9) %}
{% for i in 1..9 %}
{{- i -}}
{% endfor %}

Expand Down

0 comments on commit 4ee1d06

Please sign in to comment.