@atlaskit/codemod-cli 0.11.3 → 0.11.5

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 (57) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/cli.js +0 -10
  3. package/dist/cjs/filepath.js +1 -15
  4. package/dist/cjs/index.js +0 -3
  5. package/dist/cjs/main.js +7 -113
  6. package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +21 -70
  7. package/dist/cjs/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
  8. package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +0 -10
  9. package/dist/cjs/presets/index.js +1 -6
  10. package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +1 -6
  11. package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -23
  12. package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +2 -16
  13. package/dist/cjs/presets/theme-to-design-tokens/utils/ast.js +0 -2
  14. package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +2 -17
  15. package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -96
  16. package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +0 -6
  17. package/dist/cjs/sinceRef.js +2 -23
  18. package/dist/cjs/transforms.js +4 -31
  19. package/dist/cjs/types.js +0 -19
  20. package/dist/cjs/utils.js +1 -14
  21. package/dist/cjs/version.json +1 -1
  22. package/dist/es2019/filepath.js +7 -5
  23. package/dist/es2019/main.js +17 -51
  24. package/dist/es2019/presets/css-to-design-tokens/css-to-design-tokens.js +19 -51
  25. package/dist/es2019/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
  26. package/dist/es2019/presets/css-to-design-tokens/utils/meta.js +0 -6
  27. package/dist/es2019/presets/index.js +1 -1
  28. package/dist/es2019/presets/styled-to-emotion/styled-to-emotion.js +1 -4
  29. package/dist/es2019/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -14
  30. package/dist/es2019/presets/theme-to-design-tokens/utils/ast-meta.js +2 -11
  31. package/dist/es2019/presets/theme-to-design-tokens/utils/color.js +2 -7
  32. package/dist/es2019/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -95
  33. package/dist/es2019/presets/theme-to-design-tokens/utils/tokens.js +0 -1
  34. package/dist/es2019/sinceRef.js +2 -11
  35. package/dist/es2019/transforms.js +3 -13
  36. package/dist/es2019/types.js +1 -0
  37. package/dist/es2019/utils.js +1 -12
  38. package/dist/es2019/version.json +1 -1
  39. package/dist/esm/cli.js +0 -2
  40. package/dist/esm/filepath.js +1 -9
  41. package/dist/esm/main.js +7 -98
  42. package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +22 -58
  43. package/dist/esm/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
  44. package/dist/esm/presets/css-to-design-tokens/utils/meta.js +0 -6
  45. package/dist/esm/presets/index.js +1 -1
  46. package/dist/esm/presets/styled-to-emotion/styled-to-emotion.js +1 -4
  47. package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -15
  48. package/dist/esm/presets/theme-to-design-tokens/utils/ast-meta.js +2 -11
  49. package/dist/esm/presets/theme-to-design-tokens/utils/color.js +2 -7
  50. package/dist/esm/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -95
  51. package/dist/esm/presets/theme-to-design-tokens/utils/tokens.js +0 -1
  52. package/dist/esm/sinceRef.js +2 -16
  53. package/dist/esm/transforms.js +4 -14
  54. package/dist/esm/types.js +1 -11
  55. package/dist/esm/utils.js +1 -12
  56. package/dist/esm/version.json +1 -1
  57. package/package.json +3 -3
@@ -1,35 +1,23 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = transformer;
9
-
10
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
15
-
16
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
-
18
12
  var _postcss = _interopRequireDefault(require("postcss"));
19
-
20
13
  var _postcssLess = _interopRequireDefault(require("postcss-less"));
21
-
22
14
  var _tokensRaw = require("@atlaskit/tokens/tokens-raw");
23
-
24
15
  var _tokenNames = _interopRequireDefault(require("@atlaskit/tokens/token-names"));
25
-
26
16
  var _fuzzySearch = _interopRequireDefault(require("../theme-to-design-tokens/utils/fuzzy-search"));
27
-
28
17
  var _legacyColors = require("./utils/legacy-colors");
29
-
30
18
  var _meta = require("./utils/meta");
