From cb359bf4ddc46b50ba3c785f537c4fefca0fcb6b Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Tue, 30 Dec 2014 17:06:29 -0500 Subject: [PATCH] Adding support for rendering empty subexpressions Fixes #1 --- spec/parser/javascript/match_spec.js | 6 ++++++ src/js/parser/javascript/match.js | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/parser/javascript/match_spec.js b/spec/parser/javascript/match_spec.js index 4f74bf7..5ed5cb2 100644 --- a/spec/parser/javascript/match_spec.js +++ b/spec/parser/javascript/match_spec.js @@ -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); diff --git a/src/js/parser/javascript/match.js b/src/js/parser/javascript/match.js index d12eb6c..0ecb7fe 100644 --- a/src/js/parser/javascript/match.js +++ b/src/js/parser/javascript/match.js @@ -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);