@bbob/parser
Advanced tools
Comparing version 2.5.4 to 2.5.5
@@ -6,2 +6,10 @@ # Change Log | ||
## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) | ||
**Note:** Version bump only for package @bbob/parser | ||
<a name="2.5.4"></a> | ||
@@ -8,0 +16,0 @@ ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.BbobParser = {}))); | ||
(global = global || self, factory(global.BbobParser = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
function unwrapExports (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x; | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
@@ -18,51 +18,46 @@ | ||
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 = ' '; | ||
var PLACEHOLDER_SPACE = ' '; | ||
exports.PLACEHOLDER_SPACE_TAB = PLACEHOLDER_SPACE_TAB; | ||
var PLACEHOLDER_SPACE = ' '; // const getChar = String.fromCharCode; | ||
// const getChar = String.fromCharCode; | ||
exports.N = N; | ||
exports.F = F; | ||
exports.R = R; | ||
exports.TAB = TAB; | ||
exports.EQ = EQ; | ||
exports.QUOTEMARK = QUOTEMARK; | ||
exports.SPACE = SPACE; | ||
exports.OPEN_BRAKET = OPEN_BRAKET; | ||
exports.CLOSE_BRAKET = CLOSE_BRAKET; | ||
exports.SLASH = SLASH; | ||
exports.PLACEHOLDER_SPACE_TAB = PLACEHOLDER_SPACE_TAB; | ||
exports.PLACEHOLDER_SPACE = PLACEHOLDER_SPACE; | ||
exports.BACKSLASH = BACKSLASH; | ||
}); | ||
unwrapExports(char_1); | ||
var char_2 = char_1.N; | ||
var char_3 = char_1.F; | ||
var char_4 = char_1.R; | ||
var char_5 = char_1.TAB; | ||
var char_6 = char_1.EQ; | ||
var char_7 = char_1.QUOTEMARK; | ||
var char_2 = char_1.BACKSLASH; | ||
var char_3 = char_1.PLACEHOLDER_SPACE; | ||
var char_4 = char_1.PLACEHOLDER_SPACE_TAB; | ||
var char_5 = char_1.SLASH; | ||
var char_6 = char_1.CLOSE_BRAKET; | ||
var char_7 = char_1.OPEN_BRAKET; | ||
var char_8 = char_1.SPACE; | ||
var char_9 = char_1.OPEN_BRAKET; | ||
var char_10 = char_1.CLOSE_BRAKET; | ||
var char_11 = char_1.SLASH; | ||
var char_12 = char_1.PLACEHOLDER_SPACE_TAB; | ||
var char_13 = char_1.PLACEHOLDER_SPACE; | ||
var char_14 = char_1.BACKSLASH; | ||
var char_9 = char_1.QUOTEMARK; | ||
var char_10 = char_1.EQ; | ||
var char_11 = char_1.TAB; | ||
var char_12 = char_1.R; | ||
var char_13 = char_1.F; | ||
var char_14 = char_1.N; | ||
@@ -72,3 +67,3 @@ var lib = createCommonjsModule(function (module, exports) { | ||
exports.__esModule = true; | ||
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getNodeLength = exports.appendToNode = exports.attrValue = exports.attrsToString = undefined; | ||
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getNodeLength = exports.appendToNode = exports.attrValue = exports.attrsToString = void 0; | ||
@@ -80,5 +75,11 @@ | ||
}; | ||
exports.isTagNode = isTagNode; | ||
var isStringNode = function isStringNode(el) { | ||
return typeof el === 'string'; | ||
}; | ||
exports.isStringNode = isStringNode; | ||
var isEOL = function isEOL(el) { | ||
@@ -88,2 +89,4 @@ return el === char_1.N; | ||
exports.isEOL = isEOL; | ||
var getNodeLength = function getNodeLength(node) { | ||
@@ -94,3 +97,5 @@ if (isTagNode(node)) { | ||
}, 0); | ||
} else if (isStringNode(node)) { | ||
} | ||
if (isStringNode(node)) { | ||
return node.length; | ||
@@ -101,3 +106,2 @@ } | ||
}; | ||
/** | ||
@@ -108,6 +112,9 @@ * Appends value to Tag Node | ||
*/ | ||
exports.getNodeLength = getNodeLength; | ||
var appendToNode = function appendToNode(node, value) { | ||
node.content.push(value); | ||
}; | ||
/** | ||
@@ -117,6 +124,9 @@ * Replaces " to &qquot; | ||
*/ | ||
exports.appendToNode = appendToNode; | ||
var escapeQuote = function escapeQuote(value) { | ||
return value.replace(/"/g, '"'); | ||
}; | ||
/** | ||
@@ -128,23 +138,22 @@ * Acept name and value and return valid html5 attribute string | ||
*/ | ||
var attrValue = function attrValue(name, value) { | ||
var type = typeof value; | ||
var types = { | ||
boolean: function boolean() { | ||
return value ? '' + name : ''; | ||
"boolean": function boolean() { | ||
return value ? "" + name : ''; | ||
}, | ||
number: function number() { | ||
return name + '="' + value + '"'; | ||
return name + "=\"" + value + "\""; | ||
}, | ||
string: function string() { | ||
return name + '="' + escapeQuote(value) + '"'; | ||
return name + "=\"" + escapeQuote(value) + "\""; | ||
}, | ||
object: function object() { | ||
return name + '="' + escapeQuote(JSON.stringify(value)) + '"'; | ||
return name + "=\"" + escapeQuote(JSON.stringify(value)) + "\""; | ||
} | ||
}; | ||
return types[type] ? types[type]() : ''; | ||
}; | ||
/** | ||
@@ -154,2 +163,6 @@ * Transforms attrs to html params string | ||
*/ | ||
exports.attrValue = attrValue; | ||
var attrsToString = function attrsToString(values) { | ||
@@ -167,8 +180,2 @@ // To avoid some malformed attributes | ||
exports.attrsToString = attrsToString; | ||
exports.attrValue = attrValue; | ||
exports.appendToNode = appendToNode; | ||
exports.getNodeLength = getNodeLength; | ||
exports.isTagNode = isTagNode; | ||
exports.isStringNode = isStringNode; | ||
exports.isEOL = isEOL; | ||
}); | ||
@@ -188,13 +195,4 @@ | ||
exports.__esModule = true; | ||
exports.TagNode = undefined; | ||
exports["default"] = exports.TagNode = void 0; | ||
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; | ||
}; | ||
}(); | ||
@@ -204,13 +202,22 @@ | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a 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); | ||
} | ||
} | ||
var TagNode = function () { | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
var TagNode = | ||
/*#__PURE__*/ | ||
function () { | ||
function TagNode(tag, attrs, content) { | ||
_classCallCheck(this, TagNode); | ||
this.tag = tag.toLowerCase(); | ||
@@ -221,3 +228,5 @@ this.attrs = attrs; | ||
TagNode.prototype.attr = function attr(name, value) { | ||
var _proto = TagNode.prototype; | ||
_proto.attr = function attr(name, value) { | ||
if (typeof value !== 'undefined') { | ||
@@ -230,10 +239,9 @@ this.attrs[name] = value; | ||
TagNode.prototype.append = function append(value) { | ||
_proto.append = function append(value) { | ||
return (0, lib.appendToNode)(this, value); | ||
}; | ||
TagNode.prototype.toString = function toString() { | ||
_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) { | ||
@@ -245,3 +253,3 @@ return r + node.toString(); | ||
_createClass(TagNode, [{ | ||
key: 'length', | ||
key: "length", | ||
get: function get() { | ||
@@ -255,7 +263,16 @@ return (0, lib.getNodeLength)(this); | ||
TagNode.create = function (tag) { | ||
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var content = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
exports.TagNode = TagNode; | ||
TagNode.create = function (tag, attrs, content) { | ||
if (attrs === void 0) { | ||
attrs = {}; | ||
} | ||
if (content === void 0) { | ||
content = []; | ||
} | ||
return new TagNode(tag, attrs, content); | ||
}; | ||
TagNode.isOf = function (node, type) { | ||
@@ -265,4 +282,4 @@ return node.tag === type; | ||
exports.TagNode = TagNode; | ||
exports.default = TagNode; | ||
var _default = TagNode; | ||
exports["default"] = _default; | ||
}); | ||
@@ -273,12 +290,8 @@ | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var TOKEN_TYPE_ID = 'type'; // 0; | ||
// type, value, line, row, | ||
var TOKEN_TYPE_ID = 'type'; // 0; | ||
var TOKEN_VALUE_ID = 'value'; // 1; | ||
var TOKEN_COLUMN_ID = 'row'; // 2; | ||
var TOKEN_LINE_ID = 'line'; // 3; | ||
@@ -296,5 +309,7 @@ | ||
}; | ||
var getTokenLine = function getTokenLine(token) { | ||
return token[TOKEN_LINE_ID]; | ||
}; | ||
var getTokenColumn = function getTokenColumn(token) { | ||
@@ -311,11 +326,15 @@ return token[TOKEN_COLUMN_ID]; | ||
}; | ||
var isTagEnd = function isTagEnd(token) { | ||
return getTokenValue(token).charCodeAt(0) === char_11.charCodeAt(0); | ||
return getTokenValue(token).charCodeAt(0) === char_5.charCodeAt(0); | ||
}; | ||
var isTagStart = function isTagStart(token) { | ||
return !isTagEnd(token); | ||
}; | ||
var isAttrNameToken = function isAttrNameToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME; | ||
}; | ||
var isAttrValueToken = function isAttrValueToken(token) { | ||
@@ -327,3 +346,2 @@ return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE; | ||
var value = getTokenValue(token); | ||
return isTagEnd(token) ? value.slice(1) : value; | ||
@@ -333,11 +351,11 @@ }; | ||
var convertTagToText = function convertTagToText(token) { | ||
var text = char_9; | ||
var text = char_7; | ||
text += getTokenValue(token); | ||
text += char_10; | ||
text += char_6; | ||
return text; | ||
}; | ||
var Token = function () { | ||
var Token = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
@@ -350,4 +368,2 @@ * @param {String} type | ||
function Token(type, value, line, row) { | ||
classCallCheck(this, Token); | ||
this[TOKEN_TYPE_ID] = String(type); | ||
@@ -359,47 +375,49 @@ this[TOKEN_VALUE_ID] = String(value); | ||
Token.prototype.isEmpty = function isEmpty() { | ||
var _proto = Token.prototype; | ||
_proto.isEmpty = function isEmpty() { | ||
return !!this[TOKEN_TYPE_ID]; | ||
}; | ||
Token.prototype.isText = function isText() { | ||
_proto.isText = function isText() { | ||
return isTextToken(this); | ||
}; | ||
Token.prototype.isTag = function isTag() { | ||
_proto.isTag = function isTag() { | ||
return isTagToken(this); | ||
}; | ||
Token.prototype.isAttrName = function isAttrName() { | ||
_proto.isAttrName = function isAttrName() { | ||
return isAttrNameToken(this); | ||
}; | ||
Token.prototype.isAttrValue = function isAttrValue() { | ||
_proto.isAttrValue = function isAttrValue() { | ||
return isAttrValueToken(this); | ||
}; | ||
Token.prototype.isStart = function isStart() { | ||
_proto.isStart = function isStart() { | ||
return isTagStart(this); | ||
}; | ||
Token.prototype.isEnd = function isEnd() { | ||
_proto.isEnd = function isEnd() { | ||
return isTagEnd(this); | ||
}; | ||
Token.prototype.getName = function getName() { | ||
_proto.getName = function getName() { | ||
return getTagName(this); | ||
}; | ||
Token.prototype.getValue = function getValue() { | ||
_proto.getValue = function getValue() { | ||
return getTokenValue(this); | ||
}; | ||
Token.prototype.getLine = function getLine() { | ||
_proto.getLine = function getLine() { | ||
return getTokenLine(this); | ||
}; | ||
Token.prototype.getColumn = function getColumn() { | ||
_proto.getColumn = function getColumn() { | ||
return getTokenColumn(this); | ||
}; | ||
Token.prototype.toString = function toString() { | ||
_proto.toString = function toString() { | ||
return convertTagToText(this); | ||
@@ -432,2 +450,3 @@ }; | ||
*/ | ||
var createCharGrabber = function createCharGrabber(source, options) { | ||
@@ -447,8 +466,11 @@ // let idx = 0; | ||
}; | ||
var hasNext = function hasNext() { | ||
return cursor.length > cursor.pos; | ||
}; | ||
var getRest = function getRest() { | ||
return source.substr(cursor.pos); | ||
}; | ||
var getCurr = function getCurr() { | ||
@@ -464,2 +486,3 @@ return source[cursor.pos]; | ||
}, | ||
/** | ||
@@ -490,2 +513,3 @@ * @param {Function} cond | ||
getRest: getRest, | ||
/** | ||
@@ -496,5 +520,5 @@ * Grabs rest of string until it find a char | ||
*/ | ||
substrUntilChar: function substrUntilChar(char$$1) { | ||
substrUntilChar: function substrUntilChar(char) { | ||
var restStr = getRest(); | ||
var indexOfChar = restStr.indexOf(char$$1); | ||
var indexOfChar = restStr.indexOf(char); | ||
@@ -509,3 +533,2 @@ if (indexOfChar >= 0) { | ||
}; | ||
/** | ||
@@ -519,2 +542,3 @@ * Trims string from start and end by char | ||
*/ | ||
var trimChar = function trimChar(str, charToRemove) { | ||
@@ -533,3 +557,2 @@ while (str.charAt(0) === charToRemove) { | ||
}; | ||
/** | ||
@@ -540,6 +563,6 @@ * Unquotes \" to " | ||
*/ | ||
var unquote = function unquote(str) { | ||
return str.replace(char_14 + char_7, char_7); | ||
return str.replace(char_2 + char_9, char_9); | ||
}; | ||
/** | ||
@@ -559,5 +582,8 @@ * @typedef {Object} ItemList | ||
*/ | ||
var createList = function createList() { | ||
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var createList = function createList(values) { | ||
if (values === void 0) { | ||
values = []; | ||
} | ||
var nodes = values; | ||
@@ -567,2 +593,3 @@ /** | ||
*/ | ||
var getLast = function getLast() { | ||
@@ -575,2 +602,4 @@ return nodes.length ? nodes[nodes.length - 1] : null; | ||
*/ | ||
var flushLast = function flushLast() { | ||
@@ -587,6 +616,7 @@ if (nodes.length) { | ||
*/ | ||
var push = function push(value) { | ||
return nodes.push(value); | ||
}; | ||
/** | ||
@@ -597,2 +627,3 @@ * @callback toArrayCb | ||
return { | ||
@@ -610,5 +641,3 @@ getLast: getLast, | ||
// for cases <!-- --> | ||
var EM = '!'; | ||
/** | ||
@@ -621,8 +650,14 @@ * Creates a Token entity class | ||
*/ | ||
var createToken = function createToken(type, value) { | ||
var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
var cl = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; | ||
var createToken = function createToken(type, value, r, cl) { | ||
if (r === void 0) { | ||
r = 0; | ||
} | ||
if (cl === void 0) { | ||
cl = 0; | ||
} | ||
return new Token(type, value, r, cl); | ||
}; | ||
/** | ||
@@ -643,40 +678,45 @@ * @typedef {Object} Lexer | ||
*/ | ||
function createLexer(buffer) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
function createLexer(buffer, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var row = 0; | ||
var col = 0; | ||
var tokenIndex = -1; | ||
var tokens = new Array(Math.floor(buffer.length)); | ||
var openTag = options.openTag || char_9; | ||
var closeTag = options.closeTag || char_10; | ||
var openTag = options.openTag || char_7; | ||
var closeTag = options.closeTag || char_6; | ||
var escapeTags = options.enableEscapeTags; | ||
var RESERVED_CHARS = [closeTag, openTag, char_9, char_2, char_8, char_11, char_10, char_14, EM]; | ||
var NOT_CHAR_TOKENS = [// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
openTag, char_8, char_11, char_14]; | ||
var WHITESPACES = [char_8, char_11]; | ||
var SPECIAL_CHARS = [char_10, char_8, char_11]; | ||
var RESERVED_CHARS = [closeTag, openTag, char_7, char_14, char_8, char_5, char_6, char_2, EM]; | ||
var NOT_CHAR_TOKENS = [ | ||
// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
openTag, char_8, char_5, char_2]; | ||
var WHITESPACES = [char_8, char_5]; | ||
var SPECIAL_CHARS = [char_6, char_8, char_5]; | ||
var isCharReserved = function isCharReserved(char) { | ||
return RESERVED_CHARS.indexOf(char) >= 0; | ||
}; | ||
var isCharReserved = function isCharReserved(char$$1) { | ||
return RESERVED_CHARS.indexOf(char$$1) >= 0; | ||
var isWhiteSpace = function isWhiteSpace(char) { | ||
return WHITESPACES.indexOf(char) >= 0; | ||
}; | ||
var isWhiteSpace = function isWhiteSpace(char$$1) { | ||
return WHITESPACES.indexOf(char$$1) >= 0; | ||
var isCharToken = function isCharToken(char) { | ||
return NOT_CHAR_TOKENS.indexOf(char) === -1; | ||
}; | ||
var isCharToken = function isCharToken(char$$1) { | ||
return NOT_CHAR_TOKENS.indexOf(char$$1) === -1; | ||
var isSpecialChar = function isSpecialChar(char) { | ||
return SPECIAL_CHARS.indexOf(char) >= 0; | ||
}; | ||
var isSpecialChar = function isSpecialChar(char$$1) { | ||
return SPECIAL_CHARS.indexOf(char$$1) >= 0; | ||
var isEscapableChar = function isEscapableChar(char) { | ||
return char === openTag || char === closeTag || char === char_2; | ||
}; | ||
var isEscapableChar = function isEscapableChar(char$$1) { | ||
return char$$1 === openTag || char$$1 === closeTag || char$$1 === char_14; | ||
var isEscapeChar = function isEscapeChar(char) { | ||
return char === char_2; | ||
}; | ||
var isEscapeChar = function isEscapeChar(char$$1) { | ||
return char$$1 === char_14; | ||
}; | ||
/** | ||
@@ -686,2 +726,4 @@ * Emits newly created token to subscriber | ||
*/ | ||
var emitToken = function emitToken(token) { | ||
@@ -695,3 +737,2 @@ if (options.onToken) { | ||
}; | ||
/** | ||
@@ -702,15 +743,16 @@ * Parses params inside [myTag---params goes here---]content[/myTag] | ||
*/ | ||
var parseAttrs = function parseAttrs(str) { | ||
var tagName = null; | ||
var skipSpecialChars = false; | ||
var attrTokens = []; | ||
var attrCharGrabber = createCharGrabber(str); | ||
var validAttr = function validAttr(char$$1) { | ||
var isEQ = char$$1 === char_6; | ||
var isWS = isWhiteSpace(char$$1); | ||
var validAttr = function validAttr(char) { | ||
var isEQ = char === char_10; | ||
var isWS = isWhiteSpace(char); | ||
var prevChar = attrCharGrabber.getPrev(); | ||
var nextChar = attrCharGrabber.getNext(); | ||
var isPrevSLASH = prevChar === char_14; | ||
var isPrevSLASH = prevChar === char_2; | ||
var isTagNameEmpty = tagName === null; | ||
@@ -722,10 +764,10 @@ | ||
if (skipSpecialChars && isSpecialChar(char$$1)) { | ||
if (skipSpecialChars && isSpecialChar(char)) { | ||
return true; | ||
} | ||
if (char$$1 === char_7 && !isPrevSLASH) { | ||
if (char === char_9 && !isPrevSLASH) { | ||
skipSpecialChars = !skipSpecialChars; | ||
if (!skipSpecialChars && !(nextChar === char_6 || isWhiteSpace(nextChar))) { | ||
if (!skipSpecialChars && !(nextChar === char_10 || isWhiteSpace(nextChar))) { | ||
return false; | ||
@@ -740,9 +782,8 @@ } | ||
var attrStr = attrCharGrabber.grabWhile(validAttr); | ||
var currChar = attrCharGrabber.getCurr(); | ||
var currChar = attrCharGrabber.getCurr(); // first string before space is a tag name [tagName params...] | ||
// first string before space is a tag name [tagName params...] | ||
if (tagName === null) { | ||
tagName = attrStr; | ||
} else if (isWhiteSpace(currChar) || currChar === char_7 || !attrCharGrabber.hasNext()) { | ||
var escaped = unquote(trimChar(attrStr, char_7)); | ||
} else if (isWhiteSpace(currChar) || currChar === char_9 || !attrCharGrabber.hasNext()) { | ||
var escaped = unquote(trimChar(attrStr, char_9)); | ||
attrTokens.push(createToken(TYPE_ATTR_VALUE, escaped, row, col)); | ||
@@ -760,3 +801,6 @@ } else { | ||
return { tag: tagName, attrs: attrTokens }; | ||
return { | ||
tag: tagName, | ||
attrs: attrTokens | ||
}; | ||
}; | ||
@@ -774,7 +818,6 @@ | ||
if (currChar === char_2) { | ||
if (currChar === char_14) { | ||
bufferGrabber.skip(); | ||
col = 0; | ||
row++; | ||
emitToken(createToken(TYPE_NEW_LINE, currChar, row, col)); | ||
@@ -786,8 +829,10 @@ } else if (isWhiteSpace(currChar)) { | ||
bufferGrabber.skip(); // skip the \ without emitting anything | ||
bufferGrabber.skip(); // skip past the [, ] or \ as well | ||
emitToken(createToken(TYPE_WORD, nextChar, row, col)); | ||
} else if (currChar === openTag) { | ||
bufferGrabber.skip(); // skip openTag | ||
// detect case where we have '[My word [tag][/tag]' or we have '[My last line word' | ||
// detect case where we have '[My word [tag][/tag]' or we have '[My last line word' | ||
var substr = bufferGrabber.substrUntilChar(closeTag); | ||
@@ -805,6 +850,7 @@ var hasInvalidChars = substr.length === 0 || substr.indexOf(openTag) >= 0; | ||
// [myTag ] | ||
var isNoAttrsInTag = _str.indexOf(char_6) === -1; | ||
// [/myTag] | ||
var isClosingTag = _str[0] === char_11; | ||
var isNoAttrsInTag = _str.indexOf(char_10) === -1; // [/myTag] | ||
var isClosingTag = _str[0] === char_5; | ||
if (isNoAttrsInTag || isClosingTag) { | ||
@@ -814,5 +860,3 @@ emitToken(createToken(TYPE_TAG, _str, row, col)); | ||
var parsed = parseAttrs(_str); | ||
emitToken(createToken(TYPE_TAG, parsed.tag, row, col)); | ||
parsed.attrs.map(emitToken); | ||
@@ -830,7 +874,8 @@ } | ||
} else { | ||
var _str2 = bufferGrabber.grabWhile(function (char$$1) { | ||
var _str2 = bufferGrabber.grabWhile(function (char) { | ||
if (escapeTags) { | ||
return isCharToken(char$$1) && !isEscapeChar(char$$1); | ||
return isCharToken(char) && !isEscapeChar(char); | ||
} | ||
return isCharToken(char$$1); | ||
return isCharToken(char); | ||
}); | ||
@@ -849,3 +894,2 @@ | ||
tokens.length = tokenIndex + 1; | ||
return tokens; | ||
@@ -855,4 +899,4 @@ }; | ||
var isTokenNested = function isTokenNested(token) { | ||
var value = openTag + char_11 + token.getValue(); | ||
// potential bottleneck | ||
var value = openTag + char_5 + token.getValue(); // potential bottleneck | ||
return buffer.indexOf(value) > -1; | ||
@@ -878,9 +922,10 @@ }; | ||
*/ | ||
var parse = function parse(input) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var parse = function parse(input, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
var options = opts; | ||
var tokenizer = null; | ||
/** | ||
@@ -891,2 +936,3 @@ * Result AST of nodes | ||
*/ | ||
var nodes = createList(); | ||
@@ -898,2 +944,3 @@ /** | ||
*/ | ||
var nestedNodes = createList(); | ||
@@ -905,2 +952,3 @@ /** | ||
*/ | ||
var tagNodes = createList(); | ||
@@ -912,4 +960,4 @@ /** | ||
*/ | ||
var tagNodesAttrName = createList(); | ||
/** | ||
@@ -919,2 +967,3 @@ * Cache for nested tags checks | ||
*/ | ||
var nestedTagsMap = {}; | ||
@@ -933,3 +982,2 @@ | ||
}; | ||
/** | ||
@@ -940,2 +988,4 @@ * Flushes temp tag nodes and its attributes buffers | ||
*/ | ||
var flushTagNodes = function flushTagNodes() { | ||
@@ -946,3 +996,2 @@ if (tagNodes.flushLast()) { | ||
}; | ||
/** | ||
@@ -952,8 +1001,8 @@ * @private | ||
*/ | ||
var getNodes = function getNodes() { | ||
var lastNestedNode = nestedNodes.getLast(); | ||
return lastNestedNode ? lastNestedNode.content : nodes.toArray(); | ||
}; | ||
/** | ||
@@ -963,6 +1012,7 @@ * @private | ||
*/ | ||
var appendNodes = function appendNodes(tag) { | ||
getNodes().push(tag); | ||
}; | ||
/** | ||
@@ -973,2 +1023,4 @@ * @private | ||
*/ | ||
var isAllowedTag = function isAllowedTag(value) { | ||
@@ -981,3 +1033,2 @@ if (options.onlyAllowTags && options.onlyAllowTags.length) { | ||
}; | ||
/** | ||
@@ -987,8 +1038,8 @@ * @private | ||
*/ | ||
var handleTagStart = function handleTagStart(token) { | ||
flushTagNodes(); | ||
var tagNode = TagNode.create(token.getValue()); | ||
var isNested = isTokenNested(token); | ||
tagNodes.push(tagNode); | ||
@@ -1002,3 +1053,2 @@ | ||
}; | ||
/** | ||
@@ -1008,5 +1058,6 @@ * @private | ||
*/ | ||
var handleTagEnd = function handleTagEnd(token) { | ||
flushTagNodes(); | ||
var lastNestedNode = nestedNodes.flushLast(); | ||
@@ -1020,5 +1071,4 @@ | ||
var column = token.getColumn(); | ||
options.onError({ | ||
message: 'Inconsistent tag \'' + tag + '\' on line ' + line + ' and column ' + column, | ||
message: "Inconsistent tag '" + tag + "' on line " + line + " and column " + column, | ||
tagName: tag, | ||
@@ -1030,3 +1080,2 @@ lineNumber: line, | ||
}; | ||
/** | ||
@@ -1036,2 +1085,4 @@ * @private | ||
*/ | ||
var handleTag = function handleTag(token) { | ||
@@ -1041,5 +1092,5 @@ // [tag] | ||
handleTagStart(token); | ||
} | ||
} // [/tag] | ||
// [/tag] | ||
if (token.isEnd()) { | ||
@@ -1049,3 +1100,2 @@ handleTagEnd(token); | ||
}; | ||
/** | ||
@@ -1055,2 +1105,4 @@ * @private | ||
*/ | ||
var handleNode = function handleNode(token) { | ||
@@ -1094,3 +1146,2 @@ /** | ||
}; | ||
/** | ||
@@ -1100,2 +1151,4 @@ * @private | ||
*/ | ||
var onToken = function onToken(token) { | ||
@@ -1115,13 +1168,11 @@ if (token.isTag() && isAllowedTag(token.getName())) { | ||
enableEscapeTags: options.enableEscapeTags | ||
}); | ||
}); // eslint-disable-next-line no-unused-vars | ||
// eslint-disable-next-line no-unused-vars | ||
var tokens = tokenizer.tokenize(); | ||
return nodes.toArray(); | ||
}; | ||
exports.TagNode = TagNode_2; | ||
exports.default = parse; | ||
exports.parse = parse; | ||
exports.TagNode = TagNode_2; | ||
@@ -1128,0 +1179,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -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.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 a=e(function(t,n){n.__esModule=!0;n.N="\n",n.F="\f",n.R="\r",n.TAB="\t",n.EQ="=",n.QUOTEMARK='"',n.SPACE=" ",n.OPEN_BRAKET="[",n.CLOSE_BRAKET="]",n.SLASH="/",n.PLACEHOLDER_SPACE_TAB=" ",n.PLACEHOLDER_SPACE=" ",n.BACKSLASH="\\"});n(a);var L=a.N,b=a.TAB,S=a.EQ,O=a.QUOTEMARK,x=a.SPACE,k=a.OPEN_BRAKET,C=a.CLOSE_BRAKET,m=a.SLASH,w=a.BACKSLASH,o=e(function(t,n){n.__esModule=!0,n.isEOL=n.isStringNode=n.isTagNode=n.getNodeLength=n.appendToNode=n.attrValue=n.attrsToString=void 0;var r=function(t){return"object"==typeof t&&!!t.tag},o=function(t){return"string"==typeof t},i=function(t){return t.replace(/"/g,""")},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.attrsToString=function(e){return void 0===e?"":Object.keys(e).reduce(function(t,n){return[].concat(t,[u(n,e[n])])},[""]).join(" ")},n.attrValue=u,n.appendToNode=function(t,n){t.content.push(n)},n.getNodeLength=function e(t){return r(t)?t.content.reduce(function(t,n){return t+e(n)},0):o(t)?t.length:0},n.isTagNode=r,n.isStringNode=o,n.isEOL=function(t){return t===a.N}});n(o);var r=e(function(t,n){n.__esModule=!0,n.TagNode=void 0;var e=function(){function r(t,n){for(var e=0;e<n.length;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)}}return function(t,n,e){return n&&r(t.prototype,n),e&&r(t,e),t}}();var r=function(){function r(t,n,e){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,r),this.tag=t.toLowerCase(),this.attrs=n,this.content=[].concat(e)}return r.prototype.attr=function(t,n){return void 0!==n&&(this.attrs[t]=n),this.attrs[t]},r.prototype.append=function(t){return(0,o.appendToNode)(this,t)},r.prototype.toString=function(){var t=a.OPEN_BRAKET,n=a.CLOSE_BRAKET;return t+this.tag+n+this.content.reduce(function(t,n){return t+""+n},"")+t+a.SLASH+this.tag+n},e(r,[{key:"length",get:function(){return(0,o.getNodeLength)(this)}}]),r}();r.create=function(t){return new r(t,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},2<arguments.length&&void 0!==arguments[2]?arguments[2]:[])},r.isOf=function(t,n){return t.tag===n},n.TagNode=r,n.default=r}),h=n(r),i=r.TagNode,u="type",s="value",f="line",c="word",l="attr-name",g="attr-value",p="space",d="new-line",v=function(t){return t[s]},T=function(t){return v(t).charCodeAt(0)==m.charCodeAt(0)},y=function(){function o(t,n,e,r){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,o),this[u]=t+"",this[s]=n+"",this[f]=+e,this.row=+r}return o.prototype.isEmpty=function(){return!!this[u]},o.prototype.isText=function(){return(t=this)[u]===p||t[u]===d||t[u]===c;var t},o.prototype.isTag=function(){return"tag"===this[u]},o.prototype.isAttrName=function(){return this[u]===l},o.prototype.isAttrValue=function(){return this[u]===g},o.prototype.isStart=function(){return!T(this)},o.prototype.isEnd=function(){return T(this)},o.prototype.getName=function(){return n=v(t=this),T(t)?n.slice(1):n;var t,n},o.prototype.getValue=function(){return v(this)},o.prototype.getLine=function(){return this[f]},o.prototype.getColumn=function(){return this.row},o.prototype.toString=function(){return t=k,t+=v(this),t+=C;var t},o}(),_=c,P=function(e,t){var r={pos:0,length:e.length},o=function(){r.pos+=1,t&&t.onSkip&&t.onSkip()},i=function(){return r.pos<r.length},u=function(){return e.substr(r.pos)},a=function(){return e[r.pos]};return{skip:o,hasNext:i,isLast:function(){return r.pos===r.length},grabWhile:function(t){var n=0;if(i())for(n=r.pos;i()&&t(a());)o();return e.substr(n,r.pos-n)},getNext:function(){return e[r.pos+1]},getPrev:function(){return e[r.pos-1]},getCurr:a,getRest:u,substrUntilChar:function(t){var n=u(),e=n.indexOf(t);return e<0?"":n.substr(0,e)}}},A=function(){var n=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];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}}},B=function(t,n){return new y(t,n,2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,3<arguments.length&&void 0!==arguments[3]?arguments[3]:0)};function N(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},f=0,c=0,r=-1,o=Array(Math.floor(e.length)),s=n.openTag||k,l=n.closeTag||C,g=n.enableEscapeTags,p=[l,s,O,w,x,b,S,L,"!"],i=[s,x,b,L],u=[x,b],h=[S,x,b],d=function(t){return 0<=u.indexOf(t)},v=function(t){return-1==i.indexOf(t)},T=function(t){return t===s||t===l||t===w},y=function(t){return t===w},A=function(t){n.onToken&&n.onToken(t),o[r+=1]=t},N=function(t){for(var u=null,a=!1,r=[],s=P(t),o=function(t){var n=t===S,e=d(t),r=s.getPrev(),o=s.getNext(),i=r===w;return null===u?!1===(n||e||s.isLast()):!(!a||h.indexOf(t)<0)||!!(t!==O||i||(a=!a)||o===S||d(o))&&!1===(n||e)},n=function(){var t=s.grabWhile(o),n=s.getCurr();if(null===u)u=t;else if(d(n)||n===O||!s.hasNext()){var e=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,O).replace(w+O,O);r.push(B("attr-value",e,f,c))}else r.push(B("attr-name",t,f,c));s.skip()};s.hasNext();)n();return{tag:u,attrs:r}},E=P(e,{onSkip:function(){c++}}),t=function(){var t=E.getCurr(),n=E.getNext();if(t===L)E.skip(),A(B("new-line",t,++f,c=0));else if(d(t)){var e=E.grabWhile(d);A(B("space",e,f,c))}else if(g&&y(t)&&T(n))E.skip(),E.skip(),A(B(_,n,f,c));else if(t===s){E.skip();var r=E.substrUntilChar(l),o=0===r.length||0<=r.indexOf(s);if(0<=p.indexOf(n)||o||E.isLast())A(B(_,t,f,c));else{var i=E.grabWhile(function(t){return t!==l});if(E.skip(),-1==i.indexOf(S)||i[0]===m)A(B("tag",i,f,c));else{var u=N(i);A(B("tag",u.tag,f,c)),u.attrs.map(A)}}}else if(t===l)E.skip(),A(B(_,t,f,c));else if(v(t))if(g&&y(t)&&!T(n))E.skip(),A(B(_,t,f,c));else{var a=E.grabWhile(function(t){return g?v(t)&&!y(t):v(t)});A(B(_,a,f,c))}};return{tokenize:function(){for(;E.hasNext();)t();return o.length=r+1,o},isTokenNested:function(t){var n=s+m+t.getValue();return-1<e.indexOf(n)}}}var E=function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=n,o=null,e=A(),u=A(),a=A(),s=A(),f={},c=function(){a.flushLast()&&s.flushLast()},l=function(t){var n;(n=u.getLast(),n?n.content:e.toArray()).push(t)},r=function(t){c();var n,e=h.create(t.getValue()),r=(void 0===f[(n=t).getValue()]&&(f[n.getValue()]=o.isTokenNested(n)),f[n.getValue()]);a.push(e),r?u.push(e):l(e)},g=function(t){t.isStart()&&r(t),t.isEnd()&&function(t){c();var n=u.flushLast();if(n)l(n);else if(i.onError){var e=t.getValue(),r=t.getLine(),o=t.getColumn();i.onError({message:"Inconsistent tag '"+e+"' on line "+r+" and column "+o,tagName:e,lineNumber:r,columnNumber:o})}}(t)},p=function(t){var n=a.getLast(),e=t.getValue(),r=!!f[t];if(n)if(t.isAttrName())s.push(e),n.attr(s.getLast(),"");else if(t.isAttrValue()){var o=s.getLast();o?(n.attr(o,e),s.flushLast()):n.attr(e,e)}else t.isText()?r?n.append(e):l(e):t.isTag()&&l(""+t);else t.isText()?l(e):t.isTag()&&l(""+t)};(o=(n.createTokenizer?n.createTokenizer:N)(t,{onToken:function(t){var n;!t.isTag()||(n=t.getName(),i.onlyAllowTags&&i.onlyAllowTags.length&&i.onlyAllowTags.indexOf(n)<0)?p(t):g(t)},onlyAllowTags:i.onlyAllowTags,openTag:i.openTag,closeTag:i.closeTag,enableEscapeTags:i.enableEscapeTags})).tokenize();return e.toArray()};t.default=E,t.parse=E,t.TagNode=i,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.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,""")},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})})); |
@@ -1,2 +0,17 @@ | ||
export { default, parse } from './parse'; | ||
export { TagNode } from '@bbob/plugin-helper/lib/TagNode'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.TagNode = exports.parse = exports.default = void 0; | ||
var _parse = _interopRequireWildcard(require("./parse")); | ||
exports.default = _parse.default; | ||
exports.parse = _parse.parse; | ||
var _TagNode = require("@bbob/plugin-helper/lib/TagNode"); | ||
exports.TagNode = _TagNode.TagNode; | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } |
187
es/lexer.js
@@ -1,10 +0,16 @@ | ||
/* eslint-disable no-plusplus,no-param-reassign */ | ||
import { OPEN_BRAKET, CLOSE_BRAKET, QUOTEMARK, BACKSLASH, SLASH, SPACE, TAB, EQ, N } from '@bbob/plugin-helper/lib/char'; | ||
"use strict"; | ||
import { Token, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_NEW_LINE, TYPE_SPACE, TYPE_TAG, TYPE_WORD } from './Token'; | ||
import { createCharGrabber, trimChar, unquote } from './utils'; | ||
exports.__esModule = true; | ||
exports.createLexer = createLexer; | ||
exports.createTokenOfType = void 0; | ||
var _char = require("@bbob/plugin-helper/lib/char"); | ||
var _Token = require("./Token"); | ||
var _utils = require("./utils"); | ||
/* eslint-disable no-plusplus,no-param-reassign */ | ||
// for cases <!-- --> | ||
var EM = '!'; | ||
/** | ||
@@ -17,8 +23,14 @@ * Creates a Token entity class | ||
*/ | ||
var createToken = function createToken(type, value) { | ||
var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
var cl = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; | ||
return new Token(type, value, r, cl); | ||
var createToken = function createToken(type, value, r, cl) { | ||
if (r === void 0) { | ||
r = 0; | ||
} | ||
if (cl === void 0) { | ||
cl = 0; | ||
} | ||
return new _Token.Token(type, value, r, cl); | ||
}; | ||
/** | ||
@@ -39,40 +51,33 @@ * @typedef {Object} Lexer | ||
*/ | ||
function createLexer(buffer) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
function createLexer(buffer, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var row = 0; | ||
var col = 0; | ||
var tokenIndex = -1; | ||
var tokens = new Array(Math.floor(buffer.length)); | ||
var openTag = options.openTag || OPEN_BRAKET; | ||
var closeTag = options.closeTag || CLOSE_BRAKET; | ||
var openTag = options.openTag || _char.OPEN_BRAKET; | ||
var closeTag = options.closeTag || _char.CLOSE_BRAKET; | ||
var escapeTags = options.enableEscapeTags; | ||
var RESERVED_CHARS = [closeTag, openTag, _char.QUOTEMARK, _char.BACKSLASH, _char.SPACE, _char.TAB, _char.EQ, _char.N, EM]; | ||
var NOT_CHAR_TOKENS = [// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
openTag, _char.SPACE, _char.TAB, _char.N]; | ||
var WHITESPACES = [_char.SPACE, _char.TAB]; | ||
var SPECIAL_CHARS = [_char.EQ, _char.SPACE, _char.TAB]; | ||
var RESERVED_CHARS = [closeTag, openTag, QUOTEMARK, BACKSLASH, SPACE, TAB, EQ, N, EM]; | ||
var NOT_CHAR_TOKENS = [ | ||
// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
openTag, SPACE, TAB, N]; | ||
var WHITESPACES = [SPACE, TAB]; | ||
var SPECIAL_CHARS = [EQ, SPACE, TAB]; | ||
var isCharReserved = char => RESERVED_CHARS.indexOf(char) >= 0; | ||
var isCharReserved = function isCharReserved(char) { | ||
return RESERVED_CHARS.indexOf(char) >= 0; | ||
}; | ||
var isWhiteSpace = function isWhiteSpace(char) { | ||
return WHITESPACES.indexOf(char) >= 0; | ||
}; | ||
var isCharToken = function isCharToken(char) { | ||
return NOT_CHAR_TOKENS.indexOf(char) === -1; | ||
}; | ||
var isSpecialChar = function isSpecialChar(char) { | ||
return SPECIAL_CHARS.indexOf(char) >= 0; | ||
}; | ||
var isEscapableChar = function isEscapableChar(char) { | ||
return char === openTag || char === closeTag || char === BACKSLASH; | ||
}; | ||
var isEscapeChar = function isEscapeChar(char) { | ||
return char === BACKSLASH; | ||
}; | ||
var isWhiteSpace = char => WHITESPACES.indexOf(char) >= 0; | ||
var isCharToken = char => NOT_CHAR_TOKENS.indexOf(char) === -1; | ||
var isSpecialChar = char => SPECIAL_CHARS.indexOf(char) >= 0; | ||
var isEscapableChar = char => char === openTag || char === closeTag || char === _char.BACKSLASH; | ||
var isEscapeChar = char => char === _char.BACKSLASH; | ||
/** | ||
@@ -82,3 +87,5 @@ * Emits newly created token to subscriber | ||
*/ | ||
var emitToken = function emitToken(token) { | ||
var emitToken = token => { | ||
if (options.onToken) { | ||
@@ -91,3 +98,2 @@ options.onToken(token); | ||
}; | ||
/** | ||
@@ -98,15 +104,16 @@ * Parses params inside [myTag---params goes here---]content[/myTag] | ||
*/ | ||
var parseAttrs = function parseAttrs(str) { | ||
var parseAttrs = str => { | ||
var tagName = null; | ||
var skipSpecialChars = false; | ||
var attrTokens = []; | ||
var attrCharGrabber = createCharGrabber(str); | ||
var attrCharGrabber = (0, _utils.createCharGrabber)(str); | ||
var validAttr = function validAttr(char) { | ||
var isEQ = char === EQ; | ||
var validAttr = char => { | ||
var isEQ = char === _char.EQ; | ||
var isWS = isWhiteSpace(char); | ||
var prevChar = attrCharGrabber.getPrev(); | ||
var nextChar = attrCharGrabber.getNext(); | ||
var isPrevSLASH = prevChar === BACKSLASH; | ||
var isPrevSLASH = prevChar === _char.BACKSLASH; | ||
var isTagNameEmpty = tagName === null; | ||
@@ -122,6 +129,6 @@ | ||
if (char === QUOTEMARK && !isPrevSLASH) { | ||
if (char === _char.QUOTEMARK && !isPrevSLASH) { | ||
skipSpecialChars = !skipSpecialChars; | ||
if (!skipSpecialChars && !(nextChar === EQ || isWhiteSpace(nextChar))) { | ||
if (!skipSpecialChars && !(nextChar === _char.EQ || isWhiteSpace(nextChar))) { | ||
return false; | ||
@@ -134,14 +141,13 @@ } | ||
var nextAttr = function nextAttr() { | ||
var nextAttr = () => { | ||
var attrStr = attrCharGrabber.grabWhile(validAttr); | ||
var currChar = attrCharGrabber.getCurr(); | ||
var currChar = attrCharGrabber.getCurr(); // first string before space is a tag name [tagName params...] | ||
// first string before space is a tag name [tagName params...] | ||
if (tagName === null) { | ||
tagName = attrStr; | ||
} else if (isWhiteSpace(currChar) || currChar === QUOTEMARK || !attrCharGrabber.hasNext()) { | ||
var escaped = unquote(trimChar(attrStr, QUOTEMARK)); | ||
attrTokens.push(createToken(TYPE_ATTR_VALUE, escaped, row, col)); | ||
} else if (isWhiteSpace(currChar) || currChar === _char.QUOTEMARK || !attrCharGrabber.hasNext()) { | ||
var escaped = (0, _utils.unquote)((0, _utils.trimChar)(attrStr, _char.QUOTEMARK)); | ||
attrTokens.push(createToken(_Token.TYPE_ATTR_VALUE, escaped, row, col)); | ||
} else { | ||
attrTokens.push(createToken(TYPE_ATTR_NAME, attrStr, row, col)); | ||
attrTokens.push(createToken(_Token.TYPE_ATTR_NAME, attrStr, row, col)); | ||
} | ||
@@ -156,7 +162,10 @@ | ||
return { tag: tagName, attrs: attrTokens }; | ||
return { | ||
tag: tagName, | ||
attrs: attrTokens | ||
}; | ||
}; | ||
var bufferGrabber = createCharGrabber(buffer, { | ||
onSkip: function onSkip() { | ||
var bufferGrabber = (0, _utils.createCharGrabber)(buffer, { | ||
onSkip: () => { | ||
col++; | ||
@@ -166,23 +175,24 @@ } | ||
var next = function next() { | ||
var next = () => { | ||
var currChar = bufferGrabber.getCurr(); | ||
var nextChar = bufferGrabber.getNext(); | ||
if (currChar === N) { | ||
if (currChar === _char.N) { | ||
bufferGrabber.skip(); | ||
col = 0; | ||
row++; | ||
emitToken(createToken(TYPE_NEW_LINE, currChar, row, col)); | ||
emitToken(createToken(_Token.TYPE_NEW_LINE, currChar, row, col)); | ||
} else if (isWhiteSpace(currChar)) { | ||
var str = bufferGrabber.grabWhile(isWhiteSpace); | ||
emitToken(createToken(TYPE_SPACE, str, row, col)); | ||
emitToken(createToken(_Token.TYPE_SPACE, str, row, col)); | ||
} else if (escapeTags && isEscapeChar(currChar) && isEscapableChar(nextChar)) { | ||
bufferGrabber.skip(); // skip the \ without emitting anything | ||
bufferGrabber.skip(); // skip past the [, ] or \ as well | ||
emitToken(createToken(TYPE_WORD, nextChar, row, col)); | ||
emitToken(createToken(_Token.TYPE_WORD, nextChar, row, col)); | ||
} else if (currChar === openTag) { | ||
bufferGrabber.skip(); // skip openTag | ||
// detect case where we have '[My word [tag][/tag]' or we have '[My last line word' | ||
// detect case where we have '[My word [tag][/tag]' or we have '[My last line word' | ||
var substr = bufferGrabber.substrUntilChar(closeTag); | ||
@@ -192,21 +202,18 @@ var hasInvalidChars = substr.length === 0 || substr.indexOf(openTag) >= 0; | ||
if (isCharReserved(nextChar) || hasInvalidChars || bufferGrabber.isLast()) { | ||
emitToken(createToken(TYPE_WORD, currChar, row, col)); | ||
emitToken(createToken(_Token.TYPE_WORD, currChar, row, col)); | ||
} else { | ||
var _str = bufferGrabber.grabWhile(function (val) { | ||
return val !== closeTag; | ||
}); | ||
var _str = bufferGrabber.grabWhile(val => val !== closeTag); | ||
bufferGrabber.skip(); // skip closeTag | ||
// [myTag ] | ||
var isNoAttrsInTag = _str.indexOf(EQ) === -1; | ||
// [/myTag] | ||
var isClosingTag = _str[0] === SLASH; | ||
var isNoAttrsInTag = _str.indexOf(_char.EQ) === -1; // [/myTag] | ||
var isClosingTag = _str[0] === _char.SLASH; | ||
if (isNoAttrsInTag || isClosingTag) { | ||
emitToken(createToken(TYPE_TAG, _str, row, col)); | ||
emitToken(createToken(_Token.TYPE_TAG, _str, row, col)); | ||
} else { | ||
var parsed = parseAttrs(_str); | ||
emitToken(createToken(TYPE_TAG, parsed.tag, row, col)); | ||
emitToken(createToken(_Token.TYPE_TAG, parsed.tag, row, col)); | ||
parsed.attrs.map(emitToken); | ||
@@ -218,16 +225,17 @@ } | ||
emitToken(createToken(TYPE_WORD, currChar, row, col)); | ||
emitToken(createToken(_Token.TYPE_WORD, currChar, row, col)); | ||
} else if (isCharToken(currChar)) { | ||
if (escapeTags && isEscapeChar(currChar) && !isEscapableChar(nextChar)) { | ||
bufferGrabber.skip(); | ||
emitToken(createToken(TYPE_WORD, currChar, row, col)); | ||
emitToken(createToken(_Token.TYPE_WORD, currChar, row, col)); | ||
} else { | ||
var _str2 = bufferGrabber.grabWhile(function (char) { | ||
var _str2 = bufferGrabber.grabWhile(char => { | ||
if (escapeTags) { | ||
return isCharToken(char) && !isEscapeChar(char); | ||
} | ||
return isCharToken(char); | ||
}); | ||
emitToken(createToken(TYPE_WORD, _str2, row, col)); | ||
emitToken(createToken(_Token.TYPE_WORD, _str2, row, col)); | ||
} | ||
@@ -237,3 +245,3 @@ } | ||
var tokenize = function tokenize() { | ||
var tokenize = () => { | ||
while (bufferGrabber.hasNext()) { | ||
@@ -244,9 +252,8 @@ next(); | ||
tokens.length = tokenIndex + 1; | ||
return tokens; | ||
}; | ||
var isTokenNested = function isTokenNested(token) { | ||
var value = openTag + SLASH + token.getValue(); | ||
// potential bottleneck | ||
var isTokenNested = token => { | ||
var value = openTag + _char.SLASH + token.getValue(); // potential bottleneck | ||
return buffer.indexOf(value) > -1; | ||
@@ -256,8 +263,8 @@ }; | ||
return { | ||
tokenize: tokenize, | ||
isTokenNested: isTokenNested | ||
tokenize, | ||
isTokenNested | ||
}; | ||
} | ||
export var createTokenOfType = createToken; | ||
export { createLexer }; | ||
var createTokenOfType = createToken; | ||
exports.createTokenOfType = createTokenOfType; |
112
es/parse.js
@@ -1,5 +0,14 @@ | ||
import TagNode from '@bbob/plugin-helper/lib/TagNode'; | ||
import { createLexer } from './lexer'; | ||
import { createList } from './utils'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = exports.parse = void 0; | ||
var _TagNode = _interopRequireDefault(require("@bbob/plugin-helper/lib/TagNode")); | ||
var _lexer = require("./lexer"); | ||
var _utils = require("./utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -16,9 +25,9 @@ * @public | ||
*/ | ||
var parse = function parse(input) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var parse = function parse(input, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
var options = opts; | ||
var tokenizer = null; | ||
/** | ||
@@ -29,3 +38,4 @@ * Result AST of nodes | ||
*/ | ||
var nodes = createList(); | ||
var nodes = (0, _utils.createList)(); | ||
/** | ||
@@ -36,3 +46,4 @@ * Temp buffer of nodes that's nested to another node | ||
*/ | ||
var nestedNodes = createList(); | ||
var nestedNodes = (0, _utils.createList)(); | ||
/** | ||
@@ -43,3 +54,4 @@ * Temp buffer of nodes [tag..]...[/tag] | ||
*/ | ||
var tagNodes = createList(); | ||
var tagNodes = (0, _utils.createList)(); | ||
/** | ||
@@ -50,4 +62,4 @@ * Temp buffer of tag attributes | ||
*/ | ||
var tagNodesAttrName = createList(); | ||
var tagNodesAttrName = (0, _utils.createList)(); | ||
/** | ||
@@ -57,5 +69,6 @@ * Cache for nested tags checks | ||
*/ | ||
var nestedTagsMap = {}; | ||
var isTokenNested = function isTokenNested(token) { | ||
var isTokenNested = token => { | ||
if (typeof nestedTagsMap[token.getValue()] === 'undefined') { | ||
@@ -68,6 +81,3 @@ nestedTagsMap[token.getValue()] = tokenizer.isTokenNested(token); | ||
var isTagNested = function isTagNested(tagName) { | ||
return !!nestedTagsMap[tagName]; | ||
}; | ||
var isTagNested = tagName => !!nestedTagsMap[tagName]; | ||
/** | ||
@@ -78,3 +88,5 @@ * Flushes temp tag nodes and its attributes buffers | ||
*/ | ||
var flushTagNodes = function flushTagNodes() { | ||
var flushTagNodes = () => { | ||
if (tagNodes.flushLast()) { | ||
@@ -84,3 +96,2 @@ tagNodesAttrName.flushLast(); | ||
}; | ||
/** | ||
@@ -90,8 +101,8 @@ * @private | ||
*/ | ||
var getNodes = function getNodes() { | ||
var getNodes = () => { | ||
var lastNestedNode = nestedNodes.getLast(); | ||
return lastNestedNode ? lastNestedNode.content : nodes.toArray(); | ||
}; | ||
/** | ||
@@ -101,6 +112,7 @@ * @private | ||
*/ | ||
var appendNodes = function appendNodes(tag) { | ||
var appendNodes = tag => { | ||
getNodes().push(tag); | ||
}; | ||
/** | ||
@@ -111,3 +123,5 @@ * @private | ||
*/ | ||
var isAllowedTag = function isAllowedTag(value) { | ||
var isAllowedTag = value => { | ||
if (options.onlyAllowTags && options.onlyAllowTags.length) { | ||
@@ -119,3 +133,2 @@ return options.onlyAllowTags.indexOf(value) >= 0; | ||
}; | ||
/** | ||
@@ -125,8 +138,10 @@ * @private | ||
*/ | ||
var handleTagStart = function handleTagStart(token) { | ||
var handleTagStart = token => { | ||
flushTagNodes(); | ||
var tagNode = TagNode.create(token.getValue()); | ||
var tagNode = _TagNode.default.create(token.getValue()); | ||
var isNested = isTokenNested(token); | ||
tagNodes.push(tagNode); | ||
@@ -140,3 +155,2 @@ | ||
}; | ||
/** | ||
@@ -146,5 +160,6 @@ * @private | ||
*/ | ||
var handleTagEnd = function handleTagEnd(token) { | ||
var handleTagEnd = token => { | ||
flushTagNodes(); | ||
var lastNestedNode = nestedNodes.flushLast(); | ||
@@ -158,5 +173,4 @@ | ||
var column = token.getColumn(); | ||
options.onError({ | ||
message: 'Inconsistent tag \'' + tag + '\' on line ' + line + ' and column ' + column, | ||
message: "Inconsistent tag '" + tag + "' on line " + line + " and column " + column, | ||
tagName: tag, | ||
@@ -168,3 +182,2 @@ lineNumber: line, | ||
}; | ||
/** | ||
@@ -174,9 +187,11 @@ * @private | ||
*/ | ||
var handleTag = function handleTag(token) { | ||
var handleTag = token => { | ||
// [tag] | ||
if (token.isStart()) { | ||
handleTagStart(token); | ||
} | ||
} // [/tag] | ||
// [/tag] | ||
if (token.isEnd()) { | ||
@@ -186,3 +201,2 @@ handleTagEnd(token); | ||
}; | ||
/** | ||
@@ -192,3 +206,5 @@ * @private | ||
*/ | ||
var handleNode = function handleNode(token) { | ||
var handleNode = token => { | ||
/** | ||
@@ -231,3 +247,2 @@ * @type {TagNode} | ||
}; | ||
/** | ||
@@ -237,3 +252,5 @@ * @private | ||
*/ | ||
var onToken = function onToken(token) { | ||
var onToken = token => { | ||
if (token.isTag() && isAllowedTag(token.getName())) { | ||
@@ -246,4 +263,4 @@ handleTag(token); | ||
tokenizer = (opts.createTokenizer ? opts.createTokenizer : createLexer)(input, { | ||
onToken: onToken, | ||
tokenizer = (opts.createTokenizer ? opts.createTokenizer : _lexer.createLexer)(input, { | ||
onToken, | ||
onlyAllowTags: options.onlyAllowTags, | ||
@@ -253,11 +270,10 @@ openTag: options.openTag, | ||
enableEscapeTags: options.enableEscapeTags | ||
}); | ||
}); // eslint-disable-next-line no-unused-vars | ||
// eslint-disable-next-line no-unused-vars | ||
var tokens = tokenizer.tokenize(); | ||
return nodes.toArray(); | ||
}; | ||
export { parse }; | ||
export default parse; | ||
exports.parse = parse; | ||
var _default = parse; | ||
exports.default = _default; |
155
es/Token.js
@@ -1,9 +0,15 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
"use strict"; | ||
import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from '@bbob/plugin-helper/lib/char'; | ||
exports.__esModule = true; | ||
exports.default = exports.Token = exports.TYPE_NEW_LINE = exports.TYPE_SPACE = exports.TYPE_ATTR_VALUE = exports.TYPE_ATTR_NAME = exports.TYPE_TAG = exports.TYPE_WORD = exports.COLUMN_ID = exports.LINE_ID = exports.VALUE_ID = exports.TYPE_ID = void 0; | ||
var _char = require("@bbob/plugin-helper/lib/char"); | ||
// type, value, line, row, | ||
var TOKEN_TYPE_ID = 'type'; // 0; | ||
var TOKEN_VALUE_ID = 'value'; // 1; | ||
var TOKEN_COLUMN_ID = 'row'; // 2; | ||
var TOKEN_LINE_ID = 'line'; // 3; | ||
@@ -18,48 +24,33 @@ | ||
var getTokenValue = function getTokenValue(token) { | ||
return token[TOKEN_VALUE_ID]; | ||
}; | ||
var getTokenLine = function getTokenLine(token) { | ||
return token[TOKEN_LINE_ID]; | ||
}; | ||
var getTokenColumn = function getTokenColumn(token) { | ||
return token[TOKEN_COLUMN_ID]; | ||
}; | ||
var getTokenValue = token => token[TOKEN_VALUE_ID]; | ||
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; | ||
}; | ||
var getTokenLine = token => token[TOKEN_LINE_ID]; | ||
var isTagToken = function isTagToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG; | ||
}; | ||
var isTagEnd = function isTagEnd(token) { | ||
return getTokenValue(token).charCodeAt(0) === SLASH.charCodeAt(0); | ||
}; | ||
var isTagStart = function isTagStart(token) { | ||
return !isTagEnd(token); | ||
}; | ||
var isAttrNameToken = function isAttrNameToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME; | ||
}; | ||
var isAttrValueToken = function isAttrValueToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE; | ||
}; | ||
var getTokenColumn = token => token[TOKEN_COLUMN_ID]; | ||
var getTagName = function getTagName(token) { | ||
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 isTagToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG; | ||
var isTagEnd = token => getTokenValue(token).charCodeAt(0) === _char.SLASH.charCodeAt(0); | ||
var isTagStart = token => !isTagEnd(token); | ||
var isAttrNameToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME; | ||
var isAttrValueToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE; | ||
var getTagName = token => { | ||
var value = getTokenValue(token); | ||
return isTagEnd(token) ? value.slice(1) : value; | ||
}; | ||
var convertTagToText = function convertTagToText(token) { | ||
var text = OPEN_BRAKET; | ||
var convertTagToText = token => { | ||
var text = _char.OPEN_BRAKET; | ||
text += getTokenValue(token); | ||
text += CLOSE_BRAKET; | ||
text += _char.CLOSE_BRAKET; | ||
return text; | ||
}; | ||
var Token = function () { | ||
class Token { | ||
/** | ||
@@ -71,5 +62,3 @@ * @param {String} type | ||
*/ | ||
function Token(type, value, line, row) { | ||
_classCallCheck(this, Token); | ||
constructor(type, value, line, row) { | ||
this[TOKEN_TYPE_ID] = String(type); | ||
@@ -81,64 +70,74 @@ this[TOKEN_VALUE_ID] = String(value); | ||
Token.prototype.isEmpty = function isEmpty() { | ||
isEmpty() { | ||
return !!this[TOKEN_TYPE_ID]; | ||
}; | ||
} | ||
Token.prototype.isText = function isText() { | ||
isText() { | ||
return isTextToken(this); | ||
}; | ||
} | ||
Token.prototype.isTag = function isTag() { | ||
isTag() { | ||
return isTagToken(this); | ||
}; | ||
} | ||
Token.prototype.isAttrName = function isAttrName() { | ||
isAttrName() { | ||
return isAttrNameToken(this); | ||
}; | ||
} | ||
Token.prototype.isAttrValue = function isAttrValue() { | ||
isAttrValue() { | ||
return isAttrValueToken(this); | ||
}; | ||
} | ||
Token.prototype.isStart = function isStart() { | ||
isStart() { | ||
return isTagStart(this); | ||
}; | ||
} | ||
Token.prototype.isEnd = function isEnd() { | ||
isEnd() { | ||
return isTagEnd(this); | ||
}; | ||
} | ||
Token.prototype.getName = function getName() { | ||
getName() { | ||
return getTagName(this); | ||
}; | ||
} | ||
Token.prototype.getValue = function getValue() { | ||
getValue() { | ||
return getTokenValue(this); | ||
}; | ||
} | ||
Token.prototype.getLine = function getLine() { | ||
getLine() { | ||
return getTokenLine(this); | ||
}; | ||
} | ||
Token.prototype.getColumn = function getColumn() { | ||
getColumn() { | ||
return getTokenColumn(this); | ||
}; | ||
} | ||
Token.prototype.toString = function toString() { | ||
toString() { | ||
return convertTagToText(this); | ||
}; | ||
} | ||
return Token; | ||
}(); | ||
} | ||
export var TYPE_ID = TOKEN_TYPE_ID; | ||
export var VALUE_ID = TOKEN_VALUE_ID; | ||
export var LINE_ID = TOKEN_LINE_ID; | ||
export var COLUMN_ID = TOKEN_COLUMN_ID; | ||
export var TYPE_WORD = TOKEN_TYPE_WORD; | ||
export var TYPE_TAG = TOKEN_TYPE_TAG; | ||
export var TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME; | ||
export var TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE; | ||
export var TYPE_SPACE = TOKEN_TYPE_SPACE; | ||
export var TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE; | ||
export { Token }; | ||
export default Token; | ||
exports.Token = Token; | ||
var TYPE_ID = TOKEN_TYPE_ID; | ||
exports.TYPE_ID = TYPE_ID; | ||
var VALUE_ID = TOKEN_VALUE_ID; | ||
exports.VALUE_ID = VALUE_ID; | ||
var LINE_ID = TOKEN_LINE_ID; | ||
exports.LINE_ID = LINE_ID; | ||
var COLUMN_ID = TOKEN_COLUMN_ID; | ||
exports.COLUMN_ID = COLUMN_ID; | ||
var TYPE_WORD = TOKEN_TYPE_WORD; | ||
exports.TYPE_WORD = TYPE_WORD; | ||
var TYPE_TAG = TOKEN_TYPE_TAG; | ||
exports.TYPE_TAG = TYPE_TAG; | ||
var TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME; | ||
exports.TYPE_ATTR_NAME = TYPE_ATTR_NAME; | ||
var TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE; | ||
exports.TYPE_ATTR_VALUE = TYPE_ATTR_VALUE; | ||
var TYPE_SPACE = TOKEN_TYPE_SPACE; | ||
exports.TYPE_SPACE = TYPE_SPACE; | ||
var TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE; | ||
exports.TYPE_NEW_LINE = TYPE_NEW_LINE; | ||
var _default = Token; | ||
exports.default = _default; |
106
es/utils.js
@@ -1,3 +0,8 @@ | ||
import { QUOTEMARK, BACKSLASH } from '@bbob/plugin-helper/lib/char'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.createList = exports.unquote = exports.trimChar = exports.createCharGrabber = void 0; | ||
var _char = require("@bbob/plugin-helper/lib/char"); | ||
/** | ||
@@ -18,3 +23,3 @@ * @typedef {Object} CharGrabber | ||
*/ | ||
export var createCharGrabber = function createCharGrabber(source, options) { | ||
var createCharGrabber = (source, options) => { | ||
// let idx = 0; | ||
@@ -26,3 +31,3 @@ var cursor = { | ||
var skip = function skip() { | ||
var skip = () => { | ||
cursor.pos += 1; | ||
@@ -34,18 +39,14 @@ | ||
}; | ||
var hasNext = function hasNext() { | ||
return cursor.length > cursor.pos; | ||
}; | ||
var getRest = function getRest() { | ||
return source.substr(cursor.pos); | ||
}; | ||
var getCurr = function getCurr() { | ||
return source[cursor.pos]; | ||
}; | ||
var hasNext = () => cursor.length > cursor.pos; | ||
var getRest = () => source.substr(cursor.pos); | ||
var getCurr = () => source[cursor.pos]; | ||
return { | ||
skip: skip, | ||
hasNext: hasNext, | ||
isLast: function isLast() { | ||
return cursor.pos === cursor.length; | ||
}, | ||
skip, | ||
hasNext, | ||
isLast: () => cursor.pos === cursor.length, | ||
/** | ||
@@ -55,3 +56,3 @@ * @param {Function} cond | ||
*/ | ||
grabWhile: function grabWhile(cond) { | ||
grabWhile: cond => { | ||
var start = 0; | ||
@@ -69,10 +70,7 @@ | ||
}, | ||
getNext: function getNext() { | ||
return source[cursor.pos + 1]; | ||
}, | ||
getPrev: function getPrev() { | ||
return source[cursor.pos - 1]; | ||
}, | ||
getCurr: getCurr, | ||
getRest: getRest, | ||
getNext: () => source[cursor.pos + 1], | ||
getPrev: () => source[cursor.pos - 1], | ||
getCurr, | ||
getRest, | ||
/** | ||
@@ -83,3 +81,3 @@ * Grabs rest of string until it find a char | ||
*/ | ||
substrUntilChar: function substrUntilChar(char) { | ||
substrUntilChar: char => { | ||
var restStr = getRest(); | ||
@@ -96,3 +94,2 @@ var indexOfChar = restStr.indexOf(char); | ||
}; | ||
/** | ||
@@ -106,3 +103,7 @@ * Trims string from start and end by char | ||
*/ | ||
export var trimChar = function trimChar(str, charToRemove) { | ||
exports.createCharGrabber = createCharGrabber; | ||
var trimChar = (str, charToRemove) => { | ||
while (str.charAt(0) === charToRemove) { | ||
@@ -120,3 +121,2 @@ // eslint-disable-next-line no-param-reassign | ||
}; | ||
/** | ||
@@ -127,6 +127,7 @@ * Unquotes \" to " | ||
*/ | ||
export var unquote = function unquote(str) { | ||
return str.replace(BACKSLASH + QUOTEMARK, QUOTEMARK); | ||
}; | ||
exports.trimChar = trimChar; | ||
var unquote = str => str.replace(_char.BACKSLASH + _char.QUOTEMARK, _char.QUOTEMARK); | ||
/** | ||
@@ -146,5 +147,11 @@ * @typedef {Object} ItemList | ||
*/ | ||
export var createList = function createList() { | ||
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
exports.unquote = unquote; | ||
var createList = function createList(values) { | ||
if (values === void 0) { | ||
values = []; | ||
} | ||
var nodes = values; | ||
@@ -154,5 +161,4 @@ /** | ||
*/ | ||
var getLast = function getLast() { | ||
return nodes.length ? nodes[nodes.length - 1] : null; | ||
}; | ||
var getLast = () => nodes.length ? nodes[nodes.length - 1] : null; | ||
/** | ||
@@ -162,3 +168,5 @@ * @callback flushLastCb | ||
*/ | ||
var flushLast = function flushLast() { | ||
var flushLast = () => { | ||
if (nodes.length) { | ||
@@ -174,6 +182,5 @@ return nodes.pop(); | ||
*/ | ||
var push = function push(value) { | ||
return nodes.push(value); | ||
}; | ||
var push = value => nodes.push(value); | ||
/** | ||
@@ -184,10 +191,11 @@ * @callback toArrayCb | ||
return { | ||
getLast: getLast, | ||
flushLast: flushLast, | ||
push: push, | ||
toArray: function toArray() { | ||
return nodes; | ||
} | ||
getLast, | ||
flushLast, | ||
push, | ||
toArray: () => nodes | ||
}; | ||
}; | ||
}; | ||
exports.createList = createList; |
@@ -1,29 +0,17 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.TagNode = exports.parse = exports["default"] = void 0; | ||
var _parse = require('./parse'); | ||
var _parse = _interopRequireWildcard(require("./parse")); | ||
Object.defineProperty(exports, 'default', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_parse).default; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'parse', { | ||
enumerable: true, | ||
get: function get() { | ||
return _parse.parse; | ||
} | ||
}); | ||
exports["default"] = _parse["default"]; | ||
exports.parse = _parse.parse; | ||
var _TagNode = require('@bbob/plugin-helper/lib/TagNode'); | ||
var _TagNode = require("@bbob/plugin-helper/lib/TagNode"); | ||
Object.defineProperty(exports, 'TagNode', { | ||
enumerable: true, | ||
get: function get() { | ||
return _TagNode.TagNode; | ||
} | ||
}); | ||
exports.TagNode = _TagNode.TagNode; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } |
147
lib/lexer.js
@@ -1,15 +0,16 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.createLexer = exports.createTokenOfType = undefined; | ||
exports.createLexer = createLexer; | ||
exports.createTokenOfType = void 0; | ||
var _char = require('@bbob/plugin-helper/lib/char'); | ||
var _char9 = require("@bbob/plugin-helper/lib/char"); | ||
var _Token = require('./Token'); | ||
var _Token = require("./Token"); | ||
var _utils = require('./utils'); | ||
var _utils = require("./utils"); | ||
/* eslint-disable no-plusplus,no-param-reassign */ | ||
// for cases <!-- --> | ||
var EM = '!'; | ||
/** | ||
@@ -22,9 +23,14 @@ * Creates a Token entity class | ||
*/ | ||
/* eslint-disable no-plusplus,no-param-reassign */ | ||
var createToken = function createToken(type, value) { | ||
var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
var cl = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; | ||
var createToken = function createToken(type, value, r, cl) { | ||
if (r === void 0) { | ||
r = 0; | ||
} | ||
if (cl === void 0) { | ||
cl = 0; | ||
} | ||
return new _Token.Token(type, value, r, cl); | ||
}; | ||
/** | ||
@@ -45,40 +51,45 @@ * @typedef {Object} Lexer | ||
*/ | ||
function createLexer(buffer) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
function createLexer(buffer, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var row = 0; | ||
var col = 0; | ||
var tokenIndex = -1; | ||
var tokens = new Array(Math.floor(buffer.length)); | ||
var openTag = options.openTag || _char.OPEN_BRAKET; | ||
var closeTag = options.closeTag || _char.CLOSE_BRAKET; | ||
var openTag = options.openTag || _char9.OPEN_BRAKET; | ||
var closeTag = options.closeTag || _char9.CLOSE_BRAKET; | ||
var escapeTags = options.enableEscapeTags; | ||
var RESERVED_CHARS = [closeTag, openTag, _char9.QUOTEMARK, _char9.BACKSLASH, _char9.SPACE, _char9.TAB, _char9.EQ, _char9.N, EM]; | ||
var NOT_CHAR_TOKENS = [// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
openTag, _char9.SPACE, _char9.TAB, _char9.N]; | ||
var WHITESPACES = [_char9.SPACE, _char9.TAB]; | ||
var SPECIAL_CHARS = [_char9.EQ, _char9.SPACE, _char9.TAB]; | ||
var RESERVED_CHARS = [closeTag, openTag, _char.QUOTEMARK, _char.BACKSLASH, _char.SPACE, _char.TAB, _char.EQ, _char.N, EM]; | ||
var NOT_CHAR_TOKENS = [ | ||
// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
openTag, _char.SPACE, _char.TAB, _char.N]; | ||
var WHITESPACES = [_char.SPACE, _char.TAB]; | ||
var SPECIAL_CHARS = [_char.EQ, _char.SPACE, _char.TAB]; | ||
var isCharReserved = function isCharReserved(_char) { | ||
return RESERVED_CHARS.indexOf(_char) >= 0; | ||
}; | ||
var isCharReserved = function isCharReserved(char) { | ||
return RESERVED_CHARS.indexOf(char) >= 0; | ||
var isWhiteSpace = function isWhiteSpace(_char2) { | ||
return WHITESPACES.indexOf(_char2) >= 0; | ||
}; | ||
var isWhiteSpace = function isWhiteSpace(char) { | ||
return WHITESPACES.indexOf(char) >= 0; | ||
var isCharToken = function isCharToken(_char3) { | ||
return NOT_CHAR_TOKENS.indexOf(_char3) === -1; | ||
}; | ||
var isCharToken = function isCharToken(char) { | ||
return NOT_CHAR_TOKENS.indexOf(char) === -1; | ||
var isSpecialChar = function isSpecialChar(_char4) { | ||
return SPECIAL_CHARS.indexOf(_char4) >= 0; | ||
}; | ||
var isSpecialChar = function isSpecialChar(char) { | ||
return SPECIAL_CHARS.indexOf(char) >= 0; | ||
var isEscapableChar = function isEscapableChar(_char5) { | ||
return _char5 === openTag || _char5 === closeTag || _char5 === _char9.BACKSLASH; | ||
}; | ||
var isEscapableChar = function isEscapableChar(char) { | ||
return char === openTag || char === closeTag || char === _char.BACKSLASH; | ||
var isEscapeChar = function isEscapeChar(_char6) { | ||
return _char6 === _char9.BACKSLASH; | ||
}; | ||
var isEscapeChar = function isEscapeChar(char) { | ||
return char === _char.BACKSLASH; | ||
}; | ||
/** | ||
@@ -88,2 +99,4 @@ * Emits newly created token to subscriber | ||
*/ | ||
var emitToken = function emitToken(token) { | ||
@@ -97,3 +110,2 @@ if (options.onToken) { | ||
}; | ||
/** | ||
@@ -104,15 +116,16 @@ * Parses params inside [myTag---params goes here---]content[/myTag] | ||
*/ | ||
var parseAttrs = function parseAttrs(str) { | ||
var tagName = null; | ||
var skipSpecialChars = false; | ||
var attrTokens = []; | ||
var attrCharGrabber = (0, _utils.createCharGrabber)(str); | ||
var validAttr = function validAttr(char) { | ||
var isEQ = char === _char.EQ; | ||
var isWS = isWhiteSpace(char); | ||
var validAttr = function validAttr(_char7) { | ||
var isEQ = _char7 === _char9.EQ; | ||
var isWS = isWhiteSpace(_char7); | ||
var prevChar = attrCharGrabber.getPrev(); | ||
var nextChar = attrCharGrabber.getNext(); | ||
var isPrevSLASH = prevChar === _char.BACKSLASH; | ||
var isPrevSLASH = prevChar === _char9.BACKSLASH; | ||
var isTagNameEmpty = tagName === null; | ||
@@ -124,10 +137,10 @@ | ||
if (skipSpecialChars && isSpecialChar(char)) { | ||
if (skipSpecialChars && isSpecialChar(_char7)) { | ||
return true; | ||
} | ||
if (char === _char.QUOTEMARK && !isPrevSLASH) { | ||
if (_char7 === _char9.QUOTEMARK && !isPrevSLASH) { | ||
skipSpecialChars = !skipSpecialChars; | ||
if (!skipSpecialChars && !(nextChar === _char.EQ || isWhiteSpace(nextChar))) { | ||
if (!skipSpecialChars && !(nextChar === _char9.EQ || isWhiteSpace(nextChar))) { | ||
return false; | ||
@@ -142,9 +155,8 @@ } | ||
var attrStr = attrCharGrabber.grabWhile(validAttr); | ||
var currChar = attrCharGrabber.getCurr(); | ||
var currChar = attrCharGrabber.getCurr(); // first string before space is a tag name [tagName params...] | ||
// first string before space is a tag name [tagName params...] | ||
if (tagName === null) { | ||
tagName = attrStr; | ||
} else if (isWhiteSpace(currChar) || currChar === _char.QUOTEMARK || !attrCharGrabber.hasNext()) { | ||
var escaped = (0, _utils.unquote)((0, _utils.trimChar)(attrStr, _char.QUOTEMARK)); | ||
} else if (isWhiteSpace(currChar) || currChar === _char9.QUOTEMARK || !attrCharGrabber.hasNext()) { | ||
var escaped = (0, _utils.unquote)((0, _utils.trimChar)(attrStr, _char9.QUOTEMARK)); | ||
attrTokens.push(createToken(_Token.TYPE_ATTR_VALUE, escaped, row, col)); | ||
@@ -162,3 +174,6 @@ } else { | ||
return { tag: tagName, attrs: attrTokens }; | ||
return { | ||
tag: tagName, | ||
attrs: attrTokens | ||
}; | ||
}; | ||
@@ -176,7 +191,6 @@ | ||
if (currChar === _char.N) { | ||
if (currChar === _char9.N) { | ||
bufferGrabber.skip(); | ||
col = 0; | ||
row++; | ||
emitToken(createToken(_Token.TYPE_NEW_LINE, currChar, row, col)); | ||
@@ -188,8 +202,10 @@ } else if (isWhiteSpace(currChar)) { | ||
bufferGrabber.skip(); // skip the \ without emitting anything | ||
bufferGrabber.skip(); // skip past the [, ] or \ as well | ||
emitToken(createToken(_Token.TYPE_WORD, nextChar, row, col)); | ||
} else if (currChar === openTag) { | ||
bufferGrabber.skip(); // skip openTag | ||
// detect case where we have '[My word [tag][/tag]' or we have '[My last line word' | ||
// detect case where we have '[My word [tag][/tag]' or we have '[My last line word' | ||
var substr = bufferGrabber.substrUntilChar(closeTag); | ||
@@ -207,6 +223,7 @@ var hasInvalidChars = substr.length === 0 || substr.indexOf(openTag) >= 0; | ||
// [myTag ] | ||
var isNoAttrsInTag = _str.indexOf(_char.EQ) === -1; | ||
// [/myTag] | ||
var isClosingTag = _str[0] === _char.SLASH; | ||
var isNoAttrsInTag = _str.indexOf(_char9.EQ) === -1; // [/myTag] | ||
var isClosingTag = _str[0] === _char9.SLASH; | ||
if (isNoAttrsInTag || isClosingTag) { | ||
@@ -216,5 +233,3 @@ emitToken(createToken(_Token.TYPE_TAG, _str, row, col)); | ||
var parsed = parseAttrs(_str); | ||
emitToken(createToken(_Token.TYPE_TAG, parsed.tag, row, col)); | ||
parsed.attrs.map(emitToken); | ||
@@ -232,7 +247,8 @@ } | ||
} else { | ||
var _str2 = bufferGrabber.grabWhile(function (char) { | ||
var _str2 = bufferGrabber.grabWhile(function (_char8) { | ||
if (escapeTags) { | ||
return isCharToken(char) && !isEscapeChar(char); | ||
return isCharToken(_char8) && !isEscapeChar(_char8); | ||
} | ||
return isCharToken(char); | ||
return isCharToken(_char8); | ||
}); | ||
@@ -251,3 +267,2 @@ | ||
tokens.length = tokenIndex + 1; | ||
return tokens; | ||
@@ -257,4 +272,4 @@ }; | ||
var isTokenNested = function isTokenNested(token) { | ||
var value = openTag + _char.SLASH + token.getValue(); | ||
// potential bottleneck | ||
var value = openTag + _char9.SLASH + token.getValue(); // potential bottleneck | ||
return buffer.indexOf(value) > -1; | ||
@@ -269,3 +284,3 @@ }; | ||
var createTokenOfType = exports.createTokenOfType = createToken; | ||
exports.createLexer = createLexer; | ||
var createTokenOfType = createToken; | ||
exports.createTokenOfType = createTokenOfType; |
@@ -1,16 +0,14 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.parse = undefined; | ||
exports["default"] = exports.parse = void 0; | ||
var _TagNode = require('@bbob/plugin-helper/lib/TagNode'); | ||
var _TagNode = _interopRequireDefault(require("@bbob/plugin-helper/lib/TagNode")); | ||
var _TagNode2 = _interopRequireDefault(_TagNode); | ||
var _lexer = require("./lexer"); | ||
var _lexer = require('./lexer'); | ||
var _utils = require("./utils"); | ||
var _utils = require('./utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -27,9 +25,9 @@ * @public | ||
*/ | ||
var parse = function parse(input) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var parse = function parse(input, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
var options = opts; | ||
var tokenizer = null; | ||
/** | ||
@@ -40,2 +38,3 @@ * Result AST of nodes | ||
*/ | ||
var nodes = (0, _utils.createList)(); | ||
@@ -47,2 +46,3 @@ /** | ||
*/ | ||
var nestedNodes = (0, _utils.createList)(); | ||
@@ -54,2 +54,3 @@ /** | ||
*/ | ||
var tagNodes = (0, _utils.createList)(); | ||
@@ -61,4 +62,4 @@ /** | ||
*/ | ||
var tagNodesAttrName = (0, _utils.createList)(); | ||
/** | ||
@@ -68,2 +69,3 @@ * Cache for nested tags checks | ||
*/ | ||
var nestedTagsMap = {}; | ||
@@ -82,3 +84,2 @@ | ||
}; | ||
/** | ||
@@ -89,2 +90,4 @@ * Flushes temp tag nodes and its attributes buffers | ||
*/ | ||
var flushTagNodes = function flushTagNodes() { | ||
@@ -95,3 +98,2 @@ if (tagNodes.flushLast()) { | ||
}; | ||
/** | ||
@@ -101,8 +103,8 @@ * @private | ||
*/ | ||
var getNodes = function getNodes() { | ||
var lastNestedNode = nestedNodes.getLast(); | ||
return lastNestedNode ? lastNestedNode.content : nodes.toArray(); | ||
}; | ||
/** | ||
@@ -112,6 +114,7 @@ * @private | ||
*/ | ||
var appendNodes = function appendNodes(tag) { | ||
getNodes().push(tag); | ||
}; | ||
/** | ||
@@ -122,2 +125,4 @@ * @private | ||
*/ | ||
var isAllowedTag = function isAllowedTag(value) { | ||
@@ -130,3 +135,2 @@ if (options.onlyAllowTags && options.onlyAllowTags.length) { | ||
}; | ||
/** | ||
@@ -136,8 +140,10 @@ * @private | ||
*/ | ||
var handleTagStart = function handleTagStart(token) { | ||
flushTagNodes(); | ||
var tagNode = _TagNode2.default.create(token.getValue()); | ||
var tagNode = _TagNode["default"].create(token.getValue()); | ||
var isNested = isTokenNested(token); | ||
tagNodes.push(tagNode); | ||
@@ -151,3 +157,2 @@ | ||
}; | ||
/** | ||
@@ -157,5 +162,6 @@ * @private | ||
*/ | ||
var handleTagEnd = function handleTagEnd(token) { | ||
flushTagNodes(); | ||
var lastNestedNode = nestedNodes.flushLast(); | ||
@@ -169,5 +175,4 @@ | ||
var column = token.getColumn(); | ||
options.onError({ | ||
message: 'Inconsistent tag \'' + tag + '\' on line ' + line + ' and column ' + column, | ||
message: "Inconsistent tag '" + tag + "' on line " + line + " and column " + column, | ||
tagName: tag, | ||
@@ -179,3 +184,2 @@ lineNumber: line, | ||
}; | ||
/** | ||
@@ -185,2 +189,4 @@ * @private | ||
*/ | ||
var handleTag = function handleTag(token) { | ||
@@ -190,5 +196,5 @@ // [tag] | ||
handleTagStart(token); | ||
} | ||
} // [/tag] | ||
// [/tag] | ||
if (token.isEnd()) { | ||
@@ -198,3 +204,2 @@ handleTagEnd(token); | ||
}; | ||
/** | ||
@@ -204,2 +209,4 @@ * @private | ||
*/ | ||
var handleNode = function handleNode(token) { | ||
@@ -243,3 +250,2 @@ /** | ||
}; | ||
/** | ||
@@ -249,2 +255,4 @@ * @private | ||
*/ | ||
var onToken = function onToken(token) { | ||
@@ -264,7 +272,5 @@ if (token.isTag() && isAllowedTag(token.getName())) { | ||
enableEscapeTags: options.enableEscapeTags | ||
}); | ||
}); // eslint-disable-next-line no-unused-vars | ||
// eslint-disable-next-line no-unused-vars | ||
var tokens = tokenizer.tokenize(); | ||
return nodes.toArray(); | ||
@@ -274,2 +280,3 @@ }; | ||
exports.parse = parse; | ||
exports.default = parse; | ||
var _default = parse; | ||
exports["default"] = _default; |
@@ -1,14 +0,15 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.Token = exports.TYPE_NEW_LINE = exports.TYPE_SPACE = exports.TYPE_ATTR_VALUE = exports.TYPE_ATTR_NAME = exports.TYPE_TAG = exports.TYPE_WORD = exports.COLUMN_ID = exports.LINE_ID = exports.VALUE_ID = exports.TYPE_ID = undefined; | ||
exports["default"] = exports.Token = exports.TYPE_NEW_LINE = exports.TYPE_SPACE = exports.TYPE_ATTR_VALUE = exports.TYPE_ATTR_NAME = exports.TYPE_TAG = exports.TYPE_WORD = exports.COLUMN_ID = exports.LINE_ID = exports.VALUE_ID = exports.TYPE_ID = void 0; | ||
var _char = require('@bbob/plugin-helper/lib/char'); | ||
var _char = require("@bbob/plugin-helper/lib/char"); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
// type, value, line, row, | ||
var TOKEN_TYPE_ID = 'type'; // 0; | ||
var TOKEN_VALUE_ID = 'value'; // 1; | ||
var TOKEN_COLUMN_ID = 'row'; // 2; | ||
var TOKEN_LINE_ID = 'line'; // 3; | ||
@@ -26,5 +27,7 @@ | ||
}; | ||
var getTokenLine = function getTokenLine(token) { | ||
return token[TOKEN_LINE_ID]; | ||
}; | ||
var getTokenColumn = function getTokenColumn(token) { | ||
@@ -41,11 +44,15 @@ return token[TOKEN_COLUMN_ID]; | ||
}; | ||
var isTagEnd = function isTagEnd(token) { | ||
return getTokenValue(token).charCodeAt(0) === _char.SLASH.charCodeAt(0); | ||
}; | ||
var isTagStart = function isTagStart(token) { | ||
return !isTagEnd(token); | ||
}; | ||
var isAttrNameToken = function isAttrNameToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME; | ||
}; | ||
var isAttrValueToken = function isAttrValueToken(token) { | ||
@@ -57,3 +64,2 @@ return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE; | ||
var value = getTokenValue(token); | ||
return isTagEnd(token) ? value.slice(1) : value; | ||
@@ -64,10 +70,10 @@ }; | ||
var text = _char.OPEN_BRAKET; | ||
text += getTokenValue(token); | ||
text += _char.CLOSE_BRAKET; | ||
return text; | ||
}; | ||
var Token = function () { | ||
var Token = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
@@ -80,4 +86,2 @@ * @param {String} type | ||
function Token(type, value, line, row) { | ||
_classCallCheck(this, Token); | ||
this[TOKEN_TYPE_ID] = String(type); | ||
@@ -89,47 +93,49 @@ this[TOKEN_VALUE_ID] = String(value); | ||
Token.prototype.isEmpty = function isEmpty() { | ||
var _proto = Token.prototype; | ||
_proto.isEmpty = function isEmpty() { | ||
return !!this[TOKEN_TYPE_ID]; | ||
}; | ||
Token.prototype.isText = function isText() { | ||
_proto.isText = function isText() { | ||
return isTextToken(this); | ||
}; | ||
Token.prototype.isTag = function isTag() { | ||
_proto.isTag = function isTag() { | ||
return isTagToken(this); | ||
}; | ||
Token.prototype.isAttrName = function isAttrName() { | ||
_proto.isAttrName = function isAttrName() { | ||
return isAttrNameToken(this); | ||
}; | ||
Token.prototype.isAttrValue = function isAttrValue() { | ||
_proto.isAttrValue = function isAttrValue() { | ||
return isAttrValueToken(this); | ||
}; | ||
Token.prototype.isStart = function isStart() { | ||
_proto.isStart = function isStart() { | ||
return isTagStart(this); | ||
}; | ||
Token.prototype.isEnd = function isEnd() { | ||
_proto.isEnd = function isEnd() { | ||
return isTagEnd(this); | ||
}; | ||
Token.prototype.getName = function getName() { | ||
_proto.getName = function getName() { | ||
return getTagName(this); | ||
}; | ||
Token.prototype.getValue = function getValue() { | ||
_proto.getValue = function getValue() { | ||
return getTokenValue(this); | ||
}; | ||
Token.prototype.getLine = function getLine() { | ||
_proto.getLine = function getLine() { | ||
return getTokenLine(this); | ||
}; | ||
Token.prototype.getColumn = function getColumn() { | ||
_proto.getColumn = function getColumn() { | ||
return getTokenColumn(this); | ||
}; | ||
Token.prototype.toString = function toString() { | ||
_proto.toString = function toString() { | ||
return convertTagToText(this); | ||
@@ -141,13 +147,24 @@ }; | ||
var TYPE_ID = exports.TYPE_ID = TOKEN_TYPE_ID; | ||
var VALUE_ID = exports.VALUE_ID = TOKEN_VALUE_ID; | ||
var LINE_ID = exports.LINE_ID = TOKEN_LINE_ID; | ||
var COLUMN_ID = exports.COLUMN_ID = TOKEN_COLUMN_ID; | ||
var TYPE_WORD = exports.TYPE_WORD = TOKEN_TYPE_WORD; | ||
var TYPE_TAG = exports.TYPE_TAG = TOKEN_TYPE_TAG; | ||
var TYPE_ATTR_NAME = exports.TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME; | ||
var TYPE_ATTR_VALUE = exports.TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE; | ||
var TYPE_SPACE = exports.TYPE_SPACE = TOKEN_TYPE_SPACE; | ||
var TYPE_NEW_LINE = exports.TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE; | ||
exports.Token = Token; | ||
exports.default = Token; | ||
var TYPE_ID = TOKEN_TYPE_ID; | ||
exports.TYPE_ID = TYPE_ID; | ||
var VALUE_ID = TOKEN_VALUE_ID; | ||
exports.VALUE_ID = VALUE_ID; | ||
var LINE_ID = TOKEN_LINE_ID; | ||
exports.LINE_ID = LINE_ID; | ||
var COLUMN_ID = TOKEN_COLUMN_ID; | ||
exports.COLUMN_ID = COLUMN_ID; | ||
var TYPE_WORD = TOKEN_TYPE_WORD; | ||
exports.TYPE_WORD = TYPE_WORD; | ||
var TYPE_TAG = TOKEN_TYPE_TAG; | ||
exports.TYPE_TAG = TYPE_TAG; | ||
var TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME; | ||
exports.TYPE_ATTR_NAME = TYPE_ATTR_NAME; | ||
var TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE; | ||
exports.TYPE_ATTR_VALUE = TYPE_ATTR_VALUE; | ||
var TYPE_SPACE = TOKEN_TYPE_SPACE; | ||
exports.TYPE_SPACE = TYPE_SPACE; | ||
var TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE; | ||
exports.TYPE_NEW_LINE = TYPE_NEW_LINE; | ||
var _default = Token; | ||
exports["default"] = _default; |
@@ -1,7 +0,7 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.createList = exports.unquote = exports.trimChar = exports.createCharGrabber = undefined; | ||
exports.createList = exports.unquote = exports.trimChar = exports.createCharGrabber = void 0; | ||
var _char = require('@bbob/plugin-helper/lib/char'); | ||
var _char2 = require("@bbob/plugin-helper/lib/char"); | ||
@@ -23,3 +23,3 @@ /** | ||
*/ | ||
var createCharGrabber = exports.createCharGrabber = function createCharGrabber(source, options) { | ||
var createCharGrabber = function createCharGrabber(source, options) { | ||
// let idx = 0; | ||
@@ -38,8 +38,11 @@ var cursor = { | ||
}; | ||
var hasNext = function hasNext() { | ||
return cursor.length > cursor.pos; | ||
}; | ||
var getRest = function getRest() { | ||
return source.substr(cursor.pos); | ||
}; | ||
var getCurr = function getCurr() { | ||
@@ -55,2 +58,3 @@ return source[cursor.pos]; | ||
}, | ||
/** | ||
@@ -81,2 +85,3 @@ * @param {Function} cond | ||
getRest: getRest, | ||
/** | ||
@@ -87,5 +92,5 @@ * Grabs rest of string until it find a char | ||
*/ | ||
substrUntilChar: function substrUntilChar(char) { | ||
substrUntilChar: function substrUntilChar(_char) { | ||
var restStr = getRest(); | ||
var indexOfChar = restStr.indexOf(char); | ||
var indexOfChar = restStr.indexOf(_char); | ||
@@ -100,3 +105,2 @@ if (indexOfChar >= 0) { | ||
}; | ||
/** | ||
@@ -110,3 +114,7 @@ * Trims string from start and end by char | ||
*/ | ||
var trimChar = exports.trimChar = function trimChar(str, charToRemove) { | ||
exports.createCharGrabber = createCharGrabber; | ||
var trimChar = function trimChar(str, charToRemove) { | ||
while (str.charAt(0) === charToRemove) { | ||
@@ -124,3 +132,2 @@ // eslint-disable-next-line no-param-reassign | ||
}; | ||
/** | ||
@@ -131,6 +138,9 @@ * Unquotes \" to " | ||
*/ | ||
var unquote = exports.unquote = function unquote(str) { | ||
return str.replace(_char.BACKSLASH + _char.QUOTEMARK, _char.QUOTEMARK); | ||
exports.trimChar = trimChar; | ||
var unquote = function unquote(str) { | ||
return str.replace(_char2.BACKSLASH + _char2.QUOTEMARK, _char2.QUOTEMARK); | ||
}; | ||
/** | ||
@@ -150,5 +160,11 @@ * @typedef {Object} ItemList | ||
*/ | ||
var createList = exports.createList = function createList() { | ||
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
exports.unquote = unquote; | ||
var createList = function createList(values) { | ||
if (values === void 0) { | ||
values = []; | ||
} | ||
var nodes = values; | ||
@@ -158,2 +174,3 @@ /** | ||
*/ | ||
var getLast = function getLast() { | ||
@@ -166,2 +183,4 @@ return nodes.length ? nodes[nodes.length - 1] : null; | ||
*/ | ||
var flushLast = function flushLast() { | ||
@@ -178,6 +197,7 @@ if (nodes.length) { | ||
*/ | ||
var push = function push(value) { | ||
return nodes.push(value); | ||
}; | ||
/** | ||
@@ -188,2 +208,3 @@ * @callback toArrayCb | ||
return { | ||
@@ -197,2 +218,4 @@ getLast: getLast, | ||
}; | ||
}; | ||
}; | ||
exports.createList = createList; |
{ | ||
"name": "@bbob/parser", | ||
"version": "2.5.4", | ||
"version": "2.5.5", | ||
"description": "Just parses BBcode to AST array. Part of @bbob bbcode parser", | ||
@@ -16,3 +16,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@bbob/plugin-helper": "^2.5.4" | ||
"@bbob/plugin-helper": "^2.5.5" | ||
}, | ||
@@ -35,5 +35,5 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib", | ||
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es", | ||
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js", | ||
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs NODE_ENV=production ../../node_modules/.bin/babel src --out-dir lib", | ||
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es NODE_ENV=production ../../node_modules/.bin/babel src --out-dir es", | ||
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=production ../../node_modules/.bin/rollup --config ../../rollup.config.js", | ||
"build": "npm run build:commonjs && npm run build:es && npm run build:umd", | ||
@@ -43,4 +43,4 @@ "test": "../../node_modules/.bin/jest --", | ||
"lint": "../../node_modules/.bin/eslint .", | ||
"size": "../../node_modules/.bin/size-limit", | ||
"bundlesize": "../../node_modules/.bin/bundlesize", | ||
"size": "../../node_modules/.bin/cross-env NODE_ENV=production ../../node_modules/.bin/size-limit", | ||
"bundlesize": "../../node_modules/.bin/cross-env NODE_ENV=production ../../node_modules/.bin/bundlesize", | ||
"prepublishOnly": "npm run build" | ||
@@ -67,3 +67,4 @@ }, | ||
"es" | ||
] | ||
], | ||
"gitHead": "2670fc128892a48c636c5669b61af06f9824f057" | ||
} |
@@ -14,3 +14,5 @@ /* eslint-disable no-plusplus,no-param-reassign */ | ||
import { Token, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_NEW_LINE, TYPE_SPACE, TYPE_TAG, TYPE_WORD } from './Token'; | ||
import { | ||
Token, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_NEW_LINE, TYPE_SPACE, TYPE_TAG, TYPE_WORD, | ||
} from './Token'; | ||
import { createCharGrabber, trimChar, unquote } from './utils'; | ||
@@ -63,8 +65,8 @@ | ||
const isCharReserved = char => (RESERVED_CHARS.indexOf(char) >= 0); | ||
const isWhiteSpace = char => (WHITESPACES.indexOf(char) >= 0); | ||
const isCharToken = char => (NOT_CHAR_TOKENS.indexOf(char) === -1); | ||
const isSpecialChar = char => (SPECIAL_CHARS.indexOf(char) >= 0); | ||
const isEscapableChar = char => (char === openTag || char === closeTag || char === BACKSLASH); | ||
const isEscapeChar = char => char === BACKSLASH; | ||
const isCharReserved = (char) => (RESERVED_CHARS.indexOf(char) >= 0); | ||
const isWhiteSpace = (char) => (WHITESPACES.indexOf(char) >= 0); | ||
const isCharToken = (char) => (NOT_CHAR_TOKENS.indexOf(char) === -1); | ||
const isSpecialChar = (char) => (SPECIAL_CHARS.indexOf(char) >= 0); | ||
const isEscapableChar = (char) => (char === openTag || char === closeTag || char === BACKSLASH); | ||
const isEscapeChar = (char) => char === BACKSLASH; | ||
@@ -180,3 +182,3 @@ /** | ||
} else { | ||
const str = bufferGrabber.grabWhile(val => val !== closeTag); | ||
const str = bufferGrabber.grabWhile((val) => val !== closeTag); | ||
@@ -183,0 +185,0 @@ bufferGrabber.skip(); // skip closeTag |
@@ -60,3 +60,3 @@ import TagNode from '@bbob/plugin-helper/lib/TagNode'; | ||
const isTagNested = tagName => !!nestedTagsMap[tagName]; | ||
const isTagNested = (tagName) => !!nestedTagsMap[tagName]; | ||
@@ -63,0 +63,0 @@ /** |
@@ -20,16 +20,15 @@ import { | ||
const getTokenValue = token => token[TOKEN_VALUE_ID]; | ||
const getTokenLine = token => token[TOKEN_LINE_ID]; | ||
const getTokenColumn = token => token[TOKEN_COLUMN_ID]; | ||
const getTokenValue = (token) => token[TOKEN_VALUE_ID]; | ||
const getTokenLine = (token) => token[TOKEN_LINE_ID]; | ||
const getTokenColumn = (token) => token[TOKEN_COLUMN_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; | ||
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; | ||
const isTagToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG; | ||
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 isTagToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG; | ||
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; | ||
@@ -36,0 +35,0 @@ const getTagName = (token) => { |
@@ -109,3 +109,3 @@ import { | ||
*/ | ||
export const unquote = str => str.replace(BACKSLASH + QUOTEMARK, QUOTEMARK); | ||
export const unquote = (str) => str.replace(BACKSLASH + QUOTEMARK, QUOTEMARK); | ||
@@ -147,3 +147,3 @@ /** | ||
*/ | ||
const push = value => nodes.push(value); | ||
const push = (value) => nodes.push(value); | ||
@@ -150,0 +150,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
158766
23
3140
Updated@bbob/plugin-helper@^2.5.5