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

@compiled/codemods

Package Overview
Dependencies
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@compiled/codemods - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

91

dist/plugins/default.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var defaultCodemodPlugin = {
const defaultCodemodPlugin = {
name: 'default-plugin',
create: function (_, _a) {
var j = _a.jscodeshift;
return ({
transform: {
buildImport: function (_a) {
var compiledImportPath = _a.compiledImportPath, currentNode = _a.currentNode, specifiers = _a.specifiers;
if (specifiers.length === 0) {
return null;
create: (_, { jscodeshift: j }) => ({
transform: {
buildImport({ compiledImportPath, currentNode, specifiers }) {
if (specifiers.length === 0) {
return null;
}
const newImport = j.importDeclaration(specifiers, j.literal(compiledImportPath));
// Copy the comments from the previous import to the new one
newImport.comments = currentNode === null || currentNode === void 0 ? void 0 : currentNode.comments;
return newImport;
},
buildAttributes({ originalNode, transformedNode, composedNode }) {
var _a;
const newDeclaration = j(originalNode).replaceWith(transformedNode).get();
if (composedNode) {
let candidateForInsertion = newDeclaration;
while (((_a = candidateForInsertion.parentPath) === null || _a === void 0 ? void 0 : _a.name) !== 'body') {
candidateForInsertion = candidateForInsertion.parentPath;
}
var newImport = j.importDeclaration(specifiers, j.literal(compiledImportPath));
// Copy the comments from the previous import to the new one
newImport.comments = currentNode === null || currentNode === void 0 ? void 0 : currentNode.comments;
return newImport;
},
buildAttributes: function (_a) {
var _b;
var originalNode = _a.originalNode, transformedNode = _a.transformedNode, composedNode = _a.composedNode;
var newDeclaration = j(originalNode).replaceWith(transformedNode).get();
if (composedNode) {
var candidateForInsertion = newDeclaration;
while (((_b = candidateForInsertion.parentPath) === null || _b === void 0 ? void 0 : _b.name) !== 'body') {
candidateForInsertion = candidateForInsertion.parentPath;
}
j(candidateForInsertion).insertBefore(composedNode);
}
return newDeclaration;
},
buildRefAttribute: function (_a) {
var currentNode = _a.currentNode;
return j.jsxAttribute(j.jsxIdentifier('ref'), currentNode.value);
},
buildTemplateExpression: function (_a) {
var currentNode = _a.currentNode;
// replace single line comments
var quasi = currentNode.quasi;
var replaceRegex = /(?<!:)\/\/(.+?)(\n|$)/g;
var replacer = '/*$1 */$2';
j(quasi)
.find(j.TemplateElement)
.forEach(function (templateElement) {
var _a;
var val = templateElement.value.value;
val.cooked = val.cooked ? val.cooked.replace(replaceRegex, replacer) : null;
val.raw = (_a = val.raw) === null || _a === void 0 ? void 0 : _a.replace(replaceRegex, replacer);
});
return currentNode;
},
j(candidateForInsertion).insertBefore(composedNode);
}
return newDeclaration;
},
});
},
buildRefAttribute({ currentNode }) {
return j.jsxAttribute(j.jsxIdentifier('ref'), currentNode.value);
},
buildTemplateExpression({ currentNode }) {
// replace single line comments
const quasi = currentNode.quasi;
const replaceRegex = /(?<!:)\/\/(.+?)(\n|$)/g;
const replacer = '/*$1 */$2';
j(quasi)
.find(j.TemplateElement)
.forEach((templateElement) => {
var _a;
const val = templateElement.value.value;
val.cooked = val.cooked ? val.cooked.replace(replaceRegex, replacer) : null;
val.raw = (_a = val.raw) === null || _a === void 0 ? void 0 : _a.replace(replaceRegex, replacer);
});
return currentNode;
},
},
}),
};
exports.default = defaultCodemodPlugin;
//# sourceMappingURL=default.js.map
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -15,7 +6,7 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
var constants_1 = require("../../constants");
var default_1 = __importDefault(require("../../plugins/default"));
var utils_1 = require("../../utils");
var utils_2 = require("./utils");
var imports = {
const constants_1 = require("../../constants");
const default_1 = __importDefault(require("../../plugins/default"));
const utils_1 = require("../../utils");
const utils_2 = require("./utils");
const imports = {
compiledStyledImportName: 'styled',

@@ -33,25 +24,23 @@ emotionStyledPackageName: '@emotion/styled',

};
var removeEmotionJSXPragma = function (j, collection) {
const removeEmotionJSXPragma = (j, collection) => {
// ast-types are incorrect and can't handle both line and block types
// Cast to the correct type so we get safety
var commentCollection = collection.find(j.Comment);
commentCollection.forEach(function (commentPath) {
var commentBlockCollection = j(commentPath).filter(function (commentBlockPath) {
return commentBlockPath.value.value.includes(imports.emotionJSXPragma);
});
commentBlockCollection.forEach(function (commentBlockPath) {
const commentCollection = collection.find(j.Comment);
commentCollection.forEach((commentPath) => {
const commentBlockCollection = j(commentPath).filter((commentBlockPath) => commentBlockPath.value.value.includes(imports.emotionJSXPragma));
commentBlockCollection.forEach((commentBlockPath) => {
j(commentBlockPath).remove();
(0, utils_2.addReactIdentifier)({ j: j, collection: collection });
(0, utils_2.addReactIdentifier)({ j, collection });
});
});
};
var replaceEmotionCoreCSSTaggedTemplateExpression = function (j, collection, importPath) {
var importDeclarationCollection = (0, utils_1.getImportDeclarationCollection)({
j: j,
collection: collection,
importPath: importPath,
const replaceEmotionCoreCSSTaggedTemplateExpression = (j, collection, importPath) => {
const importDeclarationCollection = (0, utils_1.getImportDeclarationCollection)({
j,
collection,
importPath,
});
var name = (0, utils_2.findImportSpecifierName)({
j: j,
importDeclarationCollection: importDeclarationCollection,
const name = (0, utils_2.findImportSpecifierName)({
j,
importDeclarationCollection,
importName: imports.emotionCoreReactImportNames.css,

@@ -64,9 +53,7 @@ });

.find(j.TaggedTemplateExpression)
.filter(function (taggedTemplateExpressionPath) {
return j(taggedTemplateExpressionPath)
.find(j.Identifier)
.some(function (identifierPath) { return identifierPath.node.name === name; });
})
.forEach(function (taggedTemplateExpressionPath) {
var quasi = taggedTemplateExpressionPath.node.quasi;
.filter((taggedTemplateExpressionPath) => j(taggedTemplateExpressionPath)
.find(j.Identifier)
.some((identifierPath) => identifierPath.node.name === name))
.forEach((taggedTemplateExpressionPath) => {
const { quasi } = taggedTemplateExpressionPath.node;
if (quasi) {

@@ -77,47 +64,53 @@ j(taggedTemplateExpressionPath).replaceWith([quasi]);

};
var handleClassNamesCXBehavior = function (j, objectPattern) {
var cxIdentifierName = 'cx';
var axIdentifierName = 'ax';
var compiledRuntimePackageName = "".concat(constants_1.COMPILED_IMPORT_PATH, "/runtime");
var cxObjectPropertyCollection = j(objectPattern)
const handleClassNamesCXBehavior = (j, objectPattern) => {
const cxIdentifierName = 'cx';
const axIdentifierName = 'ax';
const compiledRuntimePackageName = `${constants_1.COMPILED_IMPORT_PATH}/runtime`;
const cxObjectPropertyCollection = j(objectPattern)
.find(j.ObjectProperty)
.filter(function (objectPropertyPath) {
return objectPropertyPath.node.key.type === 'Identifier' &&
objectPropertyPath.node.key.name === cxIdentifierName;
});
cxObjectPropertyCollection.forEach(function (cxObjectPropertyPath) {
.filter((objectPropertyPath) => objectPropertyPath.node.key.type === 'Identifier' &&
objectPropertyPath.node.key.name === cxIdentifierName);
cxObjectPropertyCollection.forEach((cxObjectPropertyPath) => {
(0, utils_1.addCommentBefore)({
j: j,
j,
collection: j(cxObjectPropertyPath.node),
message: "Please replace \"".concat(cxIdentifierName, "\" with \"").concat(axIdentifierName, "\" from \"").concat(compiledRuntimePackageName, "\".\n Usage: import { ").concat(axIdentifierName, " } from '").concat(compiledRuntimePackageName, "';\n\n NOTE: Both \"").concat(cxIdentifierName, "\" and \"").concat(axIdentifierName, "\" have some differences, so we have not replaced its usage.\n Please check the docs for \"").concat(axIdentifierName, "\" usage.\n\n In future, we will expose \"").concat(axIdentifierName, "\" directly from \"").concat(imports.emotionCoreReactImportNames.ClassNames, "\" props.\n\n Issue tracked on Github: https://github.com/atlassian-labs/compiled/issues/373"),
message: `Please replace "${cxIdentifierName}" with "${axIdentifierName}" from "${compiledRuntimePackageName}".
Usage: import { ${axIdentifierName} } from '${compiledRuntimePackageName}';
NOTE: Both "${cxIdentifierName}" and "${axIdentifierName}" have some differences, so we have not replaced its usage.
Please check the docs for "${axIdentifierName}" usage.
In future, we will expose "${axIdentifierName}" directly from "${imports.emotionCoreReactImportNames.ClassNames}" props.
Issue tracked on Github: https://github.com/atlassian-labs/compiled/issues/373`,
});
});
};
var handleClassNamesStyleBehavior = function (j, objectPattern) {
var styleIdentifierName = 'style';
var hasStyleObjectProperty = j(objectPattern)
const handleClassNamesStyleBehavior = (j, objectPattern) => {
const styleIdentifierName = 'style';
const hasStyleObjectProperty = j(objectPattern)
.find(j.ObjectProperty)
.some(function (objectPropertyPath) {
return objectPropertyPath.node.key.type === 'Identifier' &&
objectPropertyPath.node.key.name === styleIdentifierName;
});
.some((objectPropertyPath) => objectPropertyPath.node.key.type === 'Identifier' &&
objectPropertyPath.node.key.name === styleIdentifierName);
if (!hasStyleObjectProperty) {
var styleObjectProperty = j.objectProperty(j.identifier(styleIdentifierName), j.identifier(styleIdentifierName));
const styleObjectProperty = j.objectProperty(j.identifier(styleIdentifierName), j.identifier(styleIdentifierName));
objectPattern.properties.push(styleObjectProperty);
(0, utils_1.addCommentBefore)({
j: j,
j,
collection: j(styleObjectProperty),
message: "We have exported \"".concat(styleIdentifierName, "\" from \"").concat(imports.emotionCoreReactImportNames.ClassNames, "\" props.\n If you are using dynamic declarations, make sure to set the \"").concat(styleIdentifierName, "\"\n prop otherwise remove it."),
message: `We have exported "${styleIdentifierName}" from "${imports.emotionCoreReactImportNames.ClassNames}" props.
If you are using dynamic declarations, make sure to set the "${styleIdentifierName}"
prop otherwise remove it.`,
});
}
};
var handleClassNamesBehavior = function (j, collection, importPath) {
var importDeclarationCollection = (0, utils_1.getImportDeclarationCollection)({
j: j,
collection: collection,
importPath: importPath,
const handleClassNamesBehavior = (j, collection, importPath) => {
const importDeclarationCollection = (0, utils_1.getImportDeclarationCollection)({
j,
collection,
importPath,
});
var name = (0, utils_2.findImportSpecifierName)({
j: j,
importDeclarationCollection: importDeclarationCollection,
const name = (0, utils_2.findImportSpecifierName)({
j,
importDeclarationCollection,
importName: imports.emotionCoreReactImportNames.ClassNames,

@@ -130,14 +123,12 @@ });

.find(j.JSXElement)
.filter(function (jsxElementPath) {
return j(jsxElementPath)
.find(j.JSXIdentifier)
.some(function (jsxIdentifierPath) { return jsxIdentifierPath.node.name === name; });
})
.filter((jsxElementPath) => j(jsxElementPath)
.find(j.JSXIdentifier)
.some((jsxIdentifierPath) => jsxIdentifierPath.node.name === name))
.find(j.JSXExpressionContainer)
.forEach(function (jsxExpressionContainer) {
var expression = jsxExpressionContainer.node.expression;
.forEach((jsxExpressionContainer) => {
const { expression } = jsxExpressionContainer.node;
if (expression.type === 'FunctionExpression' ||
expression.type === 'ArrowFunctionExpression') {
if (expression.params.length && expression.params[0].type === 'ObjectPattern') {
var objectPattern = expression.params[0];
const objectPattern = expression.params[0];
handleClassNamesStyleBehavior(j, objectPattern);

@@ -149,32 +140,33 @@ handleClassNamesCXBehavior(j, objectPattern);

};
var mergeCompiledImportSpecifiers = function (j, collection) {
var allowedCompiledNames = __spreadArray([
imports.compiledStyledImportName
], Object.values(imports.emotionCoreReactImportNames), true).filter(function (name) { return ![imports.emotionCoreReactImportNames.jsx].includes(name); });
const mergeCompiledImportSpecifiers = (j, collection) => {
const allowedCompiledNames = [
imports.compiledStyledImportName,
...Object.values(imports.emotionCoreReactImportNames),
].filter((name) => ![imports.emotionCoreReactImportNames.jsx].includes(name));
(0, utils_2.mergeImportSpecifiers)({
j: j,
collection: collection,
filter: function (name) { return !!(name && allowedCompiledNames.includes(name)); },
j,
collection,
filter: (name) => !!(name && allowedCompiledNames.includes(name)),
});
};
var transformer = function (fileInfo, api, options) {
var source = fileInfo.source;
var j = api.jscodeshift;
var collection = j(source);
const transformer = (fileInfo, api, options) => {
const { source } = fileInfo;
const { jscodeshift: j } = api;
const collection = j(source);
// Run default plugin first and apply plugins in order
var plugins = __spreadArray([default_1.default], options.normalizedPlugins, true).map(function (plugin) { return plugin.create(fileInfo, api, options); });
var originalProgram = j(source).find(j.Program).get();
var hasEmotionCoreImportDeclaration = (0, utils_1.hasImportDeclaration)({
j: j,
collection: collection,
const plugins = [default_1.default, ...options.normalizedPlugins].map((plugin) => plugin.create(fileInfo, api, options));
const originalProgram = j(source).find(j.Program).get();
const hasEmotionCoreImportDeclaration = (0, utils_1.hasImportDeclaration)({
j,
collection,
importPath: imports.emotionCorePackageName,
});
var hasEmotionReactImportDeclaration = (0, utils_1.hasImportDeclaration)({
j: j,
collection: collection,
const hasEmotionReactImportDeclaration = (0, utils_1.hasImportDeclaration)({
j,
collection,
importPath: imports.emotionReactPackageName,
});
var hasEmotionStyledImportDeclaration = (0, utils_1.hasImportDeclaration)({
j: j,
collection: collection,
const hasEmotionStyledImportDeclaration = (0, utils_1.hasImportDeclaration)({
j,
collection,
importPath: imports.emotionStyledPackageName,

@@ -189,5 +181,5 @@ });

(0, utils_1.convertDefaultImportToNamedImport)({
j: j,
plugins: plugins,
collection: collection,
j,
plugins,
collection,
importPath: imports.emotionStyledPackageName,

@@ -204,5 +196,5 @@ namedImport: imports.compiledStyledImportName,

(0, utils_1.convertMixedImportToNamedImport)({
j: j,
plugins: plugins,
collection: collection,
j,
plugins,
collection,
importPath: imports.emotionCorePackageName,

@@ -217,5 +209,5 @@ defaultSourceSpecifierName: imports.compiledStyledImportName,

(0, utils_1.convertMixedImportToNamedImport)({
j: j,
plugins: plugins,
collection: collection,
j,
plugins,
collection,
importPath: imports.emotionReactPackageName,

@@ -228,4 +220,4 @@ defaultSourceSpecifierName: imports.compiledStyledImportName,

(0, utils_1.applyVisitor)({
plugins: plugins,
originalProgram: originalProgram,
plugins,
originalProgram,
currentProgram: collection.find(j.Program).get(),

@@ -232,0 +224,0 @@ });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeImportSpecifiers = exports.findImportSpecifierName = exports.addReactIdentifier = void 0;
var constants_1 = require("../../constants");
var utils_1 = require("../../utils");
var addReactIdentifier = function (_a) {
var j = _a.j, collection = _a.collection;
var hasReactImportDeclaration = (0, utils_1.hasImportDeclaration)({
j: j,
collection: collection,
const constants_1 = require("../../constants");
const utils_1 = require("../../utils");
const addReactIdentifier = ({ j, collection, }) => {
const hasReactImportDeclaration = (0, utils_1.hasImportDeclaration)({
j,
collection,
importPath: constants_1.REACT_IMPORT_PATH,
});
if (!hasReactImportDeclaration) {
collection.find(j.Program).forEach(function (programPath) {
collection.find(j.Program).forEach((programPath) => {
programPath.node.body.unshift(j.importDeclaration([j.importNamespaceSpecifier(j.identifier(constants_1.REACT_IMPORT_NAME))], j.literal(constants_1.REACT_IMPORT_PATH)));

@@ -19,12 +18,12 @@ });

else {
var importDeclarationCollection = (0, utils_1.getImportDeclarationCollection)({
j: j,
collection: collection,
const importDeclarationCollection = (0, utils_1.getImportDeclarationCollection)({
j,
collection,
importPath: constants_1.REACT_IMPORT_PATH,
});
importDeclarationCollection.forEach(function (importDeclarationPath) {
var importDefaultSpecifierCollection = j(importDeclarationPath).find(j.ImportDefaultSpecifier);
var importNamespaceSpecifierCollection = j(importDeclarationPath).find(j.ImportNamespaceSpecifier);
var hasNoDefaultReactImportDeclaration = importDefaultSpecifierCollection.length === 0;
var hasNoNamespaceReactImportDeclaration = importNamespaceSpecifierCollection.length === 0;
importDeclarationCollection.forEach((importDeclarationPath) => {
const importDefaultSpecifierCollection = j(importDeclarationPath).find(j.ImportDefaultSpecifier);
const importNamespaceSpecifierCollection = j(importDeclarationPath).find(j.ImportNamespaceSpecifier);
const hasNoDefaultReactImportDeclaration = importDefaultSpecifierCollection.length === 0;
const hasNoNamespaceReactImportDeclaration = importNamespaceSpecifierCollection.length === 0;
if (hasNoDefaultReactImportDeclaration &&

@@ -39,8 +38,7 @@ hasNoNamespaceReactImportDeclaration &&

exports.addReactIdentifier = addReactIdentifier;
var getImportSpecifierName = function (importSpecifierCollection) { return importSpecifierCollection.nodes()[0].local.name; };
var findImportSpecifierName = function (_a) {
var j = _a.j, importDeclarationCollection = _a.importDeclarationCollection, importName = _a.importName;
var importSpecifierCollection = importDeclarationCollection
const getImportSpecifierName = (importSpecifierCollection) => importSpecifierCollection.nodes()[0].local.name;
const findImportSpecifierName = ({ j, importDeclarationCollection, importName, }) => {
const importSpecifierCollection = importDeclarationCollection
.find(j.ImportSpecifier)
.filter(function (importSpecifierPath) { return importSpecifierPath.node.imported.name === importName; });
.filter((importSpecifierPath) => importSpecifierPath.node.imported.name === importName);
if (importSpecifierCollection.length === 0) {

@@ -52,23 +50,22 @@ return null;

exports.findImportSpecifierName = findImportSpecifierName;
var mergeImportSpecifiers = function (_a) {
var j = _a.j, collection = _a.collection, _b = _a.filter, filter = _b === void 0 ? function (_) { return true; } : _b;
var importDeclarationCollection = (0, utils_1.getImportDeclarationCollection)({
j: j,
collection: collection,
const mergeImportSpecifiers = ({ j, collection, filter = (_) => true, }) => {
const importDeclarationCollection = (0, utils_1.getImportDeclarationCollection)({
j,
collection,
importPath: constants_1.COMPILED_IMPORT_PATH,
});
var importSpecifiers = [];
const importSpecifiers = [];
importDeclarationCollection
.find(j.ImportSpecifier)
.filter(function (importSpecifierPath) { return filter(importSpecifierPath.node.imported.name); })
.forEach(function (importSpecifierPath) {
.filter((importSpecifierPath) => filter(importSpecifierPath.node.imported.name))
.forEach((importSpecifierPath) => {
importSpecifiers.push(importSpecifierPath.node);
});
var importDeclarationCollectionLength = importDeclarationCollection.length;
var importDeclarationComments = [];
importDeclarationCollection.forEach(function (importDeclarationPath, index) {
var oldNode = importDeclarationPath.node;
var comments = oldNode.comments;
const importDeclarationCollectionLength = importDeclarationCollection.length;
const importDeclarationComments = [];
importDeclarationCollection.forEach((importDeclarationPath, index) => {
const oldNode = importDeclarationPath.node;
const { comments } = oldNode;
if (comments) {
importDeclarationComments.push.apply(importDeclarationComments, comments);
importDeclarationComments.push(...comments);
}

@@ -79,3 +76,3 @@ if (index === importDeclarationCollectionLength - 1) {

]);
var newNode = importDeclarationPath.node;
const newNode = importDeclarationPath.node;
if (newNode !== oldNode) {

@@ -82,0 +79,0 @@ newNode.comments = importDeclarationComments;

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -15,29 +6,27 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
var default_1 = __importDefault(require("../../plugins/default"));
var utils_1 = require("../../utils");
var applyInnerRefPlugin = function (plugins, originalNode) {
return plugins.reduce(function (currentNode, plugin) {
var _a;
var buildRefAttributeImpl = (_a = plugin.transform) === null || _a === void 0 ? void 0 : _a.buildRefAttribute;
if (!buildRefAttributeImpl) {
return currentNode;
}
return buildRefAttributeImpl({ originalNode: originalNode, currentNode: currentNode });
}, originalNode);
};
var transformer = function (fileInfo, api, options) {
var source = fileInfo.source;
var j = api.jscodeshift;
var collection = j(source);
var plugins = __spreadArray([default_1.default], options.normalizedPlugins, true).map(function (plugin) { return plugin.create(fileInfo, api, options); });
var originalProgram = j(source).find(j.Program).get();
const default_1 = __importDefault(require("../../plugins/default"));
const utils_1 = require("../../utils");
const applyInnerRefPlugin = (plugins, originalNode) => plugins.reduce((currentNode, plugin) => {
var _a;
const buildRefAttributeImpl = (_a = plugin.transform) === null || _a === void 0 ? void 0 : _a.buildRefAttribute;
if (!buildRefAttributeImpl) {
return currentNode;
}
return buildRefAttributeImpl({ originalNode, currentNode });
}, originalNode);
const transformer = (fileInfo, api, options) => {
const { source } = fileInfo;
const { jscodeshift: j } = api;
const collection = j(source);
const plugins = [default_1.default, ...options.normalizedPlugins].map((plugin) => plugin.create(fileInfo, api, options));
const originalProgram = j(source).find(j.Program).get();
collection
.find(j.JSXAttribute, function (node) { return node.name.name === 'innerRef'; })
.forEach(function (innerRefProp) {
var newRefAttr = applyInnerRefPlugin(plugins, innerRefProp.value);
.find(j.JSXAttribute, (node) => node.name.name === 'innerRef')
.forEach((innerRefProp) => {
const newRefAttr = applyInnerRefPlugin(plugins, innerRefProp.value);
j(innerRefProp).replaceWith(newRefAttr);
});
(0, utils_1.applyVisitor)({
plugins: plugins,
originalProgram: originalProgram,
plugins,
originalProgram,
currentProgram: collection.find(j.Program).get(),

@@ -44,0 +33,0 @@ });

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -15,6 +6,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
var default_1 = __importDefault(require("../../plugins/default"));
var utils_1 = require("../../utils");
var utils_2 = require("./utils");
var imports = {
const default_1 = __importDefault(require("../../plugins/default"));
const utils_1 = require("../../utils");
const utils_2 = require("./utils");
const imports = {
compiledStyledImportName: 'styled',

@@ -24,11 +15,11 @@ styledComponentsSupportedImportNames: ['css', 'keyframes'],

};
var transformer = function (fileInfo, api, options) {
var source = fileInfo.source;
var j = api.jscodeshift;
var collection = j(source);
var plugins = __spreadArray([default_1.default], options.normalizedPlugins, true).map(function (plugin) { return plugin.create(fileInfo, api, options); });
var originalProgram = j(source).find(j.Program).get();
var hasStyledComponentsImportDeclaration = (0, utils_1.hasImportDeclaration)({
j: j,
collection: collection,
const transformer = (fileInfo, api, options) => {
const { source } = fileInfo;
const { jscodeshift: j } = api;
const collection = j(source);
const plugins = [default_1.default, ...options.normalizedPlugins].map((plugin) => plugin.create(fileInfo, api, options));
const originalProgram = j(source).find(j.Program).get();
const hasStyledComponentsImportDeclaration = (0, utils_1.hasImportDeclaration)({
j,
collection,
importPath: imports.styledComponentsPackageName,

@@ -40,5 +31,5 @@ });

(0, utils_1.convertMixedImportToNamedImport)({
j: j,
plugins: plugins,
collection: collection,
j,
plugins,
collection,
importPath: imports.styledComponentsPackageName,

@@ -48,18 +39,17 @@ defaultSourceSpecifierName: imports.compiledStyledImportName,

});
var compiledLocalStyledName = (0, utils_2.getCompiledLocalStyledName)(j, collection);
const compiledLocalStyledName = (0, utils_2.getCompiledLocalStyledName)(j, collection);
if (compiledLocalStyledName) {
(0, utils_2.convertTaggedTemplates)({ j: j, plugins: plugins, collection: collection, compiledLocalStyledName: compiledLocalStyledName });
(0, utils_2.convertTaggedTemplates)({ j, plugins, collection, compiledLocalStyledName });
}
(0, utils_1.applyVisitor)({
plugins: plugins,
originalProgram: originalProgram,
plugins,
originalProgram,
currentProgram: collection.find(j.Program).get(),
});
// compiled styled object might've been renamed, we need to find it again
var compiledLocalStyledNameAfterVisitor = (0, utils_2.getCompiledLocalStyledName)(j, collection);
const compiledLocalStyledNameAfterVisitor = (0, utils_2.getCompiledLocalStyledName)(j, collection);
if (compiledLocalStyledNameAfterVisitor) {
var taggedTemplateExpressionsWithAttrs = collection.find(j.TaggedTemplateExpression, function (_a) {
var tag = _a.tag;
const taggedTemplateExpressionsWithAttrs = collection.find(j.TaggedTemplateExpression, ({ tag }) => {
if (tag.type === 'CallExpression') {
var callee = tag.callee;
const { callee } = tag;
return (callee.type === 'MemberExpression' &&

@@ -76,4 +66,4 @@ callee.object.type === 'MemberExpression' &&

(0, utils_2.convertStyledAttrsToComponent)({
j: j,
plugins: plugins,
j,
plugins,
expressions: taggedTemplateExpressionsWithAttrs,

@@ -80,0 +70,0 @@ compiledLocalStyledName: compiledLocalStyledNameAfterVisitor,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertTaggedTemplates = exports.getCompiledLocalStyledName = exports.convertStyledAttrsToComponent = void 0;
var utils_1 = require("@compiled/utils");
var constants_1 = require("../../constants");
var isStyleProperty = function (property) {
return property.type === 'ObjectProperty' &&
property.key.type === 'Identifier' &&
property.key.name === 'style';
};
var getStyleAttributeExpression = function (expression) {
return expression.type === 'ObjectExpression'
? expression.properties.find(function (property) { return isStyleProperty(property); })
: null;
};
var getRestAttributeExpressions = function (expression) {
return expression.type === 'ObjectExpression'
? expression.properties.filter(function (property) { return !isStyleProperty(property); })
: null;
};
var getAlternativeComponentName = function (name) { return "".concat(name, "Styles"); };
const utils_1 = require("@compiled/utils");
const constants_1 = require("../../constants");
const isStyleProperty = (property) => property.type === 'ObjectProperty' &&
property.key.type === 'Identifier' &&
property.key.name === 'style';
const getStyleAttributeExpression = (expression) => expression.type === 'ObjectExpression'
? expression.properties.find((property) => isStyleProperty(property))
: null;
const getRestAttributeExpressions = (expression) => expression.type === 'ObjectExpression'
? expression.properties.filter((property) => !isStyleProperty(property))
: null;
const getAlternativeComponentName = (name) => `${name}Styles`;
/**

@@ -26,9 +20,8 @@ * Extracts used arguments for property value calculation and returns arrow function expression that will be used as a tagged template expression.

*/
var convertObjectPropertyToExpression = function (_a) {
var j = _a.j, params = _a.params, value = _a.value;
var usedProps;
var propsParam = params[0];
const convertObjectPropertyToExpression = ({ j, params, value, }) => {
let usedProps;
const propsParam = params[0];
if (propsParam.type === 'ObjectPattern') {
var destructedProps = propsParam.properties.filter(function (prop) {
var propName;
const destructedProps = propsParam.properties.filter((prop) => {
let propName;
if (prop.type === 'ObjectProperty' && prop.value.type === 'Identifier') {

@@ -43,3 +36,3 @@ propName = prop.value.name;

}
return j(value).find(j.Identifier, function (identifier) { return propName === identifier.name; }).length > 0;
return j(value).find(j.Identifier, (identifier) => propName === identifier.name).length > 0;
});

@@ -50,3 +43,3 @@ usedProps = j(j.objectPattern(destructedProps));

usedProps = j(value)
.find(j.Identifier, function (identifier) { return propsParam.name === identifier.name; })
.find(j.Identifier, (identifier) => propsParam.name === identifier.name)
.at(-1);

@@ -64,14 +57,13 @@ }

*/
var extractTemplateData = function (_a) {
var j = _a.j, styleFn = _a.styleFn;
var body = styleFn.body;
const extractTemplateData = ({ j, styleFn, }) => {
const body = styleFn.body;
if (body.type === 'ObjectExpression') {
var styleFnParams_1 = styleFn.params;
var properties = styleFn.body.properties;
var _b = properties.reduce(function (acc, property) {
const styleFnParams = styleFn.params;
const properties = styleFn.body.properties;
const { keys, expressions } = properties.reduce((acc, property) => {
if (property.type === 'ObjectProperty') {
var key = (0, utils_1.kebabCase)(property.key.name);
var expression = convertObjectPropertyToExpression({
j: j,
params: styleFnParams_1,
const key = (0, utils_1.kebabCase)(property.key.name);
const expression = convertObjectPropertyToExpression({
j,
params: styleFnParams,
value: property.value,

@@ -83,7 +75,7 @@ });

return acc;
}, { keys: [], expressions: [] }), keys_1 = _b.keys, expressions = _b.expressions;
var quasis = keys_1.reduce(function (quasis, key, i) {
var prefix = i === 0 ? '' : ';';
var isLast = i === keys_1.length - 1;
var element = "".concat(prefix, "\n").concat(key, ": ");
}, { keys: [], expressions: [] });
const quasis = keys.reduce((quasis, key, i) => {
const prefix = i === 0 ? '' : ';';
const isLast = i === keys.length - 1;
const element = `${prefix}\n${key}: `;
quasis.push(j.templateElement({ cooked: element, raw: element }, false));

@@ -93,3 +85,3 @@ isLast && quasis.push(j.templateElement({ cooked: ';', raw: ';' }, false));

}, []);
return { quasis: quasis, expressions: expressions };
return { quasis, expressions };
}

@@ -101,12 +93,9 @@ return { quasis: [], expressions: [] };

*/
var createWrapperNode = function (_a) {
var j = _a.j, expression = _a.expression, attrs = _a.attrs, name = _a.name, isAnonymous = _a.isAnonymous;
var propsParam = expression.type === 'ArrowFunctionExpression' && expression.params[0].type === 'Identifier'
const createWrapperNode = ({ j, expression, attrs, name, isAnonymous, }) => {
const propsParam = expression.type === 'ArrowFunctionExpression' && expression.params[0].type === 'Identifier'
? expression.params[0]
: j.identifier('props');
var jsxAttrs = attrs.map(function (attr) {
return j.jsxAttribute(j.jsxIdentifier(attr.key.name), j.jsxExpressionContainer(attr.value));
});
const jsxAttrs = attrs.map((attr) => j.jsxAttribute(j.jsxIdentifier(attr.key.name), j.jsxExpressionContainer(attr.value)));
jsxAttrs.push(j.jsxSpreadAttribute(propsParam));
var wrapperExpression = j.arrowFunctionExpression([propsParam], j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(getAlternativeComponentName(name)), jsxAttrs, true)));
const wrapperExpression = j.arrowFunctionExpression([propsParam], j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(getAlternativeComponentName(name)), jsxAttrs, true)));
return isAnonymous

@@ -116,6 +105,3 @@ ? wrapperExpression

};
var createComposedNode = function (_a) {
var j = _a.j, expression = _a.expression, name = _a.name;
return j.variableDeclaration('const', [j.variableDeclarator(j.identifier(name), expression)]);
};
const createComposedNode = ({ j, expression, name, }) => j.variableDeclaration('const', [j.variableDeclarator(j.identifier(name), expression)]);
/**

@@ -127,4 +113,4 @@ * Returns declaration data

*/
var getDeclarationData = function (expression) {
var parentDeclaration = expression.parentPath;
const getDeclarationData = (expression) => {
const parentDeclaration = expression.parentPath;
if (parentDeclaration.value.type === 'VariableDeclarator' &&

@@ -138,3 +124,3 @@ parentDeclaration.value.id.type === 'Identifier') {

return {
name: "ComposedComponent",
name: `ComposedComponent`,
declaration: expression,

@@ -147,5 +133,5 @@ isAnonymous: true,

*/
var getAttributesExpression = function (expression) {
var expressionCall = expression.value.tag;
var attrsArgumentExpression = expressionCall.arguments[0];
const getAttributesExpression = (expression) => {
const expressionCall = expression.value.tag;
const attrsArgumentExpression = expressionCall.arguments[0];
return (attrsArgumentExpression.type === 'ArrowFunctionExpression' &&

@@ -160,13 +146,11 @@ attrsArgumentExpression.body.type === 'ObjectExpression'

*/
var createNewTemplateExpression = function (_a) {
var j = _a.j, expression = _a.expression, compiledLocalStyledName = _a.compiledLocalStyledName;
var expressionCall = expression.value.tag;
var styledTagName = expressionCall.callee.object.property.name;
const createNewTemplateExpression = ({ j, expression, compiledLocalStyledName, }) => {
const expressionCall = expression.value.tag;
const styledTagName = expressionCall.callee.object.property.name;
return j.taggedTemplateExpression(j.memberExpression(j.identifier(compiledLocalStyledName), j.identifier(styledTagName)), expression.value.quasi);
};
var applyBuildAttributes = function (_a) {
var plugins = _a.plugins, originalNode = _a.originalNode, transformedNode = _a.transformedNode, composedNode = _a.composedNode;
plugins.reduce(function (currentNode, plugin) {
const applyBuildAttributes = ({ plugins, originalNode, transformedNode, composedNode, }) => {
plugins.reduce((currentNode, plugin) => {
var _a;
var buildAttributesImpl = (_a = plugin.transform) === null || _a === void 0 ? void 0 : _a.buildAttributes;
const buildAttributesImpl = (_a = plugin.transform) === null || _a === void 0 ? void 0 : _a.buildAttributes;
if (!buildAttributesImpl) {

@@ -176,11 +160,11 @@ return currentNode;

return buildAttributesImpl({
originalNode: originalNode,
transformedNode: transformedNode,
currentNode: currentNode,
composedNode: composedNode,
originalNode,
transformedNode,
currentNode,
composedNode,
});
}, originalNode);
};
var findParent = function (node, parentType) {
var parent = node;
const findParent = (node, parentType) => {
let parent = node;
while (parent.parentPath && parent.value.type !== parentType) {

@@ -191,19 +175,17 @@ parent = parent.parentPath;

};
var convertStyledAttrsToComponent = function (_a) {
var j = _a.j, plugins = _a.plugins, expressions = _a.expressions, compiledLocalStyledName = _a.compiledLocalStyledName;
expressions.forEach(function (expression) {
var _a, _b;
var transformedNode = null;
var composedNode = null;
var attributesExpression = getAttributesExpression(expression);
var styleAttributeExpression = getStyleAttributeExpression(attributesExpression);
var newTemplateExpressions = createNewTemplateExpression({
j: j,
expression: expression,
compiledLocalStyledName: compiledLocalStyledName,
const convertStyledAttrsToComponent = ({ j, plugins, expressions, compiledLocalStyledName, }) => {
expressions.forEach((expression) => {
let transformedNode = null;
let composedNode = null;
const attributesExpression = getAttributesExpression(expression);
const styleAttributeExpression = getStyleAttributeExpression(attributesExpression);
const newTemplateExpressions = createNewTemplateExpression({
j,
expression,
compiledLocalStyledName,
});
if (styleAttributeExpression) {
// extract new template data from arrow function
var newTemplateData = extractTemplateData({
j: j,
const newTemplateData = extractTemplateData({
j,
styleFn: styleAttributeExpression.value,

@@ -213,12 +195,12 @@ });

if (newTemplateData != undefined) {
var quasis = newTemplateData.quasis, expressions_1 = newTemplateData.expressions;
(_a = newTemplateExpressions.quasi.expressions).unshift.apply(_a, expressions_1);
(_b = newTemplateExpressions.quasi.quasis).unshift.apply(_b, quasis);
const { quasis, expressions } = newTemplateData;
newTemplateExpressions.quasi.expressions.unshift(...expressions);
newTemplateExpressions.quasi.quasis.unshift(...quasis);
}
}
var _c = getDeclarationData(expression), isAnonymous = _c.isAnonymous, componentName = _c.name, expressionDeclarator = _c.declaration;
var restAttributes = getRestAttributeExpressions(attributesExpression);
const { isAnonymous, name: componentName, declaration: expressionDeclarator, } = getDeclarationData(expression);
const restAttributes = getRestAttributeExpressions(attributesExpression);
if (restAttributes && restAttributes.length > 0) {
composedNode = createComposedNode({
j: j,
j,
expression: newTemplateExpressions,

@@ -228,7 +210,7 @@ name: getAlternativeComponentName(componentName),

transformedNode = createWrapperNode({
j: j,
j,
expression: attributesExpression,
attrs: restAttributes,
name: componentName,
isAnonymous: isAnonymous,
isAnonymous,
});

@@ -246,6 +228,6 @@ }

applyBuildAttributes({
plugins: plugins,
plugins,
originalNode: expressionDeclarator,
transformedNode: transformedNode,
composedNode: composedNode,
transformedNode,
composedNode,
});

@@ -255,8 +237,8 @@ });

exports.convertStyledAttrsToComponent = convertStyledAttrsToComponent;
var getCompiledLocalStyledName = function (j, collection) {
var compiledLocalStyledName = null;
var styledImports = collection.find(j.ImportSpecifier, function (specifier) { return specifier.imported.name === 'styled'; });
styledImports.forEach(function (styledImport) {
const getCompiledLocalStyledName = (j, collection) => {
let compiledLocalStyledName = null;
const styledImports = collection.find(j.ImportSpecifier, (specifier) => specifier.imported.name === 'styled');
styledImports.forEach((styledImport) => {
var _a, _b;
var isCompiledImport = ((_a = styledImport === null || styledImport === void 0 ? void 0 : styledImport.parentPath) === null || _a === void 0 ? void 0 : _a.parentPath.value.source.value) === constants_1.COMPILED_IMPORT_PATH;
const isCompiledImport = ((_a = styledImport === null || styledImport === void 0 ? void 0 : styledImport.parentPath) === null || _a === void 0 ? void 0 : _a.parentPath.value.source.value) === constants_1.COMPILED_IMPORT_PATH;
if (isCompiledImport) {

@@ -269,12 +251,10 @@ compiledLocalStyledName = ((_b = styledImport.value.local) === null || _b === void 0 ? void 0 : _b.name) || 'styled';

exports.getCompiledLocalStyledName = getCompiledLocalStyledName;
var convertTaggedTemplates = function (_a) {
var j = _a.j, plugins = _a.plugins, collection = _a.collection, compiledLocalStyledName = _a.compiledLocalStyledName;
var templateExpressions = collection.find(j.TaggedTemplateExpression, function (_a) {
var tag = _a.tag;
const convertTaggedTemplates = ({ j, plugins, collection, compiledLocalStyledName, }) => {
const templateExpressions = collection.find(j.TaggedTemplateExpression, ({ tag }) => {
if (tag.type === 'MemberExpression') {
var object = tag.object;
const { object } = tag;
return object.type === 'Identifier' && object.name === compiledLocalStyledName;
}
if (tag.type === 'CallExpression') {
var callee = tag.callee;
const { callee } = tag;
return (callee.type === 'MemberExpression' &&

@@ -287,12 +267,9 @@ callee.object.type === 'MemberExpression' &&

});
templateExpressions.forEach(function (expression) {
return applyBuildTemplateExpression({ plugins: plugins, originalNode: expression.value });
});
templateExpressions.forEach((expression) => applyBuildTemplateExpression({ plugins, originalNode: expression.value }));
};
exports.convertTaggedTemplates = convertTaggedTemplates;
var applyBuildTemplateExpression = function (_a) {
var plugins = _a.plugins, originalNode = _a.originalNode;
plugins.reduce(function (currentNode, plugin) {
const applyBuildTemplateExpression = ({ plugins, originalNode, }) => {
plugins.reduce((currentNode, plugin) => {
var _a;
var buildTemplateExpressionImpl = (_a = plugin.transform) === null || _a === void 0 ? void 0 : _a.buildTemplateExpression;
const buildTemplateExpressionImpl = (_a = plugin.transform) === null || _a === void 0 ? void 0 : _a.buildTemplateExpression;
if (!buildTemplateExpressionImpl) {

@@ -302,4 +279,4 @@ return currentNode;

return buildTemplateExpressionImpl({
originalNode: originalNode,
currentNode: currentNode,
originalNode,
currentNode,
});

@@ -306,0 +283,0 @@ }, originalNode);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addCommentBefore = void 0;
var constants_1 = require("../constants");
const constants_1 = require("../constants");
// not replacing newlines (which \s does)
var spacesAndTabs = /[ \t]{2,}/g;
var lineStartWithSpaces = /^[ \t]*/gm;
var clean = function (value) {
return value
.replace(spacesAndTabs, ' ')
.replace(lineStartWithSpaces, '')
// using .trim() to clear the any newlines before the first text and after last text
.trim();
};
var addCommentBefore = function (_a) {
var j = _a.j, collection = _a.collection, message = _a.message;
var content = " TODO(".concat(constants_1.COMPILED_IMPORT_PATH, " codemod): ").concat(clean(message), " ");
collection.forEach(function (path) {
const spacesAndTabs = /[ \t]{2,}/g;
const lineStartWithSpaces = /^[ \t]*/gm;
const clean = (value) => value
.replace(spacesAndTabs, ' ')
.replace(lineStartWithSpaces, '')
// using .trim() to clear the any newlines before the first text and after last text
.trim();
const addCommentBefore = ({ j, collection, message, }) => {
const content = ` TODO(${constants_1.COMPILED_IMPORT_PATH} codemod): ${clean(message)} `;
collection.forEach((path) => {
path.value.comments = path.value.comments || [];
var exists = path.value.comments.find(function (comment) { return comment.value === content; });
const exists = path.value.comments.find((comment) => comment.value === content);
// avoiding duplicates of the same comment

@@ -22,0 +19,0 @@ if (exists) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyVisitor = void 0;
var applyVisitor = function (_a) {
var _b;
var plugins = _a.plugins, originalProgram = _a.originalProgram, currentProgram = _a.currentProgram;
for (var _i = 0, plugins_1 = plugins; _i < plugins_1.length; _i++) {
var plugin = plugins_1[_i];
var programImpl = (_b = plugin.visitor) === null || _b === void 0 ? void 0 : _b.program;
const applyVisitor = ({ plugins, originalProgram, currentProgram, }) => {
var _a;
for (const plugin of plugins) {
const programImpl = (_a = plugin.visitor) === null || _a === void 0 ? void 0 : _a.program;
if (programImpl) {
programImpl({
originalProgram: originalProgram,
originalProgram,
program: currentProgram,

@@ -14,0 +12,0 @@ });

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertMixedImportToNamedImport = exports.convertDefaultImportToNamedImport = void 0;
var constants_1 = require("../constants");
var import_declarations_1 = require("./import-declarations");
var applyBuildImport = function (_a) {
var plugins = _a.plugins, originalNode = _a.originalNode, specifiers = _a.specifiers;
return plugins.reduce(function (currentNode, plugin) {
var _a;
var buildImportImpl = (_a = plugin.transform) === null || _a === void 0 ? void 0 : _a.buildImport;
if (!buildImportImpl) {
return currentNode;
}
return buildImportImpl({
originalNode: originalNode,
currentNode: currentNode,
specifiers: specifiers,
compiledImportPath: constants_1.COMPILED_IMPORT_PATH,
});
}, originalNode);
};
var getImportDefaultSpecifierName = function (importDefaultSpecifierCollection) {
var name = importDefaultSpecifierCollection.nodes()[0].local.name;
const constants_1 = require("../constants");
const import_declarations_1 = require("./import-declarations");
const applyBuildImport = ({ plugins, originalNode, specifiers, }) => plugins.reduce((currentNode, plugin) => {
var _a;
const buildImportImpl = (_a = plugin.transform) === null || _a === void 0 ? void 0 : _a.buildImport;
if (!buildImportImpl) {
return currentNode;
}
return buildImportImpl({
originalNode,
currentNode,
specifiers,
compiledImportPath: constants_1.COMPILED_IMPORT_PATH,
});
}, originalNode);
const getImportDefaultSpecifierName = (importDefaultSpecifierCollection) => {
const name = importDefaultSpecifierCollection.nodes()[0].local.name;
if (!name) {

@@ -38,14 +26,13 @@ throw new Error('Name should exist');

};
var convertDefaultImportToNamedImport = function (_a) {
var j = _a.j, plugins = _a.plugins, collection = _a.collection, importPath = _a.importPath, namedImport = _a.namedImport;
var importDeclarationCollection = (0, import_declarations_1.getImportDeclarationCollection)({
j: j,
collection: collection,
importPath: importPath,
const convertDefaultImportToNamedImport = ({ j, plugins, collection, importPath, namedImport, }) => {
const importDeclarationCollection = (0, import_declarations_1.getImportDeclarationCollection)({
j,
collection,
importPath,
});
importDeclarationCollection.forEach(function (importDeclarationPath) {
var importDefaultSpecifierCollection = j(importDeclarationPath).find(j.ImportDefaultSpecifier);
importDeclarationCollection.forEach((importDeclarationPath) => {
const importDefaultSpecifierCollection = j(importDeclarationPath).find(j.ImportDefaultSpecifier);
if (importDefaultSpecifierCollection.length > 0) {
var newImport = applyBuildImport({
plugins: plugins,
const newImport = applyBuildImport({
plugins,
originalNode: importDeclarationPath.node,

@@ -61,13 +48,12 @@ specifiers: [

exports.convertDefaultImportToNamedImport = convertDefaultImportToNamedImport;
var convertMixedImportToNamedImport = function (_a) {
var j = _a.j, plugins = _a.plugins, collection = _a.collection, importPath = _a.importPath, defaultSourceSpecifierName = _a.defaultSourceSpecifierName, allowedImportSpecifierNames = _a.allowedImportSpecifierNames;
var importDeclarationCollection = (0, import_declarations_1.getImportDeclarationCollection)({
j: j,
collection: collection,
importPath: importPath,
const convertMixedImportToNamedImport = ({ j, plugins, collection, importPath, defaultSourceSpecifierName, allowedImportSpecifierNames, }) => {
const importDeclarationCollection = (0, import_declarations_1.getImportDeclarationCollection)({
j,
collection,
importPath,
});
importDeclarationCollection.forEach(function (importDeclarationPath) {
importDeclarationCollection.forEach((importDeclarationPath) => {
var _a;
var newSpecifiers = (importDeclarationPath.node.specifiers || [])
.map(function (specifier) {
const newSpecifiers = (importDeclarationPath.node.specifiers || [])
.map((specifier) => {
var _a, _b, _c;

@@ -77,3 +63,3 @@ if (!(specifier.type === 'ImportDefaultSpecifier') &&

return undefined;
var newSpecifier = specifier.type === 'ImportDefaultSpecifier'
const newSpecifier = specifier.type === 'ImportDefaultSpecifier'
? j.importSpecifier(j.identifier(defaultSourceSpecifierName), j.identifier(((_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name) || ''))

@@ -86,18 +72,10 @@ : j.importSpecifier(j.identifier(specifier.imported.name), j.identifier(((_b = specifier.local) === null || _b === void 0 ? void 0 : _b.name) || ''));

newSpecifier.comments =
((_c = specifier.comments) === null || _c === void 0 ? void 0 : _c.map(function (comment) {
return j.commentBlock(comment.value, comment.leading, comment.trailing);
})) || [];
((_c = specifier.comments) === null || _c === void 0 ? void 0 : _c.map((comment) => j.commentBlock(comment.value, comment.leading, comment.trailing))) || [];
return newSpecifier;
})
.filter(function (specifier) {
return Boolean(specifier &&
__spreadArray([defaultSourceSpecifierName], allowedImportSpecifierNames, true).includes(specifier === null || specifier === void 0 ? void 0 : specifier.imported.name));
});
newSpecifiers.sort(function (_a, _b) {
var nameA = _a.imported.name;
var nameB = _b.imported.name;
return nameA.localeCompare(nameB);
});
var originalNode = importDeclarationPath.node;
var unresolvedSpecifiers = (_a = originalNode.specifiers) === null || _a === void 0 ? void 0 : _a.filter(function (specifier) {
.filter((specifier) => Boolean(specifier &&
[defaultSourceSpecifierName, ...allowedImportSpecifierNames].includes(specifier === null || specifier === void 0 ? void 0 : specifier.imported.name)));
newSpecifiers.sort(({ imported: { name: nameA } }, { imported: { name: nameB } }) => nameA.localeCompare(nameB));
const originalNode = importDeclarationPath.node;
const unresolvedSpecifiers = (_a = originalNode.specifiers) === null || _a === void 0 ? void 0 : _a.filter((specifier) => {
var _a;

@@ -112,4 +90,4 @@ return specifier.type !== 'ImportDefaultSpecifier' &&

}
var newImport = applyBuildImport({
plugins: plugins,
const newImport = applyBuildImport({
plugins,
originalNode: originalNode,

@@ -116,0 +94,0 @@ specifiers: newSpecifiers,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasImportDeclaration = exports.getImportDeclarationCollection = void 0;
var getImportDeclarationCollection = function (_a) {
var j = _a.j, collection = _a.collection, importPath = _a.importPath;
var found = collection
const getImportDeclarationCollection = ({ j, collection, importPath, }) => {
const found = collection
.find(j.ImportDeclaration)
.filter(function (importDeclarationPath) { return importDeclarationPath.node.source.value === importPath; });
.filter((importDeclarationPath) => importDeclarationPath.node.source.value === importPath);
return found;
};
exports.getImportDeclarationCollection = getImportDeclarationCollection;
var hasImportDeclaration = function (_a) {
var j = _a.j, collection = _a.collection, importPath = _a.importPath;
var result = (0, exports.getImportDeclarationCollection)({
j: j,
collection: collection,
importPath: importPath,
const hasImportDeclaration = ({ j, collection, importPath, }) => {
const result = (0, exports.getImportDeclarationCollection)({
j,
collection,
importPath,
});

@@ -19,0 +17,0 @@ return result.length > 0;

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

@@ -45,29 +34,2 @@ if (k2 === undefined) k2 = k;

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -78,8 +40,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.withPlugin = void 0;
var chalk_1 = __importDefault(require("chalk"));
var isCodemodPlugin = function (pluginItem) {
return typeof pluginItem === 'object';
};
var getPlugins = function (items) {
var pluginItems = Array.isArray(items) ? items : [items];
const chalk_1 = __importDefault(require("chalk"));
const isCodemodPlugin = (pluginItem) => typeof pluginItem === 'object';
const getPlugins = (items) => {
const pluginItems = Array.isArray(items) ? items : [items];
// Remove this code block once https://github.com/facebook/jscodeshift/issues/454 is resolved

@@ -89,30 +49,20 @@ if (pluginItems.every(isCodemodPlugin)) {

}
return Promise.all(pluginItems.map(function (pluginItem) { return __awaiter(void 0, void 0, void 0, function () {
var pluginModule, pluginName, err_1;
return Promise.all(pluginItems.map((pluginItem) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
return __generator(this, function (_b) {
var _c;
switch (_b.label) {
case 0:
if (isCodemodPlugin(pluginItem)) {
return [2 /*return*/, pluginItem];
}
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, (_c = pluginItem, Promise.resolve().then(function () { return __importStar(require(_c)); }))];
case 2:
pluginModule = _b.sent();
pluginName = (_a = pluginModule === null || pluginModule === void 0 ? void 0 : pluginModule.default) === null || _a === void 0 ? void 0 : _a.name;
if (!pluginName) {
throw new Error(chalk_1.default.yellow("".concat(chalk_1.default.bold("Plugin at path '".concat(pluginItem, "' did not export 'name'")))));
}
return [2 /*return*/, pluginModule.default];
case 3:
err_1 = _b.sent();
throw new Error(chalk_1.default.red("".concat(chalk_1.default.bold("Plugin at path '".concat(pluginItem, "' was not loaded")), "\n").concat(err_1)));
case 4: return [2 /*return*/];
var _b;
if (isCodemodPlugin(pluginItem)) {
return pluginItem;
}
try {
const pluginModule = yield (_a = pluginItem, Promise.resolve().then(() => __importStar(require(_a))));
const pluginName = (_b = pluginModule === null || pluginModule === void 0 ? void 0 : pluginModule.default) === null || _b === void 0 ? void 0 : _b.name;
if (!pluginName) {
throw new Error(chalk_1.default.yellow(`${chalk_1.default.bold(`Plugin at path '${pluginItem}' did not export 'name'`)}`));
}
});
}); }));
return pluginModule.default;
}
catch (err) {
throw new Error(chalk_1.default.red(`${chalk_1.default.bold(`Plugin at path '${pluginItem}' was not loaded`)}\n${err}`));
}
})));
};

@@ -124,17 +74,13 @@ /*

*/
var withPlugin = function (transformer) {
return function (fileInfo, api, options) {
var _a, _b;
var plugins = (_b = (_a = options.plugin) !== null && _a !== void 0 ? _a : options.plugins) !== null && _b !== void 0 ? _b : [];
// TODO Await this when https://github.com/facebook/jscodeshift/issues/454 is resolved
var maybeNormalizedPlugins = getPlugins(plugins);
if (maybeNormalizedPlugins instanceof Promise) {
return maybeNormalizedPlugins.then(function (normalizedPlugins) {
return transformer(fileInfo, api, __assign(__assign({}, options), { normalizedPlugins: normalizedPlugins }));
});
}
return transformer(fileInfo, api, __assign(__assign({}, options), { normalizedPlugins: maybeNormalizedPlugins }));
};
const withPlugin = (transformer) => (fileInfo, api, options) => {
var _a, _b;
const plugins = (_b = (_a = options.plugin) !== null && _a !== void 0 ? _a : options.plugins) !== null && _b !== void 0 ? _b : [];
// TODO Await this when https://github.com/facebook/jscodeshift/issues/454 is resolved
const maybeNormalizedPlugins = getPlugins(plugins);
if (maybeNormalizedPlugins instanceof Promise) {
return maybeNormalizedPlugins.then((normalizedPlugins) => transformer(fileInfo, api, Object.assign(Object.assign({}, options), { normalizedPlugins })));
}
return transformer(fileInfo, api, Object.assign(Object.assign({}, options), { normalizedPlugins: maybeNormalizedPlugins }));
};
exports.withPlugin = withPlugin;
//# sourceMappingURL=with-plugin.js.map
{
"name": "@compiled/codemods",
"version": "0.8.0",
"version": "0.9.0",
"description": "A familiar and performant compile time CSS-in-JS library for React.",

@@ -33,3 +33,3 @@ "keywords": [

"dependencies": {
"@compiled/utils": "^0.7.0",
"@compiled/utils": "^0.8.0",
"chalk": "^4.1.2",

@@ -36,0 +36,0 @@ "jscodeshift": "^0.14.0"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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