@vituum/vite-plugin-latte 0.1.8

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 (201) hide show
  1. package/README.md +39 -0
  2. package/handler.js +9 -0
  3. package/index.js +138 -0
  4. package/index.php +173 -0
  5. package/latte/AssetFilter.php +11 -0
  6. package/latte/FetchFunction.php +28 -0
  7. package/latte/IconFilter.php +14 -0
  8. package/latte/JsonTag.php +64 -0
  9. package/latte/PlaceholderFunction.php +11 -0
  10. package/latte/RandomColorFunction.php +14 -0
  11. package/latte/TelFilter.php +22 -0
  12. package/package.json +35 -0
  13. package/vendor/autoload.php +7 -0
  14. package/vendor/bin/latte-lint +107 -0
  15. package/vendor/composer/ClassLoader.php +572 -0
  16. package/vendor/composer/InstalledVersions.php +350 -0
  17. package/vendor/composer/LICENSE +21 -0
  18. package/vendor/composer/autoload_classmap.php +183 -0
  19. package/vendor/composer/autoload_namespaces.php +9 -0
  20. package/vendor/composer/autoload_psr4.php +9 -0
  21. package/vendor/composer/autoload_real.php +57 -0
  22. package/vendor/composer/autoload_static.php +193 -0
  23. package/vendor/composer/installed.json +93 -0
  24. package/vendor/composer/installed.php +32 -0
  25. package/vendor/composer/platform_check.php +26 -0
  26. package/vendor/latte/latte/bin/latte-lint +29 -0
  27. package/vendor/latte/latte/composer.json +53 -0
  28. package/vendor/latte/latte/license.md +60 -0
  29. package/vendor/latte/latte/ncs.php +14 -0
  30. package/vendor/latte/latte/ncs.xml +9 -0
  31. package/vendor/latte/latte/readme.md +21 -0
  32. package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +114 -0
  33. package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +99 -0
  34. package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.panel.phtml +98 -0
  35. package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.tab.phtml +15 -0
  36. package/vendor/latte/latte/src/Latte/Compiler/Block.php +44 -0
  37. package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +244 -0
  38. package/vendor/latte/latte/src/Latte/Compiler/ExpressionBuilder.php +128 -0
  39. package/vendor/latte/latte/src/Latte/Compiler/Node.php +28 -0
  40. package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +132 -0
  41. package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +77 -0
  42. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +17 -0
  43. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +27 -0
  44. package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +59 -0
  45. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +48 -0
  46. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/BogusTagNode.php +46 -0
  47. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/CommentNode.php +39 -0
  48. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +129 -0
  49. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/QuotedValue.php +53 -0
  50. package/vendor/latte/latte/src/Latte/Compiler/Nodes/NopNode.php +21 -0
  51. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +45 -0
  52. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ComplexTypeNode.php +17 -0
  53. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php +41 -0
  54. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayItemNode.php +52 -0
  55. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +94 -0
  56. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +39 -0
  57. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +45 -0
  58. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +65 -0
  59. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +43 -0
  60. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +42 -0
  61. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CloneNode.php +36 -0
  62. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +73 -0
  63. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureUseNode.php +37 -0
  64. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +37 -0
  65. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/EmptyNode.php +36 -0
  66. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ErrorSuppressNode.php +36 -0
  67. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FilterCallNode.php +39 -0
  68. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +45 -0
  69. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallableNode.php +39 -0
  70. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InRangeNode.php +42 -0
  71. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InstanceofNode.php +40 -0
  72. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +40 -0
  73. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +49 -0
  74. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +50 -0
  75. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallableNode.php +42 -0
  76. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +45 -0
  77. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NotNode.php +36 -0
  78. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +43 -0
  79. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +43 -0
  80. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PropertyFetchNode.php +42 -0
  81. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallNode.php +55 -0
  82. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallableNode.php +47 -0
  83. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticPropertyFetchNode.php +42 -0
  84. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php +50 -0
  85. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +45 -0
  86. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/VariableNode.php +40 -0
  87. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +17 -0
  88. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +67 -0
  89. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IdentifierNode.php +36 -0
  90. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IntersectionTypeNode.php +39 -0
  91. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/MatchArmNode.php +45 -0
  92. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +107 -0
  93. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +89 -0
  94. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +35 -0
  95. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ParameterNode.php +54 -0
  96. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/BooleanNode.php +30 -0
  97. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringNode.php +80 -0
  98. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringPartNode.php +30 -0
  99. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/FloatNode.php +63 -0
  100. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +70 -0
  101. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/NullNode.php +29 -0
  102. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/StringNode.php +40 -0
  103. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ScalarNode.php +15 -0
  104. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php +29 -0
  105. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/UnionTypeNode.php +39 -0
  106. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +21 -0
  107. package/vendor/latte/latte/src/Latte/Compiler/Nodes/StatementNode.php +15 -0
  108. package/vendor/latte/latte/src/Latte/Compiler/Nodes/TemplateNode.php +34 -0
  109. package/vendor/latte/latte/src/Latte/Compiler/Nodes/TextNode.php +37 -0
  110. package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +227 -0
  111. package/vendor/latte/latte/src/Latte/Compiler/Position.php +43 -0
  112. package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +334 -0
  113. package/vendor/latte/latte/src/Latte/Compiler/Tag.php +117 -0
  114. package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +399 -0
  115. package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +388 -0
  116. package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +580 -0
  117. package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +206 -0
  118. package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +391 -0
  119. package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +448 -0
  120. package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +506 -0
  121. package/vendor/latte/latte/src/Latte/Compiler/Token.php +259 -0
  122. package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +151 -0
  123. package/vendor/latte/latte/src/Latte/ContentType.php +22 -0
  124. package/vendor/latte/latte/src/Latte/Engine.php +591 -0
  125. package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +160 -0
  126. package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +232 -0
  127. package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +232 -0
  128. package/vendor/latte/latte/src/Latte/Essential/Filters.php +591 -0
  129. package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +161 -0
  130. package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +98 -0
  131. package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +74 -0
  132. package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +53 -0
  133. package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +134 -0
  134. package/vendor/latte/latte/src/Latte/Essential/Nodes/DoNode.php +49 -0
  135. package/vendor/latte/latte/src/Latte/Essential/Nodes/DumpNode.php +58 -0
  136. package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +125 -0
  137. package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +60 -0
  138. package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +81 -0
  139. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +91 -0
  140. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +155 -0
  141. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +141 -0
  142. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +82 -0
  143. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +180 -0
  144. package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +49 -0
  145. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +140 -0
  146. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +81 -0
  147. package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +94 -0
  148. package/vendor/latte/latte/src/Latte/Essential/Nodes/NAttrNode.php +105 -0
  149. package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +54 -0
  150. package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +79 -0
  151. package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +84 -0
  152. package/vendor/latte/latte/src/Latte/Essential/Nodes/PrintNode.php +70 -0
  153. package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +46 -0
  154. package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +37 -0
  155. package/vendor/latte/latte/src/Latte/Essential/Nodes/SkipNode.php +71 -0
  156. package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +62 -0
  157. package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +118 -0
  158. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +39 -0
  159. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplateTypeNode.php +38 -0
  160. package/vendor/latte/latte/src/Latte/Essential/Nodes/TraceNode.php +35 -0
  161. package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +104 -0
  162. package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +75 -0
  163. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +106 -0
  164. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +40 -0
  165. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarTypeNode.php +36 -0
  166. package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +81 -0
  167. package/vendor/latte/latte/src/Latte/Essential/Passes.php +115 -0
  168. package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +28 -0
  169. package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +16 -0
  170. package/vendor/latte/latte/src/Latte/Essential/Tracer.php +117 -0
  171. package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +101 -0
  172. package/vendor/latte/latte/src/Latte/Extension.php +97 -0
  173. package/vendor/latte/latte/src/Latte/Helpers.php +96 -0
  174. package/vendor/latte/latte/src/Latte/Loader.php +37 -0
  175. package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +95 -0
  176. package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +76 -0
  177. package/vendor/latte/latte/src/Latte/Policy.php +24 -0
  178. package/vendor/latte/latte/src/Latte/PositionAwareException.php +50 -0
  179. package/vendor/latte/latte/src/Latte/Runtime/Block.php +24 -0
  180. package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +151 -0
  181. package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +39 -0
  182. package/vendor/latte/latte/src/Latte/Runtime/Filters.php +234 -0
  183. package/vendor/latte/latte/src/Latte/Runtime/Html.php +35 -0
  184. package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +17 -0
  185. package/vendor/latte/latte/src/Latte/Runtime/Template.php +381 -0
  186. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +30 -0
  187. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallableNode.php +29 -0
  188. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +32 -0
  189. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallableNode.php +30 -0
  190. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +32 -0
  191. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +73 -0
  192. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallNode.php +31 -0
  193. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallableNode.php +30 -0
  194. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +32 -0
  195. package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +116 -0
  196. package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +132 -0
  197. package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +185 -0
  198. package/vendor/latte/latte/src/Latte/Strict.php +101 -0
  199. package/vendor/latte/latte/src/Latte/attributes.php +24 -0
  200. package/vendor/latte/latte/src/Latte/exceptions.php +69 -0
  201. package/vendor/latte/latte/src/Tools/Linter.php +175 -0
