Propagate variable types to generated code to allow statical analysis (master)#275
Propagate variable types to generated code to allow statical analysis (master)#275MartinMystikJonas wants to merge 21 commits intonette:masterfrom
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
| { | ||
| 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.
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.
| $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.
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