Adding support for rendering empty subexpressions

Fixes #1
This commit is contained in:
Jeff Avallone 2014-12-30 17:06:29 -05:00
parent d7d1a78656
commit cb359bf4dd
2 changed files with 15 additions and 2 deletions

View File

@ -52,6 +52,12 @@ describe('parser/javascript/match.js', function() {
],
proxy: undefined
},
'': {
anchorStart: false,
anchorEnd: false,
parts: [],
proxy: undefined
}
}, (content, str) => {
it(`parses "${str}" as a Match`, function() {
var parser = new javascript.Parser(str);

View File

@ -23,7 +23,8 @@ export default {
_render() {
var start, end,
partPromises;
partPromises,
items;
if (this.anchorStart) {
start = this.renderLabel('Start of line')
@ -39,7 +40,13 @@ export default {
return part.render(this.container.group());
});
return Q.all(_([start, partPromises, end]).flatten().compact().value())
items = _([start, partPromises, end]).flatten().compact().value();
if (items.length === 0) {
items = [this.container.group()];
}
return Q.all(items)
.then(items => {
this.start = _.first(items);
this.end = _.last(items);