@workday/canvas-kit-codemod 14.1.6 → 14.1.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"migrateTypeTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateTypeTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAC,MAAM,aAAa,CAAC;AASpE,QAAA,MAAM,SAAS,EAAE,SA2OhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"migrateTypeTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateTypeTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAC,MAAM,aAAa,CAAC;AASpE,QAAA,MAAM,SAAS,EAAE,SA6OhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -92,7 +92,7 @@ const transform = (file, api) => {
92
92
  return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]);
93
93
  }
94
94
  }
95
- return nodePath;
95
+ return nodePath.value;
96
96
  });
97
97
  root
98
98
  .find(j.MemberExpression, (value) => {
@@ -138,12 +138,14 @@ const transform = (file, api) => {
138
138
  const { values } = mapping.type.keys.levels;
139
139
  const levels = values[innerKey];
140
140
  const lowestKey = lowestPropertyValue;
141
- const tokens = levels[lowestKey];
142
- const props = Object.entries(tokens).map(([key, value]) => {
143
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
144
- return j.property('init', j.identifier(key), j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]));
145
- });
146
- return j.objectExpression(props);
141
+ const tokens = levels === null || levels === void 0 ? void 0 : levels[lowestKey];
142
+ if (tokens) {
143
+ const props = Object.entries(tokens).map(([key, value]) => {
144
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
145
+ return j.property('init', j.identifier(key), j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]));
146
+ });
147
+ return j.objectExpression(props);
148
+ }
147
149
  }
148
150
  }
149
151
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kCAAkC,gBAClC,GAAG,YACJ,GAAG;;wBAEQ,OAAO,eACf,MAAM,EAAE,KACpB,GA2PF,CAAC"}
1
+ {"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kCAAkC,gBAClC,GAAG,YACJ,GAAG;;wBAEQ,OAAO,eACf,MAAM,EAAE,KACpB,GA2UF,CAAC"}
@@ -1,4 +1,4 @@
1
- import { mapping, systemColors } from '../mapping';
1
+ import { mapping, paletteNames, systemColors } from '../mapping';
2
2
  import { addMissingImports } from './addMissingImports';
3
3
  import { varToMemberExpression } from './varToMemberExpression';
4
4
  export const transformObjectPropertyRecursively = ({ j, root }, property, importDeclaration, isCanvasKitStyling, tokenTypes) => {
@@ -62,6 +62,27 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
62
62
  const transformedQuasis = templateLiteral.quasis.map((quasi) => quasi);
63
63
  const transformedExpressions = templateLiteral.expressions.map((expr) => {
64
64
  var _a;
65
+ if (expr.type === 'CallExpression') {
66
+ expr.arguments = expr.arguments.map((arg) => {
67
+ var _a;
68
+ if (arg.type === 'MemberExpression' &&
69
+ arg.object.type === 'Identifier' &&
70
+ arg.object.name === 'colors' &&
71
+ arg.property.type === 'Identifier') {
72
+ const keyName = property.key.type === 'Identifier' ? property.key.name : null;
73
+ const tokens = keyName
74
+ ? (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === keyName))) === null || _a === void 0 ? void 0 : _a[1]
75
+ : {};
76
+ const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[arg.property.name];
77
+ if (colorToken) {
78
+ return isCanvasKitStyling
79
+ ? varToMemberExpression(j, colorToken)
80
+ : j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]);
81
+ }
82
+ }
83
+ return arg;
84
+ });
85
+ }
65
86
  if (expr.type === 'MemberExpression' &&
66
87
  expr.object.type === 'Identifier' &&
67
88
  expr.property.type === 'Identifier') {
@@ -74,9 +95,13 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
74
95
  : null;
75
96
  const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[expr.property.name];
76
97
  if (colorToken) {
77
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
98
+ if (!isCanvasKitStyling) {
99
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
100
+ }
78
101
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
79
- return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]);
102
+ return isCanvasKitStyling
103
+ ? varToMemberExpression(j, colorToken)
104
+ : j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]);
80
105
  }
81
106
  }
82
107
  // Handle space and borderRadius tokens
