Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"psr/log": "^1.0",
"ptachoire/cssembed": "^1.0",
"symfony/phpunit-bridge": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"twig/twig": "^2.11",
"twig/twig": "^2.11 || ^3.0",
"phpspec/prophecy-phpunit": "^2.0"
},
"suggest": {
Expand Down
12 changes: 11 additions & 1 deletion src/Assetic/Extension/Twig/AsseticNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Assetic\Extension\Twig;

use Assetic\Contracts\Asset\AssetInterface;
use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Environment;
use Twig\Node\Node;

#[YieldReady]
class AsseticNode extends Node
{
/**
Expand Down Expand Up @@ -36,7 +39,14 @@ public function __construct(AssetInterface $asset, Node $body, array $inputs, ar
array('asset' => $asset, 'inputs' => $inputs, 'filters' => $filters, 'name' => $name)
);

parent::__construct($nodes, $attributes, $lineno, $tag);
// Twig 3.12 deprecated passing the node tag to the constructor; the
// Parser now sets it automatically. Twig 2.x and Twig < 3.12 still
// expect it to be supplied here.
if (version_compare(Environment::VERSION, '3.12.0', '>=')) {
parent::__construct($nodes, $attributes, $lineno);
} else {
parent::__construct($nodes, $attributes, $lineno, $tag);
}
}

public function compile(Compiler $compiler)
Expand Down
8 changes: 7 additions & 1 deletion src/Assetic/Extension/Twig/AsseticTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ public function parse(Token $token)
// vars=['locale','browser']
$stream->next();
$stream->expect(Token::OPERATOR_TYPE, '=');
$stream->expect(Token::PUNCTUATION_TYPE, '[');

// Twig 2 lexes the opening "[" as punctuation, Twig 3 as an operator.
if ($stream->test(Token::OPERATOR_TYPE, '[')) {
$stream->next();
} else {
$stream->expect(Token::PUNCTUATION_TYPE, '[');
}

while ($stream->test(Token::STRING_TYPE)) {
$attributes['vars'][] = $stream->expect(Token::STRING_TYPE)->getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,6 @@ public function testUnclosedTag()

private function renderXml($name, $context = [])
{
return new \SimpleXMLElement($this->twig->loadTemplate($name)->render($context));
return new \SimpleXMLElement($this->twig->load($name)->render($context));
}
}
Loading