12
12
namespace Symfony \UX \TwigComponent \Twig ;
13
13
14
14
use Symfony \UX \TwigComponent \BlockStack ;
15
+ use Twig \Error \SyntaxError ;
15
16
use Twig \Node \Expression \AbstractExpression ;
16
17
use Twig \Node \Expression \ArrayExpression ;
17
18
use Twig \Node \Expression \ConstantExpression ;
@@ -33,13 +34,18 @@ final class ComponentTokenParser extends AbstractTokenParser
33
34
public function parse (Token $ token ): Node
34
35
{
35
36
$ stream = $ this ->parser ->getStream ();
37
+
36
38
if (method_exists ($ this ->parser , 'parseExpression ' )) {
37
39
// Since Twig 3.21
38
40
$ componentName = $ this ->componentName ($ this ->parser ->parseExpression ());
39
41
} else {
40
42
$ componentName = $ this ->componentName ($ this ->parser ->getExpressionParser ()->parseExpression ());
41
43
}
42
44
45
+ if (null === $ componentName ) {
46
+ throw new SyntaxError ('Could not parse component name. ' , $ stream ->getCurrent ()->getLine (), $ stream ->getSourceContext ());
47
+ }
48
+
43
49
[$ propsExpression , $ only ] = $ this ->parseArguments ();
44
50
45
51
// Write a fake: "extends __parent__" into the "embedded" template.
@@ -80,7 +86,7 @@ public function getTag(): string
80
86
return 'component ' ;
81
87
}
82
88
83
- private function componentName (AbstractExpression $ expression ): string
89
+ private function componentName (AbstractExpression $ expression ): ? string
84
90
{
85
91
if ($ expression instanceof ConstantExpression) { // using {% component 'name' %}
86
92
return $ expression ->getAttribute ('value ' );
@@ -90,7 +96,7 @@ private function componentName(AbstractExpression $expression): string
90
96
return $ expression ->getAttribute ('name ' );
91
97
}
92
98
93
- throw new \ LogicException ( ' Could not parse component name. ' ) ;
99
+ return null ;
94
100
}
95
101
96
102
/**
0 commit comments