Merge pull request #2737 from babel/thejameskyle-patch-1

Fix minify-booleans transform
This commit is contained in:
Sebastian McKenzie
2015-11-02 19:27:53 +00:00
4 changed files with 10 additions and 3 deletions

View File

@@ -0,0 +1,2 @@
true;
false;

View File

@@ -0,0 +1,3 @@
{
"plugins": ["transform-minify-booleans"]
}

View File

@@ -1,9 +1,9 @@
export default function ({ types: t }) {
return {
visitor: {
Literal(node) {
if (typeof node.value === "boolean") {
return t.unaryExpression("!", t.literal(+!node.value), true);
Literal(path) {
if (typeof path.node.value === "boolean") {
path.replaceWith(t.unaryExpression("!", t.numberLiteral(+!path.node.value), true));
}
}
}