Last active
February 1, 2022 19:51
-
-
Save sebastiancarlos/c4c66c3cfd13ea88fa7677f924b58643 to your computer and use it in GitHub Desktop.
GammaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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