Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bbob/parser

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bbob/parser - npm Package Compare versions

Comparing version 2.5.5 to 2.5.6

16

CHANGELOG.md

@@ -6,2 +6,18 @@ # Change Log

## [2.5.6](https://github.com/JiLiZART/bbob/compare/v2.5.5...v2.5.6) (2020-04-12)
### Bug Fixes
* **parser:** don't eat not allowed tags with params ([#58](https://github.com/JiLiZART/bbob/issues/58)) fixes [#54](https://github.com/JiLiZART/bbob/issues/54) ([a16b9f7](https://github.com/JiLiZART/bbob/commit/a16b9f73b0737a46e852f9c55a17a612f17a9587))
### Performance Improvements
* **parser:** optimize v8 perf deoptimizations ([#61](https://github.com/JiLiZART/bbob/issues/61)) ([97ecba0](https://github.com/JiLiZART/bbob/commit/97ecba0af61c05ab4f57516589e64c7419138fde))
## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25)

@@ -8,0 +24,0 @@

398

dist/index.js

@@ -66,3 +66,3 @@ (function (global, factory) {

exports.__esModule = true;
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getNodeLength = exports.appendToNode = exports.attrValue = exports.attrsToString = void 0;
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getUniqAttr = exports.getNodeLength = exports.appendToNode = exports.attrValue = exports.attrsToString = void 0;

@@ -169,4 +169,20 @@

};
/**
* Gets value from
* @example
* getUniqAttr({ 'foo': true, 'bar': bar' }) => 'bar'
* @param attrs
* @returns {string}
*/
exports.attrsToString = attrsToString;
var getUniqAttr = function getUniqAttr(attrs) {
return Object.keys(attrs).reduce(function (res, key) {
return attrs[key] === key ? attrs[key] : null;
}, null);
};
exports.getUniqAttr = getUniqAttr;
});

@@ -178,6 +194,7 @@

var lib_3 = lib.isTagNode;
var lib_4 = lib.getNodeLength;
var lib_5 = lib.appendToNode;
var lib_6 = lib.attrValue;
var lib_7 = lib.attrsToString;
var lib_4 = lib.getUniqAttr;
var lib_5 = lib.getNodeLength;
var lib_6 = lib.appendToNode;
var lib_7 = lib.attrValue;
var lib_8 = lib.attrsToString;

@@ -209,2 +226,36 @@ var TagNode_1 = createCommonjsModule(function (module, exports) {

function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
var getTagAttrs = function getTagAttrs(tag, params) {
var uniqAattr = (0, lib.getUniqAttr)(params);
if (uniqAattr) {
var tagAttr = (0, lib.attrValue)(tag, uniqAattr);
var attrs = _extends({}, params);
delete attrs[uniqAattr];
var attrsStr = (0, lib.attrsToString)(attrs);
return "" + tagAttr + attrsStr;
}
return "" + tag + (0, lib.attrsToString)(params);
};
var TagNode =

@@ -214,3 +265,3 @@ /*#__PURE__*/

function TagNode(tag, attrs, content) {
this.tag = tag.toLowerCase();
this.tag = tag;
this.attrs = attrs;

@@ -234,8 +285,20 @@ this.content = [].concat(content);

_proto.toTagNode = function toTagNode() {
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;
return OB + this.tag + CB + this.content.reduce(function (r, node) {
var isEmpty = this.content.length === 0;
var content = this.content.reduce(function (r, node) {
return r + node.toString();
}, '') + OB + char_1.SLASH + this.tag + CB;
}, '');
var tagAttrs = getTagAttrs(this.tag, this.attrs);
if (isEmpty) {
return "" + OB + tagAttrs + CB;
}
return "" + OB + tagAttrs + CB + content + OB + char_1.SLASH + this.tag + CB;
};

@@ -278,2 +341,185 @@

var char_1$1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.BACKSLASH = exports.PLACEHOLDER_SPACE = exports.PLACEHOLDER_SPACE_TAB = exports.SLASH = exports.CLOSE_BRAKET = exports.OPEN_BRAKET = exports.SPACE = exports.QUOTEMARK = exports.EQ = exports.TAB = exports.R = exports.F = exports.N = void 0;
var N = '\n';
exports.N = N;
var TAB = '\t';
exports.TAB = TAB;
var F = '\f';
exports.F = F;
var R = '\r';
exports.R = R;
var EQ = '=';
exports.EQ = EQ;
var QUOTEMARK = '"';
exports.QUOTEMARK = QUOTEMARK;
var SPACE = ' ';
exports.SPACE = SPACE;
var OPEN_BRAKET = '[';
exports.OPEN_BRAKET = OPEN_BRAKET;
var CLOSE_BRAKET = ']';
exports.CLOSE_BRAKET = CLOSE_BRAKET;
var SLASH = '/';
exports.SLASH = SLASH;
var BACKSLASH = '\\';
exports.BACKSLASH = BACKSLASH;
var PLACEHOLDER_SPACE_TAB = ' ';
exports.PLACEHOLDER_SPACE_TAB = PLACEHOLDER_SPACE_TAB;
var PLACEHOLDER_SPACE = ' '; // const getChar = String.fromCharCode;
exports.PLACEHOLDER_SPACE = PLACEHOLDER_SPACE;
});
unwrapExports(char_1$1);
var char_2$1 = char_1$1.BACKSLASH;
var char_3$1 = char_1$1.PLACEHOLDER_SPACE;
var char_4$1 = char_1$1.PLACEHOLDER_SPACE_TAB;
var char_5$1 = char_1$1.SLASH;
var char_6$1 = char_1$1.CLOSE_BRAKET;
var char_7$1 = char_1$1.OPEN_BRAKET;
var char_8$1 = char_1$1.SPACE;
var char_9$1 = char_1$1.QUOTEMARK;
var char_10$1 = char_1$1.EQ;
var char_11$1 = char_1$1.TAB;
var char_12$1 = char_1$1.R;
var char_13$1 = char_1$1.F;
var char_14$1 = char_1$1.N;
var es = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getUniqAttr = exports.getNodeLength = exports.appendToNode = exports.attrValue = exports.attrsToString = void 0;
var isTagNode = function isTagNode(el) {
return typeof el === 'object' && !!el.tag;
};
exports.isTagNode = isTagNode;
var isStringNode = function isStringNode(el) {
return typeof el === 'string';
};
exports.isStringNode = isStringNode;
var isEOL = function isEOL(el) {
return el === char_1$1.N;
};
exports.isEOL = isEOL;
var getNodeLength = function getNodeLength(node) {
if (isTagNode(node)) {
return node.content.reduce(function (count, contentNode) {
return count + getNodeLength(contentNode);
}, 0);
}
if (isStringNode(node)) {
return node.length;
}
return 0;
};
/**
* Appends value to Tag Node
* @param {TagNode} node
* @param value
*/
exports.getNodeLength = getNodeLength;
var appendToNode = function appendToNode(node, value) {
node.content.push(value);
};
/**
* Replaces " to &qquot;
* @param {String} value
*/
exports.appendToNode = appendToNode;
var escapeQuote = function escapeQuote(value) {
return value.replace(/"/g, '&quot;');
};
/**
* Acept name and value and return valid html5 attribute string
* @param {String} name
* @param {String} value
* @return {string}
*/
var attrValue = function attrValue(name, value) {
var type = typeof value;
var types = {
boolean: function boolean() {
return value ? "" + name : '';
},
number: function number() {
return name + "=\"" + value + "\"";
},
string: function string() {
return name + "=\"" + escapeQuote(value) + "\"";
},
object: function object() {
return name + "=\"" + escapeQuote(JSON.stringify(value)) + "\"";
}
};
return types[type] ? types[type]() : '';
};
/**
* Transforms attrs to html params string
* @param values
*/
exports.attrValue = attrValue;
var attrsToString = function attrsToString(values) {
// To avoid some malformed attributes
if (typeof values === 'undefined') {
return '';
}
return Object.keys(values).reduce(function (arr, key) {
return [].concat(arr, [attrValue(key, values[key])]);
}, ['']).join(' ');
};
/**
* Gets value from
* @example
* getUniqAttr({ 'foo': true, 'bar': bar' }) => 'bar'
* @param attrs
* @returns {string}
*/
exports.attrsToString = attrsToString;
var getUniqAttr = function getUniqAttr(attrs) {
return Object.keys(attrs).reduce(function (res, key) {
return attrs[key] === key ? attrs[key] : null;
}, null);
};
exports.getUniqAttr = getUniqAttr;
});
unwrapExports(es);
var es_1 = es.isEOL;
var es_2 = es.isStringNode;
var es_3 = es.isTagNode;
var es_4 = es.getUniqAttr;
var es_5 = es.getNodeLength;
var es_6 = es.appendToNode;
var es_7 = es.attrValue;
var es_8 = es.attrsToString;
var TOKEN_TYPE_ID = 'type'; // 0;

@@ -293,21 +539,52 @@

var TOKEN_TYPE_NEW_LINE = 'new-line';
/**
* @param {Token} token
* @returns {string}
*/
var getTokenValue = function getTokenValue(token) {
return token[TOKEN_VALUE_ID];
if (token && typeof token[TOKEN_VALUE_ID] !== 'undefined') {
return token[TOKEN_VALUE_ID];
}
return '';
};
/**
* @param {Token}token
* @returns {number}
*/
var getTokenLine = function getTokenLine(token) {
return token[TOKEN_LINE_ID];
return token && token[TOKEN_LINE_ID] || 0;
};
var getTokenColumn = function getTokenColumn(token) {
return token[TOKEN_COLUMN_ID];
return token && token[TOKEN_COLUMN_ID] || 0;
};
/**
* @param {Token} token
* @returns {boolean}
*/
var isTextToken = function isTextToken(token) {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
}
return false;
};
/**
* @param {Token} token
* @returns {boolean}
*/
var isTagToken = function isTagToken(token) {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
}
return false;
};

@@ -324,7 +601,20 @@

var isAttrNameToken = function isAttrNameToken(token) {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
}
return false;
};
/**
* @param {Token} token
* @returns {boolean}
*/
var isAttrValueToken = function isAttrValueToken(token) {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
}
return false;
};

@@ -487,6 +777,18 @@

getNext: function getNext() {
return source[cursor.pos + 1];
var nextPos = cursor.pos + 1;
if (nextPos <= source.length - 1) {
return source[nextPos];
}
return null;
},
getPrev: function getPrev() {
return source[cursor.pos - 1];
var prevPos = cursor.pos - 1;
if (typeof source[prevPos] !== 'undefined') {
return source[prevPos];
}
return null;
},

@@ -570,3 +872,7 @@ getCurr: getCurr,

var getLast = function getLast() {
return nodes.length ? nodes[nodes.length - 1] : null;
if (Array.isArray(nodes) && nodes.length > 0 && typeof nodes[nodes.length - 1] !== 'undefined') {
return nodes[nodes.length - 1];
}
return null;
};

@@ -928,3 +1234,8 @@ /**

};
/**
* @param tagName
* @returns {boolean}
*/
var isTagNested = function isTagNested(tagName) {

@@ -934,2 +1245,16 @@ return !!nestedTagsMap[tagName];

/**
* @private
* @param {String} value
* @return {boolean}
*/
var isAllowedTag = function isAllowedTag(value) {
if (options.onlyAllowTags && options.onlyAllowTags.length) {
return options.onlyAllowTags.indexOf(value) >= 0;
}
return true;
};
/**
* Flushes temp tag nodes and its attributes buffers

@@ -954,26 +1279,29 @@ * @private

var lastNestedNode = nestedNodes.getLast();
return lastNestedNode ? lastNestedNode.content : nodes.toArray();
};
/**
* @private
* @param {TagNode} tag
*/
if (lastNestedNode && Array.isArray(lastNestedNode.content)) {
return lastNestedNode.content;
}
var appendNodes = function appendNodes(tag) {
getNodes().push(tag);
return nodes.toArray();
};
/**
* @private
* @param {String} value
* @return {boolean}
* @param {string|TagNode} node
*/
var isAllowedTag = function isAllowedTag(value) {
if (options.onlyAllowTags && options.onlyAllowTags.length) {
return options.onlyAllowTags.indexOf(value) >= 0;
var appendNodes = function appendNodes(node) {
var items = getNodes();
if (Array.isArray(items)) {
if (es_3(node)) {
if (isAllowedTag(node.tag)) {
items.push(node.toTagNode());
} else {
items.push(node.toString());
}
} else {
items.push(node);
}
}
return true;
};

@@ -1010,3 +1338,3 @@ /**

appendNodes(lastNestedNode);
} else if (options.onError) {
} else if (typeof options.onError === 'function') {
var tag = token.getValue();

@@ -1091,3 +1419,3 @@ var line = token.getLine();

var onToken = function onToken(token) {
if (token.isTag() && isAllowedTag(token.getName())) {
if (token.isTag()) {
handleTag(token);

@@ -1094,0 +1422,0 @@ } else {

2

dist/index.min.js

@@ -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 o=r.BACKSLASH,i=r.SLASH,u=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.getNodeLength=n.appendToNode=n.attrValue=n.attrsToString=void 0;var e=function(t){return"object"==typeof t&&!!t.tag};n.isTagNode=e;var o=function(t){return"string"==typeof t};n.isStringNode=o;n.isEOL=function(t){return t===r.N};n.getNodeLength=function t(n){return e(n)?n.content.reduce((function(n,e){return n+t(e)}),0):o(n)?n.length:0};n.appendToNode=function(t,n){t.content.push(n)};var i=function(t){return t.replace(/"/g,"&quot;")},u=function(t,n){var e=typeof n,r={boolean:function(){return n?""+t:""},number:function(){return t+'="'+n+'"'},string:function(){return t+'="'+i(n)+'"'},object:function(){return t+'="'+i(JSON.stringify(n))+'"'}};return r[e]?r[e]():""};n.attrValue=u;n.attrsToString=function(t){return void 0===t?"":Object.keys(t).reduce((function(n,e){return[].concat(n,[u(e,t[e])])}),[""]).join(" ")}}));n(p);var h=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)}}n.__esModule=!0,n.default=n.TagNode=void 0;var o=function(){function t(t,n,e){this.tag=t.toLowerCase(),this.attrs=n,this.content=[].concat(e)}var n,o,i,u=t.prototype;return u.attr=function(t,n){return void 0!==n&&(this.attrs[t]=n),this.attrs[t]},u.append=function(t){return(0,p.appendToNode)(this,t)},u.toString=function(){var t=r.OPEN_BRAKET,n=r.CLOSE_BRAKET;return t+this.tag+n+this.content.reduce((function(t,n){return t+""+n}),"")+t+r.SLASH+this.tag+n},n=t,(o=[{key:"length",get:function(){return(0,p.getNodeLength)(this)}}])&&e(n.prototype,o),i&&e(n,i),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})),d=n(h),v=h.TagNode,T=function(t){return t.value},A=function(t){return T(t).charCodeAt(0)===i.charCodeAt(0)},E=function(){function t(t,n,e,r){this.type=t+"",this.value=n+"",this.line=Number(e),this.row=Number(r)}var n=t.prototype;return n.isEmpty=function(){return!!this.type},n.isText=function(){return"space"===(t=this).type||"new-line"===t.type||"word"===t.type;var t},n.isTag=function(){return"tag"===this.type},n.isAttrName=function(){return"attr-name"===this.type},n.isAttrValue=function(){return"attr-value"===this.type},n.isStart=function(){return!A(this)},n.isEnd=function(){return A(this)},n.getName=function(){return n=T(t=this),A(t)?n.slice(1):n;var t,n},n.getValue=function(){return T(this)},n.getLine=function(){return this.line},n.getColumn=function(){return this.row},n.toString=function(){return t=a,t+=T(this),t+=u;var t},t}(),N=function(t,n){var e={pos:0,length:t.length},r=function(){e.pos+=1,n&&n.onSkip&&n.onSkip()},o=function(){return e.length>e.pos},i=function(){return t.substr(e.pos)},u=function(){return t[e.pos]};return{skip:r,hasNext:o,isLast:function(){return e.pos===e.length},grabWhile:function(n){var i=0;if(o())for(i=e.pos;o()&&n(u());)r();return t.substr(i,e.pos-i)},getNext:function(){return t[e.pos+1]},getPrev:function(){return t[e.pos-1]},getCurr:u,getRest:i,substrUntilChar:function(t){var n=i(),e=n.indexOf(t);return 0>e?"":n.substr(0,e)}}},L=function(t){void 0===t&&(t=[]);var n=t;return{getLast:function(){return n.length?n[n.length-1]:null},flushLast:function(){return!!n.length&&n.pop()},push:function(t){return n.push(t)},toArray:function(){return n}}},S=function(t,n,e,r){return void 0===e&&(e=0),void 0===r&&(r=0),new E(t,n,e,r)};function y(t,n){void 0===n&&(n={});var e=0,r=0,p=-1,h=Array(Math.floor(t.length)),d=n.openTag||a,v=n.closeTag||u,T=n.enableEscapeTags,A=[v,d,f,o,s,l,c,g,"!"],E=[d,s,l,g],L=[s,l],y=[c,s,l],b=function(t){return L.indexOf(t)>=0},O=function(t){return-1===E.indexOf(t)},C=function(t){return t===d||t===v||t===o},x=function(t){return t===o},k=function(t){n.onToken&&n.onToken(t),h[p+=1]=t},_=function(t){for(var n=null,i=!1,u=[],a=N(t),s=function(t){var e=t===c,r=b(t),u=a.getPrev(),s=a.getNext(),l=u===o;return null===n?!1===(e||r||a.isLast()):!(!i||!function(t){return y.indexOf(t)>=0}(t))||!!(t!==f||l||(i=!i)||s===c||b(s))&&!1===(e||r)},l=function(){var t=a.grabWhile(s),i=a.getCurr();if(null===n)n=t;else if(b(i)||i===f||!a.hasNext()){var c=function(t){return t.replace(o+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));u.push(S("attr-value",c,e,r))}else u.push(S("attr-name",t,e,r));a.skip()};a.hasNext();)l();return{tag:n,attrs:u}},m=N(t,{onSkip:function(){r++}}),P=function(){var t=m.getCurr(),n=m.getNext();if(t===g)m.skip(),e++,k(S("new-line",t,e,r=0));else if(b(t)){var o=m.grabWhile(b);k(S("space",o,e,r))}else if(T&&x(t)&&C(n))m.skip(),m.skip(),k(S("word",n,e,r));else if(t===d){m.skip();var u=m.substrUntilChar(v),a=0===u.length||u.indexOf(d)>=0;if(A.indexOf(n)>=0||a||m.isLast())k(S("word",t,e,r));else{var s=m.grabWhile((function(t){return t!==v}));if(m.skip(),-1===s.indexOf(c)||s[0]===i)k(S("tag",s,e,r));else{var f=_(s);k(S("tag",f.tag,e,r)),f.attrs.map(k)}}}else if(t===v)m.skip(),k(S("word",t,e,r));else if(O(t))if(T&&x(t)&&!C(n))m.skip(),k(S("word",t,e,r));else{var l=m.grabWhile((function(t){return T?O(t)&&!x(t):O(t)}));k(S("word",l,e,r))}};return{tokenize:function(){for(;m.hasNext();)P();return h.length=p+1,h},isTokenNested:function(n){var e=d+i+n.getValue();return t.indexOf(e)>-1}}}var b=function(t,n){void 0===n&&(n={});var e=n,r=null,o=L(),i=L(),u=L(),a=L(),s={},f=function(){u.flushLast()&&a.flushLast()},c=function(t){var n;(n=i.getLast(),n?n.content:o.toArray()).push(t)},l=function(t){f();var n=d.create(t.getValue()),e=function(t){return void 0===s[t.getValue()]&&(s[t.getValue()]=r.isTokenNested(t)),s[t.getValue()]}(t);u.push(n),e?i.push(n):c(n)},g=function(t){t.isStart()&&l(t),t.isEnd()&&function(t){f();var n=i.flushLast();if(n)c(n);else if(e.onError){var r=t.getValue(),o=t.getLine(),u=t.getColumn();e.onError({message:"Inconsistent tag '"+r+"' on line "+o+" and column "+u,tagName:r,lineNumber:o,columnNumber:u})}}(t)},p=function(t){var n=u.getLast(),e=t.getValue(),r=!!s[t];if(n)if(t.isAttrName())a.push(e),n.attr(a.getLast(),"");else if(t.isAttrValue()){var o=a.getLast();o?(n.attr(o,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:y)(t,{onToken:function(t){var n;!t.isTag()||(n=t.getName(),e.onlyAllowTags&&e.onlyAllowTags.length&&0>e.onlyAllowTags.indexOf(n))?p(t):g(t)},onlyAllowTags:e.onlyAllowTags,openTag:e.openTag,closeTag:e.closeTag,enableEscapeTags:e.enableEscapeTags})).tokenize();return o.toArray()};t.TagNode=v,t.default=b,t.parse=b,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 o=r.BACKSLASH,i=r.SLASH,u=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.appendToNode=n.attrValue=n.attrsToString=void 0;var e=function(t){return"object"==typeof t&&!!t.tag};n.isTagNode=e;var o=function(t){return"string"==typeof t};n.isStringNode=o;n.isEOL=function(t){return t===r.N};n.getNodeLength=function t(n){return e(n)?n.content.reduce((function(n,e){return n+t(e)}),0):o(n)?n.length:0};n.appendToNode=function(t,n){t.content.push(n)};var i=function(t){return t.replace(/"/g,"&quot;")},u=function(t,n){var e=typeof n,r={boolean:function(){return n?""+t:""},number:function(){return t+'="'+n+'"'},string:function(){return t+'="'+i(n)+'"'},object:function(){return t+'="'+i(JSON.stringify(n))+'"'}};return r[e]?r[e]():""};n.attrValue=u;n.attrsToString=function(t){return void 0===t?"":Object.keys(t).reduce((function(n,e){return[].concat(n,[u(e,t[e])])}),[""]).join(" ")};n.getUniqAttr=function(t){return Object.keys(t).reduce((function(n,e){return t[e]===e?t[e]:null}),null)}}));n(p);var 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 o(){return(o=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 i=function(){function t(t,n,e){this.tag=t,this.attrs=n,this.content=[].concat(e)}var n,i,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.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,i=this.content.reduce((function(t,n){return t+""+n}),""),u=function(t,n){var e=(0,p.getUniqAttr)(n);if(e){var r=(0,p.attrValue)(t,e),i=o({},n);return delete i[e],""+r+(0,p.attrsToString)(i)}return""+t+(0,p.attrsToString)(n)}(this.tag,this.attrs);return e?""+t+u+n:""+t+u+n+i+t+r.SLASH+this.tag+n},n=t,(i=[{key:"length",get:function(){return(0,p.getNodeLength)(this)}}])&&e(n.prototype,i),u&&e(n,u),t}();n.TagNode=i,i.create=function(t,n,e){return void 0===n&&(n={}),void 0===e&&(e=[]),new i(t,n,e)},i.isOf=function(t,n){return t.tag===n},n.default=i})),h=n(d),A=d.TagNode,v=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(v);var T=e((function(t,n){n.__esModule=!0,n.isEOL=n.isStringNode=n.isTagNode=n.getUniqAttr=n.getNodeLength=n.appendToNode=n.attrValue=n.attrsToString=void 0;var e=function(t){return"object"==typeof t&&!!t.tag};n.isTagNode=e;var r=function(t){return"string"==typeof t};n.isStringNode=r;n.isEOL=function(t){return t===v.N};n.getNodeLength=function t(n){return e(n)?n.content.reduce((function(n,e){return n+t(e)}),0):r(n)?n.length:0};n.appendToNode=function(t,n){t.content.push(n)};var o=function(t){return t.replace(/"/g,"&quot;")},i=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=i;n.attrsToString=function(t){return void 0===t?"":Object.keys(t).reduce((function(n,e){return[].concat(n,[i(e,t[e])])}),[""]).join(" ")};n.getUniqAttr=function(t){return Object.keys(t).reduce((function(n,e){return t[e]===e?t[e]:null}),null)}}));n(T);var E=T.isTagNode,S=function(t){return t&&void 0!==t.value?t.value:""},L=function(t){return S(t).charCodeAt(0)===i.charCodeAt(0)},N=function(){function t(t,n,e,r){this.type=t+"",this.value=n+"",this.line=Number(e),this.row=Number(r)}var n=t.prototype;return n.isEmpty=function(){return!!this.type},n.isText=function(){return!(!(t=this)||void 0===t.type||"space"!==t.type&&"new-line"!==t.type&&"word"!==t.type);var t},n.isTag=function(){return!(!(t=this)||void 0===t.type)&&"tag"===t.type;var t},n.isAttrName=function(){return!(!(t=this)||void 0===t.type)&&"attr-name"===t.type;var t},n.isAttrValue=function(){return!(!(t=this)||void 0===t.type)&&"attr-value"===t.type;var t},n.isStart=function(){return!L(this)},n.isEnd=function(){return L(this)},n.getName=function(){return n=S(t=this),L(t)?n.slice(1):n;var t,n},n.getValue=function(){return S(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+=S(this),t+=u;var t},t}(),y=function(t,n){var e={pos:0,length:t.length},r=function(){e.pos+=1,n&&n.onSkip&&n.onSkip()},o=function(){return e.length>e.pos},i=function(){return t.substr(e.pos)},u=function(){return t[e.pos]};return{skip:r,hasNext:o,isLast:function(){return e.pos===e.length},grabWhile:function(n){var i=0;if(o())for(i=e.pos;o()&&n(u());)r();return t.substr(i,e.pos-i)},getNext:function(){var n=e.pos+1;return n>t.length-1?null:t[n]},getPrev:function(){var n=e.pos-1;return void 0!==t[n]?t[n]:null},getCurr:u,getRest:i,substrUntilChar:function(t){var n=i(),e=n.indexOf(t);return 0>e?"":n.substr(0,e)}}},O=function(t){void 0===t&&(t=[]);var n=t;return{getLast:function(){return Array.isArray(n)&&n.length>0&&void 0!==n[n.length-1]?n[n.length-1]:null},flushLast:function(){return!!n.length&&n.pop()},push:function(t){return n.push(t)},toArray:function(){return n}}},b=function(t,n,e,r){return void 0===e&&(e=0),void 0===r&&(r=0),new N(t,n,e,r)};function C(t,n){void 0===n&&(n={});var e=0,r=0,p=-1,d=Array(Math.floor(t.length)),h=n.openTag||a,A=n.closeTag||u,v=n.enableEscapeTags,T=[A,h,f,o,s,l,c,g,"!"],E=[h,s,l,g],S=[s,l],L=[c,s,l],N=function(t){return S.indexOf(t)>=0},O=function(t){return-1===E.indexOf(t)},C=function(t){return t===h||t===A||t===o},_=function(t){return t===o},P=function(t){n.onToken&&n.onToken(t),d[p+=1]=t},R=function(t){for(var n=null,i=!1,u=[],a=y(t),s=function(t){var e=t===c,r=N(t),u=a.getPrev(),s=a.getNext(),l=u===o;return null===n?!1===(e||r||a.isLast()):!(!i||!function(t){return L.indexOf(t)>=0}(t))||!!(t!==f||l||(i=!i)||s===c||N(s))&&!1===(e||r)},l=function(){var t=a.grabWhile(s),i=a.getCurr();if(null===n)n=t;else if(N(i)||i===f||!a.hasNext()){var c=function(t){return t.replace(o+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));u.push(b("attr-value",c,e,r))}else u.push(b("attr-name",t,e,r));a.skip()};a.hasNext();)l();return{tag:n,attrs:u}},k=y(t,{onSkip:function(){r++}}),B=function(){var t=k.getCurr(),n=k.getNext();if(t===g)k.skip(),e++,P(b("new-line",t,e,r=0));else if(N(t)){var o=k.grabWhile(N);P(b("space",o,e,r))}else if(v&&_(t)&&C(n))k.skip(),k.skip(),P(b("word",n,e,r));else if(t===h){k.skip();var u=k.substrUntilChar(A),a=0===u.length||u.indexOf(h)>=0;if(T.indexOf(n)>=0||a||k.isLast())P(b("word",t,e,r));else{var s=k.grabWhile((function(t){return t!==A}));if(k.skip(),-1===s.indexOf(c)||s[0]===i)P(b("tag",s,e,r));else{var f=R(s);P(b("tag",f.tag,e,r)),f.attrs.map(P)}}}else if(t===A)k.skip(),P(b("word",t,e,r));else if(O(t))if(v&&_(t)&&!C(n))k.skip(),P(b("word",t,e,r));else{var l=k.grabWhile((function(t){return v?O(t)&&!_(t):O(t)}));P(b("word",l,e,r))}};return{tokenize:function(){for(;k.hasNext();)B();return d.length=p+1,d},isTokenNested:function(n){var e=h+i+n.getValue();return t.indexOf(e)>-1}}}var _=function(t,n){void 0===n&&(n={});var e=n,r=null,o=O(),i=O(),u=O(),a=O(),s={},f=function(){u.flushLast()&&a.flushLast()},c=function(t){var n,r,u=(n=i.getLast())&&Array.isArray(n.content)?n.content:o.toArray();Array.isArray(u)&&(E(t)?(r=t.tag,e.onlyAllowTags&&e.onlyAllowTags.length&&0>e.onlyAllowTags.indexOf(r)?u.push(""+t):u.push(t.toTagNode())):u.push(t))},l=function(t){f();var n=h.create(t.getValue()),e=function(t){return void 0===s[t.getValue()]&&(s[t.getValue()]=r.isTokenNested(t)),s[t.getValue()]}(t);u.push(n),e?i.push(n):c(n)},g=function(t){t.isStart()&&l(t),t.isEnd()&&function(t){f();var n=i.flushLast();if(n)c(n);else if("function"==typeof e.onError){var r=t.getValue(),o=t.getLine(),u=t.getColumn();e.onError({message:"Inconsistent tag '"+r+"' on line "+o+" and column "+u,tagName:r,lineNumber:o,columnNumber:u})}}(t)},p=function(t){var n=u.getLast(),e=t.getValue(),r=!!s[t];if(n)if(t.isAttrName())a.push(e),n.attr(a.getLast(),"");else if(t.isAttrValue()){var o=a.getLast();o?(n.attr(o,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:C)(t,{onToken:function(t){t.isTag()?g(t):p(t)},onlyAllowTags:e.onlyAllowTags,openTag:e.openTag,closeTag:e.closeTag,enableEscapeTags:e.enableEscapeTags})).tokenize();return o.toArray()};t.TagNode=A,t.default=_,t.parse=_,Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -8,2 +8,4 @@ "use strict";

var _pluginHelper = require("@bbob/plugin-helper");
var _lexer = require("./lexer");

@@ -75,5 +77,24 @@

};
/**
* @param tagName
* @returns {boolean}
*/
var isTagNested = tagName => !!nestedTagsMap[tagName];
/**
* @private
* @param {String} value
* @return {boolean}
*/
var isAllowedTag = value => {
if (options.onlyAllowTags && options.onlyAllowTags.length) {
return options.onlyAllowTags.indexOf(value) >= 0;
}
return true;
};
/**
* Flushes temp tag nodes and its attributes buffers

@@ -98,26 +119,29 @@ * @private

var lastNestedNode = nestedNodes.getLast();
return lastNestedNode ? lastNestedNode.content : nodes.toArray();
};
/**
* @private
* @param {TagNode} tag
*/
if (lastNestedNode && Array.isArray(lastNestedNode.content)) {
return lastNestedNode.content;
}
var appendNodes = tag => {
getNodes().push(tag);
return nodes.toArray();
};
/**
* @private
* @param {String} value
* @return {boolean}
* @param {string|TagNode} node
*/
var isAllowedTag = value => {
if (options.onlyAllowTags && options.onlyAllowTags.length) {
return options.onlyAllowTags.indexOf(value) >= 0;
var appendNodes = node => {
var items = getNodes();
if (Array.isArray(items)) {
if ((0, _pluginHelper.isTagNode)(node)) {
if (isAllowedTag(node.tag)) {
items.push(node.toTagNode());
} else {
items.push(node.toString());
}
} else {
items.push(node);
}
}
return true;
};

@@ -141,3 +165,3 @@ /**

} else {
appendNodes(tagNode);
appendNodes(tagNode, token);
}

@@ -156,4 +180,4 @@ };

if (lastNestedNode) {
appendNodes(lastNestedNode);
} else if (options.onError) {
appendNodes(lastNestedNode, token);
} else if (typeof options.onError === 'function') {
var tag = token.getValue();

@@ -238,3 +262,3 @@ var line = token.getLine();

var onToken = token => {
if (token.isTag() && isAllowedTag(token.getName())) {
if (token.isTag()) {
handleTag(token);

@@ -241,0 +265,0 @@ } else {

@@ -23,13 +23,50 @@ "use strict";

var TOKEN_TYPE_NEW_LINE = 'new-line';
/**
* @param {Token} token
* @returns {string}
*/
var getTokenValue = token => token[TOKEN_VALUE_ID];
var getTokenValue = token => {
if (token && typeof token[TOKEN_VALUE_ID] !== 'undefined') {
return token[TOKEN_VALUE_ID];
}
var getTokenLine = token => token[TOKEN_LINE_ID];
return '';
};
/**
* @param {Token}token
* @returns {number}
*/
var getTokenColumn = token => token[TOKEN_COLUMN_ID];
var isTextToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
var getTokenLine = token => token && token[TOKEN_LINE_ID] || 0;
var isTagToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
var getTokenColumn = token => token && token[TOKEN_COLUMN_ID] || 0;
/**
* @param {Token} token
* @returns {boolean}
*/
var isTextToken = token => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
}
return false;
};
/**
* @param {Token} token
* @returns {boolean}
*/
var isTagToken = token => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
}
return false;
};
var isTagEnd = token => getTokenValue(token).charCodeAt(0) === _char.SLASH.charCodeAt(0);

@@ -39,6 +76,23 @@

var isAttrNameToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
var isAttrNameToken = token => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
}
var isAttrValueToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
return false;
};
/**
* @param {Token} token
* @returns {boolean}
*/
var isAttrValueToken = token => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
}
return false;
};
var getTagName = token => {

@@ -45,0 +99,0 @@ var value = getTokenValue(token);

@@ -66,4 +66,20 @@ "use strict";

},
getNext: () => source[cursor.pos + 1],
getPrev: () => source[cursor.pos - 1],
getNext: () => {
var nextPos = cursor.pos + 1;
if (nextPos <= source.length - 1) {
return source[nextPos];
}
return null;
},
getPrev: () => {
var prevPos = cursor.pos - 1;
if (typeof source[prevPos] !== 'undefined') {
return source[prevPos];
}
return null;
},
getCurr,

@@ -152,3 +168,9 @@ getRest,

var getLast = () => nodes.length ? nodes[nodes.length - 1] : null;
var getLast = () => {
if (Array.isArray(nodes) && nodes.length > 0 && typeof nodes[nodes.length - 1] !== 'undefined') {
return nodes[nodes.length - 1];
}
return null;
};
/**

@@ -155,0 +177,0 @@ * @callback flushLastCb

@@ -8,2 +8,4 @@ "use strict";

var _pluginHelper = require("@bbob/plugin-helper");
var _lexer = require("./lexer");

@@ -75,3 +77,8 @@

};
/**
* @param tagName
* @returns {boolean}
*/
var isTagNested = function isTagNested(tagName) {

@@ -81,2 +88,16 @@ return !!nestedTagsMap[tagName];

/**
* @private
* @param {String} value
* @return {boolean}
*/
var isAllowedTag = function isAllowedTag(value) {
if (options.onlyAllowTags && options.onlyAllowTags.length) {
return options.onlyAllowTags.indexOf(value) >= 0;
}
return true;
};
/**
* Flushes temp tag nodes and its attributes buffers

@@ -101,26 +122,29 @@ * @private

var lastNestedNode = nestedNodes.getLast();
return lastNestedNode ? lastNestedNode.content : nodes.toArray();
};
/**
* @private
* @param {TagNode} tag
*/
if (lastNestedNode && Array.isArray(lastNestedNode.content)) {
return lastNestedNode.content;
}
var appendNodes = function appendNodes(tag) {
getNodes().push(tag);
return nodes.toArray();
};
/**
* @private
* @param {String} value
* @return {boolean}
* @param {string|TagNode} node
*/
var isAllowedTag = function isAllowedTag(value) {
if (options.onlyAllowTags && options.onlyAllowTags.length) {
return options.onlyAllowTags.indexOf(value) >= 0;
var appendNodes = function appendNodes(node) {
var items = getNodes();
if (Array.isArray(items)) {
if ((0, _pluginHelper.isTagNode)(node)) {
if (isAllowedTag(node.tag)) {
items.push(node.toTagNode());
} else {
items.push(node.toString());
}
} else {
items.push(node);
}
}
return true;
};

@@ -144,3 +168,3 @@ /**

} else {
appendNodes(tagNode);
appendNodes(tagNode, token);
}

@@ -159,4 +183,4 @@ };

if (lastNestedNode) {
appendNodes(lastNestedNode);
} else if (options.onError) {
appendNodes(lastNestedNode, token);
} else if (typeof options.onError === 'function') {
var tag = token.getValue();

@@ -241,3 +265,3 @@ var line = token.getLine();

var onToken = function onToken(token) {
if (token.isTag() && isAllowedTag(token.getName())) {
if (token.isTag()) {
handleTag(token);

@@ -244,0 +268,0 @@ } else {

@@ -23,21 +23,52 @@ "use strict";

var TOKEN_TYPE_NEW_LINE = 'new-line';
/**
* @param {Token} token
* @returns {string}
*/
var getTokenValue = function getTokenValue(token) {
return token[TOKEN_VALUE_ID];
if (token && typeof token[TOKEN_VALUE_ID] !== 'undefined') {
return token[TOKEN_VALUE_ID];
}
return '';
};
/**
* @param {Token}token
* @returns {number}
*/
var getTokenLine = function getTokenLine(token) {
return token[TOKEN_LINE_ID];
return token && token[TOKEN_LINE_ID] || 0;
};
var getTokenColumn = function getTokenColumn(token) {
return token[TOKEN_COLUMN_ID];
return token && token[TOKEN_COLUMN_ID] || 0;
};
/**
* @param {Token} token
* @returns {boolean}
*/
var isTextToken = function isTextToken(token) {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
}
return false;
};
/**
* @param {Token} token
* @returns {boolean}
*/
var isTagToken = function isTagToken(token) {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
}
return false;
};

@@ -54,7 +85,20 @@

var isAttrNameToken = function isAttrNameToken(token) {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
}
return false;
};
/**
* @param {Token} token
* @returns {boolean}
*/
var isAttrValueToken = function isAttrValueToken(token) {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
}
return false;
};

