@vituum/vite-plugin-latte 2.0.0-next.5 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/README.md +1 -1
  2. package/index.js +2 -1
  3. package/package.json +20 -10
  4. package/vendor/composer/autoload_classmap.php +3 -2
  5. package/vendor/composer/autoload_static.php +3 -2
  6. package/vendor/composer/installed.json +21 -17
  7. package/vendor/composer/installed.php +8 -8
  8. package/vendor/latte/latte/composer.json +9 -2
  9. package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +7 -7
  10. package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +5 -4
  11. package/vendor/latte/latte/src/Bridges/Tracy/TracyExtension.php +2 -4
  12. package/vendor/latte/latte/src/Bridges/Tracy/dist/panel.phtml +2 -4
  13. package/vendor/latte/latte/src/Bridges/Tracy/dist/tab.phtml +2 -4
  14. package/vendor/latte/latte/src/Latte/Compiler/Block.php +1 -3
  15. package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +4 -8
  16. package/vendor/latte/latte/src/Latte/Compiler/Node.php +6 -3
  17. package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +15 -6
  18. package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +14 -9
  19. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +7 -3
  20. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +4 -3
  21. package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +5 -4
  22. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +6 -5
  23. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/BogusTagNode.php +4 -6
  24. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/CommentNode.php +4 -3
  25. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +5 -7
  26. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ExpressionAttributeNode.php +6 -4
  27. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/TagNode.php +1 -3
  28. package/vendor/latte/latte/src/Latte/Compiler/Nodes/NopNode.php +4 -3
  29. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +4 -3
  30. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArrayItemNode.php +4 -3
  31. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ClosureUseNode.php +4 -3
  32. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ComplexTypeNode.php +4 -3
  33. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php +4 -3
  34. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +4 -3
  35. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +4 -3
  36. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +5 -4
  37. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AuxiliaryNode.php +4 -3
  38. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +5 -4
  39. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +4 -3
  40. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +4 -3
  41. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CloneNode.php +4 -3
  42. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +7 -6
  43. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +5 -4
  44. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/EmptyNode.php +4 -3
  45. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FilterCallNode.php +4 -3
  46. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +4 -3
  47. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InNode.php +4 -3
  48. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InstanceofNode.php +4 -3
  49. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +4 -3
  50. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +4 -3
  51. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +4 -3
  52. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +4 -3
  53. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +4 -3
  54. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +4 -3
  55. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PropertyFetchNode.php +4 -3
  56. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticMethodCallNode.php +4 -3
  57. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticPropertyFetchNode.php +4 -3
  58. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TemporaryNode.php +7 -6
  59. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php +4 -3
  60. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +4 -3
  61. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/VariableNode.php +4 -3
  62. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +4 -3
  63. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +4 -3
  64. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IdentifierNode.php +4 -3
  65. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/InterpolatedStringPartNode.php +4 -3
  66. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IntersectionTypeNode.php +4 -3
  67. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListItemNode.php +4 -3
  68. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListNode.php +4 -3
  69. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/MatchArmNode.php +4 -3
  70. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +4 -3
  71. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +4 -3
  72. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +4 -3
  73. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/OperatorNode.php +1 -3
  74. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ParameterNode.php +4 -3
  75. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/BooleanNode.php +4 -3
  76. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/FloatNode.php +5 -4
  77. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +5 -4
  78. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/InterpolatedStringNode.php +6 -5
  79. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/NullNode.php +4 -3
  80. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/StringNode.php +5 -4
  81. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ScalarNode.php +4 -3
  82. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php +4 -3
  83. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/UnionTypeNode.php +4 -3
  84. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +4 -3
  85. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VariadicPlaceholderNode.php +4 -3
  86. package/vendor/latte/latte/src/Latte/Compiler/Nodes/PrintNode.php +3 -4
  87. package/vendor/latte/latte/src/Latte/Compiler/Nodes/StatementNode.php +7 -3
  88. package/vendor/latte/latte/src/Latte/Compiler/Nodes/TemplateNode.php +4 -3
  89. package/vendor/latte/latte/src/Latte/Compiler/Nodes/TextNode.php +5 -4
  90. package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +23 -15
  91. package/vendor/latte/latte/src/Latte/Compiler/Position.php +5 -7
  92. package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +30 -9
  93. package/vendor/latte/latte/src/Latte/Compiler/Tag.php +6 -6
  94. package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +4 -6
  95. package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +14 -11
  96. package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +2 -4
  97. package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +13 -11
  98. package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +21 -7
  99. package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +32 -19
  100. package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +28 -21
  101. package/vendor/latte/latte/src/Latte/Compiler/Token.php +10 -9
  102. package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +20 -14
  103. package/vendor/latte/latte/src/Latte/ContentType.php +4 -3
  104. package/vendor/latte/latte/src/Latte/Engine.php +64 -35
  105. package/vendor/latte/latte/src/Latte/Essential/AuxiliaryIterator.php +3 -7
  106. package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +4 -5
  107. package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +2 -3
  108. package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +1 -3
  109. package/vendor/latte/latte/src/Latte/Essential/Filters.php +65 -32
  110. package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +8 -6
  111. package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +5 -6
  112. package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +3 -4
  113. package/vendor/latte/latte/src/Latte/Essential/Nodes/CustomFunctionCallNode.php +2 -4
  114. package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +2 -3
  115. package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +6 -6
  116. package/vendor/latte/latte/src/Latte/Essential/Nodes/DoNode.php +3 -4
  117. package/vendor/latte/latte/src/Latte/Essential/Nodes/DumpNode.php +2 -3
  118. package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +3 -5
  119. package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +3 -5
  120. package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +4 -7
  121. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +3 -5
  122. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +7 -8
  123. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +4 -5
  124. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +7 -6
  125. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +6 -9
  126. package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +3 -4
  127. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +8 -7
  128. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +2 -4
  129. package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +6 -6
  130. package/vendor/latte/latte/src/Latte/Essential/Nodes/JumpNode.php +4 -8
  131. package/vendor/latte/latte/src/Latte/Essential/Nodes/NAttrNode.php +3 -5
  132. package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +3 -4
  133. package/vendor/latte/latte/src/Latte/Essential/Nodes/NElseNode.php +8 -5
  134. package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +4 -4
  135. package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +4 -4
  136. package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +2 -4
  137. package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +2 -3
  138. package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +4 -5
  139. package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +9 -7
  140. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +3 -4
  141. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplateTypeNode.php +3 -4
  142. package/vendor/latte/latte/src/Latte/Essential/Nodes/TraceNode.php +2 -3
  143. package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +3 -4
  144. package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +4 -5
  145. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +8 -7
  146. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +2 -3
  147. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarTypeNode.php +3 -4
  148. package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +5 -5
  149. package/vendor/latte/latte/src/Latte/Essential/Passes.php +26 -15
  150. package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +1 -3
  151. package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +1 -3
  152. package/vendor/latte/latte/src/Latte/Essential/Tracer.php +20 -13
  153. package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +9 -10
  154. package/vendor/latte/latte/src/Latte/Extension.php +10 -6
  155. package/vendor/latte/latte/src/Latte/Feature.php +24 -0
  156. package/vendor/latte/latte/src/Latte/Helpers.php +18 -10
  157. package/vendor/latte/latte/src/Latte/Loader.php +1 -3
  158. package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +8 -5
  159. package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +5 -13
  160. package/vendor/latte/latte/src/Latte/Policy.php +4 -3
  161. package/vendor/latte/latte/src/Latte/Runtime/Block.php +2 -4
  162. package/vendor/latte/latte/src/Latte/{Cache.php → Runtime/Cache.php} +12 -11
  163. package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +3 -5
  164. package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +10 -11
  165. package/vendor/latte/latte/src/Latte/Runtime/FunctionExecutor.php +4 -6
  166. package/vendor/latte/latte/src/Latte/Runtime/Helpers.php +5 -7
  167. package/vendor/latte/latte/src/Latte/Runtime/Html.php +3 -5
  168. package/vendor/latte/latte/src/Latte/Runtime/HtmlHelpers.php +18 -18
  169. package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +1 -3
  170. package/vendor/latte/latte/src/Latte/Runtime/Template.php +23 -42
  171. package/vendor/latte/latte/src/Latte/Runtime/XmlHelpers.php +5 -7
  172. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +14 -8
  173. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +17 -11
  174. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +4 -3
  175. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +3 -4
  176. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticMethodCallNode.php +16 -10
  177. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +4 -3
  178. package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +6 -5
  179. package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +5 -4
  180. package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +17 -16
  181. package/vendor/latte/latte/src/Latte/attributes.php +7 -3
  182. package/vendor/latte/latte/src/Latte/exceptions.php +38 -3
  183. package/vendor/latte/latte/src/Tools/Linter.php +20 -14
  184. package/vendor/latte/latte/src/Tools/LinterExtension.php +26 -7
  185. package/vendor/nette/utils/composer.json +8 -1
  186. package/vendor/nette/utils/src/HtmlStringable.php +4 -1
  187. package/vendor/nette/utils/src/Iterators/CachingIterator.php +9 -24
  188. package/vendor/nette/utils/src/Iterators/Mapper.php +2 -3
  189. package/vendor/nette/utils/src/SmartObject.php +3 -0
  190. package/vendor/nette/utils/src/StaticClass.php +1 -1
  191. package/vendor/nette/utils/src/Translator.php +1 -1
  192. package/vendor/nette/utils/src/Utils/ArrayHash.php +1 -5
  193. package/vendor/nette/utils/src/Utils/ArrayList.php +3 -6
  194. package/vendor/nette/utils/src/Utils/Arrays.php +33 -10
  195. package/vendor/nette/utils/src/Utils/Callback.php +12 -7
  196. package/vendor/nette/utils/src/Utils/DateTime.php +1 -1
  197. package/vendor/nette/utils/src/Utils/FileInfo.php +5 -7
  198. package/vendor/nette/utils/src/Utils/FileSystem.php +5 -2
  199. package/vendor/nette/utils/src/Utils/Finder.php +27 -8
  200. package/vendor/nette/utils/src/Utils/Helpers.php +7 -1
  201. package/vendor/nette/utils/src/Utils/Html.php +123 -118
  202. package/vendor/nette/utils/src/Utils/Image.php +72 -54
  203. package/vendor/nette/utils/src/Utils/ImageColor.php +4 -0
  204. package/vendor/nette/utils/src/Utils/Iterables.php +16 -8
  205. package/vendor/nette/utils/src/Utils/Paginator.php +10 -43
  206. package/vendor/nette/utils/src/Utils/Reflection.php +17 -7
  207. package/vendor/nette/utils/src/Utils/ReflectionMethod.php +4 -1
  208. package/vendor/nette/utils/src/Utils/Strings.php +48 -15
  209. package/vendor/nette/utils/src/Utils/Type.php +41 -27
  210. package/vendor/nette/utils/src/Utils/Validators.php +8 -7
  211. package/vendor/latte/latte/src/Bridges/Tracy/panel.latte +0 -94
  212. package/vendor/latte/latte/src/Bridges/Tracy/tab.latte +0 -8
  213. package/vendor/latte/latte/src/Latte/PositionAwareException.php +0 -47
@@ -1,23 +1,21 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Compiler;
11
9
 
12
10
  use function strlen, strrpos, substr_count;
13
11
 
14
12
 
15
- final class Position
13
+ final readonly class Position
16
14
  {
17
15
  public function __construct(
18
- public readonly int $line = 1,
19
- public readonly int $column = 1,
20
- public readonly int $offset = 0,
16
+ public int $line = 1,
17
+ public int $column = 1,
18
+ public int $offset = 0,
21
19
  ) {
22
20
  }
23
21
 
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Compiler;
11
9
 
12
10
  use Latte\Compiler\Nodes\Php as Nodes;
@@ -14,15 +12,19 @@ use Latte\Compiler\Nodes\Php\Expression;
14
12
  use Latte\Compiler\Nodes\Php\OperatorNode;
15
13
  use Latte\Compiler\Nodes\Php\Scalar;
16
14
  use Latte\ContentType;
17
- use function addcslashes, array_map, array_pop, end, implode, preg_replace, preg_replace_callback, strtolower, substr, trim, ucfirst;
15
+ use Latte\Feature;
16
+ use function addcslashes, array_pop, count, end, implode, preg_replace, preg_replace_callback, strtolower, substr, trim, ucfirst;
18
17
 
19
18
 
20
19
  /**
21
- * PHP printing helpers and context.
20
+ * Context for PHP code generation with escaping management.
22
21
  */
23
22
  final class PrintContext
24
23
  {
24
+ /** @var Nodes\ParameterNode[] */
25
25
  public array $paramsExtraction = [];
26
+
27
+ /** @var array<string, Block> */
26
28
  public array $blocks = [];
27
29
  private int $counter = 0;
28
30
 
@@ -32,7 +34,8 @@ final class PrintContext
32
34
 
33
35
  public function __construct(
34
36
  string $contentType = ContentType::Html,
35
- public bool $migrationWarnings = false,
37
+ /** @var array<string, bool> */
38
+ private array $features = [],
36
39
  ) {
37
40
  $this->escaperStack[] = new Escaper($contentType);
38
41
  }
@@ -63,7 +66,7 @@ final class PrintContext
63
66
  return match ($fn) {
64
67
  'modify' => $args[$pos]->printSimple($this, $var),
65
68
  'modifyContent' => $args[$pos]->printContentAware($this, $var),
66
- 'escape' => end($this->escaperStack)->escape($var),
69
+ 'escape' => $this->getEscaper()->escape($var),
67
70
  };
68
71
  },
69
72
  $mask,
@@ -100,12 +103,18 @@ final class PrintContext
100
103
  }
