Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TwigBridge] account for the short array syntax in Twig #29829

Merged
merged 1 commit into from Jan 11, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Symfony/Bridge/Twig/Node/DumpNode.php
Expand Up @@ -44,7 +44,7 @@ public function compile(Compiler $compiler)
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))
Expand All @@ -65,7 +65,7 @@ public function compile(Compiler $compiler)
} 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('');
Expand All @@ -80,7 +80,7 @@ public function compile(Compiler $compiler)
}
$compiler
->outdent()
->write("));\n");
->write("]);\n");
}

$compiler
Expand Down
Expand Up @@ -100,7 +100,7 @@ public function compile(Compiler $compiler)
// 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_])');
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php
Expand Up @@ -29,7 +29,7 @@ public function testNoVar()

$expected = <<<'EOTXT'
if ($this->env->isDebug()) {
$barvars = array();
$barvars = [];
foreach ($context as $barkey => $barval) {
if (!$barval instanceof \Twig\Template) {
$barvars[$barkey] = $barval;
Expand All @@ -53,7 +53,7 @@ public function testIndented()

$expected = <<<'EOTXT'
if ($this->env->isDebug()) {
$barvars = array();
$barvars = [];
foreach ($context as $barkey => $barval) {
if (!$barval instanceof \Twig\Template) {
$barvars[$barkey] = $barval;
Expand Down Expand Up @@ -109,10 +109,10 @@ public function testMultiVars()
$expected = <<<'EOTXT'
if ($this->env->isDebug()) {
// line 7
\Symfony\Component\VarDumper\VarDumper::dump(array(
\Symfony\Component\VarDumper\VarDumper::dump([
"foo" => %foo%,
"bar" => %bar%,
));
]);
}

EOTXT;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
Expand Up @@ -61,7 +61,7 @@ public function testCompile()

$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())
Expand All @@ -71,7 +71,7 @@ public function testCompile()

$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())
Expand Down
Expand Up @@ -58,7 +58,7 @@ public function testCompileWidgetWithVariables()

$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())
Expand All @@ -78,7 +78,7 @@ public function testCompileLabelWithLabel()

$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())
Expand Down Expand Up @@ -168,7 +168,7 @@ public function testCompileLabelWithAttributes()
// 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())
Expand All @@ -194,7 +194,7 @@ public function testCompileLabelWithLabelAndAttributes()

$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())
Expand Down Expand Up @@ -225,7 +225,7 @@ public function testCompileLabelWithLabelThatEvaluatesToNull()
// 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())
Expand Down Expand Up @@ -262,7 +262,7 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
// 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())
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
Expand Up @@ -34,7 +34,7 @@ public function testCompileStrict()

$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')
),
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/composer.json
Expand Up @@ -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",
Expand Down