@compiled/react 0.6.13 → 0.9.1

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 (219) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/browser/class-names/index.d.ts +2 -2
  3. package/dist/browser/class-names/index.js.flow +45 -0
  4. package/dist/browser/css/index.d.ts +16 -3
  5. package/dist/browser/css/index.js +0 -13
  6. package/dist/browser/css/index.js.flow +35 -0
  7. package/dist/browser/css/index.js.map +1 -1
  8. package/dist/browser/index.d.ts +4 -1
  9. package/dist/browser/index.js +1 -0
  10. package/dist/browser/index.js.flow +40 -0
  11. package/dist/browser/index.js.map +1 -1
  12. package/dist/browser/keyframes/__fixtures__/index.d.ts +3 -0
  13. package/dist/browser/keyframes/__fixtures__/index.js +12 -0
  14. package/dist/browser/keyframes/__fixtures__/index.js.map +1 -0
  15. package/dist/browser/keyframes/index.d.ts +47 -0
  16. package/dist/browser/keyframes/index.js +9 -0
  17. package/dist/browser/keyframes/index.js.flow +54 -0
  18. package/dist/browser/keyframes/index.js.map +1 -0
  19. package/dist/browser/runtime/ax.js.flow +27 -0
  20. package/dist/browser/runtime/css-custom-property.js.flow +19 -0
  21. package/dist/browser/runtime/dev-warnings.d.ts +0 -1
  22. package/dist/browser/runtime/dev-warnings.js +1 -1
  23. package/dist/browser/runtime/dev-warnings.js.flow +7 -0
  24. package/dist/browser/runtime/dev-warnings.js.map +1 -1
  25. package/dist/browser/runtime/index.js.flow +10 -0
  26. package/dist/browser/runtime/is-node.js.flow +19 -0
  27. package/dist/browser/runtime/sheet.d.ts +1 -1
  28. package/dist/browser/runtime/sheet.js.flow +36 -0
  29. package/dist/browser/runtime/style-cache.d.ts +1 -1
  30. package/dist/browser/runtime/style-cache.js.flow +19 -0
  31. package/dist/browser/runtime/style.d.ts +1 -1
  32. package/dist/browser/runtime/style.js.flow +17 -0
  33. package/dist/browser/runtime/types.js.flow +23 -0
  34. package/dist/browser/runtime.js.flow +7 -0
  35. package/dist/browser/styled/index.d.ts +6 -9
  36. package/dist/browser/styled/index.js.flow +69 -0
  37. package/dist/browser/styled/index.js.map +1 -1
  38. package/dist/browser/types.d.ts +6 -3
  39. package/dist/browser/types.js.flow +29 -0
  40. package/dist/browser/utils/error.js.flow +7 -0
  41. package/dist/cjs/class-names/index.d.ts +2 -2
  42. package/dist/cjs/class-names/index.js.flow +45 -0
  43. package/dist/cjs/css/index.d.ts +16 -3
  44. package/dist/cjs/css/index.js +0 -13
  45. package/dist/cjs/css/index.js.flow +35 -0
  46. package/dist/cjs/css/index.js.map +1 -1
  47. package/dist/cjs/index.d.ts +4 -1
  48. package/dist/cjs/index.js +3 -1
  49. package/dist/cjs/index.js.flow +40 -0
  50. package/dist/cjs/index.js.map +1 -1
  51. package/dist/cjs/keyframes/__fixtures__/index.d.ts +3 -0
  52. package/dist/cjs/keyframes/__fixtures__/index.js +15 -0
  53. package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -0
  54. package/dist/cjs/keyframes/index.d.ts +47 -0
  55. package/dist/cjs/keyframes/index.js +13 -0
  56. package/dist/cjs/keyframes/index.js.flow +54 -0
  57. package/dist/cjs/keyframes/index.js.map +1 -0
  58. package/dist/cjs/runtime/ax.js.flow +27 -0
  59. package/dist/cjs/runtime/css-custom-property.js.flow +19 -0
  60. package/dist/cjs/runtime/dev-warnings.d.ts +0 -1
  61. package/dist/cjs/runtime/dev-warnings.js +2 -3
  62. package/dist/cjs/runtime/dev-warnings.js.flow +7 -0
  63. package/dist/cjs/runtime/dev-warnings.js.map +1 -1
  64. package/dist/cjs/runtime/index.js.flow +10 -0
  65. package/dist/cjs/runtime/is-node.js.flow +19 -0
  66. package/dist/cjs/runtime/sheet.d.ts +1 -1
  67. package/dist/cjs/runtime/sheet.js.flow +36 -0
  68. package/dist/cjs/runtime/style-cache.d.ts +1 -1
  69. package/dist/cjs/runtime/style-cache.js.flow +19 -0
  70. package/dist/cjs/runtime/style.d.ts +1 -1
  71. package/dist/cjs/runtime/style.js.flow +17 -0
  72. package/dist/cjs/runtime/types.js.flow +23 -0
  73. package/dist/cjs/runtime.js.flow +7 -0
  74. package/dist/cjs/styled/index.d.ts +6 -9
  75. package/dist/cjs/styled/index.js.flow +69 -0
  76. package/dist/cjs/styled/index.js.map +1 -1
  77. package/dist/cjs/types.d.ts +6 -3
  78. package/dist/cjs/types.js.flow +29 -0
  79. package/dist/cjs/utils/error.js.flow +7 -0
  80. package/dist/esm/class-names/index.d.ts +2 -2
  81. package/dist/esm/class-names/index.js.flow +45 -0
  82. package/dist/esm/css/index.d.ts +16 -3
  83. package/dist/esm/css/index.js +0 -13
  84. package/dist/esm/css/index.js.flow +35 -0
  85. package/dist/esm/css/index.js.map +1 -1
  86. package/dist/esm/index.d.ts +4 -1
  87. package/dist/esm/index.js +1 -0
  88. package/dist/esm/index.js.flow +40 -0
  89. package/dist/esm/index.js.map +1 -1
  90. package/dist/esm/keyframes/__fixtures__/index.d.ts +3 -0
  91. package/dist/esm/keyframes/__fixtures__/index.js +12 -0
  92. package/dist/esm/keyframes/__fixtures__/index.js.map +1 -0
  93. package/dist/esm/keyframes/index.d.ts +47 -0
  94. package/dist/esm/keyframes/index.js +9 -0
  95. package/dist/esm/keyframes/index.js.flow +54 -0
  96. package/dist/esm/keyframes/index.js.map +1 -0
  97. package/dist/esm/runtime/ax.js.flow +27 -0
  98. package/dist/esm/runtime/css-custom-property.js.flow +19 -0
  99. package/dist/esm/runtime/dev-warnings.d.ts +0 -1
  100. package/dist/esm/runtime/dev-warnings.js +1 -1
  101. package/dist/esm/runtime/dev-warnings.js.flow +7 -0
  102. package/dist/esm/runtime/dev-warnings.js.map +1 -1
  103. package/dist/esm/runtime/index.js.flow +10 -0
  104. package/dist/esm/runtime/is-node.js.flow +19 -0
  105. package/dist/esm/runtime/sheet.d.ts +1 -1
  106. package/dist/esm/runtime/sheet.js.flow +36 -0
  107. package/dist/esm/runtime/style-cache.d.ts +1 -1
  108. package/dist/esm/runtime/style-cache.js.flow +19 -0
  109. package/dist/esm/runtime/style.d.ts +1 -1
  110. package/dist/esm/runtime/style.js.flow +17 -0
  111. package/dist/esm/runtime/types.js.flow +23 -0
  112. package/dist/esm/runtime.js.flow +7 -0
  113. package/dist/esm/styled/index.d.ts +6 -9
  114. package/dist/esm/styled/index.js.flow +69 -0
  115. package/dist/esm/styled/index.js.map +1 -1
  116. package/dist/esm/types.d.ts +6 -3
  117. package/dist/esm/types.js.flow +29 -0
  118. package/dist/esm/utils/error.js.flow +7 -0
  119. package/package.json +18 -20
  120. package/src/class-names/__tests__/types.test.js.flow +28 -0
  121. package/src/class-names/index.js.flow +45 -0
  122. package/src/class-names/index.tsx +2 -2
  123. package/src/css/__tests__/index.test.tsx +41 -0
  124. package/src/css/__tests__/types.test.js.flow +17 -0
  125. package/src/css/index.js.flow +35 -0
  126. package/src/css/index.tsx +25 -3
  127. package/src/index.js.flow +40 -0
  128. package/src/index.tsx +5 -2
  129. package/src/keyframes/__fixtures__/index.tsx +14 -0
  130. package/src/keyframes/__tests__/index.test.tsx +324 -0
  131. package/src/keyframes/__tests__/types.test.js.flow +31 -0
  132. package/src/keyframes/index.js.flow +54 -0
  133. package/src/keyframes/index.tsx +61 -0
  134. package/src/runtime/__tests__/style.test.tsx +91 -57
  135. package/src/runtime/ax.js.flow +27 -0
  136. package/src/runtime/css-custom-property.js.flow +19 -0
  137. package/src/runtime/dev-warnings.js.flow +7 -0
  138. package/src/runtime/dev-warnings.tsx +1 -1
  139. package/src/runtime/index.js.flow +10 -0
  140. package/src/runtime/is-node.js.flow +19 -0
  141. package/src/runtime/sheet.js.flow +36 -0
  142. package/src/runtime/sheet.tsx +1 -1
  143. package/src/runtime/style-cache.js.flow +19 -0
  144. package/src/runtime/style-cache.tsx +1 -1
  145. package/src/runtime/style.js.flow +17 -0
  146. package/src/runtime/style.tsx +1 -1
  147. package/src/runtime/types.js.flow +23 -0
  148. package/src/runtime.js.flow +7 -0
  149. package/src/styled/__tests__/types.test.js.flow +30 -0
  150. package/src/styled/index.js.flow +69 -0
  151. package/src/styled/index.tsx +6 -10
  152. package/src/types.js.flow +29 -0
  153. package/src/types.tsx +7 -3
  154. package/src/utils/error.js.flow +7 -0
  155. package/dist/browser/codemods/codemods-helpers.d.ts +0 -60
  156. package/dist/browser/codemods/codemods-helpers.js +0 -201
  157. package/dist/browser/codemods/codemods-helpers.js.map +0 -1
  158. package/dist/browser/codemods/constants.d.ts +0 -3
  159. package/dist/browser/codemods/constants.js +0 -4
  160. package/dist/browser/codemods/constants.js.map +0 -1
  161. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  162. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
  163. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  164. package/dist/browser/codemods/emotion-to-compiled/index.d.ts +0 -1
  165. package/dist/browser/codemods/emotion-to-compiled/index.js +0 -2
  166. package/dist/browser/codemods/emotion-to-compiled/index.js.map +0 -1
  167. package/dist/browser/codemods/styled-components-to-compiled/index.d.ts +0 -1
  168. package/dist/browser/codemods/styled-components-to-compiled/index.js +0 -2
  169. package/dist/browser/codemods/styled-components-to-compiled/index.js.map +0 -1
  170. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  171. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
  172. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  173. package/dist/cjs/codemods/codemods-helpers.d.ts +0 -60
  174. package/dist/cjs/codemods/codemods-helpers.js +0 -217
  175. package/dist/cjs/codemods/codemods-helpers.js.map +0 -1
  176. package/dist/cjs/codemods/constants.d.ts +0 -3
  177. package/dist/cjs/codemods/constants.js +0 -7
  178. package/dist/cjs/codemods/constants.js.map +0 -1
  179. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  180. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -180
  181. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  182. package/dist/cjs/codemods/emotion-to-compiled/index.d.ts +0 -1
  183. package/dist/cjs/codemods/emotion-to-compiled/index.js +0 -9
  184. package/dist/cjs/codemods/emotion-to-compiled/index.js.map +0 -1
  185. package/dist/cjs/codemods/styled-components-to-compiled/index.d.ts +0 -1
  186. package/dist/cjs/codemods/styled-components-to-compiled/index.js +0 -9
  187. package/dist/cjs/codemods/styled-components-to-compiled/index.js.map +0 -1
  188. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  189. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -35
  190. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  191. package/dist/esm/codemods/codemods-helpers.d.ts +0 -60
  192. package/dist/esm/codemods/codemods-helpers.js +0 -201
  193. package/dist/esm/codemods/codemods-helpers.js.map +0 -1
  194. package/dist/esm/codemods/constants.d.ts +0 -3
  195. package/dist/esm/codemods/constants.js +0 -4
  196. package/dist/esm/codemods/constants.js.map +0 -1
  197. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  198. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
  199. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  200. package/dist/esm/codemods/emotion-to-compiled/index.d.ts +0 -1
  201. package/dist/esm/codemods/emotion-to-compiled/index.js +0 -2
  202. package/dist/esm/codemods/emotion-to-compiled/index.js.map +0 -1
  203. package/dist/esm/codemods/styled-components-to-compiled/index.d.ts +0 -1
  204. package/dist/esm/codemods/styled-components-to-compiled/index.js +0 -2
  205. package/dist/esm/codemods/styled-components-to-compiled/index.js.map +0 -1
  206. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  207. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
  208. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  209. package/src/codemods/README.md +0 -8
  210. package/src/codemods/codemods-helpers.tsx +0 -369
  211. package/src/codemods/constants.tsx +0 -3
  212. package/src/codemods/emotion-to-compiled/README.md +0 -71
  213. package/src/codemods/emotion-to-compiled/__tests__/emotion-to-compiled.test.tsx +0 -526
  214. package/src/codemods/emotion-to-compiled/emotion-to-compiled.tsx +0 -249
  215. package/src/codemods/emotion-to-compiled/index.tsx +0 -1
  216. package/src/codemods/styled-components-to-compiled/README.md +0 -37
  217. package/src/codemods/styled-components-to-compiled/__tests__/styled-components-to-compiled.test.tsx +0 -109
  218. package/src/codemods/styled-components-to-compiled/index.tsx +0 -1
  219. package/src/codemods/styled-components-to-compiled/styled-components-to-compiled.tsx +0 -45
