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

@material-ui/codemod

Package Overview
Dependencies
Maintainers
6
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@material-ui/codemod - npm Package Compare versions

Comparing version 4.0.1 to 4.0.2

lib/v4.0.0/theme-spacing-api.test/actual_destructured.js

63

lib/v4.0.0/theme-spacing-api.js

@@ -69,3 +69,65 @@ "use strict";

}
/**
* Update all `spacing.unit` usages to use `spacing()`.
* Find and replace string literal AST nodes to ensure all spacing API usages get updated, regardless
* of any calculation being performed.
* @param {jscodeshift_api_object} j
* @param {jscodeshift_ast_object} root
*/
function transformThemeSpacingApiDestructured(j, root) {
var mightContainApi = function mightContainApi(path) {
return j(path).find(j.MemberExpression, {
object: {
name: 'spacing'
},
property: {
name: 'unit'
}
}).size() > 0;
};
var replaceApi = function replaceApi(pathArg) {
pathArg.find(j.MemberExpression, {
object: {
name: 'spacing'
},
property: {
name: 'unit'
}
}).replaceWith(function (path) {
var param = null;
var spacingParam = path.node.object.name;
if (j.BinaryExpression.check(path.parent.node)) {
var expression = path.parent.node;
var operation = expression.operator; // check if it's a variable
if (j.Identifier.check(expression.right)) {
param = expression.right;
} else if (j.Literal.check(expression.right)) {
var value = expression.right.value;
if (operation === '*' || operation === '/') {
param = j.literal(eval("1 ".concat(operation, " ").concat(value)));
}
}
}
if (param) {
path.parent.replace(j.callExpression(j.identifier(spacingParam), [param]));
return path.node;
}
return j.callExpression(j.identifier(spacingParam), [j.literal(1)]);
});
};
var arrowFunctions = root.find(j.ArrowFunctionExpression).filter(mightContainApi);
var functionDeclarations = root.find(j.FunctionDeclaration).filter(mightContainApi);
replaceApi(arrowFunctions);
replaceApi(functionDeclarations);
}
module.exports = function transformer(fileInfo, api) {

@@ -76,2 +138,3 @@ var j = api.jscodeshift;

transformThemeSpacingApi(j, root);
transformThemeSpacingApiDestructured(j, root);
return root.toSource({

@@ -78,0 +141,0 @@ quote: 'single'

2

package.json
{
"name": "@material-ui/codemod",
"version": "4.0.1",
"version": "4.0.2",
"private": false,

@@ -5,0 +5,0 @@ "author": "Material-UI Team",

@@ -81,2 +81,69 @@ /* eslint-disable no-eval */

/**
* Update all `spacing.unit` usages to use `spacing()`.
* Find and replace string literal AST nodes to ensure all spacing API usages get updated, regardless
* of any calculation being performed.
* @param {jscodeshift_api_object} j
* @param {jscodeshift_ast_object} root
*/
function transformThemeSpacingApiDestructured(j, root) {
const mightContainApi = path => {
return (
j(path)
.find(j.MemberExpression, {
object: {
name: 'spacing',
},
property: {
name: 'unit',
},
})
.size() > 0
);
};
const replaceApi = pathArg => {
pathArg
.find(j.MemberExpression, {
object: {
name: 'spacing',
},
property: {
name: 'unit',
},
})
.replaceWith(path => {
let param = null;
const spacingParam = path.node.object.name;
if (j.BinaryExpression.check(path.parent.node)) {
const expression = path.parent.node;
const operation = expression.operator;
// check if it's a variable
if (j.Identifier.check(expression.right)) {
param = expression.right;
} else if (j.Literal.check(expression.right)) {
const value = expression.right.value;
if (operation === '*' || operation === '/') {
param = j.literal(eval(`1 ${operation} ${value}`));
}
}
}
if (param) {
path.parent.replace(j.callExpression(j.identifier(spacingParam), [param]));
return path.node;
}
return j.callExpression(j.identifier(spacingParam), [j.literal(1)]);
});
};
const arrowFunctions = root.find(j.ArrowFunctionExpression).filter(mightContainApi);
const functionDeclarations = root.find(j.FunctionDeclaration).filter(mightContainApi);
replaceApi(arrowFunctions);
replaceApi(functionDeclarations);
}
module.exports = function transformer(fileInfo, api) {

@@ -88,3 +155,4 @@ const j = api.jscodeshift;

transformThemeSpacingApi(j, root);
transformThemeSpacingApiDestructured(j, root);
return root.toSource({ quote: 'single' });
};
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