@atlaskit/codemod-cli 0.17.10 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/filepath.js +1 -1
- package/dist/cjs/main.js +1 -1
- package/dist/cjs/presets/index.js +2 -4
- package/dist/cjs/transforms.js +3 -3
- package/dist/es2019/filepath.js +2 -2
- package/dist/es2019/presets/index.js +2 -4
- package/dist/es2019/transforms.js +3 -3
- package/dist/esm/filepath.js +2 -2
- package/dist/esm/main.js +1 -1
- package/dist/esm/presets/index.js +2 -4
- package/dist/esm/transforms.js +3 -3
- package/dist/types/presets/index.d.ts +1 -3
- package/dist/types-ts4.5/presets/index.d.ts +1 -3
- package/package.json +3 -6
- package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +0 -117
- package/dist/cjs/presets/css-to-design-tokens/lib/colors.js +0 -49
- package/dist/cjs/presets/css-to-design-tokens/lib/declaration.js +0 -29
- package/dist/cjs/presets/css-to-design-tokens/lib/legacy-colors.js +0 -338
- package/dist/cjs/presets/css-to-design-tokens/lib/logger.js +0 -18
- package/dist/cjs/presets/css-to-design-tokens/lib/meta.js +0 -157
- package/dist/cjs/presets/css-to-design-tokens/lib/tokens.js +0 -47
- package/dist/cjs/presets/css-to-design-tokens/lib/value.js +0 -80
- package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +0 -489
- package/dist/cjs/presets/theme-to-design-tokens/types.js +0 -5
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +0 -82
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast.js +0 -35
- package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +0 -44
- package/dist/cjs/presets/theme-to-design-tokens/utils/css-utils.js +0 -38
- package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +0 -289
- package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +0 -96
- package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +0 -7
- package/dist/cjs/presets/theme-to-design-tokens/utils/string-utils.js +0 -25
- package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +0 -28
- package/dist/es2019/presets/css-to-design-tokens/css-to-design-tokens.js +0 -89
- package/dist/es2019/presets/css-to-design-tokens/lib/colors.js +0 -34
- package/dist/es2019/presets/css-to-design-tokens/lib/declaration.js +0 -17
- package/dist/es2019/presets/css-to-design-tokens/lib/legacy-colors.js +0 -332
- package/dist/es2019/presets/css-to-design-tokens/lib/logger.js +0 -11
- package/dist/es2019/presets/css-to-design-tokens/lib/meta.js +0 -133
- package/dist/es2019/presets/css-to-design-tokens/lib/tokens.js +0 -24
- package/dist/es2019/presets/css-to-design-tokens/lib/value.js +0 -68
- package/dist/es2019/presets/theme-to-design-tokens/theme-to-design-tokens.js +0 -377
- package/dist/es2019/presets/theme-to-design-tokens/types.js +0 -1
- package/dist/es2019/presets/theme-to-design-tokens/utils/ast-meta.js +0 -60
- package/dist/es2019/presets/theme-to-design-tokens/utils/ast.js +0 -27
- package/dist/es2019/presets/theme-to-design-tokens/utils/color.js +0 -32
- package/dist/es2019/presets/theme-to-design-tokens/utils/css-utils.js +0 -31
- package/dist/es2019/presets/theme-to-design-tokens/utils/fuzzy-search.js +0 -279
- package/dist/es2019/presets/theme-to-design-tokens/utils/legacy-colors.js +0 -90
- package/dist/es2019/presets/theme-to-design-tokens/utils/named-colors.js +0 -1
- package/dist/es2019/presets/theme-to-design-tokens/utils/string-utils.js +0 -13
- package/dist/es2019/presets/theme-to-design-tokens/utils/tokens.js +0 -8
- package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +0 -109
- package/dist/esm/presets/css-to-design-tokens/lib/colors.js +0 -38
- package/dist/esm/presets/css-to-design-tokens/lib/declaration.js +0 -19
- package/dist/esm/presets/css-to-design-tokens/lib/legacy-colors.js +0 -332
- package/dist/esm/presets/css-to-design-tokens/lib/logger.js +0 -11
- package/dist/esm/presets/css-to-design-tokens/lib/meta.js +0 -146
- package/dist/esm/presets/css-to-design-tokens/lib/tokens.js +0 -40
- package/dist/esm/presets/css-to-design-tokens/lib/value.js +0 -73
- package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +0 -484
- package/dist/esm/presets/theme-to-design-tokens/types.js +0 -1
- package/dist/esm/presets/theme-to-design-tokens/utils/ast-meta.js +0 -74
- package/dist/esm/presets/theme-to-design-tokens/utils/ast.js +0 -27
- package/dist/esm/presets/theme-to-design-tokens/utils/color.js +0 -36
- package/dist/esm/presets/theme-to-design-tokens/utils/css-utils.js +0 -31
- package/dist/esm/presets/theme-to-design-tokens/utils/fuzzy-search.js +0 -283
- package/dist/esm/presets/theme-to-design-tokens/utils/legacy-colors.js +0 -90
- package/dist/esm/presets/theme-to-design-tokens/utils/named-colors.js +0 -1
- package/dist/esm/presets/theme-to-design-tokens/utils/string-utils.js +0 -17
- package/dist/esm/presets/theme-to-design-tokens/utils/tokens.js +0 -21
- package/dist/types/presets/css-to-design-tokens/css-to-design-tokens.d.ts +0 -2
- package/dist/types/presets/css-to-design-tokens/lib/colors.d.ts +0 -6
- package/dist/types/presets/css-to-design-tokens/lib/declaration.d.ts +0 -5
- package/dist/types/presets/css-to-design-tokens/lib/legacy-colors.d.ts +0 -3
- package/dist/types/presets/css-to-design-tokens/lib/logger.d.ts +0 -4
- package/dist/types/presets/css-to-design-tokens/lib/meta.d.ts +0 -6
- package/dist/types/presets/css-to-design-tokens/lib/tokens.d.ts +0 -7
- package/dist/types/presets/css-to-design-tokens/lib/value.d.ts +0 -6
- package/dist/types/presets/theme-to-design-tokens/theme-to-design-tokens.d.ts +0 -2
- package/dist/types/presets/theme-to-design-tokens/utils/ast-meta.d.ts +0 -3
- package/dist/types/presets/theme-to-design-tokens/utils/ast.d.ts +0 -4
- package/dist/types/presets/theme-to-design-tokens/utils/color.d.ts +0 -5
- package/dist/types/presets/theme-to-design-tokens/utils/css-utils.d.ts +0 -2
- package/dist/types/presets/theme-to-design-tokens/utils/fuzzy-search.d.ts +0 -5
- package/dist/types/presets/theme-to-design-tokens/utils/legacy-colors.d.ts +0 -3
- package/dist/types/presets/theme-to-design-tokens/utils/named-colors.d.ts +0 -1
- package/dist/types/presets/theme-to-design-tokens/utils/string-utils.d.ts +0 -3
- package/dist/types/presets/theme-to-design-tokens/utils/tokens.d.ts +0 -2
- package/dist/types-ts4.5/presets/css-to-design-tokens/css-to-design-tokens.d.ts +0 -2
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/colors.d.ts +0 -6
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/declaration.d.ts +0 -5
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/legacy-colors.d.ts +0 -3
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/logger.d.ts +0 -4
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/meta.d.ts +0 -6
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/tokens.d.ts +0 -7
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/value.d.ts +0 -6
- package/dist/types-ts4.5/presets/theme-to-design-tokens/theme-to-design-tokens.d.ts +0 -2
- package/dist/types-ts4.5/presets/theme-to-design-tokens/utils/ast-meta.d.ts +0 -3
- package/dist/types-ts4.5/presets/theme-to-design-tokens/utils/ast.d.ts +0 -4
- package/dist/types-ts4.5/presets/theme-to-design-tokens/utils/color.d.ts +0 -5
- package/dist/types-ts4.5/presets/theme-to-design-tokens/utils/css-utils.d.ts +0 -2
- package/dist/types-ts4.5/presets/theme-to-design-tokens/utils/fuzzy-search.d.ts +0 -5
- package/dist/types-ts4.5/presets/theme-to-design-tokens/utils/legacy-colors.d.ts +0 -3
- package/dist/types-ts4.5/presets/theme-to-design-tokens/utils/named-colors.d.ts +0 -1
- package/dist/types-ts4.5/presets/theme-to-design-tokens/utils/string-utils.d.ts +0 -6
- package/dist/types-ts4.5/presets/theme-to-design-tokens/utils/tokens.d.ts +0 -2
|
@@ -1,489 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = transformer;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
|
-
var _utils = require("@codeshift/utils");
|
|
13
|
-
var _ast = require("./utils/ast");
|
|
14
|
-
var _astMeta = require("./utils/ast-meta");
|
|
15
|
-
var _color = require("./utils/color");
|
|
16
|
-
var _fuzzySearch = _interopRequireDefault(require("./utils/fuzzy-search"));
|
|
17
|
-
var _legacyColors = require("./utils/legacy-colors");
|
|
18
|
-
var _tokens = require("./utils/tokens");
|
|
19
|
-
var _stringUtils = require("./utils/string-utils");
|
|
20
|
-
var _cssUtils = require("./utils/css-utils");
|
|
21
|
-
var _cssToDesignTokens = _interopRequireDefault(require("../css-to-design-tokens/css-to-design-tokens"));
|
|
22
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
23
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
24
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /* eslint-disable no-console */
|
|
25
|
-
function insertTokenImport(j, source) {
|
|
26
|
-
if ((0, _utils.hasImportDeclaration)(j, source, '@atlaskit/tokens')) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
|
|
30
|
-
source.get().node.program.body.unshift(newImport);
|
|
31
|
-
}
|
|
32
|
-
function buildToken(j, tokenId, node) {
|
|
33
|
-
var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
|
|
34
|
-
return callExpr;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Wrap over the j.templateElement builder to provide a more convenient API.
|
|
38
|
-
function buildTemplateElement(j, text) {
|
|
39
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
40
|
-
tail: false,
|
|
41
|
-
fromNode: null
|
|
42
|
-
};
|
|
43
|
-
var tail;
|
|
44
|
-
if (options.fromNode) {
|
|
45
|
-
tail = options.fromNode.tail;
|
|
46
|
-
} else {
|
|
47
|
-
tail = !!options.tail;
|
|
48
|
-
}
|
|
49
|
-
return j.templateElement({
|
|
50
|
-
raw: text,
|
|
51
|
-
cooked: null
|
|
52
|
-
}, tail);
|
|
53
|
-
}
|
|
54
|
-
function getColorFromIdentifier(expression) {
|
|
55
|
-
var value = '';
|
|
56
|
-
if (expression.type === 'Identifier') {
|
|
57
|
-
value = expression.name;
|
|
58
|
-
}
|
|
59
|
-
if (expression.type === 'StringLiteral') {
|
|
60
|
-
value = expression.value;
|
|
61
|
-
}
|
|
62
|
-
if (expression.type === 'MemberExpression' && expression.object.name === 'colors' && (0, _color.isLegacyColor)(expression.property.name)) {
|
|
63
|
-
value = expression.property.name;
|
|
64
|
-
}
|
|
65
|
-
return value;
|
|
66
|
-
}
|
|
67
|
-
function getTokenFromNode(j, path, value, propertyName) {
|
|
68
|
-
var valueMeta = (0, _astMeta.cleanMeta)(_legacyColors.legacyColorMetaMap[value] || []);
|
|
69
|
-
var ancestorMeta = (0, _astMeta.cleanMeta)([].concat((0, _toConsumableArray2.default)((0, _astMeta.getMetaFromAncestors)(j, path)), (0, _toConsumableArray2.default)((0, _stringUtils.kebabize)(propertyName).split('-'))) || []);
|
|
70
|
-
var property = (0, _astMeta.cleanMeta)([(0, _stringUtils.kebabize)(propertyName)])[0];
|
|
71
|
-
|
|
72
|
-
// Attempt to find a property from ancestors if one is not found
|
|
73
|
-
if (!property || !['border', 'icon', 'background', 'text'].includes(property)) {
|
|
74
|
-
if (ancestorMeta.includes('border')) {
|
|
75
|
-
property = 'border';
|
|
76
|
-
}
|
|
77
|
-
if (ancestorMeta.includes('icon')) {
|
|
78
|
-
property = 'icon';
|
|
79
|
-
}
|
|
80
|
-
if (ancestorMeta.includes('background')) {
|
|
81
|
-
property = 'background';
|
|
82
|
-
}
|
|
83
|
-
if (ancestorMeta.includes('color')) {
|
|
84
|
-
property = 'text';
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
var meta = [];
|
|
88
|
-
var possibleTokens = _tokens.tokens;
|
|
89
|
-
if (property === 'text') {
|
|
90
|
-
possibleTokens = _tokens.tokens.filter(function (token) {
|
|
91
|
-
return token.includes('.text');
|
|
92
|
-
});
|
|
93
|
-
if (valueMeta.includes('neutral')) {
|
|
94
|
-
meta.push('color', 'text');
|
|
95
|
-
}
|
|
96
|
-
if (valueMeta.includes('neutral') && (value === 'N400' || value === 'N500')) {
|
|
97
|
-
meta.push('color', 'text', 'subtle');
|
|
98
|
-
}
|
|
99
|
-
if (valueMeta.includes('neutral') && (value === 'N80' || value === 'N100' || value === 'N200' || value === 'N300' || value === 'N400')) {
|
|
100
|
-
meta.push('color', 'text', 'subtlest');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// handle non-neutrals
|
|
104
|
-
if (!valueMeta.includes('neutral')) {
|
|
105
|
-
meta.push.apply(meta, ['color'].concat((0, _toConsumableArray2.default)(ancestorMeta), (0, _toConsumableArray2.default)(valueMeta)));
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (property === 'background' || property === 'background-color') {
|
|
109
|
-
if (ancestorMeta.includes('disabled')) {
|
|
110
|
-
// disabled backgrounds
|
|
111
|
-
meta.push.apply(meta, [property].concat((0, _toConsumableArray2.default)(ancestorMeta)));
|
|
112
|
-
} else if (
|
|
113
|
-
// Surfaces
|
|
114
|
-
valueMeta.includes('neutral') && value !== 'N100' && value !== 'N200' && value !== 'N300' && value !== 'N400' && value !== 'N500' && value !== 'N600' && value !== 'N700' && value !== 'N800') {
|
|
115
|
-
meta.push.apply(meta, ['surface'].concat((0, _toConsumableArray2.default)(ancestorMeta)));
|
|
116
|
-
} else if (value.includes('N0')) {
|
|
117
|
-
// default surface
|
|
118
|
-
meta.push('elevation', 'surface');
|
|
119
|
-
} else if (valueMeta.includes('neutral') && (0, _color.isBoldColor)(value)) {
|
|
120
|
-
// bold netural backgrounds
|
|
121
|
-
meta.push('background', 'neutral', 'bold');
|
|
122
|
-
} else if (valueMeta.includes('neutral')) {
|
|
123
|
-
// netural backgrounds
|
|
124
|
-
meta.push('background', 'neutral');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (property === 'border' || property === 'border-color' || property === 'border-left' || property === 'border-right' || property === 'border-top' || property === 'border-bottom' || property === 'outline' || property === 'outline-color') {
|
|
128
|
-
possibleTokens = _tokens.tokens.filter(function (token) {
|
|
129
|
-
return token.includes('.border') || token.includes('.focus');
|
|
130
|
-
});
|
|
131
|
-
if (valueMeta.includes('neutral')) {
|
|
132
|
-
// standard netural boarder
|
|
133
|
-
meta.push.apply(meta, ['color', 'border'].concat((0, _toConsumableArray2.default)(ancestorMeta)));
|
|
134
|
-
} else {
|
|
135
|
-
meta.push.apply(meta, ['border'].concat((0, _toConsumableArray2.default)(valueMeta), (0, _toConsumableArray2.default)(ancestorMeta)));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (ancestorMeta.includes('icon')) {
|
|
139
|
-
possibleTokens = _tokens.tokens.filter(function (token) {
|
|
140
|
-
return token.includes('.icon');
|
|
141
|
-
});
|
|
142
|
-
if (ancestorMeta.includes('disabled')) {
|
|
143
|
-
// disabled backgrounds
|
|
144
|
-
meta.push('disabled');
|
|
145
|
-
}
|
|
146
|
-
meta.push.apply(meta, ['color', 'icon'].concat((0, _toConsumableArray2.default)(valueMeta)));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Fallback if guided behavior yields nothing
|
|
150
|
-
if (meta.length === 0) {
|
|
151
|
-
meta.push.apply(meta, [property].concat((0, _toConsumableArray2.default)(valueMeta), (0, _toConsumableArray2.default)(ancestorMeta)));
|
|
152
|
-
}
|
|
153
|
-
var search = (0, _fuzzySearch.default)(possibleTokens, false);
|
|
154
|
-
var results = search.get(meta.join(' '));
|
|
155
|
-
var tokenId = ['MISSING_TOKEN'];
|
|
156
|
-
if (results) {
|
|
157
|
-
tokenId = results.map(function (result) {
|
|
158
|
-
return result[1];
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
return tokenId[0];
|
|
162
|
-
}
|
|
163
|
-
function parseCSSPropertyName(cssString) {
|
|
164
|
-
var lastColonIndex = cssString.lastIndexOf(':');
|
|
165
|
-
if (lastColonIndex === -1) {
|
|
166
|
-
return {
|
|
167
|
-
colonIndex: null,
|
|
168
|
-
cssPropertyName: null
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
var propertyNameEndIndex = Math.max(cssString.lastIndexOf(';', lastColonIndex), cssString.lastIndexOf(' ', lastColonIndex), -1);
|
|
172
|
-
var startIndex = propertyNameEndIndex + 1;
|
|
173
|
-
return {
|
|
174
|
-
cssPropertyName: cssString.slice(startIndex, lastColonIndex).trim(),
|
|
175
|
-
colonIndex: lastColonIndex
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
function transformer(_x, _x2) {
|
|
179
|
-
return _transformer.apply(this, arguments);
|
|
180
|
-
}
|
|
181
|
-
function _transformer() {
|
|
182
|
-
_transformer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file, api) {
|
|
183
|
-
var debug,
|
|
184
|
-
j,
|
|
185
|
-
source,
|
|
186
|
-
transformed,
|
|
187
|
-
templateLiteralPaths,
|
|
188
|
-
_iterator,
|
|
189
|
-
_step,
|
|
190
|
-
_loop,
|
|
191
|
-
replaceStringLiteralIfItConsistsOnlyOfColor,
|
|
192
|
-
replaceTemplateLiteralExpression,
|
|
193
|
-
_args2 = arguments;
|
|
194
|
-
return _regenerator.default.wrap(function _callee$(_context2) {
|
|
195
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
196
|
-
case 0:
|
|
197
|
-
replaceTemplateLiteralExpression = function _replaceTemplateLiter(j, mainPath, expressionPath, expressionIndex) {
|
|
198
|
-
var expression = expressionPath.value;
|
|
199
|
-
if (!(expression.type === 'MemberExpression' || expression.type === 'Identifier')) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
if ((0, _ast.isDecendantOfToken)(j, expressionPath)) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
var value = getColorFromIdentifier(expression);
|
|
206
|
-
if (!value || !(0, _color.includesHardCodedColor)(value) && !(0, _color.isHardCodedColor)(value) && !(0, _color.isLegacyColor)(value) && !(0, _color.isLegacyNamedColor)(value)) {
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
var precedingQuasi = mainPath.value.quasis[expressionIndex];
|
|
210
|
-
var precedingQuasiText = precedingQuasi.value.raw;
|
|
211
|
-
var _parseCSSPropertyName = parseCSSPropertyName(precedingQuasiText),
|
|
212
|
-
cssPropertyName = _parseCSSPropertyName.cssPropertyName,
|
|
213
|
-
colonIndex = _parseCSSPropertyName.colonIndex;
|
|
214
|
-
if (!cssPropertyName) {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
var tokenId = getTokenFromNode(j, expressionPath, value, cssPropertyName);
|
|
218
|
-
insertTokenImport(j, source);
|
|
219
|
-
var newQuasis = (0, _toConsumableArray2.default)(mainPath.value.quasis);
|
|
220
|
-
var newExpressions = (0, _toConsumableArray2.default)(mainPath.value.expressions);
|
|
221
|
-
if (cssPropertyName !== 'box-shadow') {
|
|
222
|
-
var tokenExpression = buildToken(j, tokenId, expressionPath.value);
|
|
223
|
-
newExpressions[expressionIndex] = tokenExpression;
|
|
224
|
-
} else {
|
|
225
|
-
// box-shadow is a multi-part property where the color can appear at any
|
|
226
|
-
// part position (even though the standard suggests that color comes
|
|
227
|
-
// last, browsers' CSS parsers are more lax). If we get here, then the
|
|
228
|
-
// color part is replaceable. Textually, it's something like:
|
|
229
|
-
//
|
|
230
|
-
// <rules before>; box-shadow: 0 1px ${colors.N50} 2rem; <rules after>
|
|
231
|
-
//
|
|
232
|
-
// the fallback value will be multipart, i.e. the token call is
|
|
233
|
-
//
|
|
234
|
-
// token(<replacedValue>, `0 1px ${colors.N50} 2rem`)
|
|
235
|
-
//
|
|
236
|
-
// and it's wrapped in a substitution like this:
|
|
237
|
-
//
|
|
238
|
-
// <rules before>; box-shadow: ${token(<...>)}; <rules after>
|
|
239
|
-
//
|
|
240
|
-
// We stich the fallback from the last part of preceding quasi (after
|
|
241
|
-
// colon) and the first part of the following quasi (before ';' or '}').
|
|
242
|
-
//
|
|
243
|
-
// If multiple box-shadows are comma-separated but only one of them has a
|
|
244
|
-
// replaceable color and others are hard-coded, this logic would still
|
|
245
|
-
// work. When multiple shadows have expressions, it's unfortunately not
|
|
246
|
-
// possible to proceed because we cannot find where the value ends from a
|
|
247
|
-
// single following quasi.
|
|
248
|
-
var valueStartIndex = (0, _stringUtils.findFirstNonspaceIndexAfter)(precedingQuasiText, colonIndex);
|
|
249
|
-
var _splitAtIndex = (0, _stringUtils.splitAtIndex)(precedingQuasiText, valueStartIndex),
|
|
250
|
-
_splitAtIndex2 = (0, _slicedToArray2.default)(_splitAtIndex, 2),
|
|
251
|
-
newPrecedingQuasiText = _splitAtIndex2[0],
|
|
252
|
-
partialValueBeginning = _splitAtIndex2[1];
|
|
253
|
-
var followingQuasi = mainPath.value.quasis[expressionIndex + 1];
|
|
254
|
-
var followingQuasiText = followingQuasi.value.raw;
|
|
255
|
-
var valueEndIndex = (0, _cssUtils.findEndIndexOfCSSExpression)(followingQuasiText, followingQuasi.tail);
|
|
256
|
-
if (!valueEndIndex) {
|
|
257
|
-
console.warn('cannot find end of box-shadow value, please check manually');
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
var _splitAtIndex3 = (0, _stringUtils.splitAtIndex)(followingQuasiText, valueEndIndex + 1),
|
|
261
|
-
_splitAtIndex4 = (0, _slicedToArray2.default)(_splitAtIndex3, 2),
|
|
262
|
-
partialValueEnd = _splitAtIndex4[0],
|
|
263
|
-
newFollowingQuasiText = _splitAtIndex4[1];
|
|
264
|
-
var internalQuasis = [buildTemplateElement(j, partialValueBeginning, {
|
|
265
|
-
tail: false
|
|
266
|
-
}), buildTemplateElement(j, partialValueEnd, {
|
|
267
|
-
tail: true
|
|
268
|
-
})];
|
|
269
|
-
var internalExpressions = [expressionPath.value];
|
|
270
|
-
var newFallback = j.templateLiteral(internalQuasis, internalExpressions);
|
|
271
|
-
var newExpression = buildToken(j, tokenId, newFallback);
|
|
272
|
-
newQuasis[expressionIndex] = buildTemplateElement(j, newPrecedingQuasiText, {
|
|
273
|
-
fromNode: newQuasis[expressionIndex]
|
|
274
|
-
});
|
|
275
|
-
newExpressions[expressionIndex] = newExpression;
|
|
276
|
-
newQuasis[expressionIndex + 1] = buildTemplateElement(j, newFollowingQuasiText, {
|
|
277
|
-
fromNode: newQuasis[expressionIndex]
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
mainPath.replace(j.templateLiteral(newQuasis, newExpressions));
|
|
281
|
-
return true;
|
|
282
|
-
};
|
|
283
|
-
replaceStringLiteralIfItConsistsOnlyOfColor = function _replaceStringLiteral(j, path, value) {
|
|
284
|
-
if ((0, _ast.isDecendantOfToken)(j, path)) {
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
if ((0, _color.isHardCodedColor)(value) && !(0, _color.isLegacyColor)(value) && !(0, _color.isLegacyNamedColor)(value)) {
|
|
288
|
-
var parent = path.parent.value;
|
|
289
|
-
var key = '';
|
|
290
|
-
if (parent.type === 'VariableDeclarator') {
|
|
291
|
-
key = parent.id.name;
|
|
292
|
-
}
|
|
293
|
-
var tokenId = getTokenFromNode(j, path, value, key);
|
|
294
|
-
insertTokenImport(j, source);
|
|
295
|
-
j(path).replaceWith(buildToken(j, tokenId, path.value));
|
|
296
|
-
return true;
|
|
297
|
-
}
|
|
298
|
-
return false;
|
|
299
|
-
};
|
|
300
|
-
debug = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : false;
|
|
301
|
-
j = api.jscodeshift;
|
|
302
|
-
source = j(file.source);
|
|
303
|
-
transformed = false; // Objects
|
|
304
|
-
source.find(j.ObjectProperty).forEach(function (path) {
|
|
305
|
-
if (path.value.value.type === 'ObjectExpression') {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Avoid transforming objects that are default arguments
|
|
310
|
-
if (path.parent.parent.value.type === 'ArrowFunctionExpression' || path.parent.parent.value.type === 'FunctionDeclaration') {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
if ((0, _ast.isParentOfToken)(j, path.value.value)) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
var value = getColorFromIdentifier(path.value.value);
|
|
317
|
-
if (!value || !(0, _color.includesHardCodedColor)(value) && !(0, _color.isHardCodedColor)(value) && !(0, _color.isLegacyColor)(value) && !(0, _color.isLegacyNamedColor)(value)) {
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
var key;
|
|
321
|
-
if (path.value.key.type === 'NumericLiteral' || path.value.key.type === 'StringLiteral') {
|
|
322
|
-
key = path.value.key.value.toString();
|
|
323
|
-
}
|
|
324
|
-
if (path.value.key.type === 'Identifier') {
|
|
325
|
-
key = path.value.key.name;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// Key is a node type we do not support
|
|
329
|
-
if (!key) {
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
var tokenId = getTokenFromNode(j, path, value, key);
|
|
333
|
-
insertTokenImport(j, source);
|
|
334
|
-
j(path).replaceWith(j.objectProperty(path.value.key, buildToken(j, tokenId, path.value.value)));
|
|
335
|
-
transformed = true;
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
// JSX props
|
|
339
|
-
source.find(j.JSXAttribute).forEach(function (path) {
|
|
340
|
-
var _path$value;
|
|
341
|
-
if (((_path$value = path.value) === null || _path$value === void 0 || (_path$value = _path$value.value) === null || _path$value === void 0 ? void 0 : _path$value.type) !== 'JSXExpressionContainer') {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
if ((0, _ast.isParentOfToken)(j, path)) {
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
var expression = path.value.value.expression;
|
|
348
|
-
var value = getColorFromIdentifier(expression);
|
|
349
|
-
if (!value || !(0, _color.includesHardCodedColor)(value) && !(0, _color.isHardCodedColor)(value) && !(0, _color.isLegacyColor)(value) && !(0, _color.isLegacyNamedColor)(value)) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
var tokenId = getTokenFromNode(j, path, value, path.value.name.name);
|
|
353
|
-
insertTokenImport(j, source);
|
|
354
|
-
j(path).find(j.JSXExpressionContainer).forEach(function (path) {
|
|
355
|
-
var tokenNode = buildToken(j, tokenId, path.value.expression);
|
|
356
|
-
j(path).replaceWith(j.jsxExpressionContainer(tokenNode));
|
|
357
|
-
});
|
|
358
|
-
transformed = true;
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
// Strings
|
|
362
|
-
source.find(j.StringLiteral).forEach(function (path) {
|
|
363
|
-
j(path).filter(function (expression) {
|
|
364
|
-
return !(0, _utils.isDecendantOfType)(j, expression, j.ObjectExpression);
|
|
365
|
-
}).forEach(function (path) {
|
|
366
|
-
var value = path.value.value;
|
|
367
|
-
if (replaceStringLiteralIfItConsistsOnlyOfColor(j, path, value)) {
|
|
368
|
-
transformed = true;
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
templateLiteralPaths = source.find(j.TemplateLiteral).paths();
|
|
373
|
-
_iterator = _createForOfIteratorHelper(templateLiteralPaths);
|
|
374
|
-
_context2.prev = 11;
|
|
375
|
-
_loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
|
|
376
|
-
var path, text, quasiPaths, _iterator2, _step2, quasiPath, _text, newCSS;
|
|
377
|
-
return _regenerator.default.wrap(function _loop$(_context) {
|
|
378
|
-
while (1) switch (_context.prev = _context.next) {
|
|
379
|
-
case 0:
|
|
380
|
-
path = _step.value;
|
|
381
|
-
// Background: a 'type: TemplateLiteral' Node has quasis and expressions
|
|
382
|
-
// (see ast-types/src/gen/namedTypes.ts), and invariant holds that
|
|
383
|
-
// quasis.length === expression.length + 1.
|
|
384
|
-
//
|
|
385
|
-
// eg `${foo}bar` has quasis [Node(''), Node('bar')] and expressions
|
|
386
|
-
// [Node('foo')]. Each quasi has type: 'TemplateElement'; expressions are
|
|
387
|
-
// probably safe to treat as subtypes of Expression, though ast-types
|
|
388
|
-
// codebase has a more involved definition.
|
|
389
|
-
if (path.value.expressions.length === 0) {
|
|
390
|
-
// A single-quasi (equivalently, no-expression) template literal is
|
|
391
|
-
// basically just a string literal, possibly multi-line. We handle the
|
|
392
|
-
// simple `#ababab` case here, and the multi-line case after.
|
|
393
|
-
text = path.value.quasis[0].value.raw;
|
|
394
|
-
if (replaceStringLiteralIfItConsistsOnlyOfColor(j, path, text)) {
|
|
395
|
-
transformed = true;
|
|
396
|
-
}
|
|
397
|
-
} else {
|
|
398
|
-
j(path).find(j.Expression).filter(function (expressionPath) {
|
|
399
|
-
// jscodeshift walks over the whole tree; we are interested only in
|
|
400
|
-
// the direct children: i.e. top-level expressions appearing in ${}.
|
|
401
|
-
return expressionPath.parent === path;
|
|
402
|
-
}).forEach(function (expressionPath, expressionIndex) {
|
|
403
|
-
if (replaceTemplateLiteralExpression(j, path, expressionPath, expressionIndex)) {
|
|
404
|
-
transformed = true;
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// No matter if we have one big quasi or many small chunks between
|
|
410
|
-
// expressions (which potentially have been transformed), try to pass them
|
|
411
|
-
// through the CSS transformer; it's robust enough to understand malformed
|
|
412
|
-
// CSS that would result if we split e.g. this template:
|
|
413
|
-
//
|
|
414
|
-
// `${gridSize}px; color: red;`, giving `px; color: red;` as input; or
|
|
415
|
-
// `@media ${mobile} { color: red }`, giving `{ color: red }`.
|
|
416
|
-
quasiPaths = j(path).find(j.TemplateElement).filter(function (quasiPath) {
|
|
417
|
-
return quasiPath.parent === path;
|
|
418
|
-
}).paths();
|
|
419
|
-
_iterator2 = _createForOfIteratorHelper(quasiPaths);
|
|
420
|
-
_context.prev = 4;
|
|
421
|
-
_iterator2.s();
|
|
422
|
-
case 6:
|
|
423
|
-
if ((_step2 = _iterator2.n()).done) {
|
|
424
|
-
_context.next = 17;
|
|
425
|
-
break;
|
|
426
|
-
}
|
|
427
|
-
quasiPath = _step2.value;
|
|
428
|
-
_text = quasiPath.value.value.raw;
|
|
429
|
-
if (!((0, _color.includesHardCodedColor)(_text) && (0, _cssUtils.containsReplaceableCSSDeclarations)(_text))) {
|
|
430
|
-
_context.next = 15;
|
|
431
|
-
break;
|
|
432
|
-
}
|
|
433
|
-
_context.next = 12;
|
|
434
|
-
return (0, _cssToDesignTokens.default)(_text);
|
|
435
|
-
case 12:
|
|
436
|
-
newCSS = _context.sent;
|
|
437
|
-
j(quasiPath).replaceWith(buildTemplateElement(j, newCSS));
|
|
438
|
-
transformed = true;
|
|
439
|
-
case 15:
|
|
440
|
-
_context.next = 6;
|
|
441
|
-
break;
|
|
442
|
-
case 17:
|
|
443
|
-
_context.next = 22;
|
|
444
|
-
break;
|
|
445
|
-
case 19:
|
|
446
|
-
_context.prev = 19;
|
|
447
|
-
_context.t0 = _context["catch"](4);
|
|
448
|
-
_iterator2.e(_context.t0);
|
|
449
|
-
case 22:
|
|
450
|
-
_context.prev = 22;
|
|
451
|
-
_iterator2.f();
|
|
452
|
-
return _context.finish(22);
|
|
453
|
-
case 25:
|
|
454
|
-
case "end":
|
|
455
|
-
return _context.stop();
|
|
456
|
-
}
|
|
457
|
-
}, _loop, null, [[4, 19, 22, 25]]);
|
|
458
|
-
});
|
|
459
|
-
_iterator.s();
|
|
460
|
-
case 14:
|
|
461
|
-
if ((_step = _iterator.n()).done) {
|
|
462
|
-
_context2.next = 18;
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
465
|
-
return _context2.delegateYield(_loop(), "t0", 16);
|
|
466
|
-
case 16:
|
|
467
|
-
_context2.next = 14;
|
|
468
|
-
break;
|
|
469
|
-
case 18:
|
|
470
|
-
_context2.next = 23;
|
|
471
|
-
break;
|
|
472
|
-
case 20:
|
|
473
|
-
_context2.prev = 20;
|
|
474
|
-
_context2.t1 = _context2["catch"](11);
|
|
475
|
-
_iterator.e(_context2.t1);
|
|
476
|
-
case 23:
|
|
477
|
-
_context2.prev = 23;
|
|
478
|
-
_iterator.f();
|
|
479
|
-
return _context2.finish(23);
|
|
480
|
-
case 26:
|
|
481
|
-
return _context2.abrupt("return", transformed ? source.toSource() : file.source);
|
|
482
|
-
case 27:
|
|
483
|
-
case "end":
|
|
484
|
-
return _context2.stop();
|
|
485
|
-
}
|
|
486
|
-
}, _callee, null, [[11, 20, 23, 26]]);
|
|
487
|
-
}));
|
|
488
|
-
return _transformer.apply(this, arguments);
|
|
489
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.cleanMeta = cleanMeta;
|
|
8
|
-
exports.getMetaFromAncestors = getMetaFromAncestors;
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
-
var _ast = require("./ast");
|
|
11
|
-
var _tokens = require("./tokens");
|
|
12
|
-
function getMetaFromAncestors(j, path) {
|
|
13
|
-
var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
14
|
-
var parent = path.parentPath;
|
|
15
|
-
var grandParent = parent && parent.parentPath;
|
|
16
|
-
if (parent && parent.value.type === 'ObjectProperty') {
|
|
17
|
-
var value = '';
|
|
18
|
-
if (parent.value.key.type === 'Literal' || parent.value.key.type === 'StringLiteral' || parent.value.key.type === 'NumericLiteral') {
|
|
19
|
-
value = parent.value.key.value.toString();
|
|
20
|
-
} else {
|
|
21
|
-
value = parent.value.key.name;
|
|
22
|
-
}
|
|
23
|
-
meta.push(value);
|
|
24
|
-
}
|
|
25
|
-
if (parent && grandParent && grandParent.value.type === 'TemplateLiteral') {
|
|
26
|
-
var expressionIndex = grandParent.value.expressions.findIndex(function (exp) {
|
|
27
|
-
return exp.name === path.value.name;
|
|
28
|
-
});
|
|
29
|
-
var quasi = grandParent.value.quasis[expressionIndex];
|
|
30
|
-
var propertyName = (quasi.value.cooked || quasi.value.raw || '').replace(/\n/g, '').split(/;|{|}/).filter(function (el) {
|
|
31
|
-
return !el.match(/\.|\@|\(|\)/);
|
|
32
|
-
}).pop().split(/:/g)[0].trim();
|
|
33
|
-
grandParent.value.quasis.slice(0, expressionIndex + 1).map(function (q) {
|
|
34
|
-
return q.value.cooked;
|
|
35
|
-
})
|
|
36
|
-
// We reverse so the most nested one is first which we're more likely than not interested in
|
|
37
|
-
.reverse().some(function (str) {
|
|
38
|
-
var result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
|
|
39
|
-
if (result) {
|
|
40
|
-
meta.push(result[0]);
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
meta.push(propertyName);
|
|
45
|
-
}
|
|
46
|
-
if (parent && parent.value.type === 'JSXAttribute') {
|
|
47
|
-
if (!['css', 'styles', 'style', 'fill', 'stopColor', 'startColor'].includes(parent.value.name.name)) {
|
|
48
|
-
meta.push(parent.value.name.name);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
var closestJSXElement = (0, _ast.getClosestDecendantOfType)(j, path, j.JSXOpeningElement);
|
|
52
|
-
if (closestJSXElement) {
|
|
53
|
-
var jsxElementName = closestJSXElement.value.name.name;
|
|
54
|
-
var nameComponents = jsxElementName.replace(/([a-z])([A-Z])/g, '$1 $2').split(' ');
|
|
55
|
-
meta.push.apply(meta, (0, _toConsumableArray2.default)(nameComponents));
|
|
56
|
-
}
|
|
57
|
-
if (parent && parent.value.type === 'VariableDeclarator') {
|
|
58
|
-
meta.push(parent.value.id.name);
|
|
59
|
-
}
|
|
60
|
-
if (parent) {
|
|
61
|
-
return getMetaFromAncestors(j, parent, meta);
|
|
62
|
-
}
|
|
63
|
-
return meta;
|
|
64
|
-
}
|
|
65
|
-
function cleanMeta(meta) {
|
|
66
|
-
return meta.reduce(function (accum, val) {
|
|
67
|
-
return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
|
|
68
|
-
return e.toLowerCase();
|
|
69
|
-
}) : []));
|
|
70
|
-
}, []).reduce(function (accum, val) {
|
|
71
|
-
var cleanVal = val.replace(/:/g, '').replace(/,/g, '').replace('grey', 'neutral').replace('skeleton', 'neutral').replace('texts', 'text').replace('red', 'danger').replace('error', 'danger').replace('invalid', 'danger').replace('removed', 'danger').replace('removal', 'danger').replace('remove', 'danger').replace('focus', 'focused').replace('valid', 'success').replace('successful', 'success').replace('risk', 'warning').replace('caution', 'warning').replace('primary', 'bold').replace('secondary', 'subtle').replace('hyperlink', 'link').replace('anchor', 'link').replace('active', 'pressed').replace('hover', 'hovered').replace('card', 'raised').replace('dragged', 'surface overlay').replace('dragging', 'surface overlay').replace('drag', 'surface overlay').replace('background-color', 'background').replace('color', 'text').replace('icons', 'icon').replace('glyph', 'icon').replace('stroke', 'border').replace('border-left', 'border').replace('border-right', 'border').replace('border-top', 'border').replace('border-bottom', 'border').replace('box-shadow', 'shadow');
|
|
72
|
-
accum.push.apply(accum, (0, _toConsumableArray2.default)(cleanVal.split(' ')));
|
|
73
|
-
return accum;
|
|
74
|
-
}, []).filter(function (val) {
|
|
75
|
-
return _tokens.getUniqueWordsFromTokens.includes(val);
|
|
76
|
-
}).reduce(function (accum, val) {
|
|
77
|
-
if (!accum.includes(val)) {
|
|
78
|
-
accum.push(val);
|
|
79
|
-
}
|
|
80
|
-
return accum;
|
|
81
|
-
}, []);
|
|
82
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getClosestDecendantOfType = getClosestDecendantOfType;
|
|
7
|
-
exports.isDecendantOfToken = isDecendantOfToken;
|
|
8
|
-
exports.isParentOfToken = isParentOfToken;
|
|
9
|
-
var _utils = require("@codeshift/utils");
|
|
10
|
-
function isDecendantOfToken(j, path) {
|
|
11
|
-
if ('type' in path && path.type === 'CallExpression' && path.callee.type === 'Identifier' && path.callee.name === 'token') {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
return j(path).closest(j.CallExpression, {
|
|
15
|
-
callee: {
|
|
16
|
-
name: 'token'
|
|
17
|
-
}
|
|
18
|
-
}).length > 0;
|
|
19
|
-
}
|
|
20
|
-
function isParentOfToken(j, path) {
|
|
21
|
-
if (path.type === 'CallExpression' && path.callee.type === 'Identifier' && path.callee.name === 'token') {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
return j(path).find(j.CallExpression, {
|
|
25
|
-
callee: {
|
|
26
|
-
name: 'token'
|
|
27
|
-
}
|
|
28
|
-
}).length > 0;
|
|
29
|
-
}
|
|
30
|
-
function getClosestDecendantOfType(j, path, type) {
|
|
31
|
-
if (!(0, _utils.isDecendantOfType)(j, path, type)) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
return j(path).closest(type).get();
|
|
35
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.includesHardCodedColor = void 0;
|
|
7
|
-
exports.isBoldColor = isBoldColor;
|
|
8
|
-
exports.isLegacyNamedColor = exports.isLegacyColor = exports.isHardCodedColor = void 0;
|
|
9
|
-
var _legacyColors = require("./legacy-colors");
|
|
10
|
-
var _namedColors = require("./named-colors");
|
|
11
|
-
var isLegacyColor = exports.isLegacyColor = function isLegacyColor(value) {
|
|
12
|
-
return _legacyColors.legacyColors.includes(value);
|
|
13
|
-
};
|
|
14
|
-
var isLegacyNamedColor = exports.isLegacyNamedColor = function isLegacyNamedColor(value) {
|
|
15
|
-
return _legacyColors.legacyColorMixins.includes(value);
|
|
16
|
-
};
|
|
17
|
-
var colorRegexp = /#(?:[a-f0-9]{3}|[a-f0-9]{6}|[a-f0-9]{8})\b|(?:rgb|rgba|hsl|hsla|lch|lab|color)\([^\)]*\)/;
|
|
18
|
-
var includesHardCodedColor = exports.includesHardCodedColor = function includesHardCodedColor(raw) {
|
|
19
|
-
var value = raw.toLowerCase();
|
|
20
|
-
if (colorRegexp.exec(value)) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
for (var i = 0; i < _namedColors.namedColors.length; i++) {
|
|
24
|
-
if (value.includes("".concat(_namedColors.namedColors[i], ";"))) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
};
|
|
30
|
-
var isHardCodedColor = exports.isHardCodedColor = function isHardCodedColor(raw) {
|
|
31
|
-
var value = raw.toLowerCase();
|
|
32
|
-
if (_namedColors.namedColors.includes(value)) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
var match = value.toLowerCase().match(colorRegexp);
|
|
36
|
-
if (match && match[0] === value) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
return false;
|
|
40
|
-
};
|
|
41
|
-
function isBoldColor(color) {
|
|
42
|
-
var number = parseInt(color.replace(/^./, ''), 10);
|
|
43
|
-
return number > 300;
|
|
44
|
-
}
|