mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-17 21:07:18 +00:00
Use proper node names when they are integers
This commit is contained in:
@@ -39,13 +39,13 @@ class CacheTokenParser extends AbstractTokenParser
|
|||||||
if (1 !== \count($args)) {
|
if (1 !== \count($args)) {
|
||||||
throw new SyntaxError(\sprintf('The "ttl" modifier takes exactly one argument (%d given).', \count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
throw new SyntaxError(\sprintf('The "ttl" modifier takes exactly one argument (%d given).', \count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||||
}
|
}
|
||||||
$ttl = $args->getNode('0');
|
$ttl = $args->getNode(0);
|
||||||
break;
|
break;
|
||||||
case 'tags':
|
case 'tags':
|
||||||
if (1 !== \count($args)) {
|
if (1 !== \count($args)) {
|
||||||
throw new SyntaxError(\sprintf('The "tags" modifier takes exactly one argument (%d given).', \count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
throw new SyntaxError(\sprintf('The "tags" modifier takes exactly one argument (%d given).', \count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||||
}
|
}
|
||||||
$tags = $args->getNode('0');
|
$tags = $args->getNode(0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new SyntaxError(\sprintf('Unknown "%s" configuration.', $k), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
throw new SyntaxError(\sprintf('Unknown "%s" configuration.', $k), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class DefaultFilter extends FilterExpression
|
|||||||
|
|
||||||
if ('default' === $name && ($node instanceof NameExpression || $node instanceof GetAttrExpression)) {
|
if ('default' === $name && ($node instanceof NameExpression || $node instanceof GetAttrExpression)) {
|
||||||
$test = new DefinedTest(clone $node, new TwigTest('defined'), new Node(), $node->getTemplateLine());
|
$test = new DefinedTest(clone $node, new TwigTest('defined'), new Node(), $node->getTemplateLine());
|
||||||
$false = \count($arguments) ? $arguments->getNode('0') : new ConstantExpression('', $node->getTemplateLine());
|
$false = \count($arguments) ? $arguments->getNode(0) : new ConstantExpression('', $node->getTemplateLine());
|
||||||
|
|
||||||
$node = new ConditionalExpression($test, $default, $false, $node->getTemplateLine());
|
$node = new ConditionalExpression($test, $default, $false, $node->getTemplateLine());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class EnumCasesFunction extends FunctionExpression
|
|||||||
if ($arguments->hasNode('enum')) {
|
if ($arguments->hasNode('enum')) {
|
||||||
$firstArgument = $arguments->getNode('enum');
|
$firstArgument = $arguments->getNode('enum');
|
||||||
} elseif ($arguments->hasNode('0')) {
|
} elseif ($arguments->hasNode('0')) {
|
||||||
$firstArgument = $arguments->getNode('0');
|
$firstArgument = $arguments->getNode(0);
|
||||||
} else {
|
} else {
|
||||||
$firstArgument = null;
|
$firstArgument = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ class ConstantTest extends TestExpression
|
|||||||
if ($this->getNode('arguments')->hasNode('1')) {
|
if ($this->getNode('arguments')->hasNode('1')) {
|
||||||
$compiler
|
$compiler
|
||||||
->raw('get_class(')
|
->raw('get_class(')
|
||||||
->subcompile($this->getNode('arguments')->getNode('1'))
|
->subcompile($this->getNode('arguments')->getNode(1))
|
||||||
->raw(')."::".')
|
->raw(')."::".')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
$compiler
|
$compiler
|
||||||
->subcompile($this->getNode('arguments')->getNode('0'))
|
->subcompile($this->getNode('arguments')->getNode(0))
|
||||||
->raw('))')
|
->raw('))')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class DivisiblebyTest extends TestExpression
|
|||||||
->raw('(0 == ')
|
->raw('(0 == ')
|
||||||
->subcompile($this->getNode('node'))
|
->subcompile($this->getNode('node'))
|
||||||
->raw(' % ')
|
->raw(' % ')
|
||||||
->subcompile($this->getNode('arguments')->getNode('0'))
|
->subcompile($this->getNode('arguments')->getNode(0))
|
||||||
->raw(')')
|
->raw(')')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class SameasTest extends TestExpression
|
|||||||
->raw('(')
|
->raw('(')
|
||||||
->subcompile($this->getNode('node'))
|
->subcompile($this->getNode('node'))
|
||||||
->raw(' === ')
|
->raw(' === ')
|
||||||
->subcompile($this->getNode('arguments')->getNode('0'))
|
->subcompile($this->getNode('arguments')->getNode(0))
|
||||||
->raw(')')
|
->raw(')')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ final class ModuleNode extends Node
|
|||||||
$traitable = !$this->hasNode('parent') && 0 === \count($this->getNode('macros'));
|
$traitable = !$this->hasNode('parent') && 0 === \count($this->getNode('macros'));
|
||||||
if ($traitable) {
|
if ($traitable) {
|
||||||
if ($this->getNode('body') instanceof BodyNode) {
|
if ($this->getNode('body') instanceof BodyNode) {
|
||||||
$nodes = $this->getNode('body')->getNode('0');
|
$nodes = $this->getNode('body')->getNode(0);
|
||||||
} else {
|
} else {
|
||||||
$nodes = $this->getNode('body');
|
$nodes = $this->getNode('body');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ final class ForTokenParser extends AbstractTokenParser
|
|||||||
$stream->expect(Token::BLOCK_END_TYPE);
|
$stream->expect(Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
if (\count($targets) > 1) {
|
if (\count($targets) > 1) {
|
||||||
$keyTarget = $targets->getNode('0');
|
$keyTarget = $targets->getNode(0);
|
||||||
$keyTarget = new AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine());
|
$keyTarget = new AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine());
|
||||||
$valueTarget = $targets->getNode('1');
|
$valueTarget = $targets->getNode(1);
|
||||||
} else {
|
} else {
|
||||||
$keyTarget = new AssignNameExpression('_key', $lineno);
|
$keyTarget = new AssignNameExpression('_key', $lineno);
|
||||||
$valueTarget = $targets->getNode('0');
|
$valueTarget = $targets->getNode(0);
|
||||||
}
|
}
|
||||||
$valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
|
$valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class ExpressionParserTest extends TestCase
|
|||||||
$parser = new Parser($env);
|
$parser = new Parser($env);
|
||||||
$expected->setSourceContext($source);
|
$expected->setSourceContext($source);
|
||||||
|
|
||||||
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode('0')->getNode('expr'));
|
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -224,7 +224,7 @@ class ExpressionParserTest extends TestCase
|
|||||||
$parser = new Parser($env);
|
$parser = new Parser($env);
|
||||||
$expected->setSourceContext($source);
|
$expected->setSourceContext($source);
|
||||||
|
|
||||||
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode('0')->getNode('expr'));
|
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTestsForString()
|
public function getTestsForString()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class ArrayTest extends NodeTestCase
|
|||||||
$elements = [new ConstantExpression('foo', 1), $foo = new ConstantExpression('bar', 1)];
|
$elements = [new ConstantExpression('foo', 1), $foo = new ConstantExpression('bar', 1)];
|
||||||
$node = new ArrayExpression($elements, 1);
|
$node = new ArrayExpression($elements, 1);
|
||||||
|
|
||||||
$this->assertEquals($foo, $node->getNode('1'));
|
$this->assertEquals($foo, $node->getNode(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTests()
|
public function getTests()
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class OptimizerTest extends TestCase
|
|||||||
|
|
||||||
$stream = $env->parse($env->tokenize(new Source('{{ block("foo") }}', 'index')));
|
$stream = $env->parse($env->tokenize(new Source('{{ block("foo") }}', 'index')));
|
||||||
|
|
||||||
$node = $stream->getNode('body')->getNode('0');
|
$node = $stream->getNode('body')->getNode(0);
|
||||||
|
|
||||||
$this->assertInstanceOf(BlockReferenceExpression::class, $node);
|
$this->assertInstanceOf(BlockReferenceExpression::class, $node);
|
||||||
$this->assertTrue($node->getAttribute('output'));
|
$this->assertTrue($node->getAttribute('output'));
|
||||||
@@ -49,7 +49,7 @@ class OptimizerTest extends TestCase
|
|||||||
|
|
||||||
$stream = $env->parse($env->tokenize(new Source('{% extends "foo" %}{% block content %}{{ parent() }}{% endblock %}', 'index')));
|
$stream = $env->parse($env->tokenize(new Source('{% extends "foo" %}{% block content %}{{ parent() }}{% endblock %}', 'index')));
|
||||||
|
|
||||||
$node = $stream->getNode('blocks')->getNode('content')->getNode('0')->getNode('body');
|
$node = $stream->getNode('blocks')->getNode('content')->getNode(0)->getNode('body');
|
||||||
|
|
||||||
$this->assertInstanceOf(ParentExpression::class, $node);
|
$this->assertInstanceOf(ParentExpression::class, $node);
|
||||||
$this->assertTrue($node->getAttribute('output'));
|
$this->assertTrue($node->getAttribute('output'));
|
||||||
|
|||||||
Reference in New Issue
Block a user