Skip to content

Commit 32c9373

Browse files
committed
account for the short array syntax in Twig
1 parent e45ab51 commit 32c9373

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

Node/DumpNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function compile(Compiler $compiler)
4444
if (!$this->hasNode('values')) {
4545
// remove embedded templates (macros) from the context
4646
$compiler
47-
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
47+
->write(sprintf('$%svars = [];'."\n", $this->varPrefix))
4848
->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix))
4949
->indent()
5050
->write(sprintf('if (!$%sval instanceof \Twig\Template) {'."\n", $this->varPrefix))
@@ -65,7 +65,7 @@ public function compile(Compiler $compiler)
6565
} else {
6666
$compiler
6767
->addDebugInfo($this)
68-
->write('\Symfony\Component\VarDumper\VarDumper::dump(array('."\n")
68+
->write('\Symfony\Component\VarDumper\VarDumper::dump(['."\n")
6969
->indent();
7070
foreach ($values as $node) {
7171
$compiler->write('');
@@ -80,7 +80,7 @@ public function compile(Compiler $compiler)
8080
}
8181
$compiler
8282
->outdent()
83-
->write("));\n");
83+
->write("]);\n");
8484
}
8585

8686
$compiler

Node/SearchAndRenderBlockNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function compile(Compiler $compiler)
100100
// If not, add it to the array at runtime.
101101
$compiler->raw('(twig_test_empty($_label_ = ');
102102
$compiler->subcompile($label);
103-
$compiler->raw(') ? array() : array("label" => $_label_))');
103+
$compiler->raw(') ? [] : ["label" => $_label_])');
104104
}
105105
}
106106
}

Tests/Node/DumpNodeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testNoVar()
2929

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

5454
$expected = <<<'EOTXT'
5555
if ($this->env->isDebug()) {
56-
$barvars = array();
56+
$barvars = [];
5757
foreach ($context as $barkey => $barval) {
5858
if (!$barval instanceof \Twig\Template) {
5959
$barvars[$barkey] = $barval;
@@ -109,10 +109,10 @@ public function testMultiVars()
109109
$expected = <<<'EOTXT'
110110
if ($this->env->isDebug()) {
111111
// line 7
112-
\Symfony\Component\VarDumper\VarDumper::dump(array(
112+
\Symfony\Component\VarDumper\VarDumper::dump([
113113
"foo" => %foo%,
114114
"bar" => %bar%,
115-
));
115+
]);
116116
}
117117

118118
EOTXT;

Tests/Node/FormThemeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testCompile()
6161

6262
$this->assertEquals(
6363
sprintf(
64-
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"), true);',
64+
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, [0 => "tpl1", 1 => "tpl2"], true);',
6565
$this->getVariableGetter('form')
6666
),
6767
trim($compiler->compile($node)->getSource())
@@ -71,7 +71,7 @@ public function testCompile()
7171

7272
$this->assertEquals(
7373
sprintf(
74-
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"), false);',
74+
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, [0 => "tpl1", 1 => "tpl2"], false);',
7575
$this->getVariableGetter('form')
7676
),
7777
trim($compiler->compile($node)->getSource())

Tests/Node/SearchAndRenderBlockNodeTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testCompileWidgetWithVariables()
5858

5959
$this->assertEquals(
6060
sprintf(
61-
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'widget\', array("foo" => "bar"))',
61+
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'widget\', ["foo" => "bar"])',
6262
$this->getVariableGetter('form')
6363
),
6464
trim($compiler->compile($node)->getSource())
@@ -78,7 +78,7 @@ public function testCompileLabelWithLabel()
7878

7979
$this->assertEquals(
8080
sprintf(
81-
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', array("label" => "my label"))',
81+
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["label" => "my label"])',
8282
$this->getVariableGetter('form')
8383
),
8484
trim($compiler->compile($node)->getSource())
@@ -168,7 +168,7 @@ public function testCompileLabelWithAttributes()
168168
// https://github.com/symfony/symfony/issues/5029
169169
$this->assertEquals(
170170
sprintf(
171-
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', array("foo" => "bar"))',
171+
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar"])',
172172
$this->getVariableGetter('form')
173173
),
174174
trim($compiler->compile($node)->getSource())
@@ -194,7 +194,7 @@ public function testCompileLabelWithLabelAndAttributes()
194194

195195
$this->assertEquals(
196196
sprintf(
197-
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in argument"))',
197+
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar", "label" => "value in argument"])',
198198
$this->getVariableGetter('form')
199199
),
200200
trim($compiler->compile($node)->getSource())
@@ -225,7 +225,7 @@ public function testCompileLabelWithLabelThatEvaluatesToNull()
225225
// https://github.com/symfony/symfony/issues/5029
226226
$this->assertEquals(
227227
sprintf(
228-
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))',
228+
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
229229
$this->getVariableGetter('form')
230230
),
231231
trim($compiler->compile($node)->getSource())
@@ -262,7 +262,7 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
262262
// https://github.com/symfony/symfony/issues/5029
263263
$this->assertEquals(
264264
sprintf(
265-
'$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_)))',
265+
'$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_]))',
266266
$this->getVariableGetter('form')
267267
),
268268
trim($compiler->compile($node)->getSource())

Tests/Node/TransNodeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testCompileStrict()
3434

3535
$this->assertEquals(
3636
sprintf(
37-
'echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->getTranslator()->trans("trans %%var%%", array_merge(array("%%var%%" => %s), %s), "messages");',
37+
'echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->getTranslator()->trans("trans %%var%%", array_merge(["%%var%%" => %s], %s), "messages");',
3838
$this->getVariableGetterWithoutStrictCheck('var'),
3939
$this->getVariableGetterWithStrictCheck('foo')
4040
),

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^5.5.9|>=7.0.8",
20-
"twig/twig": "^1.35|^2.4.4"
20+
"twig/twig": "^1.36.1|^2.6.1"
2121
},
2222
"require-dev": {
2323
"symfony/asset": "~2.8|~3.0|~4.0",

0 commit comments

Comments
 (0)