101
104
 
102
105
 
106
+ /**
107
+ * Pushes current escaper onto stack.
108
+ */
103
109
  public function beginEscape(): Escaper
104
110
  {
105
111
  return $this->escaperStack[] = $this->getEscaper();
106
112
  }
107
113
 
108
114
 
115
+ /**
116
+ * Restores previous escaper from stack.
117
+ */
109
118
  public function restoreEscape(): void
110
119
  {
111
120
  array_pop($this->escaperStack);
@@ -114,7 +123,9 @@ final class PrintContext
114
123
 
115
124
  public function getEscaper(): Escaper
116
125
  {
117
- return clone end($this->escaperStack);
126
+ $escaper = end($this->escaperStack);
127
+ assert($escaper instanceof Escaper);
128
+ return clone $escaper;
118
129
  }
119
130
 
120
131
 
@@ -134,12 +145,21 @@ final class PrintContext
134
145
  }
135
146
 
136
147
 
148
+ /**
149
+ * Generates unique ID for temporary variables.
150
+ */
137
151
  public function generateId(): int
138
152
  {
139
153
  return $this->counter++;
140
154
  }
141
155
 
142
156
 
157
+ public function hasFeature(Feature $feature): bool
158
+ {
159
+ return $this->features[$feature->name] ?? false;
160
+ }
161
+
162
+
143
163
  // PHP helpers
