Skip to content

Commit 6c4249e

Browse files
authored
Merge pull request glayzzle#85 from motiz88/fix-84
Filter out falsy nodes in blocks
2 parents a99ae87 + 1e18f48 commit 6c4249e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/ast/block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var KIND = 'block';
1515
*/
1616
var Block = Statement.extends(function Block(kind, children, location) {
1717
Statement.apply(this, [kind || KIND, location]);
18-
this.children = children;
18+
this.children = children.filter(Boolean);
1919
});
2020

2121
module.exports = Block;

test/ifTests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,19 @@ describe('Test IF statements', function() {
102102
ast.children[1].alternate.kind.should.be.exactly('block');
103103
});
104104
});
105+
describe('Issue #84', function () {
106+
var ast = parser.parseCode([
107+
'<?php if (true): ?>',
108+
'<?php else: ?>',
109+
'<?php endif; ?>'
110+
].join('\n'), {
111+
parser: { debug: false }
112+
});
113+
it('if block should have zero children', function() {
114+
ast.children[0].body.children.length.should.be.exactly(0);
115+
});
116+
it('else block should have zero children', function() {
117+
ast.children[0].alternate.children.length.should.be.exactly(0);
118+
});
119+
});
105120
});

0 commit comments

Comments
 (0)