-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Propagate variable types to generated code to allow statical analysis (master) #275
Propagate variable types to generated code to allow statical analysis (master) #275
Conversation
… Character U+FFFD (instead of throwing exception)
…BC break) It will be replaced by named arguments
…WIP [Closes nette#163] (BC break)
@dg Can you please chek this if it is valid approach from your point of view? It it seems ok to you I will add some more tests for edge cases and support for extracting types from {templateType} |
@dg Should I consider that like as approval of this approach? If so can you please approve to run workflows? Thanks. |
6d7e553
to
53e5da9
Compare
2cf67a0
to
74c7abf
Compare
@@ -547,7 +552,7 @@ private function addBlock(MacroNode $node, string $layer = null): Block | |||
private function extractMethod(MacroNode $node, Block $block, string $params = null): void | |||
{ | |||
if (preg_match('#\$|n:#', $node->content)) { | |||
$node->content = '<?php extract(' . ($node->name === 'block' && $node->closest(['embed']) ? 'end($this->varStack)' : '$this->params') . ');' | |||
$node->content = '<?php ' . ($node->name === 'block' && $node->closest(['embed']) ? 'extract(end($this->varStack));' : $this->getCompiler()->paramsExtraction) |
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.
This change is necessary to keep params extraction inside block same as in top-level. Previous version always extracted all params inside block even when {parameters} is used.
@@ -174,7 +177,8 @@ private function buildClassBody(array $tokens): string | |||
$this->output = &$output; | |||
$this->inHead = true; | |||
$this->macroNode = new RootNode; | |||
$this->htmlNode = $this->context = $this->paramsExtraction = null; | |||
$this->htmlNode = $this->context = null; | |||
$this->paramsExtraction = $this->defaultParamsExtraction; |
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.
Default params extraction needs to be set in the beggining so macros can extend it with type information (prepend @var
annotations)
Hi, please give me some time, I'm busy this week. Otherwise, it's best to do PR against the last released version, because I change and forcepush the master a lot. |
@dg Understood. Take your time and look at it whenever you will have time to check it. Let me know if you have any questions or requests how to finish this PR. I will rebase it onto last release. |
New PR targeted onto v2.10 here #276 |
With this change Latte will propagate known types infomation from
{varType}
,{define}
and{parameters}
into compiled PHP code in form of/** @var type $var */
annotations. This will allow statical anylysis of resulting code by static analysers like PHPStan, Psalm, etc.See discussion about this feature here #262