@@ -61,0 +105,0 @@

@@ -75,6 +75,18 @@ "use strict";

getNext: function getNext() {
return source[cursor.pos + 1];
var nextPos = cursor.pos + 1;
if (nextPos <= source.length - 1) {
return source[nextPos];
}
return null;
},
getPrev: function getPrev() {
return source[cursor.pos - 1];
var prevPos = cursor.pos - 1;
if (typeof source[prevPos] !== 'undefined') {
return source[prevPos];
}
return null;
},

@@ -167,3 +179,7 @@ getCurr: getCurr,

var getLast = function getLast() {
return nodes.length ? nodes[nodes.length - 1] : null;
if (Array.isArray(nodes) && nodes.length > 0 && typeof nodes[nodes.length - 1] !== 'undefined') {
return nodes[nodes.length - 1];
}
return null;
};

@@ -170,0 +186,0 @@ /**

{
"name": "@bbob/parser",
"version": "2.5.5",
"version": "2.5.6",
"description": "Just parses BBcode to AST array. Part of @bbob bbcode parser",

@@ -16,3 +16,3 @@ "keywords": [

"dependencies": {
"@bbob/plugin-helper": "^2.5.5"
"@bbob/plugin-helper": "^2.5.6"
},

@@ -66,3 +66,3 @@ "main": "lib/index.js",

],
"gitHead": "2670fc128892a48c636c5669b61af06f9824f057"
"gitHead": "5af63e4158f252f901b76ba54cfa7f1bbc246ec8"
}
import TagNode from '@bbob/plugin-helper/lib/TagNode';
import { isTagNode } from '@bbob/plugin-helper';
import { createLexer } from './lexer';

@@ -60,5 +61,22 @@ import { createList } from './utils';

/**
* @param tagName
* @returns {boolean}
*/
const isTagNested = (tagName) => !!nestedTagsMap[tagName];
/**
* @private
* @param {String} value
* @return {boolean}
*/
const isAllowedTag = (value) => {
if (options.onlyAllowTags && options.onlyAllowTags.length) {
return options.onlyAllowTags.indexOf(value) >= 0;
}
return true;
};
/**
* Flushes temp tag nodes and its attributes buffers

@@ -81,3 +99,7 @@ * @private

return lastNestedNode ? lastNestedNode.content : nodes.toArray();
if (lastNestedNode && Array.isArray(lastNestedNode.content)) {
return lastNestedNode.content;
}
return nodes.toArray();
};

@@ -87,19 +109,18 @@

* @private
* @param {TagNode} tag
* @param {string|TagNode} node
*/
const appendNodes = (tag) => {
getNodes().push(tag);
};
const appendNodes = (node) => {
const items = getNodes();
/**
* @private
* @param {String} value
* @return {boolean}
*/
const isAllowedTag = (value) => {
if (options.onlyAllowTags && options.onlyAllowTags.length) {
return options.onlyAllowTags.indexOf(value) >= 0;
if (Array.isArray(items)) {
if (isTagNode(node)) {
if (isAllowedTag(node.tag)) {
items.push(node.toTagNode());
} else {
items.push(node.toString());
}
} else {
items.push(node);
}
}
return true;
};

@@ -122,3 +143,3 @@

} else {
appendNodes(tagNode);
appendNodes(tagNode, token);
}

@@ -137,4 +158,4 @@ };

