Simplifying literal merging code

This commit is contained in:
Jeff Avallone 2014-12-17 14:56:02 -05:00
parent e362a54551
commit dd6eac2b4e
3 changed files with 8 additions and 4 deletions

View File

@ -18,6 +18,11 @@ export default {
}); });
}, },
merge(other) {
this.textValue += other.textValue;
this.literal.textValue += other.literal.textValue;
},
setup() { setup() {
this.literal = this.properties.literal; this.literal = this.properties.literal;
} }

View File

@ -68,10 +68,8 @@ export default {
this.parts = _.reduce(this.properties.parts.elements, function(result, node) { this.parts = _.reduce(this.properties.parts.elements, function(result, node) {
var last = _.last(result); var last = _.last(result);
if (last && node.elements[0].type === 'literal' && node.elements[1].textValue === '' && last.elements[0].type === 'literal' && last.elements[1].textValue === '') { if (last && node.canMerge && last.canMerge) {
last.textValue += node.textValue; last.elements[0].merge(node.elements[0]);
last.elements[0].textValue += node.elements[0].textValue;
last.elements[0].literal.textValue += node.elements[0].literal.textValue;
} else { } else {
result.push(node); result.push(node);
} }

View File

@ -72,6 +72,7 @@ export default {
setup() { setup() {
this.content = this.properties.content; this.content = this.properties.content;
this.canMerge = (this.elements[0].type === 'literal' && this.elements[1].textValue === '');
if (this.properties.repeat.textValue !== '') { if (this.properties.repeat.textValue !== '') {
this.repeat = this.properties.repeat; this.repeat = this.properties.repeat;