@workday/canvas-kit-codemod 14.1.5 → 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.
Files changed (28) hide show
  1. package/dist/es6/v13.2/mapping/index.d.ts +59 -1
  2. package/dist/es6/v13.2/mapping/index.d.ts.map +1 -1
  3. package/dist/es6/v13.2/mapping/index.js +88 -1
  4. package/dist/es6/v13.2/migrateColorTokens.d.ts.map +1 -1
  5. package/dist/es6/v13.2/migrateColorTokens.js +64 -13
  6. package/dist/es6/v13.2/migrateDepthTokens.d.ts.map +1 -1
  7. package/dist/es6/v13.2/migrateDepthTokens.js +21 -9
  8. package/dist/es6/v13.2/migrateOtherTokens.d.ts.map +1 -1
  9. package/dist/es6/v13.2/migrateOtherTokens.js +37 -67
  10. package/dist/es6/v13.2/migrateTypeTokens.d.ts.map +1 -1
  11. package/dist/es6/v13.2/migrateTypeTokens.js +43 -19
  12. package/dist/es6/v13.2/utils/filterOutImports.d.ts +6 -1
  13. package/dist/es6/v13.2/utils/filterOutImports.d.ts.map +1 -1
  14. package/dist/es6/v13.2/utils/filterOutImports.js +22 -4
  15. package/dist/es6/v13.2/utils/getImports.d.ts +3 -0
  16. package/dist/es6/v13.2/utils/getImports.d.ts.map +1 -0
  17. package/dist/es6/v13.2/utils/getImports.js +12 -0
  18. package/dist/es6/v13.2/utils/index.d.ts +1 -0
  19. package/dist/es6/v13.2/utils/index.d.ts.map +1 -1
  20. package/dist/es6/v13.2/utils/index.js +1 -0
  21. package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.d.ts +1 -1
  22. package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.d.ts.map +1 -1
  23. package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.js +151 -33
  24. package/dist/es6/v13.2/utils/varToMemberExpression.d.ts.map +1 -1
  25. package/dist/es6/v13.2/utils/varToMemberExpression.js +1 -1
  26. package/dist/es6/v14-tokens/migrateColorTokens.d.ts.map +1 -1
  27. package/dist/es6/v14-tokens/migrateColorTokens.js +9 -2
  28. package/package.json +2 -2