31
-
32
19
  // @ts-ignore
20
+
33
21
  var tokens = _tokensRaw.light.filter(function (t) {
34
22
  return t.attributes.state === 'active';
35
23
  }).map(function (t) {
@@ -37,90 +25,69 @@ var tokens = _tokensRaw.light.filter(function (t) {
37
25
  }).filter(function (t) {
38
26
  return !t.includes('UNSAFE') && !t.includes('interaction');
39
27
  });
40
-
41
28
  var search = (0, _fuzzySearch.default)(tokens, false);
42
-
43
29
  function isRule(node) {
44
30
  return node.type === 'rule';
45
31
  }
46
-
47
32
  function getParentSelectors(node) {
48
33
  if (isRule(node)) {
49
34
  // @ts-expect-error
50
35
  return getParentSelectors(node.parent) + ' ' + node.selector;
51
36
  }
52
-
53
37
  if (node.parent) {
54
38
  return getParentSelectors(node.parent);
55
39
  }
56
-
57
40
  return '';
58
41
  }
59
-
60
42
  function stripVar(prop) {
61
43
  return prop.substring(prop.indexOf('(') + 1).split(/\,|\)/)[0];
62
44
  }
63
-
64
45
  function stripLessVar(prop) {
65
46
  return prop.substring(1);
66
47
  }
67
-
68
48
  function isColorProperty(prop) {
69
49
  return prop === 'color' || prop === 'background' || prop === 'background-color' || prop === 'box-shadow' || prop === 'border' || prop === 'border-left' || prop === 'border-right' || prop === 'border-top' || prop === 'border-bottom' || prop === 'border-color';
70
50
  }
71
-
72
51
  function getDeclarationMeta(decl) {
73
52
  if (decl.prop === 'color') {
74
53
  return 'text';
75
54
  }
76
-
77
55
  if (decl.prop.startsWith('background')) {
78
56
  return 'background';
79
57
  }
80
-
81
58
  if (decl.prop.includes('shadow')) {
82
59
  return 'shadow';
83
60
  }
84
-
85
61
  if (decl.prop.includes('border')) {
86
62
  return 'border';
87
63
  }
88
-
89
64
  return '';
90
65
  }
91
-
92
66
  function isDesignToken(tokenName) {
93
67
  return Boolean(Object.entries(_tokenNames.default).find(function (_ref) {
94
68
  var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
95
- _ = _ref2[0],
96
- value = _ref2[1];
97
-
69
+ _ = _ref2[0],
70
+ value = _ref2[1];
98
71
  return tokenName === value;
99
72
  }));
100
73
  }
101
-
102
74
  function getMetaFromCssVar(tokenName) {
103
75
  var meta = _legacyColors.knownVariables[tokenName];
104
-
105
76
  if (!meta || meta.length === 0) {
106
77
  return tokenName.split('-');
107
78
  }
108
-
109
79
  return meta;
110
80
  }
111
-
112
81
  function getMetaFromRawColor(rawColor) {
113
82
  var cleanColor = rawColor.toLowerCase();
114
-
115
83
  if (cleanColor.length === 4) {
116
84
  cleanColor = cleanColor + cleanColor.substring(cleanColor.indexOf('#') + 1);
117
85
  }
118
-
119
86
  return _legacyColors.knownRawColors[cleanColor];
120
- } // https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md
121
- // https://astexplorer.net/#/2uBU1BLuJ1
122
-
87
+ }
123
88
 
