2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-05-30 15:24:05 +03:00

fix(parser): try to hack terser minifier that removes working code (#49)

* fix(parser): try to hack terser minifier that removes working code Fixes #48
This commit is contained in:
Nikolay Kostyurin
2019-09-25 09:29:21 +02:00
committed by GitHub
parent 2c1fbffeb0
commit be938fd21f
+29 -16
View File
@@ -14,38 +14,51 @@ import {
/**
* Creates a grabber wrapper for source string, that helps to iterate over string char by char
* @param {String} source
* @param {Function} onSkip
* @param {Object} options
* @param {Function} options.onSkip
* @returns
*/
export const createCharGrabber = (source, { onSkip } = {}) => {
let idx = 0;
export const createCharGrabber = (source, options) => {
// let idx = 0;
const cursor = {
pos: 0,
length: source.length,
};
const skip = () => {
idx += 1;
cursor.pos += 1;
if (onSkip) {
onSkip();
if (options && options.onSkip) {
options.onSkip();
}
};
const hasNext = () => source.length > idx;
const getRest = () => source.substr(idx);
const getCurr = () => source[idx];
const hasNext = () => cursor.length > cursor.pos;
const getRest = () => source.substr(cursor.pos);
const getCurr = () => source[cursor.pos];
return {
skip,
hasNext,
isLast: () => (idx === source.length),
isLast: () => (cursor.pos === cursor.length),
/**
* @param {Function} cond
* @returns {string}
*/
grabWhile: (cond) => {
const start = idx;
let start = 0;
while (hasNext() && cond(getCurr())) {
skip();
if (hasNext()) {
start = cursor.pos;
while (hasNext() && cond(getCurr())) {
skip();
}
}
return source.substr(start, idx - start);
return source.substr(start, cursor.pos - start);
},
getNext: () => source[idx + 1],
getPrev: () => source[idx - 1],
getNext: () => source[cursor.pos + 1],
getPrev: () => source[cursor.pos - 1],
getCurr,
getRest,
/**