@@ -1,8 +1,66 @@
1
+ export declare const paletteNames: string[];
1
2
  export declare const mapping: {
2
3
  readonly colors: {
3
4
  readonly type: "base";
4
5
  readonly name: "colors";
5
6
  };
7
+ readonly commonColors: {
8
+ readonly type: "system";
9
+ readonly name: "commonColors";
10
+ readonly keys: {
11
+ readonly background: "system.color.bg.default";
12
+ readonly backgroundAlt: "system.color.bg.alt.default";
13
+ readonly focusOutline: "system.color.border.primary.default";
14
+ readonly focusBackground: "system.color.bg.primary.default";
15
+ readonly hoverBackground: "system.color.bg.alt.strong";
16
+ readonly divider: "system.color.border.divider";
17
+ };
18
+ };
19
+ readonly inputColors: {
20
+ readonly type: "system";
21
+ readonly name: "inputColors";
22
+ readonly keys: {
23
+ readonly background: "system.color.bg.default";
24
+ readonly border: "system.color.border.input.default";
25
+ readonly placeholder: "system.color.fg.muted.default";
26
+ readonly text: "system.color.fg.default";
27
+ readonly icon: "system.color.fg.muted.soft";
28
+ readonly iconHover: "system.color.fg.muted.stronger";
29
+ readonly selectionControlFill: "system.color.bg.primary.default";
30
+ readonly hoverBorder: "system.color.border.input.strong";
31
+ readonly focusBorder: "system.color.border.primary.default";
32
+ readonly disabled: {
33
+ readonly background: "system.color.bg.alt.softer";
34
+ readonly border: "system.color.border.input.strong";
35
+ readonly text: "system.color.fg.disabled";
36
+ readonly icon: "system.color.fg.disabled";
37
+ };
38
+ readonly error: {
39
+ readonly border: "system.color.border.critical.default";
40
+ readonly message: "system.color.fg.critical.default";
41
+ readonly icon: "system.color.fg.critical.default";
42
+ };
43
+ readonly alert: {
44
+ readonly border: "system.color.border.caution.default";
45
+ readonly message: "system.color.fg.caution.default";
46
+ readonly icon: "system.color.fg.caution.default";
47
+ };
48
+ };
49
+ };
50
+ readonly typeColors: {
51
+ readonly type: "system";
52
+ readonly name: "typeColors";
53
+ readonly keys: {
54
+ readonly body: "system.color.fg.default";
55
+ readonly heading: "system.color.fg.strong";
56
+ readonly hint: "system.color.fg.muted.soft";
57
+ readonly inverse: "system.color.fg.inverse";
58
+ readonly label: "system.color.fg.default";
59
+ readonly link: "system.color.fg.primary.default";
60
+ readonly selectHighlight: "system.color.fg.primary.default";
61
+ readonly selectHighlightInverse: "system.color.fg.inverse";
62
+ };
63
+ };
6
64
  readonly borderRadius: {
7
65
  readonly name: "shape";
8
66
  readonly type: "system";
@@ -215,7 +273,7 @@ export declare const systemColors: {
215
273
  licorice400: string;
216
274
  licorice500: string;
217
275
  };
218
- 'border,borderColor,borderTopColor,borderRightColor,borderBottomColor,borderLeftColor,borderInline,borderInlineStart,borderInlineEnd,borderBlock,borderBlockStart,borderBlockEnd,borderInlineColor,borderBlockColor,borderInlineStartColor,borderInlineEndColor,borderBlockStartColor,borderBlockEndColor,borderColorFocus,borderColorHover,borderColorActive': {
276
+ 'border,borderColor,borderTop,borderTopColor,borderRight,borderRightColor,borderBottom,borderBottomColor,borderLeft,borderLeftColor,borderInlineColor,borderBlockColor,borderInline,borderInlineStart,borderInlineStartColor,borderInlineEnd,borderInlineEndColor,borderBlockStart,borderBlockStartColor,borderBlockEnd,borderBlockEndColor,borderColorFocus,borderColorHover,borderColorActive': {
219
277
  blackPepper400: string;
220
278
  blackPepper500: string;
221
279
  blueberry400: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/mapping/index.ts"],"names":[],"mappings":"AAqFA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBV,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4DxB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/mapping/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,UA6BxB,CAAC;AAqFF,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkFV,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4DxB,CAAC"}
@@ -1,4 +1,34 @@
1
1
  import { generateLevelTokens } from '../utils/generateLevelTokens';
2
+ export const paletteNames = [
3
+ 'cinnamon',
4
+ 'peach',
5
+ 'chiliMango',
6
+ 'cantaloupe',
7
+ 'sourLemon',
8
+ 'juicyPear',
9
+ 'kiwi',
10
+ 'greenApple',
11
+ 'watermelon',
12
+ 'jewel',
13
+ 'toothpaste',
14
+ 'blueberry',
15
+ 'plum',
16
+ 'berrySmoothie',
17
+ 'blackberry',
18
+ 'islandPunch',
19
+ 'grapeSoda',
20
+ 'pomegranate',
21
+ 'fruitPunch',
22
+ 'rootBeer',
23
+ 'toastedMarshmallow',
24
+ 'licorice',
25
+ 'soap',
26
+ 'frenchVanilla',
27
+ 'blackPepper',
28
+ 'coconut',
29
+ 'cappuccino',
30
+ 'dragonFruit',
31
+ ];
2
32
  const typeLevelsMap = {
3
33
  subtext: {
4
34
  small: generateLevelTokens(['subtext', 'small']),
@@ -83,6 +113,63 @@ export const mapping = {
83
113
  type: 'base',
84
114
  name: 'colors',
85
115
  },
116
+ commonColors: {
117
+ type: 'system',
118
+ name: 'commonColors',
119
+ keys: {
120
+ background: 'system.color.bg.default',
121
+ backgroundAlt: 'system.color.bg.alt.default',
122
+ focusOutline: 'system.color.border.primary.default',
123
+ focusBackground: 'system.color.bg.primary.default',
124
+ hoverBackground: 'system.color.bg.alt.strong',
125
+ divider: 'system.color.border.divider',
126
+ },
127
+ },
128
+ inputColors: {
129
+ type: 'system',
130
+ name: 'inputColors',
131
+ keys: {
132
+ background: 'system.color.bg.default',
133
+ border: 'system.color.border.input.default',
134
+ placeholder: 'system.color.fg.muted.default',
135
+ text: 'system.color.fg.default',
136
+ icon: 'system.color.fg.muted.soft',
137
+ iconHover: 'system.color.fg.muted.stronger',
138
+ selectionControlFill: 'system.color.bg.primary.default',
139
+ hoverBorder: 'system.color.border.input.strong',
140
+ focusBorder: 'system.color.border.primary.default',
141
+ disabled: {
142
+ background: 'system.color.bg.alt.softer',
143
+ border: 'system.color.border.input.strong',
144
+ text: 'system.color.fg.disabled',
145
+ icon: 'system.color.fg.disabled',
146
+ },
147
+ error: {
148
+ border: 'system.color.border.critical.default',
149
+ message: 'system.color.fg.critical.default',
150
+ icon: 'system.color.fg.critical.default',
151
+ },
152
+ alert: {
153
+ border: 'system.color.border.caution.default',
154
+ message: 'system.color.fg.caution.default',
155
+ icon: 'system.color.fg.caution.default',
156
+ },
157
+ },
158
+ },
159
+ typeColors: {
160
+ type: 'system',
161
+ name: 'typeColors',
162
+ keys: {
163
+ body: 'system.color.fg.default',
164
+ heading: 'system.color.fg.strong',
165
+ hint: 'system.color.fg.muted.soft',
166
+ inverse: 'system.color.fg.inverse',
167
+ label: 'system.color.fg.default',
168
+ link: 'system.color.fg.primary.default',
169
+ selectHighlight: 'system.color.fg.primary.default',
170
+ selectHighlightInverse: 'system.color.fg.inverse',
171
+ },
172
+ },
86
173
  borderRadius: {
87
174
  name: 'shape',
88
175
  type: 'system',
@@ -148,7 +235,7 @@ export const systemColors = {
148
235
  licorice400: 'system.color.fg.muted.strong',
149
236
  licorice500: 'system.color.fg.muted.stronger',
150
237
  },
151
- 'border,borderColor,borderTopColor,borderRightColor,borderBottomColor,borderLeftColor,borderInline,borderInlineStart,borderInlineEnd,borderBlock,borderBlockStart,borderBlockEnd,borderInlineColor,borderBlockColor,borderInlineStartColor,borderInlineEndColor,borderBlockStartColor,borderBlockEndColor,borderColorFocus,borderColorHover,borderColorActive': {
238
+ 'border,borderColor,borderTop,borderTopColor,borderRight,borderRightColor,borderBottom,borderBottomColor,borderLeft,borderLeftColor,borderInlineColor,borderBlockColor,borderInline,borderInlineStart,borderInlineStartColor,borderInlineEnd,borderInlineEndColor,borderBlockStart,borderBlockStartColor,borderBlockEnd,borderBlockEndColor,borderColorFocus,borderColorHover,borderColorActive': {
152
239
  blackPepper400: 'system.color.border.contrast.default',
153
240
  blackPepper500: 'system.color.border.contrast.strong',
154
241
  blueberry400: 'system.color.border.primary.default',
@@ -1 +1 @@
1
- {"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AAQlD,QAAA,MAAM,SAAS,EAAE,SAuFhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AAkBlD,QAAA,MAAM,SAAS,EAAE,SAsKhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,6 +1,10 @@
1
- import { addMissingImports, filterOutImports, transformObjectPropertyRecursively } from './utils';
2
- import { mapping } from './mapping';
3
- const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
1
+ import { addMissingImports, filterOutImports, getImports, transformObjectPropertyRecursively, varToMemberExpression, } from './utils';
2
+ import { mapping, paletteNames } from './mapping';
3
+ const canvasImportSources = [
4
+ '@workday/canvas-kit-styling',
5
+ '@workday/canvas-kit-react/tokens',
6
+ '@workday/canvas-colors-web',
7
+ ];
4
8
  const transform = (file, api) => {
5
9
  const j = api.jscodeshift;
6
10
  const root = j(file.source);
@@ -11,7 +15,7 @@ const transform = (file, api) => {
11
15
  source: { value: (value) => canvasImportSources.includes(value) },
12
16
  })
13
17
  .forEach(nodePath => {
14
- importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
18
+ importDeclaration = { ...importDeclaration, ...getImports(nodePath) };
15
19
  });
16
20
  if (!Object.values(importDeclaration).includes('colors')) {
17
21
  return root.toSource();
@@ -26,7 +30,7 @@ const transform = (file, api) => {
26
30
  const name = nodePath.value.callee.name;
27
31
  const stylesDeclaration = nodePath.value.arguments[0];
28
32
  const isCanvasKitStyling = importDeclaration[name] === 'createStyles' || importDeclaration[name] === 'createStencil';
29
- if (stylesDeclaration.type === 'ObjectExpression') {
33
+ if ((stylesDeclaration === null || stylesDeclaration === void 0 ? void 0 : stylesDeclaration.type) === 'ObjectExpression') {
30
34
  stylesDeclaration.properties = stylesDeclaration.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling));
31
35
  }
32
36
  });
@@ -35,21 +39,61 @@ const transform = (file, api) => {
35
39
  });
36
40
  root
37
41
  .find(j.MemberExpression, (value) => {
38
- return (value.type === 'MemberExpression' &&
39
- ((value.object.type === 'MemberExpression' &&
40
- value.object.object.type === 'MemberExpression' &&
41
- checkImport(value.object.object.object.name)) ||
42
- checkImport(value.object.name)));
42
+ // Matches: commonColors.background
43
+ const isTwoParts = value.type === 'MemberExpression' &&
44
+ value.object.type === 'Identifier' &&
45
+ checkImport(value.object.name);
46
+ // Matches: inputColors.disabled.border
47
+ const isThreeParts = value.type === 'MemberExpression' &&
48
+ value.object.type === 'MemberExpression' &&
49
+ value.object.object.type === 'Identifier' &&
50
+ checkImport(value.object.object.name);
51
+ return isTwoParts || isThreeParts;
43
52
  })
44
53
  .replaceWith(nodePath => {
54
+ var _a;
45
55
  const mainWrapper = nodePath.value.object;
46
- if (mainWrapper.type === 'Identifier' && importDeclaration[mainWrapper.name] !== 'type') {
56
+ if (mainWrapper.type === 'MemberExpression') {
57
+ const mainObject = mainWrapper.object;
58
+ const mainName = mainObject.type === 'Identifier' ? mainObject.name : '';
59
+ const mainProperty = mainWrapper.property;
60
+ const lowestProperty = nodePath.value.property;
61
+ const importedName = importDeclaration[mainName];
62
+ const map = mapping[importedName];
63
+ if ((map === null || map === void 0 ? void 0 : map.type) === 'system' &&
64
+ importedName &&
65
+ importedName.toLowerCase().includes('colors') &&
66
+ mainProperty.type === 'Identifier' &&
67
+ lowestProperty.type === 'Identifier') {
68
+ const innerGroup = map.keys[mainProperty.name] || {};
69
+ const token = innerGroup[lowestProperty.name];
70
+ if (token) {
71
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
72
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
73
+ return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, token)]);
74
+ }
75
+ }
76
+ }
77
+ if (mainWrapper.type === 'Identifier' &&
78
+ ((_a = importDeclaration[mainWrapper.name]) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('colors'))) {
47
79
  const mainObject = mainWrapper;
48
80
  const mainName = mainObject.name;
49
81
  const lowestProperty = nodePath.value.property;
50
82
  const importedName = importDeclaration[mainName];
51
83
  const map = mapping[importedName];
52
- if (map.type === 'base' && lowestProperty.type === 'Identifier') {
84
+ if ((map === null || map === void 0 ? void 0 : map.type) === 'system' &&
85
+ lowestProperty.type === 'Identifier' &&
86
+ importedName !== 'inputColors') {
87
+ const token = map.keys[lowestProperty.name];
88
+ if (token && typeof token === 'string') {
89
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
90
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
91
+ return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, token)]);
92
+ }
93
+ }
94
+ if ((map === null || map === void 0 ? void 0 : map.type) === 'base' &&
95
+ lowestProperty.type === 'Identifier' &&
96
+ paletteNames.some(name => lowestProperty.name.includes(name))) {
53
97
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
54
98
  addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
55
99
  return j.callExpression(j.identifier('cssVar'), [
@@ -57,7 +101,14 @@ const transform = (file, api) => {
57
101
  ]);
58
102
  }
59
103
  }
60
- return nodePath;
104
+ return nodePath.value;
105
+ });
106
+ root
107
+ .find(j.ImportDeclaration, {
108
+ source: { value: (value) => canvasImportSources.includes(value) },
109
+ })
110
+ .forEach(nodePath => {
111
+ filterOutImports({ root, j }, nodePath, 'colors');
61
112
  });
62
113
  return root.toSource();
63
114
  };
@@ -1 +1 @@
1
- {"version":3,"file":"migrateDepthTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateDepthTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAOtC,QAAA,MAAM,SAAS,EAAE,SAoKhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"migrateDepthTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateDepthTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAWtC,QAAA,MAAM,SAAS,EAAE,SA6KhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,5 +1,9 @@
1
- import { addMissingImports, filterOutImports } from './utils';
2
- const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
1
+ import { addMissingImports, filterOutImports, getImports } from './utils';
2
+ const canvasImportSources = [
3
+ '@workday/canvas-kit-styling',
4
+ '@workday/canvas-kit-react/tokens',
5
+ '@workday/canvas-depth-web',
6
+ ];
3
7
  const transform = (file, api) => {
4
8
  const j = api.jscodeshift;
5
9
  const root = j(file.source);
@@ -10,7 +14,7 @@ const transform = (file, api) => {
10
14
  source: { value: (value) => canvasImportSources.includes(value) },
11
15
  })
12
16
  .forEach(nodePath => {
13
- importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
17
+ importDeclaration = { ...importDeclaration, ...getImports(nodePath) };
14
18
  });
15
19
  if (!Object.values(importDeclaration).includes('depth')) {
16
20
  return root.toSource();
@@ -21,7 +25,7 @@ const transform = (file, api) => {
21
25
  type: 'MemberExpression',
22
26
  object: {
23
27
  type: 'Identifier',
24
- name: 'depth',
28
+ name: (name) => importDeclaration[name] === 'depth',
25
29
  },
26
30
  property: {
27
31
  type: 'NumericLiteral',
@@ -32,17 +36,18 @@ const transform = (file, api) => {
32
36
  const argument = nodePath.value.argument;
33
37
  if (argument.type === 'MemberExpression' && argument.property.type === 'NumericLiteral') {
34
38
  const depthValue = argument.property.value;
39
+ const isDepthNotZero = depthValue > 0;
35
40
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
36
- if (depthValue > 0) {
41
+ if (isDepthNotZero) {
37
42
  addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
38
43
  }
39
- return depthValue > 0
44
+ return isDepthNotZero
40
45
  ? j.objectProperty(j.identifier('boxShadow'), j.callExpression(j.identifier('cssVar'), [
41
46
  j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(depthValue), true),
42
47
  ]))
43
48
  : j.objectProperty(j.identifier('boxShadow'), j.literal('none'));
44
49
  }
45
- return nodePath;
50
+ return nodePath.value;
46
51
  });
47
52
  root
48
53
  .find(j.MemberExpression, (value) => {
@@ -65,7 +70,7 @@ const transform = (file, api) => {
65
70
  j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(value), true),
66
71
  ]);
67
72
  }
68
- return nodePath;
73
+ return nodePath.value;
69
74
  });
70
75
  root
71
76
  .find(j.MemberExpression, (value) => {
@@ -97,7 +102,14 @@ const transform = (file, api) => {
97
102
  ]);
98
103
  }
99
104
  }
100
- return nodePath;
105
+ return nodePath.value;
106
+ });
107
+ root
108
+ .find(j.ImportDeclaration, {
109
+ source: { value: (value) => canvasImportSources.includes(value) },
110
+ })
111
+ .forEach(nodePath => {
112
+ filterOutImports({ root, j }, nodePath, 'depth');
101
113
  });
102
114
  return root.toSource();
103
115
  };
@@ -1 +1 @@
1
- {"version":3,"file":"migrateOtherTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateOtherTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAC,MAAM,aAAa,CAAC;AAQpE,QAAA,MAAM,SAAS,EAAE,SA4KhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"migrateOtherTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateOtherTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AAmBlD,QAAA,MAAM,SAAS,EAAE,SAgHhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,6 +1,11 @@
1
- import { addMissingImports, filterOutImports, varToMemberExpression } from './utils';
2
- import { mapping, systemColors } from './mapping';
3
- const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
1
+ import { addMissingImports, filterOutImports, getImports, transformObjectPropertyRecursively, } from './utils';
2
+ import { mapping } from './mapping';
3
+ const canvasImportSources = [
4
+ '@workday/canvas-kit-styling',
5
+ '@workday/canvas-kit-react/tokens',
6
+ '@workday/canvas-space-web',
7
+ ];
8
+ const tokens = ['space', 'borderRadius'];
4
9
  const transform = (file, api) => {
5
10
  const j = api.jscodeshift;
6
11
  const root = j(file.source);
@@ -11,9 +16,12 @@ const transform = (file, api) => {
11
16
  source: { value: (value) => canvasImportSources.includes(value) },
12
17
  })
13
18
  .forEach(nodePath => {
14
- importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
19
+ importDeclaration = {
20
+ ...importDeclaration,
21
+ ...getImports(nodePath),
22
+ };
15
23
  });
16
- if (!Object.values(importDeclaration).some(value => value === 'space' || value === 'borderRadius')) {
24
+ if (!Object.values(importDeclaration).some(value => tokens.includes(value))) {
17
25
  return root.toSource();
18
26
  }
19
27
  root
@@ -23,60 +31,11 @@ const transform = (file, api) => {
23
31
  },
24
32
  })