89
+ // https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md
90
+ // https://astexplorer.net/#/2uBU1BLuJ1
124
91
  var plugin = function plugin() {
125
92
  var processed = Symbol('processed');
126
93
  return {
@@ -130,88 +97,74 @@ var plugin = function plugin() {
130
97
  if (decl[processed]) {
131
98
  return;
132
99
  }
133
-
134
100
  if (!isColorProperty(decl.prop)) {
135
101
  return;
136
102
  }
137
-
138
103
  var searchTerms = [getDeclarationMeta(decl)].concat((0, _toConsumableArray2.default)(getParentSelectors(decl).split(/\-|\.|\,|\ |\:|\&/).filter(function (el) {
139
104
  return !!el;
140
105
  })));
141
106
  var match;
142
107
  var cssVarRe = /var\([^\)]+\)/g;
143
108
  var lessVarRe = /@[a-zA-Z0-9-]+/g;
144
- var rawColorRe = /(#([0-9a-f]{3}){1,2}|(rgba|hsla)\(\d{1,3}%?(,\s?\d{1,3}%?){2},\s?(1|0|0?\.\d+)\)|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\))/i; // CSS variables
109
+ var rawColorRe = /(#([0-9a-f]{3}){1,2}|(rgba|hsla)\(\d{1,3}%?(,\s?\d{1,3}%?){2},\s?(1|0|0?\.\d+)\)|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\))/i;
145
110
 
111
+ // CSS variables
146
112
  var cssVarMatch = decl.value.match(cssVarRe);
147
-
148
113
  if (cssVarMatch) {
149
114
  var _getMetaFromCssVar;
150
-
151
115
  match = cssVarMatch[0];
152
-
153
116
  if (isDesignToken(stripVar(match))) {
154
117
  return;
155
118
  }
156
-
157
119
  searchTerms.push.apply(searchTerms, (0, _toConsumableArray2.default)((_getMetaFromCssVar = getMetaFromCssVar(stripVar(match))) !== null && _getMetaFromCssVar !== void 0 ? _getMetaFromCssVar : []));
158
- } // Less variables
159
-
120
+ }
160
121
 
122
+ // Less variables
161
123
  var lassVarMatch = decl.value.match(lessVarRe);
162
-
163
124
  if (lassVarMatch) {
164
125
  var _getMetaFromCssVar2;
165
-
166
126
  match = lassVarMatch[0];
167
127
  searchTerms.push.apply(searchTerms, (0, _toConsumableArray2.default)((_getMetaFromCssVar2 = getMetaFromCssVar("--".concat(stripLessVar(match)))) !== null && _getMetaFromCssVar2 !== void 0 ? _getMetaFromCssVar2 : []));
168
- } // Raw colors
169
-
128
+ }
170
129
 
130
+ // Raw colors
171
131
  var rawColorMatch = decl.value.match(rawColorRe);
172
-
173
132
  if (rawColorMatch) {
174
133
  var _getMetaFromRawColor;
175
-
176
134
  match = rawColorMatch[0];
177
135
  searchTerms.push.apply(searchTerms, (0, _toConsumableArray2.default)((_getMetaFromRawColor = getMetaFromRawColor(match)) !== null && _getMetaFromRawColor !== void 0 ? _getMetaFromRawColor : []));
178
- } // Named colors
179
-
136
+ }
180
137
 
138
+ // Named colors
181
139
  if (_legacyColors.knownColors.hasOwnProperty(decl.value)) {
182
140
  var _knownColors$decl$val;
183
-
184
141
  match = decl.value;
185
142
  searchTerms.push.apply(searchTerms, (0, _toConsumableArray2.default)((_knownColors$decl$val = _legacyColors.knownColors[decl.value.toLowerCase()]) !== null && _knownColors$decl$val !== void 0 ? _knownColors$decl$val : []));
186
143
  }
187
-
188
144
  if (!match) {
189
145
  console.warn("Unable to find match for declaration: ".concat(decl.prop, ": ").concat(decl.value));
190
146
  return;
191
147
  }
192
-
193
148
  var cleanSearchTerms = (0, _meta.cleanMeta)(searchTerms).join(' ');
194
149
  var results = search.get(cleanSearchTerms);
195
- var replacement = results ? results.map(function (result) {
150
+ var candidates = results.map(function (result) {
196
151
  return result[1];
197
- }) : ['utility.UNSAFE_util.MISSING_TOKEN'];
198
-
152
+ });
153
+ var replacement = candidates.length ? _tokenNames.default[candidates[0]] : 'MISSING_TOKEN';
199
154
  if (decl.prop === 'box-shadow') {
200
- decl.value = "var(".concat(_tokenNames.default[replacement[0]], ", ").concat(decl.value, ")");
155
+ decl.value = "var(".concat(replacement, ", ").concat(decl.value, ")");
201
156
  } else {
202
- decl.value = decl.value.split(match).join("var(".concat(_tokenNames.default[replacement[0]], ", ").concat(match, ")"));
203
- } // @ts-expect-error
204
-
157
+ decl.value = decl.value.split(match).join("var(".concat(replacement, ", ").concat(match, ")"));
158
+ }
205
159
 
