Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-minify-guarded-expressions

Package Overview
Dependencies
Maintainers
5
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-minify-guarded-expressions - npm Package Compare versions

Comparing version 0.5.0-alpha.7b176463 to 0.5.0-alpha.7ba5821f

37

lib/index.js
"use strict";
module.exports = function (_ref) {
var t = _ref.types;
const evaluate = require("babel-helper-evaluate-path");
var flipExpressions = require("babel-helper-flip-expressions")(t);
function evaluateTruthy(path) {
const res = evaluate(path);
if (res.confident) return !!res.value;
}
module.exports = function ({
types: t
}) {
const flipExpressions = require("babel-helper-flip-expressions")(t);
return {

@@ -17,5 +24,5 @@ name: "minify-guarded-expressions",

enter: [function (path) {
var node = path.node;
var left = path.get("left");
var right = path.get("right"); // issues - 171, 174, 176
const node = path.node;
const left = path.get("left");
const right = path.get("right"); // issues - 171, 174, 176
// we assume that it is returned/assigned/part of a bigger expression

@@ -28,6 +35,6 @@ // or utilized somehow

var shouldBail = !path.parentPath.isExpressionStatement();
const shouldBail = !path.parentPath.isExpressionStatement();
if (node.operator === "&&") {
var leftTruthy = left.evaluateTruthy();
const leftTruthy = evaluateTruthy(left);

@@ -39,14 +46,14 @@ if (leftTruthy === false) {

path.replaceWith(node.right);
} else if (right.evaluateTruthy() === false && right.isPure() && !shouldBail) {
} else if (evaluateTruthy(right) === false && right.isPure() && !shouldBail) {
path.replaceWith(node.left);
}
} else if (node.operator === "||") {
var _leftTruthy = left.evaluateTruthy();
const leftTruthy = evaluateTruthy(left);
if (_leftTruthy === false && left.isPure()) {
if (leftTruthy === false && left.isPure()) {
path.replaceWith(node.right);
} else if (_leftTruthy === true) {
} else if (leftTruthy === true) {
// Short-circuit
path.replaceWith(node.left);
} else if (right.evaluateTruthy() === false && right.isPure() && !shouldBail) {
} else if (evaluateTruthy(right) === false && right.isPure() && !shouldBail) {
path.replaceWith(node.left);

@@ -56,3 +63,3 @@ }

}, function (path) {
var node = path.node;
const node = path.node;

@@ -70,3 +77,3 @@ if (flipExpressions.hasSeen(node)) {

if (flipExpressions.shouldFlip(node, 1)) {
var newNode = flipExpressions.flip(node, true);
const newNode = flipExpressions.flip(node, true);
path.replaceWith(newNode);

@@ -73,0 +80,0 @@ }

{
"name": "babel-plugin-minify-guarded-expressions",
"version": "0.5.0-alpha.7b176463",
"version": "0.5.0-alpha.7ba5821f",
"description": "",

@@ -15,4 +15,4 @@ "keywords": [

"dependencies": {
"babel-helper-flip-expressions": "^0.5.0-alpha.7b176463"
"babel-helper-flip-expressions": "^0.5.0-alpha.7ba5821f"
}
}

@@ -22,3 +22,3 @@ # babel-plugin-minify-guarded-expressions

```sh
npm install babel-plugin-minify-guarded-expressions
npm install babel-plugin-minify-guarded-expressions --save-dev
```

@@ -25,0 +25,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc