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

babel-plugin-es5-array-autopolyfill

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-es5-array-autopolyfill - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

test/fixtures/replace-object-keys/.babelrc

44

lib/index.js

@@ -41,3 +41,2 @@ 'use strict';

}
var identifierPath = path.get("callee.object", true);

@@ -48,2 +47,8 @@ if (!identifierPath.isNodeType("Identifier") && !identifierPath.isNodeType("TypeCastExpression")) {

var callee = path.node.callee;
if (isObjectKeysExpression(identifierPath, property)) {
return replaceObjectKeys(t, path, property, usedMethods);
}
annotation = identifierPath.getTypeAnnotation();

@@ -54,9 +59,20 @@

}
if (isArrayReturn(property.name) && !isReplacable(property.name) && !t.isTypeCastExpression(path.parentPath.node)) {
path.replaceWith(t.typeCastExpression(t.callExpression(callee, path.node.arguments), t.arrayTypeAnnotation(t.identifier('Any'))));
return;
}
if (!isReplacable(property.name)) {
return;
}
var oldName = property.name;
property.name = prefix + property.name;
var callee = path.node.callee;
var expression = t.callExpression(property, [callee.object].concat(path.node.arguments));
usedMethods[oldName] = true;
if (arrayReturn.indexOf(oldName) >= 0) {
path.replaceWith(t.typeCastExpression(expression, t.arrayTypeAnnotation('Any')));
path.replaceWith(t.typeCastExpression(expression, t.arrayTypeAnnotation(t.identifier('Any'))));
} else {

@@ -72,3 +88,3 @@ path.replaceWith(expression);

var replaceProperties = ['reduce', 'map', 'filter', 'forEach'];
var arrayReturn = ['map', 'filter'];
var arrayReturn = ['map', 'filter', 'concat', 'slice', 'sort', 'splice'];
var prefix = "es5";

@@ -89,7 +105,21 @@

function isObjectCaller(t, property) {
return t.isIdentifier(property) && property && replaceProperties.indexOf(property.name) >= 0;
return t.isIdentifier(property) && property;
}
function isFunctionTypeCastCaller(t, path, prop) {
return t.isTypeCastExpression(path.parentPath.node) && !prop;
function isReplacable(name) {
return replaceProperties.indexOf(name) >= 0;
}
function isArrayReturn(name) {
return arrayReturn.indexOf(name) >= 0;
}
function isObjectKeysExpression(path, prop) {
return path.node.name === 'Object' && prop.name === 'keys' && !path.scope.getBinding('Object');
}
function replaceObjectKeys(t, path, property, usedMethods) {
usedMethods[property.name] = true;
property.name = prefix + property.name;
path.replaceWith(t.typeCastExpression(t.callExpression(property, path.node.arguments), t.arrayTypeAnnotation(t.identifier('String'))));
}

2

package.json
{
"name": "babel-plugin-es5-array-autopolyfill",
"version": "3.1.0",
"version": "3.2.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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