-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce NAMED_ARGUMENT_SEPARATOR_TYPE and related rules. #302
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #302 +/- ##
=============================================
- Coverage 100.00% 99.95% -0.05%
- Complexity 734 757 +23
=============================================
Files 64 66 +2
Lines 2290 2343 +53
=============================================
+ Hits 2290 2342 +52
- Misses 0 1 +1 ☔ View full report in Codecov by Sentry. |
3081cdc
to
af51dbe
Compare
src/Token/Tokenizer.php
Outdated
@@ -587,6 +590,17 @@ private function lexOperator(string $operator): void | |||
} elseif (':' === $operator && $this->isInTernary()) { | |||
$bracket = array_pop($this->bracketsAndTernary); | |||
$this->pushToken(Token::OPERATOR_TYPE, $operator, $bracket); | |||
} elseif ('=' === $operator) { | |||
$bracket = end($this->bracketsAndTernary); | |||
if (false !== $bracket && '(' === $bracket->getValue()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not against a double check here (cc @smnandre)
I tried {{ (foo=1) }}
or {{ (1=2) }}
and nothing was supported by twig.
Is =
used somewhere else than in
{% set foo = 1 %}
{{ function(foo=1) }}
? (which means that (
imply it's a named operator)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in named arguments for functions and filters (so you may have multiple ones)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just thought about default value for macro.
{% macro input(name='foo') %}{{ name }}{% endmacro %}
This one need to be handled differently since it cannot be changed to :
.
in named arguments for functions and filters (so you may have multiple ones)
functions and filters (and tests) should work the same (and mutliple named operator too).
fe7bf65
to
7742a43
Compare
daebc61
to
676105e
Compare
if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.12.0')) { | ||
throw new \InvalidArgumentException('Named argument with semi colons requires twig/twig >= 3.12.0'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to, you can use the Twig Environment constants for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it can be trusted, when we see mistake like https://github.com/twigphp/Twig/blob/v3.11.0/src/Environment.php#L48
cd6732f
to
7d3d9d4
Compare
7d3d9d4
to
b7c7d80
Compare
Closes #300