2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-20 20:00:33 +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 * Creates a grabber wrapper for source string, that helps to iterate over string char by char
* @param {String} source * @param {String} source
* @param {Function} onSkip * @param {Object} options
* @param {Function} options.onSkip
* @returns * @returns
*/ */
export const createCharGrabber = (source, { onSkip } = {}) => { export const createCharGrabber = (source, options) => {
let idx = 0; // let idx = 0;
const cursor = {
pos: 0,
length: source.length,
};
const skip = () => { const skip = () => {
idx += 1; cursor.pos += 1;
if (onSkip) { if (options && options.onSkip) {
onSkip(); options.onSkip();
} }
}; };
const hasNext = () => source.length > idx; const hasNext = () => cursor.length > cursor.pos;
const getRest = () => source.substr(idx); const getRest = () => source.substr(cursor.pos);
const getCurr = () => source[idx]; const getCurr = () => source[cursor.pos];
return { return {
skip, skip,
hasNext, hasNext,
isLast: () => (idx === source.length), isLast: () => (cursor.pos === cursor.length),
/**
* @param {Function} cond
* @returns {string}
*/
grabWhile: (cond) => { grabWhile: (cond) => {
const start = idx; let start = 0;
while (hasNext() && cond(getCurr())) { if (hasNext()) {
skip(); 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], getNext: () => source[cursor.pos + 1],
getPrev: () => source[idx - 1], getPrev: () => source[cursor.pos - 1],
getCurr, getCurr,
getRest, getRest,
/** /**