@@ -0,0 +1,107 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php;
11
+
12
+ use Latte\Compiler\Node;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class ModifierNode extends Node
18
+ {
19
+ public function __construct(
20
+ /** @var FilterNode[] */
21
+ public array $filters,
22
+ public bool $escape = false,
23
+ public bool $check = true,
24
+ public ?Position $position = null,
25
+ ) {
26
+ (function (FilterNode ...$args) {})(...$filters);
27
+ }
28
+
29
+
30
+ public function hasFilter(string $name): bool
31
+ {
32
+ foreach ($this->filters as $filter) {
33
+ if ($filter->name->name === $name) {
34
+ return true;
35
+ }
36
+ }
37
+
38
+ return false;
39
+ }
40
+
41
+
42
+ public function print(PrintContext $context): string
43
+ {
44
+ throw new \LogicException('Cannot directly print ModifierNode');
45
+ }
46
+
47
+
48
+ public function printSimple(PrintContext $context, string $expr): string
49
+ {
50
+ $escape = $this->escape;
51
+ $check = $this->check;
52
+ foreach ($this->filters as $filter) {
53
+ $name = $filter->name->name;
54
+ if (['nocheck' => 1, 'noCheck' => 1][$name] ?? null) {
55
+ $check = false;
56
+ } elseif ($name === 'noescape') {
57
+ $escape = false;
58
+ } else {
59
+ if (['datastream' => 1, 'dataStream' => 1][$name] ?? null) {
60
+ $check = false;
61
+ }
62
+ $expr = $filter->printSimple($context, $expr);
63
+ }
64
+ }
65
+
66
+ $escaper = $context->getEscaper();
67
+ if ($check) {
68
+ $expr = $escaper->check($expr);
69
+ }
70
+
71
+ if ($escape) {
72
+ $expr = $escaper->escape($expr);
73
+ }
74
+
75
+ return $expr;
76
+ }
77
+
78
+
79
+ public function printContentAware(PrintContext $context, string $expr): string
80
+ {
81
+ foreach ($this->filters as $filter) {
82
+ $name = $filter->name->name;
83
+ if ($name === 'noescape') {
84
+ $noescape = true;
85
+ } else {
86
+ $expr = $filter->printContentAware($context, $expr);
87
+ }
88
+ }
89
+
90
+ if ($this->escape && empty($noescape)) {
91
+ $expr = 'LR\Filters::convertTo($ʟ_fi, '
92
+ . var_export($context->getEscaper()->export(), true) . ', '
93
+ . $expr
94
+ . ')';
95
+ }
96
+
97
+ return $expr;
98
+ }
99
+
100
+
101
+ public function &getIterator(): \Generator
102
+ {
103
+ foreach ($this->filters as &$filter) {
104
+ yield $filter;
105
+ }
106
+ }
107
+ }
@@ -0,0 +1,89 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php;
11
+
12
+ use Latte\Compiler\Node;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class NameNode extends Node
18
+ {
19
+ public const
20
+ KindNormal = 1,
21
+ KindFullyQualified = 2;
22
+
23
+ /** @var string[] */
24
+ public array $parts;
25
+
26
+
27
+ public function __construct(
28
+ string|array $name,
29
+ public int $kind = self::KindNormal,
30
+ public ?Position $position = null,
31
+ ) {
32
+ if ($name === '' || $name === []) {
33
+ throw new \InvalidArgumentException('Name cannot be empty');
34
+
35
+ } elseif (is_string($name)) {
36
+ if (str_starts_with($name, '\\')) {
37
+ $this->kind = self::KindFullyQualified;
38
+ $name = substr($name, 1);
39
+ } elseif (str_starts_with($name, 'namespace\\')) {
40
+ throw new \InvalidArgumentException('Relative name is not supported');
41
+ } else {
42
+ $this->kind = self::KindNormal;
43
+ }
44
+ $this->parts = explode('\\', $name);
45
+
46
+ } else {
47
+ $this->parts = $name;
48
+ }
49
+ }
50
+
51
+
52
+ private function isKeyword(): bool
53
+ {
54
+ static $keywords;
55
+ $keywords ??= array_flip([
56
+ 'include', 'include_once', 'eval', 'require', 'require_once', 'or', 'xor', 'and',
57
+ 'instanceof', 'new', 'clone', 'exit', 'if', 'elseif', 'else', 'endif', 'echo', 'do', 'while',
58
+ 'endwhile', 'for', 'endfor', 'foreach', 'endforeach', 'declare', 'enddeclare', 'as', 'try', 'catch',
59
+ 'finally', 'throw', 'use', 'insteadof', 'global', 'var', 'unset', 'isset', 'empty', 'continue', 'goto',
60
+ 'function', 'const', 'return', 'print', 'yield', 'list', 'switch', 'endswitch', 'case', 'default',
61
+ 'break', 'array', 'callable', 'extends', 'implements', 'namespace', 'trait', 'interface', 'class',
62
+ 'static', 'abstract', 'final', 'private', 'protected', 'public', 'fn', 'match', 'self', 'parent',
63
+ ]);
64
+ return count($this->parts) === 1
65
+ && (isset($keywords[strtolower($this->parts[0])]) || str_starts_with($this->parts[0], '__'));
66
+ }
67
+
68
+
69
+ public function print(PrintContext $context): string
70
+ {
71
+ return $this->toCodeString();
72
+ }
73
+
74
+
75
+ public function __toString(): string
76
+ {
77
+ return implode('\\', $this->parts);
78
+ }
79
+
80
+
81
+ public function toCodeString(): string
82
+ {
83
+ $prefix = match ($this->kind) {
84
+ self::KindNormal => $this->isKeyword() ? 'namespace\\' : '',
85
+ self::KindFullyQualified => '\\',
86
+ };
87
+ return $prefix . implode('\\', $this->parts);
88
+ }
89
+ }
@@ -0,0 +1,35 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php;
11
+
12
+ use Latte\Compiler\Position;
13
+ use Latte\Compiler\PrintContext;
14
+
15
+
16
+ class NullableTypeNode extends ComplexTypeNode
17
+ {
18
+ public function __construct(
19
+ public IdentifierNode|NameNode $type,
20
+ public ?Position $position = null,
21
+ ) {
22
+ }
23
+
24
+
25
+ public function print(PrintContext $context): string
26
+ {
27
+ return '?' . $this->type->print($context);
28
+ }
29
+
30
+
31
+ public function &getIterator(): \Generator
32
+ {
33
+ yield $this->type;
34
+ }
35
+ }
@@ -0,0 +1,54 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php;
11
+
12
+ use Latte\CompileException;
13
+ use Latte\Compiler\Node;
14
+ use Latte\Compiler\Position;
15
+ use Latte\Compiler\PrintContext;
16
+
17
+
18
+ class ParameterNode extends Node
19
+ {
20
+ public function __construct(
21
+ public Expression\VariableNode $var,
22
+ public ?ExpressionNode $default = null,
23
+ public IdentifierNode|NameNode|ComplexTypeNode|null $type = null,
24
+ public bool $byRef = false,
25
+ public bool $variadic = false,
26
+ public ?Position $position = null,
27
+ ) {
28
+ if ($variadic && $default !== null) {
29
+ throw new CompileException('Variadic parameter cannot have a default value', $position);
30
+ }
31
+ }
32
+
33
+
34
+ public function print(PrintContext $context): string
35
+ {
36
+ return ($this->type ? $this->type->print($context) . ' ' : '')
37
+ . ($this->byRef ? '&' : '')
38
+ . ($this->variadic ? '...' : '')
39
+ . $this->var->print($context)
40
+ . ($this->default ? ' = ' . $this->default->print($context) : '');
41
+ }
42
+
43
+
44
+ public function &getIterator(): \Generator
45
+ {
46
+ if ($this->type) {
47
+ yield $this->type;
48
+ }
49
+ yield $this->var;
50
+ if ($this->default) {
51
+ yield $this->default;
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,30 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Scalar;
11
+
12
+ use Latte\Compiler\Nodes\Php\ScalarNode;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class BooleanNode extends ScalarNode
18
+ {
19
+ public function __construct(
20
+ public bool $value,
21
+ public ?Position $position = null,
22
+ ) {
23
+ }
24
+
25
+
26
+ public function print(PrintContext $context): string
27
+ {
28
+ return $this->value ? 'true' : 'false';
29
+ }
30
+ }
@@ -0,0 +1,80 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Scalar;
11
+
12
+ use Latte\Compiler\Nodes\Php\Expression;
13
+ use Latte\Compiler\Nodes\Php\ExpressionNode;
14
+ use Latte\Compiler\Nodes\Php\ScalarNode;
15
+ use Latte\Compiler\PhpHelpers;
16
+ use Latte\Compiler\Position;
17
+ use Latte\Compiler\PrintContext;
18
+
19
+
20
+ class EncapsedStringNode extends ScalarNode
21
+ {
22
+ public function __construct(
23
+ /** @var ExpressionNode[] */
24
+ public array $parts,
25
+ public ?Position $position = null,
26
+ ) {
27
+ }
28
+
29
+
30
+ /** @param ExpressionNode[] $parts */
31
+ public static function parse(array $parts, Position $position): static
32
+ {
33
+ foreach ($parts as $part) {
34
+ if ($part instanceof EncapsedStringPartNode) {
35
+ $part->value = PhpHelpers::decodeEscapeSequences($part->value, '"');
36
+ }
37
+ }
38
+
39
+ return new static($parts, $position);
40
+ }
41
+
42
+
43
+ public function print(PrintContext $context): string
44
+ {
45
+ $s = '';
46
+ $expr = false;
47
+ foreach ($this->parts as $part) {
48
+ if ($part instanceof EncapsedStringPartNode) {
49
+ $s .= substr($context->encodeString($part->value, '"'), 1, -1);
50
+ continue;
51
+ }
52
+
53
+ $partStr = $part->print($context);
54
+ if ($partStr[0] === '$' &&
55
+ ($part instanceof Expression\VariableNode
56
+ || $part instanceof Expression\PropertyFetchNode
57
+ || $part instanceof Expression\MethodCallNode
58
+ || $part instanceof Expression\ArrayAccessNode
59
+ )) {
60
+ $s .= '{' . $partStr . '}';
61
+
62
+ } else {
63
+ $s .= '" . (' . $partStr . ') . "';
64
+ $expr = true;
65
+ }
66
+ }
67
+
68
+ return $expr
69
+ ? '("' . $s . '")'
70
+ : '"' . $s . '"';
71
+ }
72
+
73
+
74
+ public function &getIterator(): \Generator
75
+ {
76
+ foreach ($this->parts as &$item) {
77
+ yield $item;
78
+ }
79
+ }
80
+ }
@@ -0,0 +1,30 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Scalar;
11
+
12
+ use Latte\Compiler\Nodes\Php\ScalarNode;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class EncapsedStringPartNode extends ScalarNode
18
+ {
19
+ public function __construct(
20
+ public string $value,
21
+ public ?Position $position = null,
22
+ ) {
23
+ }
24
+
25
+
26
+ public function print(PrintContext $context): string
27
+ {
28
+ throw new \LogicException('Cannot directly print EncapsedStringPart');
29
+ }
30
+ }
@@ -0,0 +1,63 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Scalar;
11
+
12
+ use Latte\Compiler\Nodes\Php\ScalarNode;
13
+ use Latte\Compiler\PhpHelpers;
14
+ use Latte\Compiler\Position;
15
+ use Latte\Compiler\PrintContext;
16
+
17
+
18
+ class FloatNode extends ScalarNode
19
+ {
20
+ public function __construct(
21
+ public float $value,
22
+ public ?Position $position = null,
23
+ ) {
24
+ }
25
+
26
+
27
+ public static function parse(string $str, Position $position): static
28
+ {
29
+ return strpbrk($str, '.eE') === false
30
+ ? new static((float) PhpHelpers::decodeNumber($str), $position)
31
+ : new static((float) str_replace('_', '', $str), $position);
32
+ }
33
+
34
+
35
+ public function print(PrintContext $context): string
36
+ {
37
+ if (!is_finite($this->value)) {
38
+ if ($this->value === \INF) {
39
+ return '\INF';
40
+ } elseif ($this->value === -\INF) {
41
+ return '-\INF';
42
+ } else {
43
+ return '\NAN';
44
+ }
45
+ }
46
+
47
+ // Try to find a short full-precision representation
48
+ $stringValue = sprintf('%.16G', $this->value);
49
+ if ($this->value !== (float) $stringValue) {
50
+ $stringValue = sprintf('%.17G', $this->value);
51
+ }
52
+
53
+ // %G is locale dependent and there exists no locale-independent alternative. We don't want
54
+ // mess with switching locales here, so let's assume that a comma is the only non-standard
55
+ // decimal separator we may encounter...
56
+ $stringValue = str_replace(',', '.', $stringValue);
57
+
58
+ // ensure that number is really printed as float
59
+ return preg_match('/^-?[0-9]+$/', $stringValue)
60
+ ? $stringValue . '.0'
61
+ : $stringValue;
62
+ }
63
+ }
@@ -0,0 +1,70 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Scalar;
11
+
12
+ use Latte\CompileException;
13
+ use Latte\Compiler\Nodes\Php\ScalarNode;
14
+ use Latte\Compiler\PhpHelpers;
15
+ use Latte\Compiler\Position;
16
+ use Latte\Compiler\PrintContext;
17
+
18
+
19
+ class IntegerNode extends ScalarNode
20
+ {
21
+ public const KindBinary = 2;
22
+ public const KindOctal = 8;
23
+ public const KindDecimal = 10;
24
+ public const KindHexa = 16;
25
+
26
+
27
+ public function __construct(
28
+ public int $value,
29
+ public int $kind = self::KindDecimal,
30
+ public ?Position $position = null,
31
+ ) {
32
+ }
33
+
34
+
35
+ public static function parse(string $str, Position $position): static
36
+ {
37
+ $num = PhpHelpers::decodeNumber($str, $base);
38
+ if ($num === null) {
39
+ throw new CompileException('Invalid numeric literal', $position);
40
+ }
41
+ return new static($num, $base, $position);
42
+ }
43
+
44
+
45
+ public function print(PrintContext $context): string
46
+ {
47
+ if ($this->value === -\PHP_INT_MAX - 1) {
48
+ // PHP_INT_MIN cannot be represented as a literal, because the sign is not part of the literal
49
+ return '(-' . \PHP_INT_MAX . '-1)';
50
+
51
+ } elseif ($this->kind === self::KindDecimal) {
52
+ return (string) $this->value;
53
+ }
54
+
55
+ if ($this->value < 0) {
56
+ $sign = '-';
57
+ $str = (string) -$this->value;
58
+ } else {
59
+ $sign = '';
60
+ $str = (string) $this->value;
61
+ }
62
+
63
+ return match ($this->kind) {
64
+ self::KindBinary => $sign . '0b' . base_convert($str, 10, 2),
65
+ self::KindOctal => $sign . '0' . base_convert($str, 10, 8),
66
+ self::KindHexa => $sign . '0x' . base_convert($str, 10, 16),
67
+ default => throw new \Exception('Invalid number kind'),
68
+ };
69
+ }
70
+ }
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Scalar;
11
+
12
+ use Latte\Compiler\Nodes\Php\ScalarNode;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class NullNode extends ScalarNode
18
+ {
19
+ public function __construct(
20
+ public ?Position $position = null,
21
+ ) {
22
+ }
23
+
24
+
25
+ public function print(PrintContext $context): string
26
+ {
27
+ return 'null';
28
+ }
29
+ }
@@ -0,0 +1,40 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Scalar;
11
+
12
+ use Latte\Compiler\Nodes\Php\ScalarNode;
13
+ use Latte\Compiler\PhpHelpers;
14
+ use Latte\Compiler\Position;
15
+ use Latte\Compiler\PrintContext;
16
+
17
+
18
+ class StringNode extends ScalarNode
19
+ {
20
+ public function __construct(
21
+ public string $value,
22
+ public ?Position $position = null,
23
+ ) {
24
+ }
25
+
26
+
27
+ public static function parse(string $str, Position $position): static
28
+ {
29
+ $str = $str[0] === "'"
30
+ ? strtr(substr($str, 1, -1), ['\\\\' => '\\', "\\'" => "'"])
31
+ : PhpHelpers::decodeEscapeSequences(substr($str, 1, -1), '"');
32
+ return new static($str, $position);
33
+ }
34
+
35
+
36
+ public function print(PrintContext $context): string
37
+ {
38
+ return $context->encodeString($this->value);
39
+ }
40
+ }
@@ -0,0 +1,15 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php;
11
+
12
+
13
+ abstract class ScalarNode extends ExpressionNode
14
+ {
15
+ }
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php;
11
+
12
+ use Latte\Compiler\Position;
13
+ use Latte\Compiler\PrintContext;
14
+
15
+
16
+ class SuperiorTypeNode extends ComplexTypeNode
17
+ {
18
+ public function __construct(
19
+ public string $type,
20
+ public ?Position $position = null,
21
+ ) {
22
+ }
23
+
24
+
25
+ public function print(PrintContext $context): string
26
+ {
27
+ throw new \LogicException('Cannot directly print SuperiorTypeNode');
28
+ }
29
+ }