25
33
  .forEach(nodePath => {
26
- addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
27
34
  const name = nodePath.value.callee.name;
28
35
  const stylesDeclaration = nodePath.value.arguments[0];
29
36
  const isCanvasKitStyling = importDeclaration[name] === 'createStyles' || importDeclaration[name] === 'createStencil';
30
- if (stylesDeclaration.type === 'ObjectExpression') {
31
- const transformProperty = (property) => {
32
- var _a;
33
- if (property.type === 'ObjectProperty' &&
34
- property.key.type === 'Identifier' &&
35
- property.value.type === 'MemberExpression' &&
36
- property.value.object.type === 'Identifier' &&
37
- property.value.property.type === 'Identifier' &&
38
- importDeclaration[property.value.object.name] === 'colors') {
39
- const key = property.key.name;
40
- const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === key))) === null || _a === void 0 ? void 0 : _a[1];
41
- const { property: value } = property.value;
42
- const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[value.name];
43
- if (colorToken) {
44
- if (!isCanvasKitStyling) {
45
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
46
- }
47
- return j.objectProperty(j.identifier(key), isCanvasKitStyling
48
- ? varToMemberExpression(j, colorToken)
49
- : j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]));
50
- }
51
- }
52
- if (property.type === 'ObjectProperty' && property.value.type === 'TemplateLiteral') {
53
- const templateLiteral = property.value;
54
- const transformedQuasis = templateLiteral.quasis.map((quasi) => quasi);
55
- const transformedExpressions = templateLiteral.expressions.map((expr) => {
56
- var _a;
57
- if (expr.type === 'MemberExpression' &&
58
- expr.object.type === 'Identifier' &&
59
- expr.property.type === 'Identifier' &&
60
- importDeclaration[expr.object.name] === 'colors') {
61
- const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === property.key.name))) === null || _a === void 0 ? void 0 : _a[1];
62
- const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[expr.property.name];
63
- if (colorToken) {
64
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
65
- return j.callExpression(j.identifier('cssVar'), [
66
- varToMemberExpression(j, colorToken),
67
- ]);
68
- }
69
- }
70
- return expr;
71
- });
72
- return j.objectProperty(property.key, j.templateLiteral(transformedQuasis, transformedExpressions));
73
- }
74
- if (property.type === 'ObjectProperty' && property.value.type === 'ObjectExpression') {
75
- return j.objectProperty(property.key, j.objectExpression(property.value.properties.map(transformProperty)));
76
- }
77
- return property;
78
- };
79
- stylesDeclaration.properties = stylesDeclaration.properties.map(transformProperty);
37
+ if ((stylesDeclaration === null || stylesDeclaration === void 0 ? void 0 : stylesDeclaration.type) === 'ObjectExpression') {
38
+ stylesDeclaration.properties = stylesDeclaration.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling, [...tokens]));
80
39
  }