if (lastNestedNode) {
appendNodes(lastNestedNode);
} else if (options.onError) {
appendNodes(lastNestedNode, token);
} else if (typeof options.onError === 'function') {
const tag = token.getValue();

@@ -217,3 +238,3 @@ const line = token.getLine();

const onToken = (token) => {
if (token.isTag() && isAllowedTag(token.getName())) {
if (token.isTag()) {
handleTag(token);

@@ -220,0 +241,0 @@ } else {

@@ -20,16 +20,67 @@ import {

const getTokenValue = (token) => token[TOKEN_VALUE_ID];
const getTokenLine = (token) => token[TOKEN_LINE_ID];
const getTokenColumn = (token) => token[TOKEN_COLUMN_ID];
/**
* @param {Token} token
* @returns {string}
*/
const getTokenValue = (token) => {
if (token && typeof token[TOKEN_VALUE_ID] !== 'undefined') {
return token[TOKEN_VALUE_ID];
}
const isTextToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE
|| token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE
|| token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
return '';
};
/**
* @param {Token}token
* @returns {number}
*/
const getTokenLine = (token) => (token && token[TOKEN_LINE_ID]) || 0;
const getTokenColumn = (token) => (token && token[TOKEN_COLUMN_ID]) || 0;
const isTagToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
/**
* @param {Token} token
* @returns {boolean}
*/
const isTextToken = (token) => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE
|| token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE
|| token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
}
return false;
};
/**
* @param {Token} token
* @returns {boolean}
*/
const isTagToken = (token) => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
}
return false;
};
const isTagEnd = (token) => getTokenValue(token).charCodeAt(0) === SLASH.charCodeAt(0);
const isTagStart = (token) => !isTagEnd(token);
const isAttrNameToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
const isAttrValueToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
const isAttrNameToken = (token) => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
}
return false;
};
/**
* @param {Token} token
* @returns {boolean}
*/
const isAttrValueToken = (token) => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
}
return false;
};
const getTagName = (token) => {

@@ -36,0 +87,0 @@ const value = getTokenValue(token);

@@ -60,4 +60,18 @@ import {

},
getNext: () => source[cursor.pos + 1],
getPrev: () => source[cursor.pos - 1],
getNext: () => {
const nextPos = cursor.pos + 1;
if (nextPos <= (source.length - 1)) {
return source[nextPos];
}
return null;
},
getPrev: () => {
const prevPos = cursor.pos - 1;
if (typeof source[prevPos] !== 'undefined') {
return source[prevPos];
}
return null;
},
getCurr,

@@ -131,3 +145,9 @@ getRest,

*/
const getLast = () => (nodes.length ? nodes[nodes.length - 1] : null);
const getLast = () => {
if (Array.isArray(nodes) && nodes.length > 0 && typeof nodes[nodes.length - 1] !== 'undefined') {
return nodes[nodes.length - 1];
}
return null;
};
/**

@@ -134,0 +154,0 @@ * @callback flushLastCb

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc