File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,7 +54,8 @@ public function generate(
5454 $ this ->addConstant ('ContentType ' , $ node ->contentType );
5555 }
5656
57- if ($ templateName !== null && !preg_match ('#\n|\?# ' , $ templateName )) {
57+ $ templateName = $ templateName === null || preg_match ('#\n|\?# ' , $ templateName ) ? null : $ templateName ;
58+ if ($ templateName !== null ) {
5859 $ this ->addConstant ('Source ' , $ templateName );
5960 }
6061
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ use Tester \Assert ;
4+
5+ require __DIR__ . '/../bootstrap.php ' ;
6+
7+
8+ test ('simple name is emitted as Source constant and /** source */ comment ' , function () {
9+ $ latte = createLatte ();
10+ $ code = $ latte ->compile ('hello.latte ' );
11+ Assert::contains ("public const Source = 'hello.latte'; " , $ code );
12+ Assert::contains ('/** source: hello.latte */ ' , $ code );
13+ });
14+
15+
16+ test ('multi-line name (e.g. string loader content) is not emitted ' , function () {
17+ $ latte = createLatte ();
18+ $ code = $ latte ->compile ("{switch 0} \n{case ''}string \n{/switch} " );
19+ Assert::notContains ('public const Source ' , $ code );
20+ Assert::notContains ('/** source: ' , $ code );
21+ });
22+
23+
24+ test ('name with question mark is not emitted ' , function () {
25+ $ latte = createLatte ();
26+ $ code = $ latte ->compile ('template?query ' );
27+ Assert::notContains ('public const Source ' , $ code );
28+ Assert::notContains ('/** source: ' , $ code );
29+ });
You can’t perform that action at this time.
0 commit comments