160
+ // @ts-expect-error
206
161
  decl[processed] = true;
207
162
  }
208
163
  };
209
164
  };
210
-
211
165
  function transformer(_x) {
212
166
  return _transformer.apply(this, arguments);
213
167
  }
214
-
215
168
  function _transformer() {
216
169
  _transformer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file) {
217
170
  return _regenerator.default.wrap(function _callee$(_context) {
@@ -222,10 +175,8 @@ function _transformer() {
222
175
  return (0, _postcss.default)([plugin()]).process(file.source, {
223
176
  syntax: _postcssLess.default
224
177
  }).css;
225
-
226
178
  case 2:
227
179
  return _context.abrupt("return", _context.sent);
228
-
229
180
  case 3:
230
181
  case "end":
231
182
  return _context.stop();
@@ -156,7 +156,6 @@ var knownVariables = {
156
156
  '--adg3-color-green-light': ['accent', 'subtler', 'green'],
157
157
  '--adg3-color-green-dark': ['accent', 'bolder', 'green'],
158
158
  '--adg3-color-N20-transparent': [],
159
-
160
159
  /* Alias variables */
161
160
  '--jpo-theme-color': ['brand'],
162
161
  '--jpo-text-default-color': ['text'],
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.cleanMeta = cleanMeta;
9
-
10
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
9
  var _tokenNames = _interopRequireDefault(require("@atlaskit/tokens/token-names"));
13
-
14
10
  var getUniqueWordsFromTokens = Object.keys(_tokenNames.default).reduce(function (accum, val) {
15
11
  return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(val.split('.')));
16
12
  }, []).reduce(function (accum, val) {
@@ -21,10 +17,8 @@ var getUniqueWordsFromTokens = Object.keys(_tokenNames.default).reduce(function
21
17
  if (!accum.includes(val)) {
22
18
  accum.push(val);
23
19
  }
24
-
25
20
  return accum;
26
21
  }, []);
27
-
28
22
  function filterDuplciateFoundations(meta) {
29
23
  var foundations = ['text', 'background', 'shadow', 'border'];
30
24
  var hasFoundation = false;
@@ -33,15 +27,12 @@ function filterDuplciateFoundations(meta) {
33
27
  hasFoundation = true;
34
28
  return true;
35
29
  }
36
-
37
30
  if (hasFoundation && foundations.includes(val)) {
38
31
  return false;
39
32
  }
40
-
41
33
  return true;
42
34
  });
43
35
  }
44
-
45
36
  function cleanMeta(meta) {
46
37
  var cleanMeta = meta.reduce(function (accum, val) {
47
38
  return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
@@ -56,7 +47,6 @@ function cleanMeta(meta) {
56
47
  if (!accum.includes(val)) {
57
48
  accum.push(val);
58
49
  }
59
-
60
50
  return accum;
61
51
  }, []);
62
52
  return filterDuplciateFoundations(cleanMeta);
@@ -1,24 +1,19 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _path = _interopRequireDefault(require("path"));
11
-
12
9
  require("./styled-to-emotion/styled-to-emotion");
13
-
14
10
  require("./theme-to-design-tokens/theme-to-design-tokens");
15
-
16
11
  require("./css-to-design-tokens/css-to-design-tokens");
17
-
18
12
  /**
19
13
  * Manually import presets to make sure typescript includes them
20
14
  * in the final bundle
21
15
  */
16
+
22
17
  var presets = ['styled-to-emotion', 'theme-to-design-tokens', 'css-to-design-tokens'].map(function (preset) {
23
18
  return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
24
19
  });
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = transformer;
7
7
  exports.parser = void 0;
8
-
9
8
  function buildCoreImportDeclaration(j, path) {
10
9
  var coreExports = ['css', 'keyframes'];
11
10
  var specifiers = [];
@@ -16,14 +15,12 @@ function buildCoreImportDeclaration(j, path) {
16
15
  });
17
16
  return specifiers.length ? j.importDeclaration(specifiers, j.literal('@emotion/core')) : null;
18
17
  }
19
-
20
18
  function buildStyledImportDeclaration(j, path) {
21
19
  var specifier = j(path).find(j.ImportDefaultSpecifier).filter(function (specifier) {
22
20
  return specifier.value.local.name === 'styled';
23
21
  });
24
22
  return specifier && specifier.length ? j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.get(0).node.local.name))], j.literal('@emotion/styled')) : null;
25
23
  }
