This PR was merged into the 3.x branch.
Discussion
----------
Fix null coalescing operator with imported macros
Closes#4776
When using the null coalescing operator with a macro imported via the `from` tag, the `TemplateVariable` node inside `MacroReferenceExpression` was deep-cloned, causing the clone to generate a different `$macros` key than the one assigned by `AssignTemplateVariable`. This resulted in a `Call to a member function hasMacro() on null` error.
Commits
-------
efa004caab Fix null coalescing operator with imported macros
This PR was merged into the 3.x branch.
Discussion
----------
Add getOperatorTokens() to ExpressionParserInterface to separate operator token registration from parser identity
Closes#4767Closes#4774
Commits
-------
e5eb95d0d7 Add getOperatorTokens() to ExpressionParserInterface to separate operator token registration from parser identity
This PR was merged into the 3.x branch.
Discussion
----------
fix documentation typos for singular filter arguments
This pull request makes a minor update to the documentation for the `singular` filter in `doc/filters/singular.rst`. The change clarifies that the `all` argument returns all possible singulars, not plurals, and fixes the formatting of the links at the end of the file.
Commits
-------
734720e5e7 fix documentation typos for singular filter arguments
This PR was merged into the 3.x branch.
Discussion
----------
Ensure filters/attributes aren't mistaken for operators
Updates the regex in `Lexer::getOperatorRegex()` to account for filters/attributes that have a space between their `|`/`.` operator and the filter/attribute name, to ensure they aren’t mistaken for operators.
A test is included that checks the following template.
```twig
{{ 'foo'|and }}
{{ 'bar' | and }}
{{ foo.and }}
{{ bar . and }}
{{ foo and bar }}
```
(Only the `and` in the last tag should be considered an operator.)
Fixes#4767
Commits
-------
a9ac993938 Ensure filters/attributes aren't mistaken for operators
This PR was merged into the 3.x branch.
Discussion
----------
Enforce more precise type on ListExpression
Commits
-------
dcfc419a25 Enforce more precise type on ListExpression
This PR was merged into the 3.x branch.
Discussion
----------
Deprecate passing non AbstractExpression nodes to MatchesBinary
Commits
-------
379fb2faca Deprecate passing non AbstractExpression nodes to MatchesBinary
This PR was merged into the 3.x branch.
Discussion
----------
Deprecate passing a non-AbstractExpression node to Parser::setParent()
Commits
-------
54d5c004b4 Deprecate passing a non-AbstractExpression node to Parser::setParent()
This PR was merged into the 3.x branch.
Discussion
----------
Support short-circuiting in null-safe operator chains
This PR adds short-circuiting for null-safe operator chains, using the same rules as PHP, `PropertyAccess`, and the `ExpressionLanguage`.
Previously, only the immediate null-safe access was guarded. With this change, as soon as a `null` is encountered at a null-safe access, the rest of the chain is skipped.
My approach was to move the null check outside of the `getAttribute()` calls so the expression can immediately return `null`, eg:
```twig
foo?.bar.baz
```
Before:
```php
yield $this->env
->getRuntime('Twig\Runtime\EscaperRuntime')
->escape(
CoreExtension::getAttribute(
$this->env,
$this->source,
(
null === (
$_v0 = (
isset($context['foo']) || array_key_exists('foo', $context)
? $context['foo']
: throw new RuntimeError('Variable "foo" does not exist.', 3, $this->source)
)
)
? null
: CoreExtension::getAttribute(
$this->env,
$this->source,
$_v0,
'bar',
[],
'any',
false,
false,
false,
3
)
),
'baz',
[],
'any',
false,
false,
false,
3
),
'html',
null,
true
);
```
Now:
```php
yield $this->env
->getRuntime('Twig\Runtime\EscaperRuntime')
->escape(
(
null === (
$_v0 = (
isset($context['foo']) || array_key_exists('foo', $context)
? $context['foo']
: throw new RuntimeError('Variable "foo" does not exist.', 3, $this->source)
)
)
? null
: CoreExtension::getAttribute(
$this->env,
$this->source,
CoreExtension::getAttribute(
$this->env,
$this->source,
$_v0,
'bar',
[],
'any',
false,
false,
false,
3
),
'baz',
[],
'any',
false,
false,
false,
3
)
),
'html',
null,
true
);
```
Commits
-------
d56e8e2dba Support short-circuiting in null-safe operator chains
This PR was merged into the 3.x branch.
Discussion
----------
Add support for renaming variables in object destructuring
Closes#4747
Commits
-------
3cc1b5233c Add support for renaming variables in object destructuring
This PR was merged into the 3.x branch.
Discussion
----------
[Doc] Fix intro for operator precedence table ?
The table introductory paragraph says operator with lowest precedence are listed first ( I assume it means "listed first in the operator table" ).
However, the table starts with a precedence of 500, which seems to be the highest.
Am I completely misreading this ?
Commits
-------
26a12f73f2 Fix intro for operator precedence table ?
This PR was merged into the 3.x branch.
Discussion
----------
Update .gitattributes to remove splitsh.json
- Updated .gitattributes to remove splitsh.json
Commits
-------
79aecfbae0 Update .gitattributes to remove splitsh.json
This PR was merged into the 3.x branch.
Discussion
----------
Add a not about the return value of destructuring
Commits
-------
c38868cdd0 Add a not about the return value of destructuring
This PR was merged into the 3.x branch.
Discussion
----------
Fix null-safe operator test
Noticed this while working on #4748.
Without `strict_variables`, the tests always pass, even when the null-safe operator is not used.
Commits
-------
a16ac6bd35 Fix null-safe operator test
This PR was merged into the 3.x branch.
Discussion
----------
Add support for object and mapping destructuring
Refs https://github.com/twigphp/Twig/issues/3399
Commits
-------
8a0f8acbdf Add support for object and mapping destructuring
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Assignment operator array destructuring
Follow-up to the introduction of the new = operator, array destructuring.
Refs #3399
Commits
-------
bb99af3b39 Assignment operator array destructuring
This PR was merged into the 3.x branch.
Discussion
----------
Fix grammar and spelling mistakes in documentation
Commits
-------
77cd2fd9f7 Fix grammar and spelling mistakes in documentation
This PR was merged into the 3.x branch.
Discussion
----------
Tweak null-safe operator implementation
Follow-up for #4717
Commits
-------
6904954165 Tweak null-safe operator implementation