@@ -1,249 +0,0 @@
1
- import core, {
2
- FileInfo,
3
- API,
4
- Options,
5
- Collection,
6
- ASTPath,
7
- CommentBlock,
8
- ObjectPattern,
9
- } from 'jscodeshift';
10
-
11
- import { COMPILED_IMPORT_PATH } from '../constants';
12
-
13
- import {
14
- hasImportDeclaration,
15
- getImportDeclarationCollection,
16
- findImportSpecifierName,
17
- addCommentForUnresolvedImportSpecifiers,
18
- addReactIdentifier,
19
- convertDefaultImportToNamedImport,
20
- replaceImportDeclaration,
21
- mergeImportSpecifiersAlongWithTheirComments,
22
- addCommentBefore,
23
- } from '../codemods-helpers';
24
-
25
- const imports = {
26
- compiledStyledImportName: 'styled',
27
- emotionStyledPackageName: '@emotion/styled',
28
- emotionCoreJSXPragma: '@jsx jsx',
29
- emotionCoreImportNames: { jsx: 'jsx', css: 'css', ClassNames: 'ClassNames' },
30
- emotionCorePackageName: '@emotion/core',
31
- };
32
-
33
- const removeEmotionCoreJSXPragma = (j: core.JSCodeshift, collection: Collection) => {
34
- const commentCollection = collection.find(j.Comment);
35
-
36
- commentCollection.forEach((commentPath) => {
37
- const commentBlockCollection = j(
38
- (commentPath as unknown) as ASTPath<CommentBlock>
39
- ).filter((commentBlockPath) =>
40
- commentBlockPath.value.value.includes(imports.emotionCoreJSXPragma)
41
- );
42
-
43
- commentBlockCollection.forEach((commentBlockPath) => {
44
- j(commentBlockPath).remove();
45
-
46
- addReactIdentifier({ j, collection });
47
- });
48
- });
49
- };
50
-
51
- const replaceEmotionCoreCSSTaggedTemplateExpression = (
52
- j: core.JSCodeshift,
53
- collection: Collection
54
- ) => {
55
- const importDeclarationCollection = getImportDeclarationCollection({
56
- j,
57
- collection,
58
- importPath: imports.emotionCorePackageName,
59
- });
60
- const name = findImportSpecifierName({
61
- j,
62
- importDeclarationCollection,
63
- importName: imports.emotionCoreImportNames.css,
64
- });
65
-
66
- if (name == null) {
67
- return;
68
- }
69
-
70
- collection
71
- .find(j.TaggedTemplateExpression)
72
- .filter((taggedTemplateExpressionPath) =>
73
- j(taggedTemplateExpressionPath)
74
- .find(j.Identifier)
75
- .some((identifierPath) => identifierPath.node.name === name)
76
- )
77
- .forEach((taggedTemplateExpressionPath) => {
78
- const { quasi } = taggedTemplateExpressionPath.node;
79
-
80
- if (quasi) {
81
- j(taggedTemplateExpressionPath).replaceWith([quasi]);
82
- }
83
- });
84
- };
85
-
86
- const handleClassNamesCXBehavior = (j: core.JSCodeshift, objectPattern: ObjectPattern) => {
87
- const cxIdentifierName = 'cx';
88
- const axIdentifierName = 'ax';
89
- const compiledRuntimePackageName = `${COMPILED_IMPORT_PATH}/runtime`;
90
-
91
- const cxObjectPropertyCollection = j(objectPattern)
92
- .find(j.ObjectProperty)
93
- .filter(
94
- (objectPropertyPath) =>
95
- objectPropertyPath.node.key.type === 'Identifier' &&
96
- objectPropertyPath.node.key.name === cxIdentifierName
97
- );
98
-
99
- cxObjectPropertyCollection.forEach((cxObjectPropertyPath) => {
100
- addCommentBefore({
101
- j,
102
- collection: j(cxObjectPropertyPath.node),
103
- message: `Please replace "${cxIdentifierName}" with "${axIdentifierName}" from "${compiledRuntimePackageName}".
104
- Usage: import { ${axIdentifierName} } from '${compiledRuntimePackageName}';
105
-
106
- NOTE: Both "${cxIdentifierName}" and "${axIdentifierName}" have some differences, so we have not replaced its usage.
107
- Please check the docs for "${axIdentifierName}" usage.
108
-
109
- In future, we will expose "${axIdentifierName}" directly from "${imports.emotionCoreImportNames.ClassNames}" props.
110
-
111
- Issue tracked on Github: https://github.com/atlassian-labs/compiled/issues/373`,
112
- });
113
- });
114
- };
115
-
116
- const handleClassNamesStyleBehavior = (j: core.JSCodeshift, objectPattern: ObjectPattern) => {
117
- const styleIdentifierName = 'style';
118
-
119
- const hasStyleObjectProperty = j(objectPattern)
120
- .find(j.ObjectProperty)
121
- .some(
122
- (objectPropertyPath) =>
123
- objectPropertyPath.node.key.type === 'Identifier' &&
124
- objectPropertyPath.node.key.name === styleIdentifierName
125
- );
126
-
127
- if (!hasStyleObjectProperty) {
128
- const styleObjectProperty = j.objectProperty(
129
- j.identifier(styleIdentifierName),
130
- j.identifier(styleIdentifierName)
131
- );
132
-
133
- objectPattern.properties.push(styleObjectProperty);
134
-
135
- addCommentBefore({
136
- j,
137
- collection: j(styleObjectProperty),
138
- message: `We have exported "${styleIdentifierName}" from "${imports.emotionCoreImportNames.ClassNames}" props.
139
- If you are using dynamic declarations, make sure to set the "${styleIdentifierName}"
140
- prop otherwise remove it.`,
141
- });
142
- }
143
- };
144
-
145
- const handleClassNamesBehavior = (j: core.JSCodeshift, collection: Collection) => {
146
- const importDeclarationCollection = getImportDeclarationCollection({
147
- j,
148
- collection,
149
- importPath: imports.emotionCorePackageName,
150
- });
151
- const name = findImportSpecifierName({
152
- j,
153
- importDeclarationCollection,
154
- importName: imports.emotionCoreImportNames.ClassNames,
155
- });
156
-
157
- if (name == null) {
158
- return;
159
- }
160
-
161
- collection
162
- .find(j.JSXElement)
163
- .filter((jsxElementPath) =>
164
- j(jsxElementPath)
165
- .find(j.JSXIdentifier)
166
- .some((jsxIdentifierPath) => jsxIdentifierPath.node.name === name)
167
- )
168
- .find(j.JSXExpressionContainer)
169
- .forEach((jsxExpressionContainer) => {
170
- const { expression } = jsxExpressionContainer.node;
171
-
172
- if (
173
- expression.type === 'FunctionExpression' ||
174
- expression.type === 'ArrowFunctionExpression'
175
- ) {
176
- if (expression.params.length && expression.params[0].type === 'ObjectPattern') {
177
- const objectPattern = expression.params[0];
178
-
179
- handleClassNamesStyleBehavior(j, objectPattern);
180
-
181
- handleClassNamesCXBehavior(j, objectPattern);
182
- }
183
- }
184
- });
185
- };
186
-
187
- const mergeCompiledImportSpecifiers = (j: core.JSCodeshift, collection: Collection) => {
188
- const allowedCompiledNames = [
189
- imports.compiledStyledImportName,
190
- ...Object.values(imports.emotionCoreImportNames),
191
- ].filter(
192
- (name) =>
193
- ![imports.emotionCoreImportNames.jsx, imports.emotionCoreImportNames.css].includes(name)
194
- );
195
-
196
- mergeImportSpecifiersAlongWithTheirComments({
197
- j,
198
- collection,
199
- filter: (name) => !!(name && allowedCompiledNames.includes(name)),
200
- });
201
- };
202
-
203
- const transformer = (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options): string => {
204
- const { source } = fileInfo;
205
- const collection = j(source);
206
-
207
- const hasEmotionCoreImportDeclaration = hasImportDeclaration({
208
- j,
209
- collection,
210
- importPath: imports.emotionCorePackageName,
211
- });
212
- const hasEmotionStyledImportDeclaration = hasImportDeclaration({
213
- j,
214
- collection,
215
- importPath: imports.emotionStyledPackageName,
216
- });
217
-
218
- if (!hasEmotionCoreImportDeclaration && !hasEmotionStyledImportDeclaration) {
219
- return source;
220
- }
221
-
222
- if (hasEmotionStyledImportDeclaration) {
223
- convertDefaultImportToNamedImport({
224
- j,
225
- collection,
226
- importPath: imports.emotionStyledPackageName,
227
- namedImport: imports.compiledStyledImportName,
228
- });
229
- }
230
-
231
- if (hasEmotionCoreImportDeclaration) {
232
- removeEmotionCoreJSXPragma(j, collection);
233
- addCommentForUnresolvedImportSpecifiers({
234
- j,
235
- collection,
236
- importPath: imports.emotionCorePackageName,
237
- allowedImportSpecifierNames: Object.values(imports.emotionCoreImportNames),
238
- });
239
- replaceEmotionCoreCSSTaggedTemplateExpression(j, collection);
240
- handleClassNamesBehavior(j, collection);
241
- replaceImportDeclaration({ j, collection, importPath: imports.emotionCorePackageName });
242
- }
243
-
244
- mergeCompiledImportSpecifiers(j, collection);
245
-
246
- return collection.toSource(options.printOptions || { quote: 'single' });
247
- };
248
-
249
- export default transformer;
@@ -1 +0,0 @@
1
- export { default } from './emotion-to-compiled';
@@ -1,37 +0,0 @@
1
- # styled-components-to-compiled
2
-
3
- > Codemod for easy migration from styled components.
4
-
5
- ## Usage
6
-
7
- ```bash
8
- npx @compiled/cli --preset codemods
9
- # and follow the instructions
10
- ```
11
-
12
- **Will modify files in place, so make sure you can recover if it goes wrong!**
13
-
14
- ## Examples
15
-
16
- ```javascript
17
- import styled from 'styled-components';
18
- ```
19
-
20
- Is transformed to:
21
-
22
- ```javascript
23
- import { styled } from '@compiled/react';
24
- ```
25
-
26
- ## Updating Instructions
27
-
28
- When wanting to update to a later version make sure `@compiled/cli` is being ran with the same version.
29
-
30
- > Watch out for it being cached!
31
-
32
- For example when upgrading `@compiled/react` to `v0.6.0` where you've already used the CLI,
33
- on your next run explicitly set the version number:
34
-
35
- ```bash
36
- npx @compiled/cli@0.6.0 --preset codemods
37
- ```
@@ -1,109 +0,0 @@
1
- jest.disableAutomock();
2
-
3
- // eslint-disable-next-line @typescript-eslint/no-var-requires
4
- const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
5
-
6
- import transformer from '../styled-components-to-compiled';
7
-
8
- describe('styled-components-to-compiled transformer', () => {
9
- defineInlineTest(
10
- { default: transformer, parser: 'tsx' },
11
- {},
12
- "import styled from 'styled-components';",
13
- "import { styled } from '@compiled/react';",
14
- 'it transforms default styled-components imports'
15
- );
16
-
17
- defineInlineTest(
18
- { default: transformer, parser: 'tsx' },
19
- {},
20
- "import sc from 'styled-components';",
21
- "import { styled as sc } from '@compiled/react';",
22
- 'it transforms default with different name than "styled" styled-components imports'
23
- );
24
-
25
- defineInlineTest(
26
- { default: transformer, parser: 'tsx' },
27
- {},
28
- `
29
- import styled from 'styled-components';
30
- import * as React from 'react';
31
- `,
32
- `
33
- import { styled } from '@compiled/react';
34
- import * as React from 'react';
35
- `,
36
- 'it ignores other imports'
37
- );
38
-
39
- defineInlineTest(
40
- { default: transformer, parser: 'tsx' },
41
- {},
42
- `
43
- // @top-level comment
44
-
45
- // comment 1
46
- import styled from 'styled-components';
47
- // comment 2
48
- import * as React from 'react';
49
- `,
50
- `
51
- // @top-level comment
52
-
53
- // comment 1
54
- import { styled } from '@compiled/react';
55
- // comment 2
56
- import * as React from 'react';
57
- `,
58
- 'it should not remove top level comments when transformed'
59
- );
60
-
61
- defineInlineTest(
62
- { default: transformer, parser: 'tsx' },
63
- {},
64
- `
65
- // @top-level comment
66
-
67
- // comment 1
68
- import * as React from 'react';
69
- // comment 2
70
- import styled from 'styled-components';
71
- `,
72
- `
73
- // @top-level comment
74
-
75
- // comment 1
76
- import * as React from 'react';
77
- // comment 2
78
- import { styled } from '@compiled/react';
79
- `,
80
- 'it should not remove comments before transformed statement when not on top'
81
- );
82
-
83
- defineInlineTest(
84
- { default: transformer, parser: 'tsx' },
85
- {},
86
- `
87
- import styled, { css, keyframes, createGlobalStyle, ThemeProvider, withTheme } from 'styled-components';
88
- import * as React from 'react';
89
- `,
90
- `
91
- /* TODO(@compiled/react codemod): "css" is not exported from "@compiled/react" at the moment. Please find an alternative for it. */
92
- /* TODO(@compiled/react codemod): "keyframes" is not exported from "@compiled/react" at the moment. Please find an alternative for it. */
93
- /* TODO(@compiled/react codemod): "createGlobalStyle" is not exported from "@compiled/react" at the moment. Please find an alternative for it. */
94
- /* TODO(@compiled/react codemod): "ThemeProvider" is not exported from "@compiled/react" at the moment. Please find an alternative for it. */
95
- /* TODO(@compiled/react codemod): "withTheme" is not exported from "@compiled/react" at the moment. Please find an alternative for it. */
96
- import { styled } from '@compiled/react';
97
- import * as React from 'react';
98
- `,
99
- 'it adds TODO comment for imports which are not resolved'
100
- );
101
-
102
- defineInlineTest(
103
- { default: transformer, parser: 'tsx' },
104
- {},
105
- "import * as React from 'react';",
106
- "import * as React from 'react';",
107
- 'it should not transform when styled-components imports are not present'
108
- );
109
- });
@@ -1 +0,0 @@
1
- export { default } from './styled-components-to-compiled';
@@ -1,45 +0,0 @@
1
- import { FileInfo, API, Options } from 'jscodeshift';
2
-
3
- import {
4
- hasImportDeclaration,
5
- convertDefaultImportToNamedImport,
6
- addCommentForUnresolvedImportSpecifiers,
7
- } from '../codemods-helpers';
8
-
9
- const imports = {
10
- compiledStyledImportName: 'styled',
11
- styledComponentsPackageName: 'styled-components',
12
- };
13
-
14
- const transformer = (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options): string => {
15
- const { source } = fileInfo;
16
- const collection = j(source);
17
-
18
- const hasStyledComponentsImportDeclaration = hasImportDeclaration({
19
- j,
20
- collection,
21
- importPath: imports.styledComponentsPackageName,
22
- });
23
-
24
- if (!hasStyledComponentsImportDeclaration) {
25
- return source;
26
- }
27
-
28
- addCommentForUnresolvedImportSpecifiers({
29
- j,
30
- collection,
31
- importPath: imports.styledComponentsPackageName,
32
- allowedImportSpecifierNames: [],
33
- });
34
-
35
- convertDefaultImportToNamedImport({
36
- j,
37
- collection,
38
- importPath: imports.styledComponentsPackageName,
39
- namedImport: imports.compiledStyledImportName,
40
- });
41
-
42
- return collection.toSource(options.printOptions || { quote: 'single' });
43
- };
44
-
45
- export default transformer;