@bbob/parser
Advanced tools
Comparing version 2.6.1 to 2.6.2
@@ -6,2 +6,24 @@ # Change Log | ||
## [2.6.2](https://github.com/JiLiZART/bbob/compare/v2.5.8...v2.6.2) (2020-12-16) | ||
### Bug Fixes | ||
* **parser:** dont process nested tags as string if parent is not allowed ([#84](https://github.com/JiLiZART/bbob/issues/84)) ([70ff2e6](https://github.com/JiLiZART/bbob/commit/70ff2e6660bb507f6ed57cb91e850b3879bdb7eb)) | ||
* **parser:** tag inside tag parsing regression ([#81](https://github.com/JiLiZART/bbob/issues/81)) ([09bda26](https://github.com/JiLiZART/bbob/commit/09bda26d7ca9c3f4c5f1565a2ca22d16bf1d27ab)) | ||
### Features | ||
* **parser:** rewrite lexer to make it faster ([#50](https://github.com/JiLiZART/bbob/issues/50)) ([772d422](https://github.com/JiLiZART/bbob/commit/772d422d770b0f7716a86ac82c10eb3baaf77828)) | ||
### Performance Improvements | ||
* **parser:** cache nested tokens in Set to prevent deoptimization ([#83](https://github.com/JiLiZART/bbob/issues/83)) ([cad0e9e](https://github.com/JiLiZART/bbob/commit/cad0e9e7f4cc5fd9f82cfd25223561d186804e22)) | ||
## [2.6.1](https://github.com/JiLiZART/bbob/compare/v2.5.8...v2.6.1) (2020-12-15) | ||
@@ -8,0 +30,0 @@ |
@@ -288,2 +288,23 @@ (function (global, factory) { | ||
_proto.toTagStart = function toTagStart(_temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
_ref$openTag = _ref.openTag, | ||
openTag = _ref$openTag === void 0 ? char_1.OPEN_BRAKET : _ref$openTag, | ||
_ref$closeTag = _ref.closeTag, | ||
closeTag = _ref$closeTag === void 0 ? char_1.CLOSE_BRAKET : _ref$closeTag; | ||
var tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
return "" + openTag + tagAttrs + closeTag; | ||
}; | ||
_proto.toTagEnd = function toTagEnd(_temp2) { | ||
var _ref2 = _temp2 === void 0 ? {} : _temp2, | ||
_ref2$openTag = _ref2.openTag, | ||
openTag = _ref2$openTag === void 0 ? char_1.OPEN_BRAKET : _ref2$openTag, | ||
_ref2$closeTag = _ref2.closeTag, | ||
closeTag = _ref2$closeTag === void 0 ? char_1.CLOSE_BRAKET : _ref2$closeTag; | ||
return "" + openTag + char_1.SLASH + this.tag + closeTag; | ||
}; | ||
_proto.toTagNode = function toTagNode() { | ||
@@ -293,16 +314,29 @@ return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
_proto.toString = function toString() { | ||
var OB = char_1.OPEN_BRAKET; | ||
var CB = char_1.CLOSE_BRAKET; | ||
_proto.toString = function toString(_temp3) { | ||
var _ref3 = _temp3 === void 0 ? {} : _temp3, | ||
_ref3$openTag = _ref3.openTag, | ||
openTag = _ref3$openTag === void 0 ? char_1.OPEN_BRAKET : _ref3$openTag, | ||
_ref3$closeTag = _ref3.closeTag, | ||
closeTag = _ref3$closeTag === void 0 ? char_1.CLOSE_BRAKET : _ref3$closeTag; | ||
var isEmpty = this.content.length === 0; | ||
var content = this.content.reduce(function (r, node) { | ||
return r + node.toString(); | ||
return r + node.toString({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
}, ''); | ||
var tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
var tagStart = this.toTagStart({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
if (isEmpty) { | ||
return "" + OB + tagAttrs + CB; | ||
return tagStart; | ||
} | ||
return "" + OB + tagAttrs + CB + content + OB + char_1.SLASH + this.tag + CB; | ||
return "" + tagStart + content + this.toTagEnd({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
}; | ||
@@ -1120,2 +1154,4 @@ | ||
var options = opts; | ||
var openTag = options.openTag || char_7; | ||
var closeTag = options.closeTag || char_6; | ||
var tokenizer = null; | ||
@@ -1152,13 +1188,20 @@ /** | ||
* Cache for nested tags checks | ||
* @type {{}} | ||
*/ | ||
var nestedTagsMap = {}; | ||
var nestedTagsMap = new Set(); | ||
/** | ||
* | ||
* @param token | ||
* @returns {boolean} | ||
*/ | ||
var isTokenNested = function isTokenNested(token) { | ||
if (typeof nestedTagsMap[token.getValue()] === 'undefined') { | ||
nestedTagsMap[token.getValue()] = tokenizer.isTokenNested(token); | ||
var value = token.getValue(); | ||
if (!nestedTagsMap.has(value) && tokenizer.isTokenNested && tokenizer.isTokenNested(token)) { | ||
nestedTagsMap.add(value); | ||
return true; | ||
} | ||
return nestedTagsMap[token.getValue()]; | ||
return nestedTagsMap.has(value); | ||
}; | ||
@@ -1172,3 +1215,3 @@ /** | ||
var isTagNested = function isTagNested(tagName) { | ||
return !!nestedTagsMap[tagName]; | ||
return Boolean(nestedTagsMap.has(tagName)); | ||
}; | ||
@@ -1230,3 +1273,16 @@ /** | ||
} else { | ||
items.push(node.toString()); | ||
items.push(node.toTagStart({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
})); | ||
if (node.content.length) { | ||
node.content.forEach(function (item) { | ||
items.push(item); | ||
}); | ||
items.push(node.toTagEnd({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
})); | ||
} | ||
} | ||
@@ -1358,4 +1414,4 @@ } else { | ||
onlyAllowTags: options.onlyAllowTags, | ||
openTag: options.openTag, | ||
closeTag: options.closeTag, | ||
openTag: openTag, | ||
closeTag: closeTag, | ||
enableEscapeTags: options.enableEscapeTags | ||
@@ -1362,0 +1418,0 @@ }); // eslint-disable-next-line no-unused-vars |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).BbobParser={})}(this,(function(t){"use strict";function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function e(t,n){return t(n={exports:{}},n.exports),n.exports}var r=e((function(t,n){n.__esModule=!0,n.BACKSLASH=n.PLACEHOLDER_SPACE=n.PLACEHOLDER_SPACE_TAB=n.SLASH=n.CLOSE_BRAKET=n.OPEN_BRAKET=n.SPACE=n.QUOTEMARK=n.EQ=n.TAB=n.R=n.F=n.N=void 0;n.N="\n";n.TAB="\t";n.F="\f";n.R="\r";n.EQ="=";n.QUOTEMARK='"';n.SPACE=" ";n.OPEN_BRAKET="[";n.CLOSE_BRAKET="]";n.SLASH="/";n.BACKSLASH="\\";n.PLACEHOLDER_SPACE_TAB=" ";n.PLACEHOLDER_SPACE=" "}));n(r);var i=r.BACKSLASH,u=r.SLASH,o=r.CLOSE_BRAKET,a=r.OPEN_BRAKET,s=r.SPACE,f=r.QUOTEMARK,c=r.EQ,l=r.TAB,g=r.N,p=e((function(t,n){n.__esModule=!0,n.isEOL=n.isStringNode=n.isTagNode=n.getUniqAttr=n.getNodeLength=n.escapeHTML=n.appendToNode=n.attrValue=n.attrsToString=void 0;var e=function(t){return"object"==typeof t&&!!t.tag};n.isTagNode=e;var i=function(t){return"string"==typeof t};n.isStringNode=i;n.isEOL=function(t){return t===r.N};var u=function(t,n,e){return Object.keys(t).reduce(n,e)};n.getNodeLength=function t(n){return e(n)?n.content.reduce((function(n,e){return n+t(e)}),0):i(n)?n.length:0};n.appendToNode=function(t,n){t.content.push(n)};var o=function(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript):/gi,"$1%3A")};n.escapeHTML=o;var a=function(t,n){var e=typeof n,r={boolean:function(){return n?""+t:""},number:function(){return t+'="'+n+'"'},string:function(){return t+'="'+o(n)+'"'},object:function(){return t+'="'+o(JSON.stringify(n))+'"'}};return r[e]?r[e]():""};n.attrValue=a;n.attrsToString=function(t){return null==t?"":u(t,(function(n,e){return[].concat(n,[a(e,t[e])])}),[""]).join(" ")};n.getUniqAttr=function(t){return u(t,(function(n,e){return t[e]===e?t[e]:null}),null)}}));n(p);var h=p.isTagNode,d=e((function(t,n){function e(t,n){for(var e=0;n.length>e;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(){return(i=Object.assign||function(t){for(var n=1;arguments.length>n;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t}).apply(this,arguments)}n.__esModule=!0,n.default=n.TagNode=void 0;var u=function(){function t(t,n,e){this.tag=t,this.attrs=n,this.content=Array.isArray(e)?e:[e]}var n,u,o,a=t.prototype;return a.attr=function(t,n){return void 0!==n&&(this.attrs[t]=n),this.attrs[t]},a.append=function(t){return(0,p.appendToNode)(this,t)},a.toTagNode=function(){return new t(this.tag.toLowerCase(),this.attrs,this.content)},a.toString=function(){var t=r.OPEN_BRAKET,n=r.CLOSE_BRAKET,e=0===this.content.length,u=this.content.reduce((function(t,n){return t+""+n}),""),o=function(t,n){var e=(0,p.getUniqAttr)(n);if(e){var r=(0,p.attrValue)(t,e),u=i({},n);return delete u[e],""+r+(0,p.attrsToString)(u)}return""+t+(0,p.attrsToString)(n)}(this.tag,this.attrs);return e?""+t+o+n:""+t+o+n+u+t+r.SLASH+this.tag+n},n=t,(u=[{key:"length",get:function(){return(0,p.getNodeLength)(this)}}])&&e(n.prototype,u),o&&e(n,o),t}();n.TagNode=u,u.create=function(t,n,e){return void 0===n&&(n={}),void 0===e&&(e=[]),new u(t,n,e)},u.isOf=function(t,n){return t.tag===n},n.default=u})),v=n(d),A=d.TagNode,T=function(t){return t&&void 0!==t.value?t.value:""},y=function(t){return T(t).charCodeAt(0)===u.charCodeAt(0)},E=function(){function t(t,n,e,r){this.type=Number(t),this.value=n+"",this.line=Number(e),this.row=Number(r)}var n=t.prototype;return n.isEmpty=function(){return isNaN(this.type)},n.isText=function(){return!(!(t=this)||void 0===t.type||5!==t.type&&6!==t.type&&1!==t.type);var t},n.isTag=function(){return!(!(t=this)||void 0===t.type)&&2===t.type;var t},n.isAttrName=function(){return!(!(t=this)||void 0===t.type)&&3===t.type;var t},n.isAttrValue=function(){return!(!(t=this)||void 0===t.type)&&4===t.type;var t},n.isStart=function(){return!y(this)},n.isEnd=function(){return y(this)},n.getName=function(){return n=T(t=this),y(t)?n.slice(1):n;var t,n},n.getValue=function(){return T(this)},n.getLine=function(){return(t=this)&&t.line||0;var t},n.getColumn=function(){return(t=this)&&t.row||0;var t},n.toString=function(){return t=a,t+=T(this),t+=o;var t},t}();function N(t,n){var e={pos:0,len:t.length},r=function(){return e.len>e.pos},i=function(t,r){void 0===t&&(t=1),e.pos+=t,n&&n.onSkip&&!r&&n.onSkip()},u=function(){return t[e.pos]};this.skip=i,this.hasNext=r,this.getCurr=u,this.getRest=function(){return t.substr(e.pos)},this.getNext=function(){var n=e.pos+1;return n>t.length-1?null:t[n]},this.getPrev=function(){var n=e.pos-1;return void 0!==t[n]?t[n]:null},this.isLast=function(){return e.pos===e.len},this.includes=function(n){return t.indexOf(n,e.pos)>=0},this.grabWhile=function(n,o){var a=0;if(r())for(a=e.pos;r()&&n(u());)i(1,o);return t.substr(a,e.pos-a)},this.substrUntilChar=function(n){var r=e.pos,i=t.indexOf(n,r);return 0>i?"":t.substr(r,i-r)}}var b=function(t,n){return new N(t,n)};function L(t){void 0===t&&(t=[]);var n=t;this.push=function(t){return n.push(t)},this.toArray=function(){return n},this.getLast=function(){return Array.isArray(n)&&n.length>0&&void 0!==n[n.length-1]?n[n.length-1]:null},this.flushLast=function(){return!!n.length&&n.pop()}}var S=function(t){return void 0===t&&(t=[]),new L(t)};function O(t,n){void 0===n&&(n={});var e=0,r=0,p=-1,h=0,d=0,v=Array(Math.floor(t.length)),A=n.openTag||a,T=n.closeTag||o,y=!!n.enableEscapeTags,N=n.onToken||function(){},L=[T,A,f,i,s,l,c,g,"!"],S=[A,s,l,g],O=[s,l],C=[c,s,l],k=function(t){return O.indexOf(t)>=0},x=function(t){return-1===S.indexOf(t)},_=function(t){return t===i},P=function(){r++},m=function(t){return function(t){return t.replace(i+f,f)}(function(t,n){for(;t.charAt(0)===n;)t=t.substring(1);for(;t.charAt(t.length-1)===n;)t=t.substring(0,t.length-1);return t}(t,f))},R=b(t,{onSkip:P});function w(t,n){var i=function(t,n,e,r){return void 0===e&&(e=0),void 0===r&&(r=0),new E(t,n,e,r)}(t,n,e,r);N(i),v[p+=1]=i}function B(t,n){if(1===d){var e=t.grabWhile((function(t){return!(t===c||k(t))})),r=t.isLast(),u=t.getCurr()!==c;return t.skip(),r||u?w(4,m(e)):w(3,e),r?0:u?1:2}if(2===d){var o=!1,a=t.grabWhile((function(e){var r=e===f,u=t.getPrev(),a=t.getNext(),s=u===i,l=a===c,g=k(e),p=k(a);return!(!o||!function(t){return C.indexOf(t)>=0}(e))||!!(!r||s||(o=!o)||l||p)&&(!!n||!1===g)}));return t.skip(),w(4,m(a)),t.isLast()?0:1}return w(2,t.grabWhile((function(n){return!(n===c||k(n)||t.isLast())}))),t.skip(),n?2:t.includes(c)?1:2}function K(){var t=R.getCurr();if(t===A){var n=R.getNext();R.skip();var e=R.substrUntilChar(T),r=0===e.length||e.indexOf(A)>=0;if(L.indexOf(n)>=0||r||R.isLast())return w(1,t),0;if(-1===e.indexOf(c)||e[0]===u){var i=R.grabWhile((function(t){return t!==T}));return R.skip(),w(2,i),0}return 2}return 0}function H(){var t=R.grabWhile((function(t){return t!==T}),!0),n=b(t,{onSkip:P}),e=n.includes(s);for(d=0;n.hasNext();)d=B(n,!e);return R.skip(),0}function V(){if(R.getCurr()===g)return w(6,R.getCurr()),R.skip(),r=0,e++,0;if(k(R.getCurr()))return w(5,R.grabWhile(k)),0;if(R.getCurr()===A)return R.includes(T)?1:(w(1,R.getCurr()),R.skip(),0);if(y){if(_(R.getCurr())){var t=R.getCurr(),n=R.getNext();return R.skip(),function(t){return t===A||t===T||t===i}(n)?(R.skip(),w(1,n),0):(w(1,t),0)}return w(1,R.grabWhile((function(t){return x(t)&&!_(t)}))),0}return w(1,R.grabWhile(x)),0}return{tokenize:function(){for(h=0;R.hasNext();)switch(h){case 1:h=K();break;case 2:h=H();break;case 0:h=V();break;default:h=0}return v.length=p+1,v},isTokenNested:function(n){var e=A+u+n.getValue();return t.indexOf(e)>-1}}}var C=function(t,n){void 0===n&&(n={});var e=n,r=null,i=S(),u=S(),o=S(),a=S(),s={},f=function(){o.flushLast()&&a.flushLast()},c=function(t){var n,r,o=(n=u.getLast())&&Array.isArray(n.content)?n.content:i.toArray();Array.isArray(o)&&(h(t)?(r=t.tag,e.onlyAllowTags&&e.onlyAllowTags.length&&0>e.onlyAllowTags.indexOf(r)?o.push(""+t):o.push(t.toTagNode())):o.push(t))},l=function(t){f();var n=v.create(t.getValue()),e=function(t){return void 0===s[t.getValue()]&&(s[t.getValue()]=r.isTokenNested(t)),s[t.getValue()]}(t);o.push(n),e?u.push(n):c(n)},g=function(t){t.isStart()&&l(t),t.isEnd()&&function(t){f();var n=u.flushLast();if(n)c(n);else if("function"==typeof e.onError){var r=t.getValue(),i=t.getLine(),o=t.getColumn();e.onError({message:"Inconsistent tag '"+r+"' on line "+i+" and column "+o,tagName:r,lineNumber:i,columnNumber:o})}}(t)},p=function(t){var n=o.getLast(),e=t.getValue(),r=!!s[t];if(n)if(t.isAttrName())a.push(e),n.attr(a.getLast(),"");else if(t.isAttrValue()){var i=a.getLast();i?(n.attr(i,e),a.flushLast()):n.attr(e,e)}else t.isText()?r?n.append(e):c(e):t.isTag()&&c(""+t);else t.isText()?c(e):t.isTag()&&c(""+t)};(r=(n.createTokenizer?n.createTokenizer:O)(t,{onToken:function(t){t.isTag()?g(t):p(t)},onlyAllowTags:e.onlyAllowTags,openTag:e.openTag,closeTag:e.closeTag,enableEscapeTags:e.enableEscapeTags})).tokenize();return i.toArray()};t.TagNode=A,t.default=C,t.parse=C,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).BbobParser={})}(this,(function(t){"use strict";function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function e(t,n){return t(n={exports:{}},n.exports),n.exports}var r=e((function(t,n){n.__esModule=!0,n.BACKSLASH=n.PLACEHOLDER_SPACE=n.PLACEHOLDER_SPACE_TAB=n.SLASH=n.CLOSE_BRAKET=n.OPEN_BRAKET=n.SPACE=n.QUOTEMARK=n.EQ=n.TAB=n.R=n.F=n.N=void 0;n.N="\n";n.TAB="\t";n.F="\f";n.R="\r";n.EQ="=";n.QUOTEMARK='"';n.SPACE=" ";n.OPEN_BRAKET="[";n.CLOSE_BRAKET="]";n.SLASH="/";n.BACKSLASH="\\";n.PLACEHOLDER_SPACE_TAB=" ";n.PLACEHOLDER_SPACE=" "}));n(r);var i=r.BACKSLASH,o=r.SLASH,u=r.CLOSE_BRAKET,a=r.OPEN_BRAKET,s=r.SPACE,c=r.QUOTEMARK,f=r.EQ,g=r.TAB,l=r.N,p=e((function(t,n){n.__esModule=!0,n.isEOL=n.isStringNode=n.isTagNode=n.getUniqAttr=n.getNodeLength=n.escapeHTML=n.appendToNode=n.attrValue=n.attrsToString=void 0;var e=function(t){return"object"==typeof t&&!!t.tag};n.isTagNode=e;var i=function(t){return"string"==typeof t};n.isStringNode=i;n.isEOL=function(t){return t===r.N};var o=function(t,n,e){return Object.keys(t).reduce(n,e)};n.getNodeLength=function t(n){return e(n)?n.content.reduce((function(n,e){return n+t(e)}),0):i(n)?n.length:0};n.appendToNode=function(t,n){t.content.push(n)};var u=function(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript):/gi,"$1%3A")};n.escapeHTML=u;var a=function(t,n){var e=typeof n,r={boolean:function(){return n?""+t:""},number:function(){return t+'="'+n+'"'},string:function(){return t+'="'+u(n)+'"'},object:function(){return t+'="'+u(JSON.stringify(n))+'"'}};return r[e]?r[e]():""};n.attrValue=a;n.attrsToString=function(t){return null==t?"":o(t,(function(n,e){return[].concat(n,[a(e,t[e])])}),[""]).join(" ")};n.getUniqAttr=function(t){return o(t,(function(n,e){return t[e]===e?t[e]:null}),null)}}));n(p);var h=p.isTagNode,d=e((function(t,n){function e(t,n){for(var e=0;n.length>e;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(){return(i=Object.assign||function(t){for(var n=1;arguments.length>n;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t}).apply(this,arguments)}n.__esModule=!0,n.default=n.TagNode=void 0;var o=function(){function t(t,n,e){this.tag=t,this.attrs=n,this.content=Array.isArray(e)?e:[e]}var n,o,u,a=t.prototype;return a.attr=function(t,n){return void 0!==n&&(this.attrs[t]=n),this.attrs[t]},a.append=function(t){return(0,p.appendToNode)(this,t)},a.toTagStart=function(t){var n=void 0===t?{}:t,e=n.openTag,o=n.closeTag,u=void 0===o?r.CLOSE_BRAKET:o;return""+(void 0===e?r.OPEN_BRAKET:e)+function(t,n){var e=(0,p.getUniqAttr)(n);if(e){var r=(0,p.attrValue)(t,e),o=i({},n);return delete o[e],""+r+(0,p.attrsToString)(o)}return""+t+(0,p.attrsToString)(n)}(this.tag,this.attrs)+u},a.toTagEnd=function(t){var n=void 0===t?{}:t,e=n.openTag,i=n.closeTag;return""+(void 0===e?r.OPEN_BRAKET:e)+r.SLASH+this.tag+(void 0===i?r.CLOSE_BRAKET:i)},a.toTagNode=function(){return new t(this.tag.toLowerCase(),this.attrs,this.content)},a.toString=function(t){var n=void 0===t?{}:t,e=n.openTag,i=void 0===e?r.OPEN_BRAKET:e,o=n.closeTag,u=void 0===o?r.CLOSE_BRAKET:o,a=0===this.content.length,s=this.content.reduce((function(t,n){return t+n.toString({openTag:i,closeTag:u})}),""),c=this.toTagStart({openTag:i,closeTag:u});return a?c:""+c+s+this.toTagEnd({openTag:i,closeTag:u})},n=t,(o=[{key:"length",get:function(){return(0,p.getNodeLength)(this)}}])&&e(n.prototype,o),u&&e(n,u),t}();n.TagNode=o,o.create=function(t,n,e){return void 0===n&&(n={}),void 0===e&&(e=[]),new o(t,n,e)},o.isOf=function(t,n){return t.tag===n},n.default=o})),v=n(d),T=d.TagNode,A=function(t){return t&&void 0!==t.value?t.value:""},E=function(t){return A(t).charCodeAt(0)===o.charCodeAt(0)},y=function(){function t(t,n,e,r){this.type=Number(t),this.value=n+"",this.line=Number(e),this.row=Number(r)}var n=t.prototype;return n.isEmpty=function(){return isNaN(this.type)},n.isText=function(){return!(!(t=this)||void 0===t.type||5!==t.type&&6!==t.type&&1!==t.type);var t},n.isTag=function(){return!(!(t=this)||void 0===t.type)&&2===t.type;var t},n.isAttrName=function(){return!(!(t=this)||void 0===t.type)&&3===t.type;var t},n.isAttrValue=function(){return!(!(t=this)||void 0===t.type)&&4===t.type;var t},n.isStart=function(){return!E(this)},n.isEnd=function(){return E(this)},n.getName=function(){return n=A(t=this),E(t)?n.slice(1):n;var t,n},n.getValue=function(){return A(this)},n.getLine=function(){return(t=this)&&t.line||0;var t},n.getColumn=function(){return(t=this)&&t.row||0;var t},n.toString=function(){return t=a,t+=A(this),t+=u;var t},t}();function N(t,n){var e={pos:0,len:t.length},r=function(){return e.len>e.pos},i=function(t,r){void 0===t&&(t=1),e.pos+=t,n&&n.onSkip&&!r&&n.onSkip()},o=function(){return t[e.pos]};this.skip=i,this.hasNext=r,this.getCurr=o,this.getRest=function(){return t.substr(e.pos)},this.getNext=function(){var n=e.pos+1;return n>t.length-1?null:t[n]},this.getPrev=function(){var n=e.pos-1;return void 0!==t[n]?t[n]:null},this.isLast=function(){return e.pos===e.len},this.includes=function(n){return t.indexOf(n,e.pos)>=0},this.grabWhile=function(n,u){var a=0;if(r())for(a=e.pos;r()&&n(o());)i(1,u);return t.substr(a,e.pos-a)},this.substrUntilChar=function(n){var r=e.pos,i=t.indexOf(n,r);return 0>i?"":t.substr(r,i-r)}}var S=function(t,n){return new N(t,n)};function L(t){void 0===t&&(t=[]);var n=t;this.push=function(t){return n.push(t)},this.toArray=function(){return n},this.getLast=function(){return Array.isArray(n)&&n.length>0&&void 0!==n[n.length-1]?n[n.length-1]:null},this.flushLast=function(){return!!n.length&&n.pop()}}var b=function(t){return void 0===t&&(t=[]),new L(t)};function O(t,n){void 0===n&&(n={});var e=0,r=0,p=-1,h=0,d=0,v=Array(Math.floor(t.length)),T=n.openTag||a,A=n.closeTag||u,E=!!n.enableEscapeTags,N=n.onToken||function(){},L=[A,T,c,i,s,g,f,l,"!"],b=[T,s,g,l],O=[s,g],C=[f,s,g],k=function(t){return O.indexOf(t)>=0},_=function(t){return-1===b.indexOf(t)},x=function(t){return t===i},P=function(){r++},R=function(t){return function(t){return t.replace(i+c,c)}(function(t,n){for(;t.charAt(0)===n;)t=t.substring(1);for(;t.charAt(t.length-1)===n;)t=t.substring(0,t.length-1);return t}(t,c))},m=S(t,{onSkip:P});function B(t,n){var i=function(t,n,e,r){return void 0===e&&(e=0),void 0===r&&(r=0),new y(t,n,e,r)}(t,n,e,r);N(i),v[p+=1]=i}function w(t,n){if(1===d){var e=t.grabWhile((function(t){return!(t===f||k(t))})),r=t.isLast(),o=t.getCurr()!==f;return t.skip(),r||o?B(4,R(e)):B(3,e),r?0:o?1:2}if(2===d){var u=!1,a=t.grabWhile((function(e){var r=e===c,o=t.getPrev(),a=t.getNext(),s=o===i,g=a===f,l=k(e),p=k(a);return!(!u||!function(t){return C.indexOf(t)>=0}(e))||!!(!r||s||(u=!u)||g||p)&&(!!n||!1===l)}));return t.skip(),B(4,R(a)),t.isLast()?0:1}return B(2,t.grabWhile((function(n){return!(n===f||k(n)||t.isLast())}))),t.skip(),n?2:t.includes(f)?1:2}function K(){var t=m.getCurr();if(t===T){var n=m.getNext();m.skip();var e=m.substrUntilChar(A),r=0===e.length||e.indexOf(T)>=0;if(L.indexOf(n)>=0||r||m.isLast())return B(1,t),0;if(-1===e.indexOf(f)||e[0]===o){var i=m.grabWhile((function(t){return t!==A}));return m.skip(),B(2,i),0}return 2}return 0}function H(){var t=m.grabWhile((function(t){return t!==A}),!0),n=S(t,{onSkip:P}),e=n.includes(s);for(d=0;n.hasNext();)d=w(n,!e);return m.skip(),0}function j(){if(m.getCurr()===l)return B(6,m.getCurr()),m.skip(),r=0,e++,0;if(k(m.getCurr()))return B(5,m.grabWhile(k)),0;if(m.getCurr()===T)return m.includes(A)?1:(B(1,m.getCurr()),m.skip(),0);if(E){if(x(m.getCurr())){var t=m.getCurr(),n=m.getNext();return m.skip(),function(t){return t===T||t===A||t===i}(n)?(m.skip(),B(1,n),0):(B(1,t),0)}return B(1,m.grabWhile((function(t){return _(t)&&!x(t)}))),0}return B(1,m.grabWhile(_)),0}return{tokenize:function(){for(h=0;m.hasNext();)switch(h){case 1:h=K();break;case 2:h=H();break;case 0:h=j();break;default:h=0}return v.length=p+1,v},isTokenNested:function(n){var e=T+o+n.getValue();return t.indexOf(e)>-1}}}var C=function(t,n){void 0===n&&(n={});var e=n,r=e.openTag||a,i=e.closeTag||u,o=null,s=b(),c=b(),f=b(),g=b(),l=new Set,p=function(){f.flushLast()&&g.flushLast()},d=function(t){var n,o,u=(n=c.getLast())&&Array.isArray(n.content)?n.content:s.toArray();Array.isArray(u)&&(h(t)?(o=t.tag,e.onlyAllowTags&&e.onlyAllowTags.length&&0>e.onlyAllowTags.indexOf(o)?(u.push(t.toTagStart({openTag:r,closeTag:i})),t.content.length&&(t.content.forEach((function(t){u.push(t)})),u.push(t.toTagEnd({openTag:r,closeTag:i})))):u.push(t.toTagNode())):u.push(t))},T=function(t){p();var n=v.create(t.getValue()),e=function(t){var n=t.getValue();return!l.has(n)&&o.isTokenNested&&o.isTokenNested(t)?(l.add(n),!0):l.has(n)}(t);f.push(n),e?c.push(n):d(n)},A=function(t){t.isStart()&&T(t),t.isEnd()&&function(t){p();var n=c.flushLast();if(n)d(n);else if("function"==typeof e.onError){var r=t.getValue(),i=t.getLine(),o=t.getColumn();e.onError({message:"Inconsistent tag '"+r+"' on line "+i+" and column "+o,tagName:r,lineNumber:i,columnNumber:o})}}(t)},E=function(t){var n=f.getLast(),e=t.getValue(),r=!!l.has(t);if(n)if(t.isAttrName())g.push(e),n.attr(g.getLast(),"");else if(t.isAttrValue()){var i=g.getLast();i?(n.attr(i,e),g.flushLast()):n.attr(e,e)}else t.isText()?r?n.append(e):d(e):t.isTag()&&d(""+t);else t.isText()?d(e):t.isTag()&&d(""+t)};(o=(n.createTokenizer?n.createTokenizer:O)(t,{onToken:function(t){t.isTag()?A(t):E(t)},onlyAllowTags:e.onlyAllowTags,openTag:r,closeTag:i,enableEscapeTags:e.enableEscapeTags})).tokenize();return s.toArray()};t.TagNode=T,t.default=C,t.parse=C,Object.defineProperty(t,"__esModule",{value:!0})})); |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _char = require("@bbob/plugin-helper/lib/char"); | ||
var _index = require("@bbob/plugin-helper/lib/index"); | ||
@@ -34,2 +36,4 @@ | ||
var options = opts; | ||
var openTag = options.openTag || _char.OPEN_BRAKET; | ||
var closeTag = options.closeTag || _char.CLOSE_BRAKET; | ||
var tokenizer = null; | ||
@@ -66,13 +70,20 @@ /** | ||
* Cache for nested tags checks | ||
* @type {{}} | ||
*/ | ||
var nestedTagsMap = {}; | ||
var nestedTagsMap = new Set(); | ||
/** | ||
* | ||
* @param token | ||
* @returns {boolean} | ||
*/ | ||
var isTokenNested = token => { | ||
if (typeof nestedTagsMap[token.getValue()] === 'undefined') { | ||
nestedTagsMap[token.getValue()] = tokenizer.isTokenNested(token); | ||
var value = token.getValue(); | ||
if (!nestedTagsMap.has(value) && tokenizer.isTokenNested && tokenizer.isTokenNested(token)) { | ||
nestedTagsMap.add(value); | ||
return true; | ||
} | ||
return nestedTagsMap[token.getValue()]; | ||
return nestedTagsMap.has(value); | ||
}; | ||
@@ -85,3 +96,3 @@ /** | ||
var isTagNested = tagName => !!nestedTagsMap[tagName]; | ||
var isTagNested = tagName => Boolean(nestedTagsMap.has(tagName)); | ||
/** | ||
@@ -142,3 +153,16 @@ * @private | ||
} else { | ||
items.push(node.toString()); | ||
items.push(node.toTagStart({ | ||
openTag, | ||
closeTag | ||
})); | ||
if (node.content.length) { | ||
node.content.forEach(item => { | ||
items.push(item); | ||
}); | ||
items.push(node.toTagEnd({ | ||
openTag, | ||
closeTag | ||
})); | ||
} | ||
} | ||
@@ -272,4 +296,4 @@ } else { | ||
onlyAllowTags: options.onlyAllowTags, | ||
openTag: options.openTag, | ||
closeTag: options.closeTag, | ||
openTag, | ||
closeTag, | ||
enableEscapeTags: options.enableEscapeTags | ||
@@ -276,0 +300,0 @@ }); // eslint-disable-next-line no-unused-vars |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _char = require("@bbob/plugin-helper/lib/char"); | ||
var _index = require("@bbob/plugin-helper/lib/index"); | ||
@@ -34,2 +36,4 @@ | ||
var options = opts; | ||
var openTag = options.openTag || _char.OPEN_BRAKET; | ||
var closeTag = options.closeTag || _char.CLOSE_BRAKET; | ||
var tokenizer = null; | ||
@@ -66,13 +70,20 @@ /** | ||
* Cache for nested tags checks | ||
* @type {{}} | ||
*/ | ||
var nestedTagsMap = {}; | ||
var nestedTagsMap = new Set(); | ||
/** | ||
* | ||
* @param token | ||
* @returns {boolean} | ||
*/ | ||
var isTokenNested = function isTokenNested(token) { | ||
if (typeof nestedTagsMap[token.getValue()] === 'undefined') { | ||
nestedTagsMap[token.getValue()] = tokenizer.isTokenNested(token); | ||
var value = token.getValue(); | ||
if (!nestedTagsMap.has(value) && tokenizer.isTokenNested && tokenizer.isTokenNested(token)) { | ||
nestedTagsMap.add(value); | ||
return true; | ||
} | ||
return nestedTagsMap[token.getValue()]; | ||
return nestedTagsMap.has(value); | ||
}; | ||
@@ -86,3 +97,3 @@ /** | ||
var isTagNested = function isTagNested(tagName) { | ||
return !!nestedTagsMap[tagName]; | ||
return Boolean(nestedTagsMap.has(tagName)); | ||
}; | ||
@@ -144,3 +155,16 @@ /** | ||
} else { | ||
items.push(node.toString()); | ||
items.push(node.toTagStart({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
})); | ||
if (node.content.length) { | ||
node.content.forEach(function (item) { | ||
items.push(item); | ||
}); | ||
items.push(node.toTagEnd({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
})); | ||
} | ||
} | ||
@@ -274,4 +298,4 @@ } else { | ||
onlyAllowTags: options.onlyAllowTags, | ||
openTag: options.openTag, | ||
closeTag: options.closeTag, | ||
openTag: openTag, | ||
closeTag: closeTag, | ||
enableEscapeTags: options.enableEscapeTags | ||
@@ -278,0 +302,0 @@ }); // eslint-disable-next-line no-unused-vars |
{ | ||
"name": "@bbob/parser", | ||
"version": "2.6.1", | ||
"version": "2.6.2", | ||
"description": "Just parses BBcode to AST array. Part of @bbob bbcode parser", | ||
@@ -16,3 +16,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@bbob/plugin-helper": "^2.6.1" | ||
"@bbob/plugin-helper": "^2.6.2" | ||
}, | ||
@@ -66,3 +66,3 @@ "main": "lib/index.js", | ||
], | ||
"gitHead": "58e6fba8ac5ac8fe368cade48d439671f86e727d" | ||
"gitHead": "689d5a84cc6b88e96fe74481bb82997d924799fd" | ||
} |
import TagNode from '@bbob/plugin-helper/lib/TagNode'; | ||
import { CLOSE_BRAKET, OPEN_BRAKET } from '@bbob/plugin-helper/lib/char'; | ||
import { isTagNode } from '@bbob/plugin-helper/lib/index'; | ||
@@ -19,2 +20,4 @@ import { createLexer } from './lexer'; | ||
const options = opts; | ||
const openTag = options.openTag || OPEN_BRAKET; | ||
const closeTag = options.closeTag || CLOSE_BRAKET; | ||
@@ -50,12 +53,20 @@ let tokenizer = null; | ||
* Cache for nested tags checks | ||
* @type {{}} | ||
*/ | ||
const nestedTagsMap = {}; | ||
const nestedTagsMap = new Set(); | ||
/** | ||
* | ||
* @param token | ||
* @returns {boolean} | ||
*/ | ||
const isTokenNested = (token) => { | ||
if (typeof nestedTagsMap[token.getValue()] === 'undefined') { | ||
nestedTagsMap[token.getValue()] = tokenizer.isTokenNested(token); | ||
const value = token.getValue(); | ||
if (!nestedTagsMap.has(value) && tokenizer.isTokenNested && tokenizer.isTokenNested(token)) { | ||
nestedTagsMap.add(value); | ||
return true; | ||
} | ||
return nestedTagsMap[token.getValue()]; | ||
return nestedTagsMap.has(value); | ||
}; | ||
@@ -67,3 +78,3 @@ | ||
*/ | ||
const isTagNested = (tagName) => !!nestedTagsMap[tagName]; | ||
const isTagNested = (tagName) => Boolean(nestedTagsMap.has(tagName)); | ||
@@ -120,3 +131,11 @@ /** | ||
} else { | ||
items.push(node.toString()); | ||
items.push(node.toTagStart({ openTag, closeTag })); | ||
if (node.content.length) { | ||
node.content.forEach((item) => { | ||
items.push(item); | ||
}); | ||
items.push(node.toTagEnd({ openTag, closeTag })); | ||
} | ||
} | ||
@@ -247,4 +266,4 @@ } else { | ||
onlyAllowTags: options.onlyAllowTags, | ||
openTag: options.openTag, | ||
closeTag: options.closeTag, | ||
openTag, | ||
closeTag, | ||
enableEscapeTags: options.enableEscapeTags, | ||
@@ -251,0 +270,0 @@ }); |
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
216131
4856
Updated@bbob/plugin-helper@^2.6.2