26
-
27
24
  function buildThemingImportDeclaration(j, path) {
28
25
  var themingExports = ['ThemeProvider', 'withTheme'];
29
26
  var specifiers = [];
@@ -34,11 +31,10 @@ function buildThemingImportDeclaration(j, path) {
34
31
  });
35
32
  return specifiers && specifiers.length ? j.importDeclaration(specifiers, j.literal('emotion-theming')) : null;
36
33
  }
34
+
37
35
  /**
38
36
  * Converts all imports of `styled-components` to `@emotion/styled`
39
37
  */
40
-
41
-
42
38
  function transformer(fileInfo, _ref, options) {
43
39
  var j = _ref.jscodeshift;
44
40
  var source = j(fileInfo.source).find(j.ImportDeclaration).filter(function (path) {
@@ -50,6 +46,5 @@ function transformer(fileInfo, _ref, options) {
50
46
  });
51
47
  return source;
52
48
  }
53
-
54
49
  var parser = 'tsx';
55
50
  exports.parser = parser;
@@ -1,35 +1,25 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = transformer;
9
-
10
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
9
  var _ast = require("./utils/ast");
13
-
14
10
  var _astMeta = require("./utils/ast-meta");
15
-
16
11
  var _color = require("./utils/color");
17
-
18
12
  var _fuzzySearch = _interopRequireDefault(require("./utils/fuzzy-search"));
19
-
20
13
  var _legacyColors = require("./utils/legacy-colors");
21
-
22
14
  var _tokens = require("./utils/tokens");
23
-
24
15
  /* eslint-disable no-console */
25
- var search = (0, _fuzzySearch.default)(_tokens.tokens, false);
26
16
 
17
+ var search = (0, _fuzzySearch.default)(_tokens.tokens, false);
27
18
  function hasImportDeclaration(j, source, sourcePath) {
28
19
  return !!source.find(j.ImportDeclaration).filter(function (path) {
29
20
  return path.node.source.value === sourcePath;
30
21
  }).length;
31
22
  }
32
-
33
23
  function hasImportSpecifier(j, source, specifier, sourcePath) {
34
24
  return !!source.find(j.ImportDeclaration).filter(function (path) {
35
25
  return path.node.source.value === sourcePath;
@@ -39,43 +29,37 @@ function hasImportSpecifier(j, source, specifier, sourcePath) {
39
29
  }
40
30
  }).length;
41
31
  }
42
-
43
32
  function insertTokenImport(j, source) {
44
33
  if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
45
34
  return;
46
35
  }
47
-
48
36
  var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
49
37
  source.get().node.program.body.unshift(newImport);
50
38
  }
51
-
52
39
  function buildToken(j, tokenId, node) {
53
40
  var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
54
41
  return callExpr;
55
42
  }