@@ -88,10 +113,14 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
88
113
  if ((map === null || map === void 0 ? void 0 : map.type) === 'system' && map.keys) {
89
114
  const newValue = map.keys[propertyName];
90
115
  if (newValue) {
91
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
116
+ if (!isCanvasKitStyling) {
117
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
118
+ }
92
119
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
93
120
  const tokenPath = j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(newValue));
94
- return j.callExpression(j.identifier('cssVar'), [tokenPath]);
121
+ return isCanvasKitStyling
122
+ ? tokenPath
123
+ : j.callExpression(j.identifier('cssVar'), [tokenPath]);
95
124
  }
96
125
  }
97
126
  }
@@ -120,18 +149,46 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
120
149
  const consequentColorToken = consequentTokens === null || consequentTokens === void 0 ? void 0 : consequentTokens[consequent.property.name];
121
150
  const alternateColorToken = alternateTokens === null || alternateTokens === void 0 ? void 0 : alternateTokens[alternate.property.name];
122
151
  if (consequentColorToken && alternateColorToken) {
123
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
152
+ if (!isCanvasKitStyling) {
153
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
154
+ }
124
155
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
125
- return createObjectProperty(property.key, j.conditionalExpression(test, j.callExpression(j.identifier('cssVar'), [
126
- varToMemberExpression(j, consequentColorToken),
127
- ]), j.callExpression(j.identifier('cssVar'), [
128
- varToMemberExpression(j, alternateColorToken),
129
- ])));
156
+ return createObjectProperty(property.key, j.conditionalExpression(test, isCanvasKitStyling
157
+ ? varToMemberExpression(j, consequentColorToken)
158
+ : j.callExpression(j.identifier('cssVar'), [
159
+ varToMemberExpression(j, consequentColorToken),
160
+ ]), isCanvasKitStyling
161
+ ? varToMemberExpression(j, alternateColorToken)
162
+ : j.callExpression(j.identifier('cssVar'), [
163
+ varToMemberExpression(j, alternateColorToken),
164
+ ])));
130
165
  }
131
166
  }
132
167
  }
133
168
  if (property.type === 'ObjectProperty' && property.value.type === 'ObjectExpression') {
134
169
  return createObjectProperty(property.key, j.objectExpression(property.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling, tokenTypes))));
135
170
  }
171
+ if (property.type === 'ObjectProperty' &&
172
+ property.key.type === 'Identifier' &&
173
+ property.value.type === 'MemberExpression' &&
174
+ property.value.object.type === 'Identifier' &&
175
+ property.value.property.type === 'Identifier') {
176
+ const importedTokenName = importDeclaration[property.value.object.name];
177
+ // Handle colors tokens
178
+ if (importedTokenName === 'colors' && (!tokenTypes || tokenTypes.includes('colors'))) {
179
+ const { property: value } = property.value;
180
+ if (paletteNames.some(name => value.name.includes(name))) {
181
+ if (!isCanvasKitStyling) {
182
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
183
+ }
184
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
185
+ return createObjectProperty(property.key, isCanvasKitStyling
186
+ ? j.memberExpression(j.identifier('base'), j.identifier(value.name))
187
+ : j.callExpression(j.identifier('cssVar'), [
188
+ j.memberExpression(j.identifier('base'), j.identifier(value.name)),
189
+ ]));
190
+ }
191
+ }
192
+ }
136
193
  return property;
137
194
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@workday/canvas-kit-codemod",
3
3
  "author": "Workday, Inc. (https://www.workday.com)",
4
4
  "license": "Apache-2.0",
5
- "version": "14.1.6",
5
+ "version": "14.1.7",
6
6
  "description": "A collection of codemods for use on Workday Canvas Kit packages.",
7
7
  "main": "dist/es6/index.js",
8
8
  "sideEffects": false,
@@ -46,5 +46,5 @@
46
46
  "resolutions": {
47
47
  "recast": "0.20.4"
48
48
  },
49
- "gitHead": "74a7a93b6735770faecf184e4d74a4d0b1f04d86"
49
+ "gitHead": "3808e546938e4ee8ad73e75484bc49eeef7da755"
50
50
  }