New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

inline-loops.macro

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inline-loops.macro - npm Package Compare versions

Comparing version 2.0.0-beta.1 to 2.0.0-beta.2

44

dist/utils.js

@@ -12,3 +12,2 @@ "use strict";

exports.handleInvalidUsage = handleInvalidUsage;
exports.isConditionalUsage = isConditionalUsage;
exports.isMacroHandlerName = isMacroHandlerName;

@@ -18,2 +17,3 @@ exports.processNestedInlineLoopMacros = processNestedInlineLoopMacros;

exports.replaceOrRemove = replaceOrRemove;
exports.shouldWrapInClosure = shouldWrapInClosure;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

@@ -98,6 +98,2 @@ var _babelPluginMacros = require("babel-plugin-macros");

}
function isConditionalUsage(path) {
var parentPath = path.parentPath;
return parentPath.isConditionalExpression() || parentPath.isLogicalExpression();
}
function isMacroHandlerName(handlers, name) {

@@ -123,8 +119,4 @@ return !!(name && handlers[name]);

function replaceOrRemove(_ref, path, local, templates, replacement) {
var _functionParent$get;
var t = _ref.types;
var functionParent = path.getFunctionParent();
var contents = functionParent === null || functionParent === void 0 || (_functionParent$get = functionParent.get('body')) === null || _functionParent$get === void 0 ? void 0 : _functionParent$get.get('body');
var shouldWrapInIife = functionParent && (Array.isArray(contents) && contents.length > 1 || local.contents.length > 1 || isConditionalUsage(path));
if (shouldWrapInIife) {
if (shouldWrapInClosure(path, local)) {
if (!t.isIdentifier(replacement, {

@@ -154,2 +146,34 @@ name: 'undefined'

}
}
function shouldWrapInClosure(path, local) {
var _functionParent$get;
var parentPath = path.parentPath;
if (!parentPath) {
return false;
}
var functionParent = path.getFunctionParent();
var grandparentPath = parentPath.parentPath;
if (!functionParent || !grandparentPath) {
return false;
}
if (parentPath.isPattern() || local.contents.length > 1) {
return true;
}
var contents = functionParent === null || functionParent === void 0 || (_functionParent$get = functionParent.get('body')) === null || _functionParent$get === void 0 ? void 0 : _functionParent$get.get('body');
if (Array.isArray(contents) && contents.length > 1) {
return contents.flat().some(function (content) {
return content.isVariableDeclaration();
});
}
if (!parentPath.isExpression()) {
return false;
}
var maybeNestedConditional = grandparentPath.isPattern() || grandparentPath.isExpression() && !grandparentPath.isBinaryExpression();
if (parentPath.isLogicalExpression()) {
return !maybeNestedConditional && parentPath.get('right').node === path.node;
}
if (parentPath.isConditionalExpression()) {
return !maybeNestedConditional && parentPath.get('test').node !== path.node;
}
return maybeNestedConditional;
}

@@ -61,3 +61,3 @@ {

"typings": "./index.d.ts",
"version": "2.0.0-beta.1"
"version": "2.0.0-beta.2"
}
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