@plumeria/codemod 19.15.0 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -105,6 +105,12 @@ exports.adoptStyles = {
|
|
|
105
105
|
(current.parent.name?.name === 'className' ||
|
|
106
106
|
current.parent.name?.name === styleProp));
|
|
107
107
|
};
|
|
108
|
+
const lone = (node) => node?.type === 'LogicalExpression' &&
|
|
109
|
+
node.operator === '||' &&
|
|
110
|
+
node.right.type === 'Identifier' &&
|
|
111
|
+
node.right.name === 'undefined'
|
|
112
|
+
? [node.left]
|
|
113
|
+
: undefined;
|
|
108
114
|
const joinedElements = (node) => {
|
|
109
115
|
if (node?.type === 'TemplateLiteral' && node.expressions.length > 1) {
|
|
110
116
|
const spaced = node.quasis.every((quasi, index) => index === 0 || index === node.quasis.length - 1
|
|
@@ -117,7 +123,7 @@ exports.adoptStyles = {
|
|
|
117
123
|
node.callee.property?.name !== 'join' ||
|
|
118
124
|
node.arguments.length !== 1 ||
|
|
119
125
|
node.arguments[0].value !== ' ')
|
|
120
|
-
return
|
|
126
|
+
return lone(node);
|
|
121
127
|
const joined = node.callee.object;
|
|
122
128
|
if (joined?.type === 'ArrayExpression')
|
|
123
129
|
return joined.elements.filter(Boolean);
|
|
@@ -76,6 +76,13 @@ const walk = (node, visit) => {
|
|
|
76
76
|
const needsFilter = (node) => node.type === 'LogicalExpression' ||
|
|
77
77
|
node.type === 'ConditionalExpression' ||
|
|
78
78
|
node.type === 'SpreadElement';
|
|
79
|
+
const mayBeFalsy = (node) => {
|
|
80
|
+
if (node.type === 'LogicalExpression')
|
|
81
|
+
return node.operator === '&&' || mayBeFalsy(node.right);
|
|
82
|
+
if (node.type === 'ConditionalExpression')
|
|
83
|
+
return mayBeFalsy(node.consequent) || mayBeFalsy(node.alternate);
|
|
84
|
+
return node.type === 'Literal' && !node.value;
|
|
85
|
+
};
|
|
79
86
|
exports.__private = { memberPath, isCreate, needsFilter };
|
|
80
87
|
exports.releaseStyles = {
|
|
81
88
|
meta: {
|
|
@@ -101,6 +108,7 @@ exports.releaseStyles = {
|
|
|
101
108
|
styleType: 'A released style is a class name.',
|
|
102
109
|
folded: 'This only named a style key, which the export has resolved.',
|
|
103
110
|
read: 'Read this style by the name the export gave it.',
|
|
111
|
+
falsy: 'className takes a string or undefined, so a condition that can be false reads as undefined.',
|
|
104
112
|
functionStyle: 'Use the CSS Module class and pass function arguments as custom properties.',
|
|
105
113
|
unsupportedFunctionStyle: 'This function style call cannot be converted without changing its behavior.',
|
|
106
114
|
},
|
|
@@ -923,6 +931,18 @@ exports.releaseStyles = {
|
|
|
923
931
|
const text = expression ? resolveText(expression) : undefined;
|
|
924
932
|
if (!complete && expression && text === undefined)
|
|
925
933
|
return;
|
|
934
|
+
if (!carried &&
|
|
935
|
+
expression &&
|
|
936
|
+
text !== undefined &&
|
|
937
|
+
mayBeFalsy(expression)) {
|
|
938
|
+
context.report({
|
|
939
|
+
node: expression,
|
|
940
|
+
messageId: 'falsy',
|
|
941
|
+
fix: (fixer) => fixer.replaceText(expression, `(${text}) || undefined`),
|
|
942
|
+
});
|
|
943
|
+
takeProp();
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
926
946
|
const foldsKey = expression?.type === 'MemberExpression' &&
|
|
927
947
|
expression.computed &&
|
|
928
948
|
expression.property.type === 'Identifier' &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/codemod",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20.0.0",
|
|
4
4
|
"description": "Codemods for Plumeria: migrate a CSS Modules codebase in, export it back out, and rename the styling prop",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"get-tsconfig": "^4.14.2",
|
|
38
38
|
"postcss": "8.5.26",
|
|
39
39
|
"postcss-selector-parser": "^7.1.1",
|
|
40
|
-
"zss-engine": "
|
|
40
|
+
"zss-engine": "3.0.1"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public",
|