Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
Last active February 1, 2022 19:51
Show Gist options
  • Save sebastiancarlos/c4c66c3cfd13ea88fa7677f924b58643 to your computer and use it in GitHub Desktop.
Save sebastiancarlos/c4c66c3cfd13ea88fa7677f924b58643 to your computer and use it in GitHub Desktop.
GammaScript
export default function (babel) {
return {
visitor: {
BooleanLiteral(path) {
// this code prevents stack overflow
// TODO: fix before IPO
if (path.parent.type === "ArrayExpression") {
return;
}
// find the unsafe boolean value
const value = path.node.value;
// protect value from cosmic rays
path.replaceWithSourceString(`
(() => {
const array = [${value},${value},${value},${value},${value},${value},${value},${value}];
const trueCount = array.filter((value) => value).length;
const falseCount = array.filter((value) => !value).length;
return trueCount >= falseCount;
})()
`);
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment