@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.
- package/README.md +39 -0
- package/handler.js +9 -0
- package/index.js +138 -0
- package/index.php +173 -0
- package/latte/AssetFilter.php +11 -0
- package/latte/FetchFunction.php +28 -0
- package/latte/IconFilter.php +14 -0
- package/latte/JsonTag.php +64 -0
- package/latte/PlaceholderFunction.php +11 -0
- package/latte/RandomColorFunction.php +14 -0
- package/latte/TelFilter.php +22 -0
- package/package.json +35 -0
- package/vendor/autoload.php +7 -0
- package/vendor/bin/latte-lint +107 -0
- package/vendor/composer/ClassLoader.php +572 -0
- package/vendor/composer/InstalledVersions.php +350 -0
- package/vendor/composer/LICENSE +21 -0
- package/vendor/composer/autoload_classmap.php +183 -0
- package/vendor/composer/autoload_namespaces.php +9 -0
- package/vendor/composer/autoload_psr4.php +9 -0
- package/vendor/composer/autoload_real.php +57 -0
- package/vendor/composer/autoload_static.php +193 -0
- package/vendor/composer/installed.json +93 -0
- package/vendor/composer/installed.php +32 -0
- package/vendor/composer/platform_check.php +26 -0
- package/vendor/latte/latte/bin/latte-lint +29 -0
- package/vendor/latte/latte/composer.json +53 -0
- package/vendor/latte/latte/license.md +60 -0
- package/vendor/latte/latte/ncs.php +14 -0
- package/vendor/latte/latte/ncs.xml +9 -0
- package/vendor/latte/latte/readme.md +21 -0
- package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +114 -0
- package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +99 -0
- package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.panel.phtml +98 -0
- package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.tab.phtml +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Block.php +44 -0
- package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +244 -0
- package/vendor/latte/latte/src/Latte/Compiler/ExpressionBuilder.php +128 -0
- package/vendor/latte/latte/src/Latte/Compiler/Node.php +28 -0
- package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +132 -0
- package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +77 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +27 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +59 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +48 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/BogusTagNode.php +46 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/CommentNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +129 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/QuotedValue.php +53 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/NopNode.php +21 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ComplexTypeNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php +41 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayItemNode.php +52 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +94 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +65 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CloneNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +73 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureUseNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/EmptyNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ErrorSuppressNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FilterCallNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallableNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InRangeNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InstanceofNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +50 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallableNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NotNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PropertyFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallNode.php +55 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallableNode.php +47 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticPropertyFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php +50 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/VariableNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +67 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IdentifierNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IntersectionTypeNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/MatchArmNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +107 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +89 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +35 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ParameterNode.php +54 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/BooleanNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringNode.php +80 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringPartNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/FloatNode.php +63 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +70 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/NullNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/StringNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ScalarNode.php +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/UnionTypeNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +21 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/StatementNode.php +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/TemplateNode.php +34 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/TextNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +227 -0
- package/vendor/latte/latte/src/Latte/Compiler/Position.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +334 -0
- package/vendor/latte/latte/src/Latte/Compiler/Tag.php +117 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +399 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +388 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +580 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +206 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +391 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +448 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +506 -0
- package/vendor/latte/latte/src/Latte/Compiler/Token.php +259 -0
- package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +151 -0
- package/vendor/latte/latte/src/Latte/ContentType.php +22 -0
- package/vendor/latte/latte/src/Latte/Engine.php +591 -0
- package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +160 -0
- package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +232 -0
- package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +232 -0
- package/vendor/latte/latte/src/Latte/Essential/Filters.php +591 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +161 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +98 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +74 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +53 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +134 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DoNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DumpNode.php +58 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +125 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +60 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +91 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +155 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +141 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +82 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +180 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +140 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +94 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NAttrNode.php +105 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +54 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +79 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +84 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/PrintNode.php +70 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +46 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SkipNode.php +71 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +62 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +118 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplateTypeNode.php +38 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TraceNode.php +35 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +104 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +75 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +106 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarTypeNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Passes.php +115 -0
- package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +28 -0
- package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +16 -0
- package/vendor/latte/latte/src/Latte/Essential/Tracer.php +117 -0
- package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +101 -0
- package/vendor/latte/latte/src/Latte/Extension.php +97 -0
- package/vendor/latte/latte/src/Latte/Helpers.php +96 -0
- package/vendor/latte/latte/src/Latte/Loader.php +37 -0
- package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +95 -0
- package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +76 -0
- package/vendor/latte/latte/src/Latte/Policy.php +24 -0
- package/vendor/latte/latte/src/Latte/PositionAwareException.php +50 -0
- package/vendor/latte/latte/src/Latte/Runtime/Block.php +24 -0
- package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +151 -0
- package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +39 -0
- package/vendor/latte/latte/src/Latte/Runtime/Filters.php +234 -0
- package/vendor/latte/latte/src/Latte/Runtime/Html.php +35 -0
- package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +17 -0
- package/vendor/latte/latte/src/Latte/Runtime/Template.php +381 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallableNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallableNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +73 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallNode.php +31 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallableNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +116 -0
- package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +132 -0
- package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +185 -0
- package/vendor/latte/latte/src/Latte/Strict.php +101 -0
- package/vendor/latte/latte/src/Latte/attributes.php +24 -0
- package/vendor/latte/latte/src/Latte/exceptions.php +69 -0
- package/vendor/latte/latte/src/Tools/Linter.php +175 -0
|
@@ -0,0 +1,39 @@
|
|
|
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 UnionTypeNode extends ComplexTypeNode
|
|
17
|
+
{
|
|
18
|
+
public function __construct(
|
|
19
|
+
/** @var array<IdentifierNode|NameNode> */
|
|
20
|
+
public array $types,
|
|
21
|
+
public ?Position $position = null,
|
|
22
|
+
) {
|
|
23
|
+
(function (IdentifierNode|NameNode ...$args) {})(...$types);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
public function print(PrintContext $context): string
|
|
28
|
+
{
|
|
29
|
+
return $context->implode($this->types, '|');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
public function &getIterator(): \Generator
|
|
34
|
+
{
|
|
35
|
+
foreach ($this->types as &$item) {
|
|
36
|
+
yield $item;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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\PrintContext;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class VarLikeIdentifierNode extends IdentifierNode
|
|
16
|
+
{
|
|
17
|
+
public function print(PrintContext $context): string
|
|
18
|
+
{
|
|
19
|
+
return '$' . $this->name;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -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;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
abstract class StatementNode extends AreaNode
|
|
14
|
+
{
|
|
15
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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;
|
|
11
|
+
|
|
12
|
+
use Latte\Compiler\Node;
|
|
13
|
+
use Latte\Compiler\PrintContext;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
final class TemplateNode extends Node
|
|
17
|
+
{
|
|
18
|
+
public FragmentNode $head;
|
|
19
|
+
public FragmentNode $main;
|
|
20
|
+
public string $contentType;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
public function print(PrintContext $context): string
|
|
24
|
+
{
|
|
25
|
+
throw new \LogicException('Cannot directly print TemplateNode');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
public function &getIterator(): \Generator
|
|
30
|
+
{
|
|
31
|
+
yield $this->head;
|
|
32
|
+
yield $this->main;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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;
|
|
11
|
+
|
|
12
|
+
use Latte\Compiler\Position;
|
|
13
|
+
use Latte\Compiler\PrintContext;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TextNode extends AreaNode
|
|
17
|
+
{
|
|
18
|
+
public function __construct(
|
|
19
|
+
public string $content,
|
|
20
|
+
public ?Position $position = null,
|
|
21
|
+
) {
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
public function print(PrintContext $context): string
|
|
26
|
+
{
|
|
27
|
+
return $this->content === ''
|
|
28
|
+
? ''
|
|
29
|
+
: 'echo ' . var_export($this->content, true) . ";\n";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
public function isWhitespace(): bool
|
|
34
|
+
{
|
|
35
|
+
return trim($this->content) === '';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
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;
|
|
11
|
+
|
|
12
|
+
use Latte\CompileException;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* PHP helpers.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
final class PhpHelpers
|
|
20
|
+
{
|
|
21
|
+
/**
|
|
22
|
+
* Optimizes code readability.
|
|
23
|
+
*/
|
|
24
|
+
public static function reformatCode(string $source): string
|
|
25
|
+
{
|
|
26
|
+
$res = '';
|
|
27
|
+
$lastChar = ';';
|
|
28
|
+
$tokens = new \ArrayIterator(token_get_all($source));
|
|
29
|
+
$level = 0;
|
|
30
|
+
|
|
31
|
+
foreach ($tokens as $n => $token) {
|
|
32
|
+
$next = $tokens[$n + 1] ?? [null, ''];
|
|
33
|
+
|
|
34
|
+
if (is_array($token)) {
|
|
35
|
+
[$name, $token] = $token;
|
|
36
|
+
if ($name === T_ELSE || $name === T_ELSEIF) {
|
|
37
|
+
if ($next === ':' && $lastChar === '}') {
|
|
38
|
+
$res .= ';'; // semicolon needed in if(): ... if() ... else:
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
$lastChar = '';
|
|
42
|
+
$res .= $token;
|
|
43
|
+
|
|
44
|
+
} elseif ($name === T_DOC_COMMENT || $name === T_COMMENT) {
|
|
45
|
+
$res .= preg_replace("#\n[ \t]*+(?!\n)#", "\n" . str_repeat("\t", $level), $token);
|
|
46
|
+
|
|
47
|
+
} elseif ($name === T_WHITESPACE) {
|
|
48
|
+
$prev = $tokens[$n - 1];
|
|
49
|
+
$lines = substr_count($token, "\n");
|
|
50
|
+
if ($prev === '}' && in_array($next[0], [T_ELSE, T_ELSEIF, T_CATCH, T_FINALLY], true)) {
|
|
51
|
+
$token = ' ';
|
|
52
|
+
} elseif ($prev === '{' || $prev === '}' || $prev === ';' || $lines) {
|
|
53
|
+
$token = str_repeat("\n", max(1, $lines)) . str_repeat("\t", $level); // indent last line
|
|
54
|
+
} elseif ($prev[0] === T_OPEN_TAG) {
|
|
55
|
+
$token = '';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
$res .= $token;
|
|
59
|
+
|
|
60
|
+
} elseif ($name === T_OBJECT_OPERATOR) {
|
|
61
|
+
$lastChar = '->';
|
|
62
|
+
$res .= $token;
|
|
63
|
+
|
|
64
|
+
} elseif ($name === T_OPEN_TAG) {
|
|
65
|
+
$res .= "<?php\n";
|
|
66
|
+
|
|
67
|
+
} elseif ($name === T_CLOSE_TAG) {
|
|
68
|
+
throw new \LogicException('Unexpected token');
|
|
69
|
+
|
|
70
|
+
} else {
|
|
71
|
+
if (in_array($name, [T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES], true)) {
|
|
72
|
+
$level++;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
$lastChar = '';
|
|
76
|
+
$res .= $token;
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
if ($token === '{' || $token === '[') {
|
|
80
|
+
$level++;
|
|
81
|
+
} elseif ($token === '}' || $token === ']') {
|
|
82
|
+
$level--;
|
|
83
|
+
$res .= "\x08";
|
|
84
|
+
|
|
85
|
+
} elseif ($token === ';') {
|
|
86
|
+
if ($next[0] !== T_WHITESPACE) {
|
|
87
|
+
$token .= "\n" . str_repeat("\t", $level); // indent last line
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
$lastChar = $token;
|
|
92
|
+
$res .= $token;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
$res = str_replace(["\t\x08", "\x08"], '', $res);
|
|
97
|
+
return $res;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
public static function dump(mixed $value, bool $multiline = false): string
|
|
102
|
+
{
|
|
103
|
+
if (is_array($value)) {
|
|
104
|
+
$indexed = $value && array_keys($value) === range(0, count($value) - 1);
|
|
105
|
+
$s = '';
|
|
106
|
+
foreach ($value as $k => $v) {
|
|
107
|
+
$s .= $multiline
|
|
108
|
+
? ($s === '' ? "\n" : '') . "\t" . ($indexed ? '' : self::dump($k) . ' => ') . self::dump($v) . ",\n"
|
|
109
|
+
: ($s === '' ? '' : ', ') . ($indexed ? '' : self::dump($k) . ' => ') . self::dump($v);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return '[' . $s . ']';
|
|
113
|
+
} elseif ($value === null) {
|
|
114
|
+
return 'null';
|
|
115
|
+
} else {
|
|
116
|
+
return var_export($value, true);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
public static function optimizeEcho(string $source): string
|
|
122
|
+
{
|
|
123
|
+
$res = '';
|
|
124
|
+
$tokens = token_get_all($source);
|
|
125
|
+
$start = null;
|
|
126
|
+
|
|
127
|
+
for ($i = 0; $i < \count($tokens); $i++) {
|
|
128
|
+
$token = $tokens[$i];
|
|
129
|
+
if ($token[0] === T_ECHO) {
|
|
130
|
+
if (!$start) {
|
|
131
|
+
$str = '';
|
|
132
|
+
$start = strlen($res);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
} elseif ($start && $token[0] === T_CONSTANT_ENCAPSED_STRING && $token[1][0] === "'") {
|
|
136
|
+
$str .= stripslashes(substr($token[1], 1, -1));
|
|
137
|
+
|
|
138
|
+
} elseif ($start && $token === ';') {
|
|
139
|
+
if ($str !== '') {
|
|
140
|
+
$res = substr_replace(
|
|
141
|
+
$res,
|
|
142
|
+
'echo ' . ($str === "\n" ? '"\n"' : var_export($str, true)),
|
|
143
|
+
$start,
|
|
144
|
+
strlen($res) - $start,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
} elseif ($token[0] !== T_WHITESPACE) {
|
|
149
|
+
$start = null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
$res .= is_array($token) ? $token[1] : $token;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return $res;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
public static function decodeNumber(string $str, &$base = null): int|float|null
|
|
160
|
+
{
|
|
161
|
+
$str = str_replace('_', '', $str);
|
|
162
|
+
|
|
163
|
+
if ($str[0] !== '0' || $str === '0') {
|
|
164
|
+
$base = 10;
|
|
165
|
+
return $str + 0;
|
|
166
|
+
} elseif ($str[1] === 'x' || $str[1] === 'X') {
|
|
167
|
+
$base = 16;
|
|
168
|
+
return hexdec($str);
|
|
169
|
+
} elseif ($str[1] === 'b' || $str[1] === 'B') {
|
|
170
|
+
$base = 2;
|
|
171
|
+
return bindec($str);
|
|
172
|
+
} elseif (strpbrk($str, '89')) {
|
|
173
|
+
return null;
|
|
174
|
+
} else {
|
|
175
|
+
$base = 8;
|
|
176
|
+
return octdec($str);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
public static function decodeEscapeSequences(string $str, ?string $quote): string
|
|
182
|
+
{
|
|
183
|
+
if ($quote !== null) {
|
|
184
|
+
$str = str_replace('\\' . $quote, $quote, $str);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return preg_replace_callback(
|
|
188
|
+
'~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}|u\{([0-9a-fA-F]+)\})~',
|
|
189
|
+
function ($matches) {
|
|
190
|
+
$ch = $matches[1];
|
|
191
|
+
$replacements = [
|
|
192
|
+
'\\' => '\\',
|
|
193
|
+
'$' => '$',
|
|
194
|
+
'n' => "\n",
|
|
195
|
+
'r' => "\r",
|
|
196
|
+
't' => "\t",
|
|
197
|
+
'f' => "\f",
|
|
198
|
+
'v' => "\v",
|
|
199
|
+
'e' => "\x1B",
|
|
200
|
+
];
|
|
201
|
+
if (isset($replacements[$ch])) {
|
|
202
|
+
return $replacements[$ch];
|
|
203
|
+
} elseif ($ch[0] === 'x' || $ch[0] === 'X') {
|
|
204
|
+
return chr(hexdec(substr($ch, 1)));
|
|
205
|
+
} elseif ($ch[0] === 'u') {
|
|
206
|
+
return self::codePointToUtf8(hexdec($matches[2]));
|
|
207
|
+
} else {
|
|
208
|
+
return chr(octdec($ch));
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
$str,
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
private static function codePointToUtf8(int $num): string
|
|
217
|
+
{
|
|
218
|
+
return match (true) {
|
|
219
|
+
$num <= 0x7F => chr($num),
|
|
220
|
+
$num <= 0x7FF => chr(($num >> 6) + 0xC0) . chr(($num & 0x3F) + 0x80),
|
|
221
|
+
$num <= 0xFFFF => chr(($num >> 12) + 0xE0) . chr((($num >> 6) & 0x3F) + 0x80) . chr(($num & 0x3F) + 0x80),
|
|
222
|
+
$num <= 0x1FFFFF => chr(($num >> 18) + 0xF0) . chr((($num >> 12) & 0x3F) + 0x80)
|
|
223
|
+
. chr((($num >> 6) & 0x3F) + 0x80) . chr(($num & 0x3F) + 0x80),
|
|
224
|
+
default => throw new CompileException('Invalid UTF-8 codepoint escape sequence: Codepoint too large'),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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;
|
|
11
|
+
|
|
12
|
+
use Latte;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
final class Position
|
|
16
|
+
{
|
|
17
|
+
use Latte\Strict;
|
|
18
|
+
|
|
19
|
+
public function __construct(
|
|
20
|
+
public /*readonly*/ int $line,
|
|
21
|
+
public /*readonly*/ int $column,
|
|
22
|
+
public /*readonly*/ int $offset = 0,
|
|
23
|
+
) {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
public function advance(string $str): self
|
|
28
|
+
{
|
|
29
|
+
if ($lines = substr_count($str, "\n")) {
|
|
30
|
+
return new self(
|
|
31
|
+
$this->line + $lines,
|
|
32
|
+
strlen($str) - strrpos($str, "\n"),
|
|
33
|
+
$this->offset + strlen($str),
|
|
34
|
+
);
|
|
35
|
+
} else {
|
|
36
|
+
return new self(
|
|
37
|
+
$this->line,
|
|
38
|
+
$this->column + strlen($str),
|
|
39
|
+
$this->offset + strlen($str),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|