81
40
  });
82
41
  root
@@ -89,23 +48,34 @@ const transform = (file, api) => {
89
48
  })
90
49
  .replaceWith(nodePath => {
91
50
  const mainWrapper = nodePath.value.object;
92
- if (mainWrapper.type === 'Identifier' && importDeclaration[mainWrapper.name] !== 'type') {
93
- const mainObject = mainWrapper;
94
- const mainName = mainObject.name;
51
+ if (mainWrapper.type === 'Identifier' &&
52
+ tokens.includes(importDeclaration[mainWrapper.name])) {
53
+ const mainName = mainWrapper.name;
95
54
  const lowestProperty = nodePath.value.property;
96
55
  const importedName = importDeclaration[mainName];
97
56
  const map = mapping[importedName];
98
- if (importedName !== 'depth') {
99
- if (map.type === 'system' && lowestProperty.type === 'Identifier') {
100
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
101
- addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
102
- return j.callExpression(j.identifier('cssVar'), [
103
- j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(map.keys[lowestProperty.name])),
104
- ]);
57
+ if (['space', 'borderRadius'].includes(importedName) &&
58
+ (map === null || map === void 0 ? void 0 : map.type) === 'system' &&
59
+ lowestProperty.type === 'Identifier') {
60
+ const newValue = map.keys[lowestProperty.name];
61
+ if (!newValue) {
62
+ return nodePath.value;
105
63
  }
64
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
65
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
66
+ return j.callExpression(j.identifier('cssVar'), [
67
+ j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(map.keys[lowestProperty.name])),
68
+ ]);
106
69
  }
107
70
  }
108
- return nodePath;
71
+ return nodePath.value;
72
+ });
73
+ root
74
+ .find(j.ImportDeclaration, {
75
+ source: { value: (value) => canvasImportSources.includes(value) },
76
+ })
77
+ .forEach(nodePath => {
78
+ filterOutImports({ root, j }, nodePath, tokens);
109
79
  });
110
80
  return root.toSource();
111
81
  };
@@ -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,SAiOhB,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"}
@@ -1,4 +1,4 @@
1
- import { addMissingImports, filterOutImports, varToMemberExpression } from './utils';
1
+ import { addMissingImports, filterOutImports, getImports, varToMemberExpression } from './utils';
2
2
  import { typeProps } from './mapping/typeProps';
3
3
  import { mapping } from './mapping';
4
4
  const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
@@ -12,7 +12,7 @@ const transform = (file, api) => {
12
12
  source: { value: (value) => canvasImportSources.includes(value) },
13
13
  })
14
14
  .forEach(nodePath => {
15
- importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
15
+ importDeclaration = { ...importDeclaration, ...getImports(nodePath) };
16
16
  });
17
17
  if (!Object.values(importDeclaration).includes('type')) {
18
18
  return root.toSource();
@@ -40,14 +40,26 @@ const transform = (file, api) => {
40
40
  const object = argument.object;
41
41
  const level = object.property.name;
42
42
  const size = argument.property.name;
43
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
44
- addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
45
- nodePath.insertAfter(j.objectProperty(j.identifier('color'), j.callExpression(j.identifier('cssVar'), [
46
- j.memberExpression(j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('color')), j.identifier('fg')), j.identifier(['heading', 'title'].includes(level) ? 'strong' : 'default')),
47
- ])));
48
- return [
49
- j.spreadElement(j.memberExpression(j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('type')), j.identifier(level)), j.identifier(size))),
50
- ];
43
+ const mapKeys = mapping.type.keys.levels.values;
44
+ const levelKeys = mapKeys[level] || {};
45
+ const tokens = levelKeys[size];
46
+ if (tokens) {
47
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
48
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
49
+ const properties = typeProps
50
+ .filter(prop => tokens[prop])
51
+ .map((key) => {
52
+ const tokenValue = tokens[key];
53
+ if (!tokenValue) {
54
+ return null;
55
+ }
56
+ return j.objectProperty(j.identifier(key), j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, tokenValue)]));
57
+ })
58
+ .filter((prop) => prop !== null);
59
+ // Replace the spread element with individual properties
60
+ return properties;
61
+ }
62
+ return nodePath.value;
51
63
  });
52
64
  root
53
65
  .find(j.MemberExpression, (value) => {
@@ -80,7 +92,7 @@ const transform = (file, api) => {
80
92
  return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]);
81
93
  }
82
94
  }
83
- return nodePath;
95
+ return nodePath.value;
84
96
  });
85
97
  root
86
98
  .find(j.MemberExpression, (value) => {
@@ -104,7 +116,10 @@ const transform = (file, api) => {
104
116
  const lowestPropertyValue = lowestProperty.type === 'Identifier' ? lowestProperty.name : lowestProperty.value;
105
117
  const innerKey = innerProperty.name;
106
118
  if (mainProperty.name === 'properties') {
107
- const { name, values } = mapping.type.keys[innerKey];
119
+ const { name, values } = mapping.type.keys[innerKey] || {};
120
+ if (!name || !values) {
121
+ return nodePath.value;
122
+ }
108
123
  const newValue = values[lowestPropertyValue];
109
124
  addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
110
125
  if (newValue.includes('.')) {
@@ -123,16 +138,25 @@ const transform = (file, api) => {
123
138
  const { values } = mapping.type.keys.levels;
124
139
  const levels = values[innerKey];
125
140
  const lowestKey = lowestPropertyValue;
126
- const tokens = levels[lowestKey];
127
- const props = Object.entries(tokens).map(([key, value]) => {
128
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
129
- return j.property('init', j.identifier(key), j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]));
130
- });
131
- 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
+ }
132
149
  }
133
150
  }
134
151
  }
135
- return nodePath;
152
+ return nodePath.value;
153
+ });
154
+ root
155
+ .find(j.ImportDeclaration, {
156
+ source: { value: (value) => canvasImportSources.includes(value) },
157
+ })
158
+ .forEach(nodePath => {
159
+ filterOutImports({ root, j }, nodePath, 'type');
136
160
  });
137
161
  return root.toSource();
138
162
  };
@@ -1,3 +1,8 @@
1
1
  import { ASTPath, ImportDeclaration } from 'jscodeshift';
2
- export declare const filterOutImports: (nodePath: ASTPath<ImportDeclaration>) => Record<string, string>;
2
+ type ImportType = 'colors' | 'depth' | 'space' | 'type' | 'borderRadius';
3
+ export declare const filterOutImports: ({ root, j }: {
4
+ root: any;
5
+ j: any;
6
+ }, nodePath: ASTPath<ImportDeclaration>, type: ImportType | ImportType[]) => Record<string, string>;
7
+ export {};
3
8
  //# sourceMappingURL=filterOutImports.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filterOutImports.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/filterOutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,gBAAgB,aAAc,QAAQ,iBAAiB,CAAC,2BAwBpE,CAAC"}
1
+ {"version":3,"file":"filterOutImports.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/filterOutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEvD,KAAK,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,cAAc,CAAC;AASzE,eAAO,MAAM,gBAAgB;UACT,GAAG;OAAK,GAAG;aACnB,QAAQ,iBAAiB,CAAC,QAC9B,UAAU,GAAG,UAAU,EAAE,2BA0ChC,CAAC"}
@@ -1,14 +1,32 @@
1
- export const filterOutImports = (nodePath) => {
1
+ const canvasImportSources = [
2
+ '@workday/canvas-kit-react/tokens',
3
+ '@workday/canvas-colors-web',
4
+ '@workday/canvas-space-web',
5
+ '@workday/canvas-depth-web',
6
+ ];
7
+ export const filterOutImports = ({ root, j }, nodePath, type) => {
2
8
  var _a, _b;
3
9
  const importName = {};
4
10
  nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(specifier => {
5
- var _a;
6
11
  if (specifier.type === 'ImportSpecifier' && specifier.local) {
12
+ let isInstanceExist = false;
7
13
  const localName = specifier.local.name.toString();
8
14
  const importedName = specifier.imported.name.toString();
9
15
  importName[localName] = importedName;
10
- return !(typeof nodePath.value.source.value === 'string' &&
11
- ((_a = nodePath.value.source.value) === null || _a === void 0 ? void 0 : _a.endsWith('tokens')));
16
+ root
17
+ .find(j.MemberExpression, {
18
+ object: {
19
+ name: importedName,
20
+ },
21
+ })
22
+ .forEach(() => {
23
+ isInstanceExist = true;
24
+ });
25
+ return (isInstanceExist ||
26
+ !(((typeof type === 'string' && importedName.toLowerCase().includes(type)) ||
27
+ type.includes(importedName)) &&
28
+ typeof nodePath.value.source.value === 'string' &&
29
+ canvasImportSources.includes(nodePath.value.source.value)));
12
30
  }
13
31
  return true;
14
32
  });
@@ -0,0 +1,3 @@
1
+ import { ASTPath, ImportDeclaration } from 'jscodeshift';
2
+ export declare const getImports: (nodePath: ASTPath<ImportDeclaration>) => Record<string, string>;
3
+ //# sourceMappingURL=getImports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getImports.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/getImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,UAAU,aAAc,QAAQ,iBAAiB,CAAC,2BAa9D,CAAC"}
@@ -0,0 +1,12 @@
1
+ export const getImports = (nodePath) => {
2
+ var _a;
3
+ const importName = {};
4
+ (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
5
+ if (specifier.type === 'ImportSpecifier' && specifier.local) {
6
+ const localName = specifier.local.name.toString();
7
+ const importedName = specifier.imported.name.toString();
8
+ importName[localName] = importedName;
9
+ }
10
+ });
11
+ return importName;
12
+ };
@@ -1,5 +1,6 @@
1
1
  export * from './addMissingImports';
2
2
  export * from './filterOutImports';
3
+ export * from './getImports';
3
4
  export * from './generateLevelTokens';
4
5
  export * from './expectTransformFactory';
5
6
  export * from './varToMemberExpression';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sCAAsC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from './addMissingImports';
2
2
  export * from './filterOutImports';
3
+ export * from './getImports';
3
4
  export * from './generateLevelTokens';
4
5
  export * from './expectTransformFactory';
5
6
  export * from './varToMemberExpression';
@@ -1,4 +1,4 @@
1
1
  export declare const transformObjectPropertyRecursively: ({ j, root }: any, property: any, importDeclaration: {
2
2
  [key: string]: any;
3
- }, isCanvasKitStyling?: boolean) => any;
3
+ }, isCanvasKitStyling?: boolean, tokenTypes?: string[]) => any;
4
4
  //# sourceMappingURL=transformObjectPropertyRecursively.d.ts.map
@@ -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,KAC3B,GAgJF,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,26 +1,60 @@
1
- import { systemColors } from '../mapping';
1
+ import { mapping, paletteNames, systemColors } from '../mapping';
2
2
  import { addMissingImports } from './addMissingImports';
3
3
  import { varToMemberExpression } from './varToMemberExpression';
4
- export const transformObjectPropertyRecursively = ({ j, root }, property, importDeclaration, isCanvasKitStyling) => {
4
+ export const transformObjectPropertyRecursively = ({ j, root }, property, importDeclaration, isCanvasKitStyling, tokenTypes) => {
5
5
  var _a, _b, _c;
6
+ // Helper to create object property preserving computed flag
7
+ const createObjectProperty = (key, value) => {
8
+ var _a, _b, _c;
9
+ const prop = j.objectProperty(key, value);
10
+ // Preserve computed flag: if explicitly true, or if key is not a simple literal/identifier
11
+ if (property.computed === true ||
12
+ (((_a = property.key) === null || _a === void 0 ? void 0 : _a.type) !== 'Identifier' &&
13
+ ((_b = property.key) === null || _b === void 0 ? void 0 : _b.type) !== 'StringLiteral' &&
14
+ ((_c = property.key) === null || _c === void 0 ? void 0 : _c.type) !== 'NumericLiteral')) {
15
+ prop.computed = true;
16
+ }
17
+ return prop;
18
+ };
6
19
  if (property.type === 'ObjectProperty' &&
7
20
  property.key.type === 'Identifier' &&
8
21
  property.value.type === 'MemberExpression' &&
9
22
  property.value.object.type === 'Identifier' &&
10
- property.value.property.type === 'Identifier' &&
11
- importDeclaration[property.value.object.name] === 'colors') {
12
- const key = property.key.name;
13
- const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === key))) === null || _a === void 0 ? void 0 : _a[1];
14
- const { property: value } = property.value;
15
- const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[value.name];
16
- if (colorToken) {
17
- if (!isCanvasKitStyling) {
18
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
23
+ property.value.property.type === 'Identifier') {
24
+ const importedTokenName = importDeclaration[property.value.object.name];
25
+ // Handle colors tokens
26
+ if (importedTokenName === 'colors' && (!tokenTypes || tokenTypes.includes('colors'))) {
27
+ const key = property.key.name;
28
+ const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === key))) === null || _a === void 0 ? void 0 : _a[1];
29
+ const { property: value } = property.value;
30
+ const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[value.name];
31
+ if (colorToken) {
32
+ if (!isCanvasKitStyling) {
33
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
34
+ }
35
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
36
+ return createObjectProperty(property.key, isCanvasKitStyling
37
+ ? varToMemberExpression(j, colorToken)
38
+ : j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]));
39
+ }
40
+ }
41
+ // Handle space and borderRadius tokens
42
+ if (tokenTypes &&
43
+ tokenTypes.includes(importedTokenName) &&
44
+ ['space', 'borderRadius'].includes(importedTokenName)) {
45
+ const map = mapping[importedTokenName];
46
+ const propertyName = property.value.property.name;
47
+ if ((map === null || map === void 0 ? void 0 : map.type) === 'system' && map.keys) {
48
+ const newValue = map.keys[propertyName];
49
+ if (newValue) {
50
+ if (!isCanvasKitStyling) {
51
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
52
+ }
53
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
54
+ const tokenPath = j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(newValue));
55
+ return createObjectProperty(property.key, isCanvasKitStyling ? tokenPath : j.callExpression(j.identifier('cssVar'), [tokenPath]));
56
+ }
19
57
  }
20
- addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
21
- return j.objectProperty(j.identifier(key), isCanvasKitStyling
22
- ? varToMemberExpression(j, colorToken)
23
- : j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]));
24
58
  }
25
59
  }
26
60
  if (property.type === 'ObjectProperty' && property.value.type === 'TemplateLiteral') {
@@ -28,21 +62,72 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
28
62
  const transformedQuasis = templateLiteral.quasis.map((quasi) => quasi);
29
63
  const transformedExpressions = templateLiteral.expressions.map((expr) => {
30
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
+ }
31
86
  if (expr.type === 'MemberExpression' &&
32
87
  expr.object.type === 'Identifier' &&
33
- expr.property.type === 'Identifier' &&
34
- importDeclaration[expr.object.name] === 'colors') {
35
- const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === property.key.name))) === null || _a === void 0 ? void 0 : _a[1];
36
- const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[expr.property.name];
37
- if (colorToken) {
38
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
39
- addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
40
- return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]);
88
+ expr.property.type === 'Identifier') {
89
+ const importedTokenName = importDeclaration[expr.object.name];
90
+ // Handle colors tokens
91
+ if (importedTokenName === 'colors' && (!tokenTypes || tokenTypes.includes('colors'))) {
92
+ const keyName = property.key.type === 'Identifier' ? property.key.name : null;
93
+ const tokens = keyName
94
+ ? (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === keyName))) === null || _a === void 0 ? void 0 : _a[1]
95
+ : null;
96
+ const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[expr.property.name];
97
+ if (colorToken) {
98
+ if (!isCanvasKitStyling) {
99
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
100
+ }
101
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
102
+ return isCanvasKitStyling
103
+ ? varToMemberExpression(j, colorToken)
104
+ : j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]);
105
+ }
106
+ }
107
+ // Handle space and borderRadius tokens
108
+ if (tokenTypes &&
109
+ tokenTypes.includes(importedTokenName) &&
110
+ ['space', 'borderRadius'].includes(importedTokenName)) {
111
+ const map = mapping[importedTokenName];
112
+ const propertyName = expr.property.name;
113
+ if ((map === null || map === void 0 ? void 0 : map.type) === 'system' && map.keys) {
114
+ const newValue = map.keys[propertyName];
115
+ if (newValue) {
116
+ if (!isCanvasKitStyling) {
117
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
118
+ }
119
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
120
+ const tokenPath = j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(newValue));
121
+ return isCanvasKitStyling
122
+ ? tokenPath
123
+ : j.callExpression(j.identifier('cssVar'), [tokenPath]);
124
+ }
125
+ }
41
126
  }
42
127
  }
43
128
  return expr;
44
129
  });
45
- return j.objectProperty(property.key, j.templateLiteral(transformedQuasis, transformedExpressions));
130
+ return createObjectProperty(property.key, j.templateLiteral(transformedQuasis, transformedExpressions));
46
131
  }
47
132
  if (property.type === 'ObjectProperty' && property.value.type === 'ConditionalExpression') {
48
133
  const { test, consequent, alternate } = property.value;
@@ -54,23 +139,56 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
54
139
  alternate.object.type === 'Identifier' &&
55
140
  alternate.property.type === 'Identifier' &&
56
141
  importDeclaration[alternate.object.name] === 'colors') {
57
- const consequentTokens = (_b = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === property.key.name))) === null || _b === void 0 ? void 0 : _b[1];
58
- const alternateTokens = (_c = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === property.key.name))) === null || _c === void 0 ? void 0 : _c[1];
142
+ const keyName = property.key.type === 'Identifier' ? property.key.name : null;
143
+ const consequentTokens = keyName
144
+ ? (_b = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === keyName))) === null || _b === void 0 ? void 0 : _b[1]
145
+ : null;
146
+ const alternateTokens = keyName
147
+ ? (_c = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === keyName))) === null || _c === void 0 ? void 0 : _c[1]
148
+ : null;
59
149
  const consequentColorToken = consequentTokens === null || consequentTokens === void 0 ? void 0 : consequentTokens[consequent.property.name];
60
150
  const alternateColorToken = alternateTokens === null || alternateTokens === void 0 ? void 0 : alternateTokens[alternate.property.name];
61
151
  if (consequentColorToken && alternateColorToken) {
62
- 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
+ }
63
155
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
64
- return j.objectProperty(property.key, j.conditionalExpression(test, j.callExpression(j.identifier('cssVar'), [
65
- varToMemberExpression(j, consequentColorToken),
66
- ]), j.callExpression(j.identifier('cssVar'), [
67
- varToMemberExpression(j, alternateColorToken),
68
- ])));
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
+ ])));
69
165
  }
70
166
  }
71
167
  }
72
168
  if (property.type === 'ObjectProperty' && property.value.type === 'ObjectExpression') {
73
- return j.objectProperty(property.key, j.objectExpression(property.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling))));
169
+ return createObjectProperty(property.key, j.objectExpression(property.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling, tokenTypes))));
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
+ }
74
192
  }
75
193
  return property;
76
194
  };
@@ -1 +1 @@
1
- {"version":3,"file":"varToMemberExpression.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/varToMemberExpression.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,MAAO,GAAG,SAAS,MAAM,QAQ1D,CAAC"}
1
+ {"version":3,"file":"varToMemberExpression.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/varToMemberExpression.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,MAAO,GAAG,SAAS,MAAM,QAU1D,CAAC"}
@@ -1,7 +1,7 @@
1
1
  export const varToMemberExpression = (j, value) => {
2
2
  const valuesKeys = value.split('.');
3
3
  return valuesKeys.reduce((acc, key, index) => {
4
- if (index === 0) {
4
+ if (!index) {
5
5
  return j.identifier(key);
6
6
  }
7
7
  return j.memberExpression(acc, j.identifier(key));
@@ -1 +1 @@
1
- {"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v14-tokens/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AAclD,QAAA,MAAM,SAAS,EAAE,SAsIhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v14-tokens/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AAclD,QAAA,MAAM,SAAS,EAAE,SA+IhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,4 +1,4 @@
1
- import { addMissingImports, filterOutImports } from '../v13.2/utils';
1
+ import { addMissingImports, filterOutImports, getImports } from '../v13.2/utils';
2
2
  import { transformObjectPropertyRecursively } from './utils/transformObjectPropertyRecursively';
3
3
  import { mapping } from '../v13.2/mapping';
4
4
  import baseMapping from './baseMapping';
@@ -17,7 +17,7 @@ const transform = (file, api) => {
17
17
  source: { value: (value) => canvasImportSources.includes(value) },
18
18
  })
19
19
  .forEach(nodePath => {
20
- importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
20
+ importDeclaration = { ...importDeclaration, ...getImports(nodePath) };
21
21
  });
22
22
  if (!Object.values(importDeclaration).some(importedValue => importedValue === 'colors' || importedValue === 'base')) {
23
23
  return root.toSource();
@@ -96,6 +96,13 @@ const transform = (file, api) => {
96
96
  return true;
97
97
  });
98
98
  });
99
+ root
100
+ .find(j.ImportDeclaration, {
101
+ source: { value: (value) => canvasImportSources.includes(value) },
102
+ })
103
+ .forEach(nodePath => {
104
+ filterOutImports({ root, j }, nodePath, 'colors');
105
+ });
99
106
  return root.toSource();
100
107
  };
101
108
  export default transform;
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.5",
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": "79a0516e51e4855e2b661cf7d7045f972df3570c"
49
+ "gitHead": "3808e546938e4ee8ad73e75484bc49eeef7da755"
50
50
  }