forked from twigphp/Twig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These nodes have no effect on compiled templates. Adding these to the TokenStream and AST enables extensions to add logic in node visitors, such as parsing PHPDoc-style `@var string name` comments. This in turn is invaluable for static code analysis of Twig templates as briefly discussed in [twigphp#4003](twigphp#4003) and in more detail in [TwigStan](https://github.com/alisqi/twig-stan/)'s README.
- Loading branch information
Showing
6 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) Fabien Potencier | ||
* (c) Armin Ronacher | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Twig\Node; | ||
|
||
use Twig\Attribute\YieldReady; | ||
use Twig\Compiler; | ||
|
||
/** | ||
* Represents a comment node. | ||
* | ||
* @author Jeroen Versteeg <[email protected]> | ||
*/ | ||
#[YieldReady] | ||
class CommentNode extends Node | ||
{ | ||
public function __construct(string $data, int $lineno) | ||
{ | ||
parent::__construct([], ['text' => $data], $lineno); | ||
} | ||
|
||
public function compile(Compiler $compiler): void | ||
{ | ||
// skip comments in compilation | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Twig\Tests\Node; | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Twig\Node\CommentNode; | ||
use Twig\Test\NodeTestCase; | ||
|
||
class CommentTest extends NodeTestCase | ||
{ | ||
public function testConstructor() | ||
{ | ||
$node = new CommentNode('foo', 1); | ||
|
||
$this->assertEquals('foo', $node->getAttribute('text')); | ||
} | ||
|
||
public function getTests() | ||
{ | ||
return [ | ||
[new CommentNode('foo', 1), ""], | ||
]; | ||
} | ||
} |