Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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