@vituum/vite-plugin-latte 1.1.0 → 1.2.0
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/latte/PlaceholderFunction.php +2 -2
- package/package.json +1 -1
- package/vendor/autoload.php +1 -1
- package/vendor/composer/autoload_classmap.php +2 -0
- package/vendor/composer/autoload_real.php +4 -4
- package/vendor/composer/autoload_static.php +4 -2
- package/vendor/composer/installed.json +7 -7
- package/vendor/composer/installed.php +5 -5
- package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +11 -2
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +1 -1
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +2 -2
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +11 -21
- package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +1 -1
- package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +2 -2
- package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +275 -280
- package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +4 -4
- package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +10 -2
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +6 -2
- package/vendor/latte/latte/src/Latte/Engine.php +109 -97
- package/vendor/latte/latte/src/Latte/Essential/AuxiliaryIterator.php +46 -0
- package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +42 -25
- package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +76 -72
- package/vendor/latte/latte/src/Latte/Essential/Filters.php +95 -37
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +7 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +25 -3
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +9 -2
- package/vendor/latte/latte/src/Latte/Essential/Passes.php +10 -50
- package/vendor/latte/latte/src/Latte/Helpers.php +3 -1
- package/vendor/latte/latte/src/Latte/Loader.php +1 -0
- package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +1 -2
- package/vendor/latte/latte/src/Latte/Runtime/Filters.php +1 -4
- package/vendor/latte/latte/src/Latte/Runtime/FunctionExecutor.php +68 -0
- package/vendor/latte/latte/src/Latte/Runtime/Template.php +1 -3
|
@@ -9,71 +9,31 @@ declare(strict_types=1);
|
|
|
9
9
|
|
|
10
10
|
namespace Latte\Essential;
|
|
11
11
|
|
|
12
|
-
use Latte;
|
|
13
12
|
use Latte\CompileException;
|
|
14
13
|
use Latte\Compiler\Node;
|
|
15
|
-
use Latte\Compiler\Nodes\AuxiliaryNode;
|
|
16
14
|
use Latte\Compiler\Nodes\Php\Expression;
|
|
17
15
|
use Latte\Compiler\Nodes\Php\Expression\VariableNode;
|
|
18
16
|
use Latte\Compiler\Nodes\Php\NameNode;
|
|
19
17
|
use Latte\Compiler\Nodes\TemplateNode;
|
|
20
18
|
use Latte\Compiler\NodeTraverser;
|
|
21
19
|
use Latte\Compiler\PrintContext;
|
|
22
|
-
use Latte\
|
|
20
|
+
use Latte\Engine;
|
|
23
21
|
|
|
24
22
|
|
|
25
23
|
final class Passes
|
|
26
24
|
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
public static function overwrittenVariablesPass(TemplateNode $node): void
|
|
31
|
-
{
|
|
32
|
-
$vars = [];
|
|
33
|
-
(new NodeTraverser)->traverse($node, function (Node $node) use (&$vars) {
|
|
34
|
-
if ($node instanceof ForeachNode && $node->checkArgs) {
|
|
35
|
-
foreach ([$node->key, $node->value] as $var) {
|
|
36
|
-
if ($var instanceof VariableNode) {
|
|
37
|
-
$vars[$var->name][] = $node->position->line;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
if ($vars) {
|
|
43
|
-
array_unshift($node->head->children, new AuxiliaryNode(fn(PrintContext $context) => $context->format(
|
|
44
|
-
<<<'XX'
|
|
45
|
-
if (!$this->getReferringTemplate() || $this->getReferenceType() === 'extends') {
|
|
46
|
-
foreach (array_intersect_key(%dump, $this->params) as $ʟ_v => $ʟ_l) {
|
|
47
|
-
trigger_error("Variable \$$ʟ_v overwritten in foreach on line $ʟ_l");
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
XX,
|
|
52
|
-
array_map(fn($l) => implode(', ', $l), $vars),
|
|
53
|
-
)));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Move TemplatePrintNode to head.
|
|
60
|
-
*/
|
|
61
|
-
public static function moveTemplatePrintToHeadPass(TemplateNode $templateNode): void
|
|
62
|
-
{
|
|
63
|
-
(new NodeTraverser)->traverse($templateNode->main, function (Node $node) use ($templateNode) {
|
|
64
|
-
if ($node instanceof Latte\Essential\Nodes\TemplatePrintNode) {
|
|
65
|
-
array_unshift($templateNode->head->children, $node);
|
|
66
|
-
return new Latte\Compiler\Nodes\NopNode;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
25
|
+
public function __construct(
|
|
26
|
+
private Engine $engine,
|
|
27
|
+
) {
|
|
69
28
|
}
|
|
70
29
|
|
|
71
30
|
|
|
72
31
|
/**
|
|
73
32
|
* Enable custom functions.
|
|
74
33
|
*/
|
|
75
|
-
public
|
|
34
|
+
public function customFunctionsPass(TemplateNode $node): void
|
|
76
35
|
{
|
|
36
|
+
$functions = $this->engine->getFunctions();
|
|
77
37
|
$names = array_keys($functions);
|
|
78
38
|
$names = array_combine(array_map('strtolower', $names), $names);
|
|
79
39
|
|
|
@@ -87,7 +47,7 @@ final class Passes
|
|
|
87
47
|
}
|
|
88
48
|
|
|
89
49
|
return new Expression\AuxiliaryNode(
|
|
90
|
-
fn(PrintContext $context, ...$args) => '($this->global->fn->' . $orig . ')(' . $context->implode($args) . ')',
|
|
50
|
+
fn(PrintContext $context, ...$args) => '($this->global->fn->' . $orig . ')($this, ' . $context->implode($args) . ')',
|
|
91
51
|
$node->args,
|
|
92
52
|
);
|
|
93
53
|
}
|
|
@@ -96,11 +56,11 @@ final class Passes
|
|
|
96
56
|
|
|
97
57
|
|
|
98
58
|
/**
|
|
99
|
-
* $ʟ_xxx
|
|
59
|
+
* $ʟ_xxx, $GLOBALS and $this are forbidden
|
|
100
60
|
*/
|
|
101
|
-
public
|
|
61
|
+
public function forbiddenVariablesPass(TemplateNode $node): void
|
|
102
62
|
{
|
|
103
|
-
$forbidden = $
|
|
63
|
+
$forbidden = $this->engine->isStrictParsing() ? ['GLOBALS', 'this'] : ['GLOBALS'];
|
|
104
64
|
(new NodeTraverser)->traverse($node, function (Node $node) use ($forbidden) {
|
|
105
65
|
if ($node instanceof VariableNode
|
|
106
66
|
&& is_string($node->name)
|
|
@@ -46,7 +46,9 @@ class Helpers
|
|
|
46
46
|
public static function toReflection($callable): \ReflectionFunctionAbstract
|
|
47
47
|
{
|
|
48
48
|
if (is_string($callable) && strpos($callable, '::')) {
|
|
49
|
-
return
|
|
49
|
+
return PHP_VERSION_ID < 80300
|
|
50
|
+
? new \ReflectionMethod($callable)
|
|
51
|
+
: \ReflectionMethod::createFromMethodName($callable);
|
|
50
52
|
} elseif (is_array($callable)) {
|
|
51
53
|
return new \ReflectionMethod($callable[0], $callable[1]);
|
|
52
54
|
} elseif (is_object($callable) && !$callable instanceof \Closure) {
|
|
@@ -24,9 +24,6 @@ class Filters
|
|
|
24
24
|
/** @deprecated */
|
|
25
25
|
public static string $dateFormat = "j.\u{a0}n.\u{a0}Y";
|
|
26
26
|
|
|
27
|
-
/** @internal use XML syntax? */
|
|
28
|
-
public static bool $xml = false;
|
|
29
|
-
|
|
30
27
|
|
|
31
28
|
/**
|
|
32
29
|
* Escapes string for use everywhere inside HTML (except for comments).
|
|
@@ -259,7 +256,7 @@ class Filters
|
|
|
259
256
|
/**
|
|
260
257
|
* Sanitizes string for use inside href attribute.
|
|
261
258
|
*/
|
|
262
|
-
public static function safeUrl(
|
|
259
|
+
public static function safeUrl($s): string
|
|
263
260
|
{
|
|
264
261
|
$s = $s instanceof HtmlStringable
|
|
265
262
|
? self::convertHtmlToText((string) $s)
|
|
@@ -0,0 +1,68 @@
|
|
|
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\Runtime;
|
|
11
|
+
|
|
12
|
+
use Latte\Helpers;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Functions executor.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
#[\AllowDynamicProperties]
|
|
20
|
+
class FunctionExecutor
|
|
21
|
+
{
|
|
22
|
+
/** @var callable[] */
|
|
23
|
+
private array $_list = [];
|
|
24
|
+
|
|
25
|
+
/** @var bool[] */
|
|
26
|
+
private array $_aware = [];
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Registers run-time function.
|
|
31
|
+
*/
|
|
32
|
+
public function add(string $name, callable $callback): static
|
|
33
|
+
{
|
|
34
|
+
$this->_list[$name] = $callback;
|
|
35
|
+
unset($this->$name, $this->_aware[$name]);
|
|
36
|
+
return $this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns all run-time functions.
|
|
42
|
+
* @return callable[]
|
|
43
|
+
*/
|
|
44
|
+
public function getAll(): array
|
|
45
|
+
{
|
|
46
|
+
return $this->_list;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
public function __get(string $name): callable
|
|
51
|
+
{
|
|
52
|
+
$callback = $this->_list[$name] ?? null;
|
|
53
|
+
if (!$callback) {
|
|
54
|
+
$hint = ($t = Helpers::getSuggestion(array_keys($this->_list), $name))
|
|
55
|
+
? ", did you mean '$t'?"
|
|
56
|
+
: '.';
|
|
57
|
+
throw new \LogicException("Function '$name' is not defined$hint");
|
|
58
|
+
|
|
59
|
+
} elseif (!isset($this->_aware[$name])) {
|
|
60
|
+
$params = Helpers::toReflection($callback)->getParameters();
|
|
61
|
+
$this->_aware[$name] = $params && (string) $params[0]->getType() === Template::class;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return $this->$name = $this->_aware[$name]
|
|
65
|
+
? $callback
|
|
66
|
+
: fn($info, ...$args) => $callback(...$args);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -142,8 +142,6 @@ class Template
|
|
|
142
142
|
$this->parentName = ($this->global->coreParentFinder)($this);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
Filters::$xml = static::ContentType === Latte\ContentType::Xml;
|
|
146
|
-
|
|
147
145
|
if ($this->referenceType === 'import') {
|
|
148
146
|
if ($this->parentName) {
|
|
149
147
|
throw new Latte\RuntimeException('Imported template cannot use {extends} or {layout}, use {import}');
|
|
@@ -172,7 +170,7 @@ class Template
|
|
|
172
170
|
$name = $this->engine->getLoader()->getReferredName($name, $this->name);
|
|
173
171
|
$referred = $referenceType === 'sandbox'
|
|
174
172
|
? (clone $this->engine)->setSandboxMode()->createTemplate($name, $params)
|
|
175
|
-
: $this->engine->createTemplate($name, $params);
|
|
173
|
+
: $this->engine->createTemplate($name, $params, clearCache: false);
|
|
176
174
|
|
|
177
175
|
$referred->referringTemplate = $this;
|
|
178
176
|
$referred->referenceType = $referenceType;
|