144
164
 
145
165
 
@@ -180,7 +200,7 @@ final class PrintContext
180
200
  public function parenthesize(OperatorNode $parentNode, Node $childNode, int $childPosition): string
181
201
  {
182
202
  [$parentPrec, $parentAssoc] = $parentNode->getOperatorPrecedence();
183
- [$childPrec] = $childNode instanceof OperatorNode ? $childNode->getOperatorPrecedence() : null;
203
+ [$childPrec] = $childNode instanceof OperatorNode ? $childNode->getOperatorPrecedence() : [null];
184
204
  return $childPrec && ($childPrec < $parentPrec || ($parentPrec === $childPrec && $parentAssoc !== $childPosition))
185
205
  ? '(' . $childNode->print($this) . ')'
186
206
  : $childNode->print($this);
@@ -189,6 +209,7 @@ final class PrintContext
189
209
 
190
210
  /**
191
211
  * Prints an array of nodes and implodes the printed values with $glue
212
+ * @param (?Node)[] $nodes
192
213
  */
193
214
  public function implode(array $nodes, string $glue = ', '): string
194
215
  {
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Compiler;
11
9
 
12
10
  use Latte\CompileException;
@@ -16,7 +14,7 @@ use function array_search, in_array;
16
14
 
17
15
 
18
16
  /**
19
- * Latte tag or n:attribute.
17
+ * Represents a Latte tag or n:attribute during parsing.
20
18
  */
21
19
  final class Tag
22
20
  {
@@ -34,6 +32,7 @@ final class Tag
34
32
  public int $outputMode = self::OutputNone;
35
33
 
36
34
 
35
+ /** @param list<Token> $tokens */
37
36
  public function __construct(
38
37
  public readonly string $name,
39
38
  array $tokens,
@@ -91,7 +90,7 @@ final class Tag
91
90
  {
92
91
  $tag = $this->parent;
93
92
  while ($tag && (
94
- !in_array($tag->node ? $tag->node::class : null, $classes, true)
93
+ !in_array($tag->node ? $tag->node::class : null, $classes, strict: true)
95
94
  || ($condition && !$condition($tag))
96
95
  )) {
97
96
  $tag = $tag->parent;
@@ -111,7 +110,8 @@ final class Tag
111
110
 
112
111
  public function replaceNAttribute(AreaNode $node): void
113
112
  {
114
- $index = array_search($this->nAttribute, $this->htmlElement->attributes->children, true);
113
+ assert($this->htmlElement !== null);
114
+ $index = array_search($this->nAttribute, $this->htmlElement->attributes->children, strict: true);
115
115
  $this->htmlElement->attributes->children[$index] = $this->nAttribute = $node;
116
116
  }
117
117
  }
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Compiler;
11
9
 
12
10
  use Latte\CompileException;
@@ -211,7 +209,7 @@ final class TagLexer
211
209
  || isset($m[$type = 'Php_NullsafeObjectOperator'])
212
210
  || isset($m[$type = 'Php_UndefinedsafeObjectOperator'])
213
211
  ) {
214
- $this->addToken(constant(Token::class . '::' . $type), $m[$type]);
212
+ $this->addToken(constant(Token::class . '::' . $type), $m[$type] ?? '');
215
213
  if (isset($m['Php_Whitespace'])) {
216
214
  $this->addToken(Token::Php_Whitespace, $m['Php_Whitespace']);
217
215
  }
@@ -361,8 +359,8 @@ final class TagLexer
361
359
  || isset($m[$type = 'Php_NullsafeObjectOperator'])
362
360
  || isset($m[$type = 'Php_UndefinedsafeObjectOperator'])
363
361
  ) {
364
- $this->addToken(constant(Token::class . '::' . $type), $m[$type]);
365
- $this->addToken(Token::Php_Identifier, $m['Php_Identifier']);
362
+ $this->addToken(constant(Token::class . '::' . $type), $m[$type] ?? '');
363
+ $this->addToken(Token::Php_Identifier, $m['Php_Identifier'] ?? '');
366
364
 
367
365
  } elseif (isset($m['offset'])) {
368
366
  $this->addToken(null, '[');
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Compiler;
11
9
 
12
10
  use Latte;
@@ -38,11 +36,12 @@ final class TagParser
38
36
  public readonly TokenStream $stream;
39
37
  public string $text;
40
38
 
41
- /** @var \SplObjectStorage<Expression\ArrayNode> */
39
+ /** @var \SplObjectStorage<Expression\ArrayNode, null> */
42
40
  protected \SplObjectStorage $shortArrays;
43
41
  private readonly int $offsetDelta;
44
42
 
45
43
 
44
+ /** @param array<int, mixed> $tokens */
46
45
  public function __construct(array $tokens)
47
46
  {
48
47
  $this->offsetDelta = $tokens[0]->position->offset;
@@ -124,6 +123,7 @@ final class TagParser
124
123
 
125
124
  /**
126
125
  * Parses variables used in foreach.
126
+ * @return array{?Nodes\Php\ExpressionNode, Nodes\Php\ExpressionNode|Nodes\Php\ListNode, bool}
127
127
  * @internal
128
128
  */
129
129
  public function parseForeach(): array
@@ -291,13 +291,13 @@ final class TagParser
291
291
  }
292
292
 
293
293
 
294
- public function throwReservedKeywordException(Token $token)
294
+ public function throwReservedKeywordException(Token $token): never
295
295
  {
296
296
  throw new Latte\CompileException("Keyword '$token->text' cannot be used in Latte.", $token->position);
297
297
  }
298
298
 
299
299
 
300
- protected function checkFunctionName(Expression\FunctionCallNode $func): ExpressionNode
300
+ private function checkFunctionName(Expression\FunctionCallNode $func): Expression\FunctionCallNode
301
301
  {
302
302
  if ($func->name instanceof NameNode && $func->name->isKeyword()) {
303
303
  $this->throwReservedKeywordException(new Token(0, (string) $func->name, $func->name->position));
@@ -306,7 +306,7 @@ final class TagParser
306
306
  }
307
307
 
308
308
 
309
- protected static function handleBuiltinTypes(NameNode $name): NameNode|Node\IdentifierNode
309
+ private static function handleBuiltinTypes(NameNode $name): NameNode|Node\IdentifierNode
310
310
  {
311
311
  $builtinTypes = [
312
312
  'bool' => true, 'int' => true, 'float' => true, 'string' => true, 'iterable' => true, 'void' => true,
@@ -320,7 +320,7 @@ final class TagParser
320
320
  }
321
321
 
322
322
 
323
- protected static function parseOffset(string $str, Position $position): Scalar\StringNode|Scalar\IntegerNode
323
+ private static function parseOffset(string $str, Position $position): Scalar\StringNode|Scalar\IntegerNode
324
324
  {
325
325
  if (!preg_match('/^(?:0|-?[1-9][0-9]*)$/', $str)) {
326
326
  return new Scalar\StringNode($str, $position);
@@ -335,8 +335,8 @@ final class TagParser
335
335
  }
336
336
 
337
337
 
338
- /** @param ExpressionNode[] $parts */
339
- protected function parseDocString(
338
+ /** @param ExpressionNode[] $parts */
339
+ private function parseDocString(
340
340
  string $startToken,
341
341
  array $parts,
342
342
  string $endToken,
@@ -458,7 +458,10 @@ final class TagParser
458
458
  }
459
459
 
460
460
 
461
- /** @param Token[] $tokens */
461
+ /**
462
+ * @param Token[] $tokens
463
+ * @return Token[]
464
+ */
462
465
  private function filterTokens(array $tokens): array
463
466
  {
464
467
  $this->text = '';
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Compiler;
11
9
 
12
10
  use Latte\Compiler\Nodes\Php as Node;
@@ -428,7 +426,7 @@ trait TagParserData
428
426
  /** Semantic value stack (contains values of tokens and semantic action results) */
429
427
  protected array $semStack;
430
428
 
431
- /** @var Token[] Start attribute stack */
429
+ /** @var array<int, ?Token> Start attribute stack */
432
430
  protected array $startTokenStack;
433
431
 
434
432
 
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Compiler;
11
9
 
12
10
  use Latte\ContentType;
@@ -31,10 +29,11 @@ final class TemplateGenerator
31
29
 
32
30
  /**
33
31
  * Builds template class.
32
+ * @param array<string, bool> $features
34
33
  */
35
- public function buildClass(Nodes\TemplateNode $node, bool $migrationWarnings): void
34
+ public function buildClass(Nodes\TemplateNode $node, array $features = []): void
36
35
  {
37
- $context = new PrintContext($node->contentType, $migrationWarnings);
36
+ $context = new PrintContext($node->contentType, $features);
38
37
  $this->generateBase($node, $context);
39
38
  $this->generateBlocks($context);
40
39
  }
@@ -47,11 +46,11 @@ final class TemplateGenerator
47
46
  {
48
47
  $members = [];
49
48
  foreach ($this->constants as $name => $value) {
50
- $members[] = "\tpublic const $name = " . PhpHelpers::dump($value, true) . ';';
49
+ $members[] = "\tpublic const $name = " . PhpHelpers::dump($value, multiline: true) . ';';
51
50
  }
52
51
 
53
52
  foreach ($this->properties as $name => $value) {
54
- $members[] = "\tpublic $$name = " . PhpHelpers::dump($value, true) . ';';
53
+ $members[] = "\tpublic $$name = " . PhpHelpers::dump($value, multiline: true) . ';';
55
54
  }
56
55
 
57
56
  foreach (array_filter($this->methods) as $name => $method) {
@@ -87,7 +86,7 @@ final class TemplateGenerator
87
86
  $node->head,
88
87
  fn(Node $node) => $node instanceof Nodes\TextNode ? new Nodes\NopNode : $node,
89
88
  );
90
- $code = $head->print($context);
89
+ $code = $head?->print($context) ?? '';
91
90
  if ($code || $context->paramsExtraction) {
92
91
  $code .= 'return get_defined_vars();';
93
92
  $code = self::buildParams($code, $context->paramsExtraction, '$this->params', $context);
@@ -100,13 +99,15 @@ final class TemplateGenerator
100
99
  }
101
100
 
102
101
 
103
- /** @param Block[] $blocks */
104
102
  private function generateBlocks(PrintContext $context): void
105
103
  {
106
104
  $contentType = $context->getEscaper()->getContentType();
107
105
  foreach ($context->blocks as $block) {
108
- if (!$block->isDynamic()) {
109
- $meta[$block->layer][$block->name->value] = $contentType === $block->escaping
106
+ $name = $block->name;
107
+ if (!$block->isDynamic()
108
+ && ($name instanceof Nodes\Php\Scalar\StringNode || $name instanceof Nodes\Php\Scalar\IntegerNode)
109
+ ) {
110
+ $meta[$block->layer][$name->value] = $contentType === $block->escaping
110
111
  ? $block->method
111
112
  : [$block->method, $block->escaping];
112
113
  }
@@ -132,6 +133,7 @@ final class TemplateGenerator
132
133
  }
133
134
 
134
135
 
136
+ /** @param Nodes\Php\ParameterNode[] $params */
135
137
  private function buildParams(string $body, array $params, string $cont, PrintContext $context): string
136
138
  {
137
139
  if (!str_contains($body, '$') && !str_contains($body, 'get_defined_vars()')) {
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Compiler;
11
9
 
12
10
  use Latte\CompileException;
@@ -14,6 +12,9 @@ use function array_merge, array_pop, array_shift, array_unshift, constant, deche
14
12
  use const PREG_UNMATCHED_AS_NULL;
15
13
 
16
14
 
15
+ /**
16
+ * Tokenizes Latte template source code.
17
+ */
17
18
  final class TemplateLexer
18
19
  {
19
20
  public const
@@ -40,6 +41,8 @@ final class TemplateLexer
40
41
 
41
42
  private string $openDelimiter = '';
42
43
  private string $closeDelimiter = '';
44
+
45
+ /** @var array{string, string}[] */
43
46
  private array $delimiters = [];
44
47
  private TagLexer $tagLexer;
45
48
 
@@ -79,6 +82,7 @@ final class TemplateLexer
79
82
  }
80
83
 
81
84
 
85
+ /** @return Token[] */
82
86
  private function statePlain(): array
83
87
  {
84
88
  return $this->match('~
@@ -93,6 +97,7 @@ final class TemplateLexer
93
97
  }
94
98
 
95
99
 
100
+ /** @return Token[] */
96
101
  private function stateLatteTag(): array
97
102
  {
98
103
  $tokens[] = $this->match('~
@@ -106,6 +111,7 @@ final class TemplateLexer
106
111
  }
107
112
 
108
113
 
114
+ /** @return Token[] */
109
115
  private function stateLatteContent(): array
110
116
  {
111
117
  $tokens[] = $this->tagLexer->tokenizePartially($this->input, $this->position);
@@ -120,6 +126,7 @@ final class TemplateLexer
120
126
  }
121
127
 
122
128
 
129
+ /** @return Token[] */
123
130
  private function stateLatteComment(): array
124
131
  {
125
132
  return $this->match('~
@@ -132,6 +139,7 @@ final class TemplateLexer
132
139
  }
133
140
 
134
141
 
142
+ /** @return Token[] */
135
143
  private function stateHtmlText(): array
136
144
  {
137
145
  return $this->match('~(?J)
@@ -148,6 +156,7 @@ final class TemplateLexer
148
156
  }
149
157
 
150
158
 
159
+ /** @return Token[] */
151
160
  private function stateHtmlTag(): array
152
161
  {
153
162
  return $this->match('~(?J)
@@ -165,6 +174,7 @@ final class TemplateLexer
165
174
  }
166
175
 
167
176
 
177
+ /** @return Token[] */
168
178
  private function stateHtmlQuotedValue(string $quote): array
169
179
  {
170
180
  return $this->match('~
@@ -179,6 +189,7 @@ final class TemplateLexer
179
189
  }
180
190
 
181
191
 
192
+ /** @return Token[] */
182
193
  private function stateHtmlQuotedNAttrValue(string $quote): array
183
194
  {
184
195
  return $this->match('~
@@ -191,6 +202,7 @@ final class TemplateLexer
191
202
  }
192
203
 
193
204
 
205
+ /** @return Token[] */
194
206
  private function stateHtmlRawText(string $tagName): array
195
207
  {
196
208
  return $this->match('~
@@ -206,6 +218,7 @@ final class TemplateLexer
206
218
  }
207
219
 
208
220
 
221
+ /** @return Token[] */
209
222
  private function stateHtmlComment(): array
210
223
  {
211
224
  return $this->match('~(?J)
@@ -220,6 +233,7 @@ final class TemplateLexer
220
233
  }
221
234
 
222
235
 
236
+ /** @return Token[] */
223
237
  private function stateHtmlBogus(): array
224
238
  {
225
239
  return $this->match('~
@@ -257,15 +271,15 @@ final class TemplateLexer
257
271
  }
258
272
 
259
273
 
260
- public function setState(string $state, ...$args): void
274
+ public function setState(string $state, mixed ...$args): void
261
275
  {
262
276
  $this->states[0] = ['name' => $state, 'args' => $args];
263
277
  }
264
278
 
265
279
 
266
- public function pushState(string $state, ...$args): void
280
+ public function pushState(string $state, mixed ...$args): void
267
281
  {
268
- array_unshift($this->states, null);
282
+ array_unshift($this->states, ['name' => '', 'args' => []]);
269
283
  $this->setState($state, ...$args);
270
284
  }
271
285
 
@@ -305,7 +319,7 @@ final class TemplateLexer
305
319
 
306
320
  public function popSyntax(): void
307
321
  {
308
- [$this->openDelimiter, $this->closeDelimiter] = array_pop($this->delimiters);
322
+ [$this->openDelimiter, $this->closeDelimiter] = array_pop($this->delimiters) ?? throw new \LogicException;
309
323
  }
310
324
 
311
325