From dd6eac2b4ed63169881d5e1bbde00c016ef4619e Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Wed, 17 Dec 2014 14:56:02 -0500 Subject: [PATCH] Simplifying literal merging code --- src/js/parser/javascript/literal.js | 5 +++++ src/js/parser/javascript/match.js | 6 ++---- src/js/parser/javascript/match_fragment.js | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/js/parser/javascript/literal.js b/src/js/parser/javascript/literal.js index 57790f6..f75707a 100644 --- a/src/js/parser/javascript/literal.js +++ b/src/js/parser/javascript/literal.js @@ -18,6 +18,11 @@ export default { }); }, + merge(other) { + this.textValue += other.textValue; + this.literal.textValue += other.literal.textValue; + }, + setup() { this.literal = this.properties.literal; } diff --git a/src/js/parser/javascript/match.js b/src/js/parser/javascript/match.js index 92192d2..5e5e9e3 100644 --- a/src/js/parser/javascript/match.js +++ b/src/js/parser/javascript/match.js @@ -68,10 +68,8 @@ export default { this.parts = _.reduce(this.properties.parts.elements, function(result, node) { var last = _.last(result); - if (last && node.elements[0].type === 'literal' && node.elements[1].textValue === '' && last.elements[0].type === 'literal' && last.elements[1].textValue === '') { - last.textValue += node.textValue; - last.elements[0].textValue += node.elements[0].textValue; - last.elements[0].literal.textValue += node.elements[0].literal.textValue; + if (last && node.canMerge && last.canMerge) { + last.elements[0].merge(node.elements[0]); } else { result.push(node); } diff --git a/src/js/parser/javascript/match_fragment.js b/src/js/parser/javascript/match_fragment.js index 1ef1163..c4fa9e8 100644 --- a/src/js/parser/javascript/match_fragment.js +++ b/src/js/parser/javascript/match_fragment.js @@ -72,6 +72,7 @@ export default { setup() { this.content = this.properties.content; + this.canMerge = (this.elements[0].type === 'literal' && this.elements[1].textValue === ''); if (this.properties.repeat.textValue !== '') { this.repeat = this.properties.repeat;