Simplifying literal normalization code

This commit is contained in:
Jeff Avallone 2014-12-10 20:11:51 -05:00
parent 2e60561be6
commit 340d6b4859

View File

@ -47,22 +47,16 @@ export default _.extend({}, Base, {
parts() {
return _.reduce(this._parts.elements, function(result, node) {
var last = result.pop();
var last = _.last(result);
if (last) {
if (node.elements[0].type === 'literal' && node.elements[1].textValue === '' && last.elements[0].type === 'literal' && last.elements[1].textValue === '') {
last = _.clone(last, true);
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;
last.elements[1] = node.elements[1];
node = last;
} else {
result.push(last);
}
result.push(node);
}
result.push(node);
return result;
}, []);
}