@plumeria/codemod 18.2.22 → 18.2.23

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.
@@ -150,6 +150,26 @@ exports.adoptStyles = {
150
150
  : node?.type === 'MemberExpression'
151
151
  ? node
152
152
  : undefined;
153
+ const unguarded = (node) => {
154
+ if (node?.type !== 'ConditionalExpression')
155
+ return node;
156
+ const { test, consequent, alternate } = node;
157
+ if (test.type !== 'BinaryExpression' ||
158
+ test.operator !== '===' ||
159
+ test.left.type !== 'UnaryExpression' ||
160
+ test.left.operator !== 'typeof' ||
161
+ test.right.type !== 'Literal' ||
162
+ test.right.value !== 'number' ||
163
+ consequent.type !== 'TemplateLiteral' ||
164
+ consequent.expressions.length !== 1 ||
165
+ consequent.quasis.at(-1)?.value.raw !== 'px')
166
+ return node;
167
+ const written = context.sourceCode.getText(alternate);
168
+ return context.sourceCode.getText(test.left.argument) === written &&
169
+ context.sourceCode.getText(consequent.expressions[0]) === written
170
+ ? alternate
171
+ : node;
172
+ };
153
173
  const insideUse = (node) => {
154
174
  let current = node;
155
175
  while (current.parent &&
@@ -359,7 +379,7 @@ exports.adoptStyles = {
359
379
  for (const variable of variables)
360
380
  consumed.add(named.get(variable));
361
381
  return `${binding.local}.${key}(${variables
362
- .map((variable) => context.sourceCode.getText(named.get(variable).value))
382
+ .map((variable) => context.sourceCode.getText(unguarded(named.get(variable).value)))
363
383
  .join(', ')})`;
364
384
  };
365
385
  const expression = node.value.expression;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/codemod",
3
- "version": "18.2.22",
3
+ "version": "18.2.23",
4
4
  "description": "Codemods for migrating Plumeria APIs",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",