Skip to content

Commit 5bf74ad

Browse files
committed
Convert blockless foreach
1 parent 94f3e20 commit 5bf74ad

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

node_translators/foreach.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function (node, indent) {
1818
str += this.ws + '{' + this.nl;
1919
}
2020

21-
str += doBody.call(this, codegen, indent, node.body.children);
21+
str += doBody.call(this, codegen, indent, node.body.children || [node.body]);
2222
if (node.shortForm) {
2323
str += indent + 'endforeach;';
2424
} else {

test/tests.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ describe('Blocks', function () {
2323
expect(parseUnparse('<?php {{\n// Code generation for this\n}}')).toBe(['<?php', '', '{', ' ', ' {', ' ', ' // Code generation for this', ' }', '', '}', '', ''].join('\n'));
2424
});
2525
});
26+
describe('Blocks', function () {
27+
it('should be present even if it was a blockless foreach', function () {
28+
expect(parseUnparse('<?php\nforeach($a as $c) $c;')).toBe(['<?php', 'foreach ($a as $c) {', ' $c;', '}', ''].join('\n'));
29+
});
30+
});
2631

2732
describe('acid1.php', function () {
2833
it('must correcty convert nested blocks', function (done) {

0 commit comments

Comments
 (0)