Merge pull request #2737 from babel/thejameskyle-patch-1
Fix minify-booleans transform
This commit is contained in:
2
packages/babel-core/test/fixtures/transformation/minification.booleans/booleans/actual.js
vendored
Normal file
2
packages/babel-core/test/fixtures/transformation/minification.booleans/booleans/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
true;
|
||||
false;
|
||||
2
packages/babel-core/test/fixtures/transformation/minification.booleans/booleans/expected.js
vendored
Normal file
2
packages/babel-core/test/fixtures/transformation/minification.booleans/booleans/expected.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
!0;
|
||||
!1;
|
||||
3
packages/babel-core/test/fixtures/transformation/minification.booleans/options.json
vendored
Normal file
3
packages/babel-core/test/fixtures/transformation/minification.booleans/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["transform-minify-booleans"]
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user