minor #29829 [TwigBridge] account for the short array syntax in Twig (xabbuh)
This PR was merged into the 3.4 branch.
Discussion
----------
[TwigBridge] account for the short array syntax in Twig
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Commits
-------
59a4dc609d
account for the short array syntax in Twig
This commit is contained in:
commit
497309a20f
@ -44,7 +44,7 @@ class DumpNode extends Node
|
||||
if (!$this->hasNode('values')) {
|
||||
// remove embedded templates (macros) from the context
|
||||
$compiler
|
||||
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
|
||||
->write(sprintf('$%svars = [];'."\n", $this->varPrefix))
|
||||
->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix))
|
||||
->indent()
|
||||
->write(sprintf('if (!$%sval instanceof \Twig\Template) {'."\n", $this->varPrefix))
|
||||
@ -65,7 +65,7 @@ class DumpNode extends Node
|
||||
} else {
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write('\Symfony\Component\VarDumper\VarDumper::dump(array('."\n")
|
||||
->write('\Symfony\Component\VarDumper\VarDumper::dump(['."\n")
|
||||
->indent();
|
||||
foreach ($values as $node) {
|
||||
$compiler->write('');
|
||||
@ -80,7 +80,7 @@ class DumpNode extends Node
|
||||
}
|
||||
$compiler
|
||||
->outdent()
|
||||
->write("));\n");
|
||||
->write("]);\n");
|
||||
}
|
||||
|
||||
$compiler
|
||||
|
@ -100,7 +100,7 @@ class SearchAndRenderBlockNode extends FunctionExpression
|
||||
// If not, add it to the array at runtime.
|
||||
$compiler->raw('(twig_test_empty($_label_ = ');
|
||||
$compiler->subcompile($label);
|
||||
$compiler->raw(') ? array() : array("label" => $_label_))');
|
||||
$compiler->raw(') ? [] : ["label" => $_label_])');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class DumpNodeTest extends TestCase
|
||||
|
||||
$expected = <<<'EOTXT'
|
||||
if ($this->env->isDebug()) {
|
||||
$barvars = array();
|
||||
$barvars = [];
|
||||
foreach ($context as $barkey => $barval) {
|
||||
if (!$barval instanceof \Twig\Template) {
|
||||
$barvars[$barkey] = $barval;
|
||||
@ -53,7 +53,7 @@ EOTXT;
|
||||
|
||||
$expected = <<<'EOTXT'
|
||||
if ($this->env->isDebug()) {
|
||||
$barvars = array();
|
||||
$barvars = [];
|
||||
foreach ($context as $barkey => $barval) {
|
||||
if (!$barval instanceof \Twig\Template) {
|
||||
$barvars[$barkey] = $barval;
|
||||
@ -109,10 +109,10 @@ EOTXT;
|
||||
$expected = <<<'EOTXT'
|
||||
if ($this->env->isDebug()) {
|
||||
// line 7
|
||||
\Symfony\Component\VarDumper\VarDumper::dump(array(
|
||||
\Symfony\Component\VarDumper\VarDumper::dump([
|
||||
"foo" => %foo%,
|
||||
"bar" => %bar%,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
EOTXT;
|
||||
|
@ -61,7 +61,7 @@ class FormThemeTest extends TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
sprintf(
|
||||
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"), true);',
|
||||
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, [0 => "tpl1", 1 => "tpl2"], true);',
|
||||
$this->getVariableGetter('form')
|
||||
),
|
||||
trim($compiler->compile($node)->getSource())
|
||||
@ -71,7 +71,7 @@ class FormThemeTest extends TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
sprintf(
|
||||
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"), false);',
|
||||
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, [0 => "tpl1", 1 => "tpl2"], false);',
|
||||
$this->getVariableGetter('form')
|
||||
),
|
||||
trim($compiler->compile($node)->getSource())
|
||||
|
@ -58,7 +58,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
sprintf(
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'widget\', array("foo" => "bar"))',
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'widget\', ["foo" => "bar"])',
|
||||
$this->getVariableGetter('form')
|
||||
),
|
||||
trim($compiler->compile($node)->getSource())
|
||||
@ -78,7 +78,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
sprintf(
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', array("label" => "my label"))',
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["label" => "my label"])',
|
||||
$this->getVariableGetter('form')
|
||||
),
|
||||
trim($compiler->compile($node)->getSource())
|
||||
@ -168,7 +168,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||
// https://github.com/symfony/symfony/issues/5029
|
||||
$this->assertEquals(
|
||||
sprintf(
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', array("foo" => "bar"))',
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar"])',
|
||||
$this->getVariableGetter('form')
|
||||
),
|
||||
trim($compiler->compile($node)->getSource())
|
||||
@ -194,7 +194,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
sprintf(
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in argument"))',
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar", "label" => "value in argument"])',
|
||||
$this->getVariableGetter('form')
|
||||
),
|
||||
trim($compiler->compile($node)->getSource())
|
||||
@ -225,7 +225,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||
// https://github.com/symfony/symfony/issues/5029
|
||||
$this->assertEquals(
|
||||
sprintf(
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))',
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
|
||||
$this->getVariableGetter('form')
|
||||
),
|
||||
trim($compiler->compile($node)->getSource())
|
||||
@ -262,7 +262,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||
// https://github.com/symfony/symfony/issues/5029
|
||||
$this->assertEquals(
|
||||
sprintf(
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in attributes") + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))',
|
||||
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar", "label" => "value in attributes"] + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
|
||||
$this->getVariableGetter('form')
|
||||
),
|
||||
trim($compiler->compile($node)->getSource())
|
||||
|
@ -34,7 +34,7 @@ class TransNodeTest extends TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
sprintf(
|
||||
'echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->getTranslator()->trans("trans %%var%%", array_merge(array("%%var%%" => %s), %s), "messages");',
|
||||
'echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->getTranslator()->trans("trans %%var%%", array_merge(["%%var%%" => %s], %s), "messages");',
|
||||
$this->getVariableGetterWithoutStrictCheck('var'),
|
||||
$this->getVariableGetterWithStrictCheck('foo')
|
||||
),
|
||||
|
@ -17,7 +17,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": "^5.5.9|>=7.0.8",
|
||||
"twig/twig": "^1.35|^2.4.4"
|
||||
"twig/twig": "^1.36.1|^2.6.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/asset": "~2.8|~3.0|~4.0",
|
||||
|
Reference in New Issue
Block a user