56
-
57
43
  function getTokenFromNode(j, path) {
58
44
  var baseMeta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
59
45
  var foundMeta = (0, _astMeta.getMetaFromAncestors)(j, path);
60
46
  var meta = (0, _astMeta.cleanMeta)([].concat((0, _toConsumableArray2.default)(foundMeta), (0, _toConsumableArray2.default)(baseMeta)));
61
47
  var results = search.get(meta.join(' '));
62
- var tokenId = ['utility.UNSAFE_util.MISSING_TOKEN'];
63
-
48
+ var tokenId = ['MISSING_TOKEN'];
64
49
  if (results) {
65
50
  tokenId = results.map(function (result) {
66
51
  return result[1];
67
52
  });
68
53
  }
69
-
70
54
  return tokenId[0];
71
55
  }
72
-
73
56
  function transformer(file, api) {
74
57
  var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
75
58
  var j = api.jscodeshift;
76
59
  var source = j(file.source);
77
60
  var transformed = false;
78
- source // Handle colors.N100
61
+ source
62
+ // Handle colors.N100
79
63
  .find(j.MemberExpression).filter(function (path) {
80
64
  return path.value.object.type === 'Identifier' && path.value.object.name === 'colors' && path.value.property.type === 'Identifier' && (0, _color.isLegacyColor)(path.value.property.name);
81
65
  }).filter(function (path) {
@@ -126,7 +110,6 @@ function transformer(file, api) {
126
110
  return !(0, _ast.isDecendantOfToken)(j, path);
127
111
  }).forEach(function (path) {
128
112
  var _path$value, _path$value$value;
129
-
130
113
  debug && console.log('file:', file.path);
131
114
  insertTokenImport(j, source);
132
115
  var value = path === null || path === void 0 ? void 0 : (_path$value = path.value) === null || _path$value === void 0 ? void 0 : (_path$value$value = _path$value.value) === null || _path$value$value === void 0 ? void 0 : _path$value$value.toString();
@@ -136,10 +119,8 @@ function transformer(file, api) {
136
119
  j(path).replaceWith((0, _ast.isDecendantOfType)(j, path, j.JSXAttribute) ? j.jsxExpressionContainer(tokenNode) : tokenNode);
137
120
  transformed = true;
138
121
  });
139
-
140
122
  if (transformed) {
141
123
  return source.toSource();
142
124
  }
143
-
144
125
  return file.source;
145
126
  }
@@ -1,34 +1,26 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.cleanMeta = cleanMeta;
9
8
  exports.getMetaFromAncestors = getMetaFromAncestors;
10
-
11
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
-
13
10
  var _tokens = require("./tokens");
14
-
15
11
  function getMetaFromAncestors(j, path) {
16
12
  var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
17
13
  var parent = path.parentPath;
18
14
  var grandParent = parent && parent.parentPath;
19
-
20
15
  if (parent && parent.value.type === 'ObjectProperty') {
21
16
  var value = '';
22
-
23
17
  if (parent.value.key.type === 'Literal' || parent.value.key.type === 'StringLiteral' || parent.value.key.type === 'NumericLiteral') {
24
18
  value = parent.value.key.value.toString();
25
19
  } else {
26
20
  value = parent.value.key.name;
27
21
  }
28
-
29
22
  meta.push(value);
30
23
  }
31
-
32
24
  if (parent && grandParent && grandParent.value.type === 'TemplateLiteral') {
33
25
  var expressionIndex = grandParent.value.expressions.findIndex(function (exp) {
34
26
  return exp.name === path.value.name;
@@ -39,10 +31,10 @@ function getMetaFromAncestors(j, path) {
39
31
  }).pop().split(/:/g)[0].trim();
40
32
  grandParent.value.quasis.slice(0, expressionIndex + 1).map(function (q) {
41
33
  return q.value.cooked;
42
- }) // We reverse so the most nested one is first which we're more likely than not interested in
34
+ })
35
+ // We reverse so the most nested one is first which we're more likely than not interested in
43
36
  .reverse().some(function (str) {
44
37
  var result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
45
-
46
38
  if (result) {
47
39
  meta.push(result[0]);
48
40
  return true;
@@ -50,24 +42,19 @@ function getMetaFromAncestors(j, path) {
50
42
  });
51
43
  meta.push(propertyName);
52
44
  }
53
-
54
45
  if (parent && parent.value.type === 'JSXAttribute') {
55
46
  if (!['css', 'styles', 'style'].includes(parent.value.name.name)) {
56
47
  meta.push(parent.value.name.name);
57
48
  }
58
49
  }
59
-
60
50
  if (parent && parent.value.type === 'VariableDeclarator') {
61
51
  meta.push(parent.value.id.name);
62
52
  }
63
-
64
53
  if (parent) {
65
54
  return getMetaFromAncestors(j, parent, meta);
66
55
  }
67
-
68
56
  return meta;
69
57
  }
70
-
71
58
  function cleanMeta(meta) {
72
59
  return meta.reduce(function (accum, val) {
73
60
  return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
@@ -82,7 +69,6 @@ function cleanMeta(meta) {
82
69
  if (!accum.includes(val)) {
83
70
  accum.push(val);
84
71
  }
85
-
86
72
  return accum;
87
73
  }, []);
88
74
  }
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isDecendantOfToken = isDecendantOfToken;
7
7
  exports.isDecendantOfType = isDecendantOfType;
8
-
9
8
  function isDecendantOfToken(j, path) {
10
9
  return j(path).closest(j.CallExpression, {
11
10
  callee: {
@@ -13,7 +12,6 @@ function isDecendantOfToken(j, path) {
13
12
  }
14
13
  }).length > 0;
15
14
  }
16
-
17
15
  function isDecendantOfType(j, path, type) {
18
16
  return j(path).closest(type).length > 0;
19
17
  }
@@ -4,56 +4,41 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isLegacyNamedColor = exports.isLegacyColor = exports.isHardCodedColor = exports.includesHardCodedColor = void 0;
7
-
8
7
  var _legacyColors = require("./legacy-colors");
9
-
10
8
  var _namedColors = require("./named-colors");
11
-
12
9
  var isLegacyColor = function isLegacyColor(value) {
13
10
  return _legacyColors.legacyColors.includes(value);
14
11
  };
15
-
16
12
  exports.isLegacyColor = isLegacyColor;
17
-
18
13
  var isLegacyNamedColor = function isLegacyNamedColor(value) {
19
14
  return _legacyColors.legacyColorMixins.includes(value);
20
15
  };
21
-
22
16
  exports.isLegacyNamedColor = isLegacyNamedColor;
23
-
24
17
  var includesHardCodedColor = function includesHardCodedColor(raw) {
25
18
  var value = raw.toLowerCase();
26
-
27
19
  if (/#(?:[a-f0-9]{3}|[a-f0-9]{6}|[a-f0-9]{8})\b|(?:rgb|hsl)a?\([^\)]*\)/.exec(value.toLowerCase())) {
28
20
  return true;
29
21
  }
30
-
31
22
  for (var i = 0; i < _namedColors.namedColors.length; i++) {
32
23
  if (value.includes("".concat(_namedColors.namedColors[i], ";"))) {
33
24
  return true;
34
25
  }
35
26
  }
36
-
37
27
  return false;
38
28
  };
39
-
40
29
  exports.includesHardCodedColor = includesHardCodedColor;
41
-
42
30
  var isHardCodedColor = function isHardCodedColor(value) {
43
31
  if (_namedColors.namedColors.includes(value.toLowerCase())) {
44
32
  return true;
45
33
  }
46
-
47
34
  if (value.startsWith('rgb(') || value.startsWith('rgba(') || value.startsWith('hsl(') || value.startsWith('hsla(') || value.startsWith('lch(') || value.startsWith('lab(') || value.startsWith('color(')) {
48
35
  return true;
49
36
  }
50
-
51
- if (value.startsWith('#') && ( // short hex, hex, or hex with alpha
37
+ if (value.startsWith('#') && (
38
+ // short hex, hex, or hex with alpha
52
39
  value.length === 4 || value.length === 7 || value.length === 9)) {
53
40
  return true;
54
41
  }
55
-
56
42
  return false;
57
43
  };
58
-
59
44
  exports.isHardCodedColor = isHardCodedColor;