message-accumulator
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -41,5 +41,5 @@ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();/** | ||
* @private | ||
*/value:function _parse(string,mapping,parent){var match=void 0;re.lastIndex=0;var parts=string.split(re);for(var i=0;i<parts.length;i++){first.lastIndex=0;selfclosing.lastIndex=0;if((match=first.exec(parts[i]))!==null){var index=match[1];var len=match[0].length;// strip off the outer tags before processing the stuff in the middle | ||
*/value:function _parse(string,mapping,parent){var match=void 0;re.lastIndex=0;var parts=string.split(re);for(var i=0;i<parts.length;i++){first.lastIndex=0;selfclosing.lastIndex=0;if((match=first.exec(parts[i]))!==null){var index=parseInt(match[1]);var len=match[0].length;// strip off the outer tags before processing the stuff in the middle | ||
var substr=parts[i].substring(len,parts[i].length-len-1);var component=new _ilibTreeNode2.default({type:'component',parent:parent,index:index,extra:mapping&&mapping['c'+index]});this._parse(substr,mapping,component);parent.add(component);i++;// skip the number in the next iteration | ||
}else if(parts[i]&&parts[i].length){var subparts=parts[i].split(selfclosing);for(var j=0;j<subparts.length;j++){selfclosing.lastIndex=0;if((match=selfclosing.exec(subparts[j]))!==null){var _index=match[3];parent.add(new _ilibTreeNode2.default({type:match[2][0]==='p'?'param':'component',parent:parent,index:_index,extra:mapping&&mapping[match[2]]}));j+=2;// skip the other parts of the match in the next iteration | ||
}else if(parts[i]&&parts[i].length){var subparts=parts[i].split(selfclosing);for(var j=0;j<subparts.length;j++){selfclosing.lastIndex=0;if((match=selfclosing.exec(subparts[j]))!==null){var _index=parseInt(match[3]);parent.add(new _ilibTreeNode2.default({type:match[2][0]==='p'?'param':'component',parent:parent,index:_index,extra:mapping&&mapping[match[2]]}));j+=2;// skip the other parts of the match in the next iteration | ||
}else if(subparts[j]&&subparts[j].length){// don't store empty strings | ||
@@ -97,3 +97,5 @@ parent.add(new _ilibTreeNode2.default({type:'text',value:subparts[j]}))}}}}}/** | ||
* be a node in an AST from parsing the original text. | ||
*/},{key:'push',value:function push(extra){var newNode=new _ilibTreeNode2.default({type:'component',parent:this.currentLevel,index:this.componentIndex++,extra:extra,closed:false});this.currentLevel.add(newNode);this.currentLevel=newNode;this.mapping['c'+newNode.index]=extra}/** | ||
* @param {boolean} keep true if this node should always be kept and | ||
* not optimized out during the getMinimalString | ||
*/},{key:'push',value:function push(extra,keep){var newNode=new _ilibTreeNode2.default({type:'component',parent:this.currentLevel,index:this.componentIndex++,extra:extra,closed:false,keep:keep});this.currentLevel.add(newNode);this.currentLevel=newNode;this.mapping['c'+newNode.index]=extra}/** | ||
* Pop the current context from the stack and return to the previous | ||
@@ -113,3 +115,3 @@ * context. If the current context is already the root, then this | ||
* @private | ||
*/},{key:'_isEmpty',value:function _isEmpty(node){var _this=this;whiteSpace.lastIndex=0;if(node.type==='param')return false;if(node.type==='text'&&node.value.replace(whiteSpace,'')!=='')return false;if(node.type==='component'&&node.children&&node.children.length){return node.children.every(function(child){return _this._isEmpty(child)})}return true}/** | ||
*/},{key:'_isEmpty',value:function _isEmpty(node){var _this=this;whiteSpace.lastIndex=0;if(node.type==='param')return false;if(node.type==='text'&&node.value.replace(whiteSpace,'')!=='')return false;if(node.type==='component'){if(node.keep)return false;if(node.children&&node.children.length){return node.children.every(function(child){return _this._isEmpty(child)})}}return true}/** | ||
* @private | ||
@@ -120,3 +122,3 @@ */},{key:'_renumber',value:function _renumber(node){var _this2=this;if(node.type==='component'){node.index=this.componentIndex++;this.mapping['c'+node.index]=node.extra}else if(node.type==='param'){this.mapping['p'+node.index]=node.extra}if(node.children){node.children.forEach(function(child){_this2._renumber(child)})}}/** | ||
while(changed&&this.root.children&&this.root.children.length){changed=false;var subroot=this.root;// check for "outer" components -- components that surround localizable text without adding anything to it | ||
while(subroot.children&&subroot.children.length===1&&subroot.children[0].type!=='text'){subroot=subroot.children[0];value=new _ilibTreeNode2.default(subroot);value.use='start';this.prefixes.push(value);value=new _ilibTreeNode2.default(subroot);value.use='end';this.suffixes=[value].concat(this.suffixes);changed=true}var children=subroot.children;// find empty components at the start | ||
while(subroot.children&&subroot.children.length===1&&subroot.children[0].type!=='text'&&!subroot.children[0].keep){subroot=subroot.children[0];value=new _ilibTreeNode2.default(subroot);value.use='start';this.prefixes.push(value);value=new _ilibTreeNode2.default(subroot);value.use='end';this.suffixes=[value].concat(this.suffixes);changed=true}var children=subroot.children;// find empty components at the start | ||
var i=0;while(i<children.length&&children[i]&&this._isEmpty(children[i])){this.prefixes=this.prefixes.concat(children[i].toArray());i++;changed=true}children=i>0?children.slice(i):children;// then find empty components at the end | ||
@@ -123,0 +125,0 @@ var i=children.length-1;while(i>0&&children[i]&&this._isEmpty(children[i])){this.suffixes=children[i].toArray().concat(this.suffixes);i--;changed=true}// now strip off the leading and trailing whitespace |
@@ -88,3 +88,3 @@ /** | ||
if ((match = first.exec(parts[i])) !== null) { | ||
const index = match[1]; | ||
const index = parseInt(match[1]); | ||
const len = match[0].length; | ||
@@ -108,3 +108,3 @@ // strip off the outer tags before processing the stuff in the middle | ||
if ((match = selfclosing.exec(subparts[j])) !== null) { | ||
const index = match[3]; | ||
const index = parseInt(match[3]); | ||
parent.add(new Node({ | ||
@@ -205,4 +205,6 @@ type: match[2][0] === "p" ? 'param' : 'component', | ||
* be a node in an AST from parsing the original text. | ||
* @param {boolean} keep true if this node should always be kept and | ||
* not optimized out during the getMinimalString | ||
*/ | ||
push(extra) { | ||
push(extra, keep) { | ||
const newNode = new Node({ | ||
@@ -213,3 +215,4 @@ type: 'component', | ||
extra, | ||
closed: false | ||
closed: false, | ||
keep | ||
}); | ||
@@ -278,6 +281,9 @@ this.currentLevel.add(newNode); | ||
if (node.type === "text" && node.value.replace(whiteSpace, '') !== "") return false; | ||
if (node.type === "component" && node.children && node.children.length) { | ||
return node.children.every(child => { | ||
return this._isEmpty(child); | ||
}); | ||
if (node.type === "component") { | ||
if (node.keep) return false; | ||
if (node.children && node.children.length) { | ||
return node.children.every(child => { | ||
return this._isEmpty(child); | ||
}); | ||
} | ||
} | ||
@@ -320,3 +326,3 @@ return true; | ||
// check for "outer" components -- components that surround localizable text without adding anything to it | ||
while (subroot.children && subroot.children.length === 1 && subroot.children[0].type !== "text") { | ||
while (subroot.children && subroot.children.length === 1 && subroot.children[0].type !== "text" && !subroot.children[0].keep) { | ||
subroot = subroot.children[0]; | ||
@@ -323,0 +329,0 @@ value = new Node(subroot); |
{ | ||
"name": "message-accumulator", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"main": "./message-accumulator-es5.js", | ||
@@ -5,0 +5,0 @@ "main-es6": "./message-accumulator.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89079
731