Skip to content

Commit

Permalink
fix(parser): try to hack terser minifier that removes working code (#49)
Browse files Browse the repository at this point in the history
* fix(parser): try to hack terser minifier that removes working code Fixes #48
  • Loading branch information
JiLiZART authored Sep 25, 2019
1 parent 2c1fbff commit be938fd
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions packages/bbob-parser/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

if (hasNext()) {
start = cursor.pos;

while (hasNext() && cond(getCurr())) {
skip();
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,
/**
Expand Down

0 comments on commit be938fd

Please sign in to comment.