@compiled/react 0.7.0 → 0.10.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.
Files changed (265) hide show
  1. package/CHANGELOG.md +68 -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/class-names/index.js.map +1 -1
  5. package/dist/browser/css/index.d.ts +16 -3
  6. package/dist/browser/css/index.js +1 -13
  7. package/dist/browser/css/index.js.flow +35 -0
  8. package/dist/browser/css/index.js.map +1 -1
  9. package/dist/browser/index.d.ts +15 -23
  10. package/dist/browser/index.js +4 -0
  11. package/dist/browser/index.js.flow +15 -0
  12. package/dist/browser/index.js.map +1 -1
  13. package/dist/browser/jsx/jsx-dev-runtime.d.ts +2 -0
  14. package/dist/browser/jsx/jsx-dev-runtime.js +4 -0
  15. package/dist/browser/jsx/jsx-dev-runtime.js.map +1 -0
  16. package/dist/browser/jsx/jsx-local-namespace.d.ts +40 -0
  17. package/dist/browser/jsx/jsx-local-namespace.js +2 -0
  18. package/dist/browser/jsx/jsx-local-namespace.js.map +1 -0
  19. package/dist/browser/jsx/jsx-runtime.d.ts +2 -0
  20. package/dist/browser/jsx/jsx-runtime.js +4 -0
  21. package/dist/browser/jsx/jsx-runtime.js.map +1 -0
  22. package/dist/browser/keyframes/index.js.flow +54 -0
  23. package/dist/browser/runtime/ax.js.flow +27 -0
  24. package/dist/browser/runtime/css-custom-property.d.ts +1 -1
  25. package/dist/browser/runtime/css-custom-property.js.flow +19 -0
  26. package/dist/browser/runtime/css-custom-property.js.map +1 -1
  27. package/dist/browser/runtime/dev-warnings.d.ts +0 -1
  28. package/dist/browser/runtime/dev-warnings.js +1 -1
  29. package/dist/browser/runtime/dev-warnings.js.flow +7 -0
  30. package/dist/browser/runtime/dev-warnings.js.map +1 -1
  31. package/dist/browser/runtime/index.js.flow +10 -0
  32. package/dist/browser/runtime/is-node.js.flow +19 -0
  33. package/dist/browser/runtime/sheet.d.ts +1 -1
  34. package/dist/browser/runtime/sheet.js.flow +36 -0
  35. package/dist/browser/runtime/style-cache.d.ts +1 -1
  36. package/dist/browser/runtime/style-cache.js.flow +19 -0
  37. package/dist/browser/runtime/style-cache.js.map +1 -1
  38. package/dist/browser/runtime/style.d.ts +1 -1
  39. package/dist/browser/runtime/style.js +2 -2
  40. package/dist/browser/runtime/style.js.flow +17 -0
  41. package/dist/browser/runtime/style.js.map +1 -1
  42. package/dist/browser/runtime/types.js.flow +23 -0
  43. package/dist/browser/runtime.js.flow +7 -0
  44. package/dist/browser/styled/index.d.ts +6 -9
  45. package/dist/browser/styled/index.js.flow +69 -0
  46. package/dist/browser/styled/index.js.map +1 -1
  47. package/dist/browser/types.d.ts +6 -3
  48. package/dist/browser/types.js.flow +29 -0
  49. package/dist/browser/utils/error.js.flow +7 -0
  50. package/dist/cjs/class-names/index.d.ts +2 -2
  51. package/dist/cjs/class-names/index.js.flow +45 -0
  52. package/dist/cjs/class-names/index.js.map +1 -1
  53. package/dist/cjs/css/index.d.ts +16 -3
  54. package/dist/cjs/css/index.js +1 -13
  55. package/dist/cjs/css/index.js.flow +35 -0
  56. package/dist/cjs/css/index.js.map +1 -1
  57. package/dist/cjs/index.d.ts +15 -23
  58. package/dist/cjs/index.js +5 -1
  59. package/dist/cjs/index.js.flow +15 -0
  60. package/dist/cjs/index.js.map +1 -1
  61. package/dist/cjs/jsx/jsx-dev-runtime.d.ts +2 -0
  62. package/dist/cjs/jsx/jsx-dev-runtime.js +16 -0
  63. package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -0
  64. package/dist/cjs/jsx/jsx-local-namespace.d.ts +40 -0
  65. package/dist/cjs/jsx/jsx-local-namespace.js +3 -0
  66. package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -0
  67. package/dist/cjs/jsx/jsx-runtime.d.ts +2 -0
  68. package/dist/cjs/jsx/jsx-runtime.js +16 -0
  69. package/dist/cjs/jsx/jsx-runtime.js.map +1 -0
  70. package/dist/cjs/keyframes/index.js.flow +54 -0
  71. package/dist/cjs/runtime/ax.js.flow +27 -0
  72. package/dist/cjs/runtime/css-custom-property.d.ts +1 -1
  73. package/dist/cjs/runtime/css-custom-property.js.flow +19 -0
  74. package/dist/cjs/runtime/css-custom-property.js.map +1 -1
  75. package/dist/cjs/runtime/dev-warnings.d.ts +0 -1
  76. package/dist/cjs/runtime/dev-warnings.js +2 -3
  77. package/dist/cjs/runtime/dev-warnings.js.flow +7 -0
  78. package/dist/cjs/runtime/dev-warnings.js.map +1 -1
  79. package/dist/cjs/runtime/index.js.flow +10 -0
  80. package/dist/cjs/runtime/is-node.js.flow +19 -0
  81. package/dist/cjs/runtime/sheet.d.ts +1 -1
  82. package/dist/cjs/runtime/sheet.js.flow +36 -0
  83. package/dist/cjs/runtime/style-cache.d.ts +1 -1
  84. package/dist/cjs/runtime/style-cache.js.flow +19 -0
  85. package/dist/cjs/runtime/style-cache.js.map +1 -1
  86. package/dist/cjs/runtime/style.d.ts +1 -1
  87. package/dist/cjs/runtime/style.js +2 -2
  88. package/dist/cjs/runtime/style.js.flow +17 -0
  89. package/dist/cjs/runtime/style.js.map +1 -1
  90. package/dist/cjs/runtime/types.js.flow +23 -0
  91. package/dist/cjs/runtime.js.flow +7 -0
  92. package/dist/cjs/styled/index.d.ts +6 -9
  93. package/dist/cjs/styled/index.js.flow +69 -0
  94. package/dist/cjs/styled/index.js.map +1 -1
  95. package/dist/cjs/types.d.ts +6 -3
  96. package/dist/cjs/types.js.flow +29 -0
  97. package/dist/cjs/utils/error.js.flow +7 -0
  98. package/dist/esm/class-names/index.d.ts +2 -2
  99. package/dist/esm/class-names/index.js.flow +45 -0
  100. package/dist/esm/class-names/index.js.map +1 -1
  101. package/dist/esm/css/index.d.ts +16 -3
  102. package/dist/esm/css/index.js +1 -13
  103. package/dist/esm/css/index.js.flow +35 -0
  104. package/dist/esm/css/index.js.map +1 -1
  105. package/dist/esm/index.d.ts +15 -23
  106. package/dist/esm/index.js +4 -0
  107. package/dist/esm/index.js.flow +15 -0
  108. package/dist/esm/index.js.map +1 -1
  109. package/dist/esm/jsx/jsx-dev-runtime.d.ts +2 -0
  110. package/dist/esm/jsx/jsx-dev-runtime.js +4 -0
  111. package/dist/esm/jsx/jsx-dev-runtime.js.map +1 -0
  112. package/dist/esm/jsx/jsx-local-namespace.d.ts +40 -0
  113. package/dist/esm/jsx/jsx-local-namespace.js +2 -0
  114. package/dist/esm/jsx/jsx-local-namespace.js.map +1 -0
  115. package/dist/esm/jsx/jsx-runtime.d.ts +2 -0
  116. package/dist/esm/jsx/jsx-runtime.js +4 -0
  117. package/dist/esm/jsx/jsx-runtime.js.map +1 -0
  118. package/dist/esm/keyframes/index.js.flow +54 -0
  119. package/dist/esm/runtime/ax.js.flow +27 -0
  120. package/dist/esm/runtime/css-custom-property.d.ts +1 -1
  121. package/dist/esm/runtime/css-custom-property.js.flow +19 -0
  122. package/dist/esm/runtime/css-custom-property.js.map +1 -1
  123. package/dist/esm/runtime/dev-warnings.d.ts +0 -1
  124. package/dist/esm/runtime/dev-warnings.js +1 -1
  125. package/dist/esm/runtime/dev-warnings.js.flow +7 -0
  126. package/dist/esm/runtime/dev-warnings.js.map +1 -1
  127. package/dist/esm/runtime/index.js.flow +10 -0
  128. package/dist/esm/runtime/is-node.js.flow +19 -0
  129. package/dist/esm/runtime/sheet.d.ts +1 -1
  130. package/dist/esm/runtime/sheet.js.flow +36 -0
  131. package/dist/esm/runtime/style-cache.d.ts +1 -1
  132. package/dist/esm/runtime/style-cache.js.flow +19 -0
  133. package/dist/esm/runtime/style-cache.js.map +1 -1
  134. package/dist/esm/runtime/style.d.ts +1 -1
  135. package/dist/esm/runtime/style.js +2 -2
  136. package/dist/esm/runtime/style.js.flow +17 -0
  137. package/dist/esm/runtime/style.js.map +1 -1
  138. package/dist/esm/runtime/types.js.flow +23 -0
  139. package/dist/esm/runtime.js.flow +7 -0
  140. package/dist/esm/styled/index.d.ts +6 -9
  141. package/dist/esm/styled/index.js.flow +69 -0
  142. package/dist/esm/styled/index.js.map +1 -1
  143. package/dist/esm/types.d.ts +6 -3
  144. package/dist/esm/types.js.flow +29 -0
  145. package/dist/esm/utils/error.js.flow +7 -0
  146. package/jsx-dev-runtime/package.json +6 -0
  147. package/jsx-runtime/package.json +6 -0
  148. package/package.json +41 -15
  149. package/src/__tests__/browser.test.tsx +5 -5
  150. package/src/__tests__/jest-matcher.test.tsx +197 -0
  151. package/src/__tests__/server-side-hydrate.test.tsx +1 -0
  152. package/src/__tests__/ssr.test.tsx +2 -2
  153. package/src/class-names/__tests__/index.test.tsx +1 -1
  154. package/src/class-names/__tests__/types.test.js.flow +28 -0
  155. package/src/class-names/index.js.flow +45 -0
  156. package/src/class-names/index.tsx +3 -2
  157. package/src/css/__tests__/index.test.tsx +40 -0
  158. package/src/css/__tests__/types.test.js.flow +17 -0
  159. package/src/css/index.js.flow +35 -0
  160. package/src/css/index.tsx +27 -3
  161. package/src/index.js.flow +15 -0
  162. package/src/index.tsx +20 -26
  163. package/src/jsx/__tests__/index.test.tsx +1 -2
  164. package/src/jsx/__tests__/jsx-import-source-pragma.test.tsx +37 -0
  165. package/src/jsx/__tests__/jsx-pragma.test.tsx +39 -0
  166. package/src/jsx/jsx-dev-runtime.tsx +5 -0
  167. package/src/jsx/jsx-local-namespace.tsx +49 -0
  168. package/src/jsx/jsx-runtime.tsx +5 -0
  169. package/src/keyframes/__tests__/index.test.tsx +2 -1
  170. package/src/keyframes/__tests__/types.test.js.flow +31 -0
  171. package/src/keyframes/index.js.flow +54 -0
  172. package/src/runtime/__perf__/ax.test.ts +42 -0
  173. package/src/runtime/__perf__/cs.test.tsx +111 -0
  174. package/src/runtime/__perf__/sheet.test.ts +61 -0
  175. package/src/runtime/__perf__/utils/cs.tsx +60 -0
  176. package/src/runtime/__perf__/utils/sheet.tsx +151 -0
  177. package/src/runtime/__tests__/style-ssr.test.tsx +1 -0
  178. package/src/runtime/__tests__/style.test.tsx +92 -58
  179. package/src/runtime/ax.js.flow +27 -0
  180. package/src/runtime/css-custom-property.js.flow +19 -0
  181. package/src/runtime/css-custom-property.tsx +1 -1
  182. package/src/runtime/dev-warnings.js.flow +7 -0
  183. package/src/runtime/dev-warnings.tsx +1 -1
  184. package/src/runtime/index.js.flow +10 -0
  185. package/src/runtime/is-node.js.flow +19 -0
  186. package/src/runtime/sheet.js.flow +36 -0
  187. package/src/runtime/sheet.tsx +1 -1
  188. package/src/runtime/style-cache.js.flow +19 -0
  189. package/src/runtime/style-cache.tsx +2 -1
  190. package/src/runtime/style.js.flow +17 -0
  191. package/src/runtime/style.tsx +4 -3
  192. package/src/runtime/types.js.flow +23 -0
  193. package/src/runtime.js.flow +7 -0
  194. package/src/styled/__tests__/index.test.tsx +3 -3
  195. package/src/styled/__tests__/types.test.js.flow +30 -0
  196. package/src/styled/index.js.flow +69 -0
  197. package/src/styled/index.tsx +7 -10
  198. package/src/types.js.flow +29 -0
  199. package/src/types.tsx +7 -3
  200. package/src/utils/error.js.flow +7 -0
  201. package/dist/browser/codemods/codemods-helpers.d.ts +0 -60
  202. package/dist/browser/codemods/codemods-helpers.js +0 -201
  203. package/dist/browser/codemods/codemods-helpers.js.map +0 -1
  204. package/dist/browser/codemods/constants.d.ts +0 -3
  205. package/dist/browser/codemods/constants.js +0 -4
  206. package/dist/browser/codemods/constants.js.map +0 -1
  207. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  208. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
  209. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  210. package/dist/browser/codemods/emotion-to-compiled/index.d.ts +0 -1
  211. package/dist/browser/codemods/emotion-to-compiled/index.js +0 -2
  212. package/dist/browser/codemods/emotion-to-compiled/index.js.map +0 -1
  213. package/dist/browser/codemods/styled-components-to-compiled/index.d.ts +0 -1
  214. package/dist/browser/codemods/styled-components-to-compiled/index.js +0 -2
  215. package/dist/browser/codemods/styled-components-to-compiled/index.js.map +0 -1
  216. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  217. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
  218. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  219. package/dist/cjs/codemods/codemods-helpers.d.ts +0 -60
  220. package/dist/cjs/codemods/codemods-helpers.js +0 -217
  221. package/dist/cjs/codemods/codemods-helpers.js.map +0 -1
  222. package/dist/cjs/codemods/constants.d.ts +0 -3
  223. package/dist/cjs/codemods/constants.js +0 -7
  224. package/dist/cjs/codemods/constants.js.map +0 -1
  225. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  226. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -180
  227. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  228. package/dist/cjs/codemods/emotion-to-compiled/index.d.ts +0 -1
  229. package/dist/cjs/codemods/emotion-to-compiled/index.js +0 -9
  230. package/dist/cjs/codemods/emotion-to-compiled/index.js.map +0 -1
  231. package/dist/cjs/codemods/styled-components-to-compiled/index.d.ts +0 -1
  232. package/dist/cjs/codemods/styled-components-to-compiled/index.js +0 -9
  233. package/dist/cjs/codemods/styled-components-to-compiled/index.js.map +0 -1
  234. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  235. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -35
  236. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  237. package/dist/esm/codemods/codemods-helpers.d.ts +0 -60
  238. package/dist/esm/codemods/codemods-helpers.js +0 -201
  239. package/dist/esm/codemods/codemods-helpers.js.map +0 -1
  240. package/dist/esm/codemods/constants.d.ts +0 -3
  241. package/dist/esm/codemods/constants.js +0 -4
  242. package/dist/esm/codemods/constants.js.map +0 -1
  243. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  244. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
  245. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  246. package/dist/esm/codemods/emotion-to-compiled/index.d.ts +0 -1
  247. package/dist/esm/codemods/emotion-to-compiled/index.js +0 -2
  248. package/dist/esm/codemods/emotion-to-compiled/index.js.map +0 -1
  249. package/dist/esm/codemods/styled-components-to-compiled/index.d.ts +0 -1
  250. package/dist/esm/codemods/styled-components-to-compiled/index.js +0 -2
  251. package/dist/esm/codemods/styled-components-to-compiled/index.js.map +0 -1
  252. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  253. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
  254. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  255. package/src/codemods/README.md +0 -8
  256. package/src/codemods/codemods-helpers.tsx +0 -369
  257. package/src/codemods/constants.tsx +0 -3
  258. package/src/codemods/emotion-to-compiled/README.md +0 -71
  259. package/src/codemods/emotion-to-compiled/__tests__/emotion-to-compiled.test.tsx +0 -526
  260. package/src/codemods/emotion-to-compiled/emotion-to-compiled.tsx +0 -249
  261. package/src/codemods/emotion-to-compiled/index.tsx +0 -1
  262. package/src/codemods/styled-components-to-compiled/README.md +0 -37
  263. package/src/codemods/styled-components-to-compiled/__tests__/styled-components-to-compiled.test.tsx +0 -109
  264. package/src/codemods/styled-components-to-compiled/index.tsx +0 -1
  265. package/src/codemods/styled-components-to-compiled/styled-components-to-compiled.tsx +0 -45
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.15.0
5
+ * @flow
6
+ */
7
+ import type { ComponentType } from 'react';
8
+ import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
9
+ /**
10
+ * Typing for the CSS object.
11
+ */
12
+ export type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
13
+ /**
14
+ * Extra props added to the output Styled Component.
15
+ */
16
+ export type StyledProps = {
17
+ as?: $Keys<$JSXIntrinsics>,
18
+ };
19
+ export type Interpolations<TProps: mixed> = (
20
+ | BasicTemplateInterpolations
21
+ | FunctionInterpolation<TProps>
22
+ | CssObject<TProps>
23
+ | CssObject<TProps>[]
24
+ )[];
25
+ /**
26
+ * This allows us to take the generic `TTag` (that will be a valid `DOM` tag) and then use it to
27
+ * define correct props based on it from `$JSXIntrinsics`, while also injecting our own
28
+ * props from `StyledProps`.
29
+ */
30
+ export interface StyledFunctionFromTag<TTag: $Keys<$JSXIntrinsics>> {
31
+ <TProps: mixed>(
32
+ css: CssObject<TProps> | $ReadOnlyArray<CssObject<TProps>>,
33
+ ...interpolations: Interpolations<TProps>
34
+ ): React$ComponentType<{
35
+ ...TProps,
36
+ ...$Exact<$ElementType<$JSXIntrinsics, TTag>>,
37
+ ...StyledProps,
38
+ }>;
39
+ }
40
+ export interface StyledFunctionFromComponent<TInheritedProps: mixed> {
41
+ <TProps: mixed>(
42
+ css: CssObject<TProps> | $ReadOnlyArray<string>,
43
+ ...interpolations: Interpolations<TProps>
44
+ ): React$ComponentType<{ ...TProps, ...StyledProps, ...TInheritedProps }>;
45
+ }
46
+ export type StyledComponentMap = $ObjMapi<$JSXIntrinsics, <Tag>(Tag) => StyledFunctionFromTag<Tag>>;
47
+ export type StyledComponentInstantiator = {
48
+ /**
49
+ * Typing to enable consumers to compose components, e.g: `styled(Component)`
50
+ */
51
+ <TInheritedProps: mixed>(
52
+ Component: ComponentType<TInheritedProps>
53
+ ): StyledFunctionFromComponent<TInheritedProps>,
54
+ ...
55
+ } & StyledComponentMap;
56
+ /**
57
+ * Create a component that ties styles to an element which comes with built-in behavior such as `ref` and `as` prop support.
58
+ *
59
+ * ```
60
+ * styled.div`font-size: 12px`; // Template literal CSS
61
+ * styled.div({ fontSize: 12 }); // Object CSS
62
+ * styled.div([{ fontSize: 12 }, `font-size: 12px;`]) // Array CSS
63
+ * styled.div({ fontSize: 12 }, `font-size: 12px`) Multi arguments CSS
64
+ * ```
65
+ *
66
+ * For more help, read the docs:
67
+ * https://compiledcssinjs.com/docs/api-styled
68
+ */
69
+ declare export var styled: StyledComponentInstantiator;
@@ -1,15 +1,12 @@
1
- import { ComponentType } from 'react';
2
- import { createSetupError } from '../utils/error';
3
- import { BasicTemplateInterpolations, CssFunction, CSSProps } from '../types';
1
+ import type { ComponentType } from 'react';
4
2
 
5
- export interface FunctionIterpolation<TProps> {
6
- (props: TProps): CSSProps | string | number | boolean | undefined;
7
- }
3
+ import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
4
+ import { createSetupError } from '../utils/error';
8
5
 
9
6
  /**
10
7
  * Typing for the CSS object.
11
8
  */
12
- export type CssObject<TProps> = CssFunction<FunctionIterpolation<TProps>>;
9
+ export type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
13
10
 
14
11
  /**
15
12
  * Extra props added to the output Styled Component.
@@ -20,7 +17,7 @@ export interface StyledProps {
20
17
 
21
18
  export type Interpolations<TProps extends unknown> = (
22
19
  | BasicTemplateInterpolations
23
- | FunctionIterpolation<TProps>
20
+ | FunctionInterpolation<TProps>
24
21
  | CssObject<TProps>
25
22
  | CssObject<TProps>[]
26
23
  )[];
@@ -34,7 +31,7 @@ export interface StyledFunctionFromTag<TTag extends keyof JSX.IntrinsicElements>
34
31
  <TProps extends unknown>(
35
32
  // Allows either string or object (`` or ({}))
36
33
  css: CssObject<TProps> | CssObject<TProps>[],
37
- ...interpoltations: Interpolations<TProps>
34
+ ...interpolations: Interpolations<TProps>
38
35
  ): React.ComponentType<TProps & JSX.IntrinsicElements[TTag] & StyledProps>;
39
36
  }
40
37
 
@@ -42,7 +39,7 @@ export interface StyledFunctionFromComponent<TInheritedProps extends unknown> {
42
39
  <TProps extends unknown>(
43
40
  // Allows either string or object (`` or ({}))
44
41
  css: CssObject<TProps> | TemplateStringsArray,
45
- ...interpoltations: Interpolations<TProps>
42
+ ...interpolations: Interpolations<TProps>
46
43
  ): React.ComponentType<TProps & StyledProps & TInheritedProps>;
47
44
  }
48
45
 
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Flowtype definitions for types
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.15.0
5
+ * @flow
6
+ */
7
+ import * as CSS from 'csstype';
8
+ /**
9
+ * Typing for the interpolations.
10
+ */
11
+ export type BasicTemplateInterpolations = string | number;
12
+ export interface FunctionInterpolation<TProps> {
13
+ (props: TProps): CSSProps | BasicTemplateInterpolations | boolean | void;
14
+ }
15
+ /**
16
+ * These are all the CSS props that will exist.
17
+ */
18
+ export type CSSProps = CSS.Properties<BasicTemplateInterpolations>;
19
+ export type AnyKeyCssProps<TValue> = {
20
+ [key: string]: AnyKeyCssProps<TValue> | CSSProps | BasicTemplateInterpolations | TValue,
21
+ ...
22
+ };
23
+ export type CssFunction<TValue = void> =
24
+ | CSSProps
25
+ | AnyKeyCssProps<TValue>
26
+ | $ReadOnlyArray<string>
27
+ | string
28
+ | boolean
29
+ | void;
package/src/types.tsx CHANGED
@@ -1,17 +1,21 @@
1
- import * as CSS from 'csstype';
1
+ import type * as CSS from 'csstype';
2
2
 
3
3
  /**
4
4
  * Typing for the interpolations.
5
5
  */
6
6
  export type BasicTemplateInterpolations = string | number;
7
7
 
8
+ export interface FunctionInterpolation<TProps> {
9
+ (props: TProps): CSSProps | BasicTemplateInterpolations | boolean | undefined;
10
+ }
11
+
8
12
  /**
9
13
  * These are all the CSS props that will exist.
10
14
  */
11
- export type CSSProps = CSS.Properties<string | number>;
15
+ export type CSSProps = CSS.Properties<BasicTemplateInterpolations>;
12
16
 
13
17
  export type AnyKeyCssProps<TValue> = {
14
- [key: string]: AnyKeyCssProps<TValue> | CSSProps | string | number | TValue;
18
+ [key: string]: AnyKeyCssProps<TValue> | CSSProps | BasicTemplateInterpolations | TValue;
15
19
  };
16
20
 
17
21
  export type CssFunction<TValue = void> =
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Flowtype definitions for error
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.15.0
5
+ * @flow
6
+ */
7
+ declare export var createSetupError: () => Error;
@@ -1,60 +0,0 @@
1
- import { JSCodeshift, ImportDeclaration, ImportDefaultSpecifier, ImportSpecifier, Program, Identifier, JSXIdentifier, TSTypeParameter, Node, Collection } from 'jscodeshift';
2
- declare type Identifiers = Array<Identifier | JSXIdentifier | TSTypeParameter>;
3
- export declare const getImportDeclarationCollection: ({ j, collection, importPath, }: {
4
- j: JSCodeshift;
5
- collection: Collection<any>;
6
- importPath: string;
7
- }) => Collection<ImportDeclaration>;
8
- export declare const hasImportDeclaration: ({ j, collection, importPath, }: {
9
- j: JSCodeshift;
10
- collection: Collection<any>;
11
- importPath: string;
12
- }) => boolean;
13
- export declare const getImportDefaultSpecifierName: (importDefaultSpecifierCollection: Collection<ImportDefaultSpecifier>) => string;
14
- export declare const getImportSpecifierName: (importSpecifierCollection: Collection<ImportSpecifier>) => string | undefined;
15
- export declare const getAllImportSpecifiers: ({ j, importDeclarationCollection, }: {
16
- j: JSCodeshift;
17
- importDeclarationCollection: Collection<ImportDeclaration>;
18
- }) => Identifiers;
19
- export declare const findImportSpecifierName: ({ j, importDeclarationCollection, importName, }: {
20
- j: JSCodeshift;
21
- importDeclarationCollection: Collection<ImportDeclaration>;
22
- importName: string;
23
- }) => string | null | undefined;
24
- export declare const convertDefaultImportToNamedImport: ({ j, collection, importPath, namedImport, }: {
25
- j: JSCodeshift;
26
- collection: Collection<any>;
27
- importPath: string;
28
- namedImport: string;
29
- }) => void;
30
- export declare const addCommentBefore: ({ j, collection, message, }: {
31
- j: JSCodeshift;
32
- collection: Collection<Program>;
33
- message: string;
34
- }) => void;
35
- export declare const addCommentToStartOfFile: ({ j, collection, message, }: {
36
- j: JSCodeshift;
37
- collection: Collection<Node>;
38
- message: string;
39
- }) => void;
40
- export declare const addCommentForUnresolvedImportSpecifiers: ({ j, collection, importPath, allowedImportSpecifierNames, }: {
41
- j: JSCodeshift;
42
- collection: Collection<Node>;
43
- importPath: string;
44
- allowedImportSpecifierNames: string[];
45
- }) => void;
46
- export declare const addReactIdentifier: ({ j, collection, }: {
47
- j: JSCodeshift;
48
- collection: Collection<Node>;
49
- }) => void;
50
- export declare const replaceImportDeclaration: ({ j, collection, importPath, }: {
51
- j: JSCodeshift;
52
- collection: Collection<Node>;
53
- importPath: string;
54
- }) => void;
55
- export declare const mergeImportSpecifiersAlongWithTheirComments: ({ j, collection, filter, }: {
56
- j: JSCodeshift;
57
- collection: Collection<Node>;
58
- filter?: ((name: string | undefined) => boolean) | undefined;
59
- }) => void;
60
- export {};
@@ -1,201 +0,0 @@
1
- import { COMPILED_IMPORT_PATH, REACT_IMPORT_PATH, REACT_IMPORT_NAME } from './constants';
2
- export var getImportDeclarationCollection = function (_a) {
3
- var j = _a.j, collection = _a.collection, importPath = _a.importPath;
4
- var found = collection
5
- .find(j.ImportDeclaration)
6
- .filter(function (importDeclarationPath) { return importDeclarationPath.node.source.value === importPath; });
7
- return found;
8
- };
9
- export var hasImportDeclaration = function (_a) {
10
- var j = _a.j, collection = _a.collection, importPath = _a.importPath;
11
- var result = getImportDeclarationCollection({
12
- j: j,
13
- collection: collection,
14
- importPath: importPath,
15
- });
16
- return result.length > 0;
17
- };
18
- export var getImportDefaultSpecifierName = function (importDefaultSpecifierCollection) {
19
- var name = importDefaultSpecifierCollection.nodes()[0].local.name;
20
- if (!name) {
21
- throw new Error('Name should exist.');
22
- }
23
- return name;
24
- };
25
- export var getImportSpecifierName = function (importSpecifierCollection) { return importSpecifierCollection.nodes()[0].local.name; };
26
- export var getAllImportSpecifiers = function (_a) {
27
- var j = _a.j, importDeclarationCollection = _a.importDeclarationCollection;
28
- var importSpecifiersImportedNodes = [];
29
- importDeclarationCollection.find(j.ImportSpecifier).forEach(function (importSpecifierPath) {
30
- var node = importSpecifierPath.node.imported;
31
- if (node) {
32
- importSpecifiersImportedNodes.push(node);
33
- }
34
- });
35
- return importSpecifiersImportedNodes;
36
- };
37
- export var findImportSpecifierName = function (_a) {
38
- var j = _a.j, importDeclarationCollection = _a.importDeclarationCollection, importName = _a.importName;
39
- var importSpecifierCollection = importDeclarationCollection
40
- .find(j.ImportSpecifier)
41
- .filter(function (importSpecifierPath) { return importSpecifierPath.node.imported.name === importName; });
42
- if (importSpecifierCollection.length === 0) {
43
- return null;
44
- }
45
- return getImportSpecifierName(importSpecifierCollection);
46
- };
47
- export var convertDefaultImportToNamedImport = function (_a) {
48
- var j = _a.j, collection = _a.collection, importPath = _a.importPath, namedImport = _a.namedImport;
49
- var importDeclarationCollection = getImportDeclarationCollection({
50
- j: j,
51
- collection: collection,
52
- importPath: importPath,
53
- });
54
- importDeclarationCollection.forEach(function (importDeclarationPath) {
55
- var importDefaultSpecifierCollection = j(importDeclarationPath).find(j.ImportDefaultSpecifier);
56
- if (importDefaultSpecifierCollection.length > 0) {
57
- var oldNode = importDeclarationPath.node;
58
- var comments = oldNode.comments;
59
- j(importDeclarationPath).replaceWith([
60
- j.importDeclaration([
61
- j.importSpecifier(j.identifier(namedImport), j.identifier(getImportDefaultSpecifierName(importDefaultSpecifierCollection))),
62
- ], j.literal(COMPILED_IMPORT_PATH)),
63
- ]);
64
- var newNode = importDeclarationPath.node;
65
- if (newNode !== oldNode) {
66
- newNode.comments = comments;
67
- }
68
- }
69
- });
70
- };
71
- // not replacing newlines (which \s does)
72
- var spacesAndTabs = /[ \t]{2,}/g;
73
- var lineStartWithSpaces = /^[ \t]*/gm;
74
- var clean = function (value) {
75
- return value
76
- .replace(spacesAndTabs, ' ')
77
- .replace(lineStartWithSpaces, '')
78
- // using .trim() to clear the any newlines before the first text and after last text
79
- .trim();
80
- };
81
- export var addCommentBefore = function (_a) {
82
- var j = _a.j, collection = _a.collection, message = _a.message;
83
- var content = " TODO(" + COMPILED_IMPORT_PATH + " codemod): " + clean(message) + " ";
84
- collection.forEach(function (path) {
85
- path.value.comments = path.value.comments || [];
86
- var exists = path.value.comments.find(function (comment) { return comment.value === content; });
87
- // avoiding duplicates of the same comment
88
- if (exists) {
89
- return;
90
- }
91
- path.value.comments.push(j.commentBlock(content));
92
- });
93
- };
94
- export var addCommentToStartOfFile = function (_a) {
95
- var j = _a.j, collection = _a.collection, message = _a.message;
96
- addCommentBefore({
97
- j: j,
98
- collection: collection.find(j.Program),
99
- message: message,
100
- });
101
- };
102
- export var addCommentForUnresolvedImportSpecifiers = function (_a) {
103
- var j = _a.j, collection = _a.collection, importPath = _a.importPath, allowedImportSpecifierNames = _a.allowedImportSpecifierNames;
104
- var importDeclarationCollection = getImportDeclarationCollection({
105
- j: j,
106
- collection: collection,
107
- importPath: importPath,
108
- });
109
- var importSpecifiers = getAllImportSpecifiers({
110
- j: j,
111
- importDeclarationCollection: importDeclarationCollection,
112
- });
113
- importSpecifiers
114
- .filter(function (identifierPath) { return !allowedImportSpecifierNames.includes(identifierPath.name); })
115
- .forEach(function (importSpecifierPath) {
116
- addCommentToStartOfFile({
117
- j: j,
118
- collection: collection,
119
- message: "\"" + importSpecifierPath.name + "\" is not exported from \"" + COMPILED_IMPORT_PATH + "\" at the moment. Please find an alternative for it.",
120
- });
121
- });
122
- };
123
- export var addReactIdentifier = function (_a) {
124
- var j = _a.j, collection = _a.collection;
125
- var hasReactImportDeclaration = hasImportDeclaration({
126
- j: j,
127
- collection: collection,
128
- importPath: REACT_IMPORT_PATH,
129
- });
130
- if (!hasReactImportDeclaration) {
131
- collection.find(j.Program).forEach(function (programPath) {
132
- programPath.node.body.unshift(j.importDeclaration([j.importNamespaceSpecifier(j.identifier(REACT_IMPORT_NAME))], j.literal(REACT_IMPORT_PATH)));
133
- });
134
- }
135
- else {
136
- var importDeclarationCollection = getImportDeclarationCollection({
137
- j: j,
138
- collection: collection,
139
- importPath: REACT_IMPORT_PATH,
140
- });
141
- importDeclarationCollection.forEach(function (importDeclarationPath) {
142
- var importDefaultSpecifierCollection = j(importDeclarationPath).find(j.ImportDefaultSpecifier);
143
- var importNamespaceSpecifierCollection = j(importDeclarationPath).find(j.ImportNamespaceSpecifier);
144
- var hasNoDefaultReactImportDeclaration = importDefaultSpecifierCollection.length === 0;
145
- var hasNoNamespaceReactImportDeclaration = importNamespaceSpecifierCollection.length === 0;
146
- if (hasNoDefaultReactImportDeclaration &&
147
- hasNoNamespaceReactImportDeclaration &&
148
- importDeclarationPath.node.specifiers) {
149
- importDeclarationPath.node.specifiers.unshift(j.importDefaultSpecifier(j.identifier(REACT_IMPORT_NAME)));
150
- }
151
- });
152
- }
153
- };
154
- export var replaceImportDeclaration = function (_a) {
155
- var j = _a.j, collection = _a.collection, importPath = _a.importPath;
156
- var importDeclarationCollection = getImportDeclarationCollection({
157
- j: j,
158
- collection: collection,
159
- importPath: importPath,
160
- });
161
- importDeclarationCollection.forEach(function (importDeclarationPath) {
162
- importDeclarationPath.node.source.value = COMPILED_IMPORT_PATH;
163
- });
164
- };
165
- export var mergeImportSpecifiersAlongWithTheirComments = function (_a) {
166
- var j = _a.j, collection = _a.collection, _b = _a.filter, filter = _b === void 0 ? function (_) { return true; } : _b;
167
- var importDeclarationCollection = getImportDeclarationCollection({
168
- j: j,
169
- collection: collection,
170
- importPath: COMPILED_IMPORT_PATH,
171
- });
172
- var importSpecifiers = [];
173
- importDeclarationCollection
174
- .find(j.ImportSpecifier)
175
- .filter(function (importSpecifierPath) { return filter(importSpecifierPath.node.imported.name); })
176
- .forEach(function (importSpecifierPath) {
177
- importSpecifiers.push(importSpecifierPath.node);
178
- });
179
- var importDeclarationCollectionLength = importDeclarationCollection.length;
180
- var importDeclarationComments = [];
181
- importDeclarationCollection.forEach(function (importDeclarationPath, index) {
182
- var oldNode = importDeclarationPath.node;
183
- var comments = oldNode.comments;
184
- if (comments) {
185
- importDeclarationComments.push.apply(importDeclarationComments, comments);
186
- }
187
- if (index === importDeclarationCollectionLength - 1) {
188
- j(importDeclarationPath).replaceWith([
189
- j.importDeclaration(importSpecifiers, j.literal(COMPILED_IMPORT_PATH)),
190
- ]);
191
- var newNode = importDeclarationPath.node;
192
- if (newNode !== oldNode) {
193
- newNode.comments = importDeclarationComments;
194
- }
195
- }
196
- else {
197
- j(importDeclarationPath).remove();
198
- }
199
- });
200
- };
201
- //# sourceMappingURL=codemods-helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codemods-helpers.js","sourceRoot":"","sources":["../../../src/codemods/codemods-helpers.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIzF,MAAM,CAAC,IAAM,8BAA8B,GAAG,UAAC,EAQ9C;QAPC,CAAC,OAAA,EACD,UAAU,gBAAA,EACV,UAAU,gBAAA;IAMV,IAAM,KAAK,GAAkC,UAAU;SACpD,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC;SACzB,MAAM,CAAC,UAAC,qBAAqB,IAAK,OAAA,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,UAAU,EAAtD,CAAsD,CAAC,CAAC;IAE7F,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,oBAAoB,GAAG,UAAC,EAQpC;QAPC,CAAC,OAAA,EACD,UAAU,gBAAA,EACV,UAAU,gBAAA;IAMV,IAAM,MAAM,GAAkC,8BAA8B,CAAC;QAC3E,CAAC,GAAA;QACD,UAAU,YAAA;QACV,UAAU,YAAA;KACX,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,6BAA6B,GAAG,UAC3C,gCAAoE;IAEpE,IAAM,IAAI,GAAG,gCAAgC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAE,CAAC,KAAM,CAAC,IAAI,CAAC;IACtE,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,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- export var COMPILED_IMPORT_PATH = '@compiled/react';
2
- export var REACT_IMPORT_PATH = 'react';
3
- export var REACT_IMPORT_NAME = 'React';
4
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/codemods/constants.tsx"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD,MAAM,CAAC,IAAM,iBAAiB,GAAG,OAAO,CAAC;AACzC,MAAM,CAAC,IAAM,iBAAiB,GAAG,OAAO,CAAC"}
@@ -1,3 +0,0 @@
1
- import { FileInfo, API, Options } from 'jscodeshift';
2
- declare const transformer: (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => string;
3
- export default transformer;
@@ -1,178 +0,0 @@
1
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
2
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
3
- to[j] = from[i];
4
- return to;
5
- };
6
- import { COMPILED_IMPORT_PATH } from '../constants';
7
- import { hasImportDeclaration, getImportDeclarationCollection, findImportSpecifierName, addCommentForUnresolvedImportSpecifiers, addReactIdentifier, convertDefaultImportToNamedImport, replaceImportDeclaration, mergeImportSpecifiersAlongWithTheirComments, addCommentBefore, } from '../codemods-helpers';
8
- var imports = {
9
- compiledStyledImportName: 'styled',
10
- emotionStyledPackageName: '@emotion/styled',
11
- emotionCoreJSXPragma: '@jsx jsx',
12
- emotionCoreImportNames: { jsx: 'jsx', css: 'css', ClassNames: 'ClassNames' },
13
- emotionCorePackageName: '@emotion/core',
14
- };
15
- var removeEmotionCoreJSXPragma = function (j, collection) {
16
- var commentCollection = collection.find(j.Comment);
17
- commentCollection.forEach(function (commentPath) {
18
- var commentBlockCollection = j(commentPath).filter(function (commentBlockPath) {
19
- return commentBlockPath.value.value.includes(imports.emotionCoreJSXPragma);
20
- });
21
- commentBlockCollection.forEach(function (commentBlockPath) {
22
- j(commentBlockPath).remove();
23
- addReactIdentifier({ j: j, collection: collection });
24
- });
25
- });
26
- };
27
- var replaceEmotionCoreCSSTaggedTemplateExpression = function (j, collection) {
28
- var importDeclarationCollection = getImportDeclarationCollection({
29
- j: j,
30
- collection: collection,
31
- importPath: imports.emotionCorePackageName,
32
- });
33
- var name = findImportSpecifierName({
34
- j: j,
35
- importDeclarationCollection: importDeclarationCollection,
36
- importName: imports.emotionCoreImportNames.css,
37
- });
38
- if (name == null) {
39
- return;
40
- }
41
- collection
42
- .find(j.TaggedTemplateExpression)
43
- .filter(function (taggedTemplateExpressionPath) {
44
- return j(taggedTemplateExpressionPath)
45
- .find(j.Identifier)
46
- .some(function (identifierPath) { return identifierPath.node.name === name; });
47
- })
48
- .forEach(function (taggedTemplateExpressionPath) {
49
- var quasi = taggedTemplateExpressionPath.node.quasi;
50
- if (quasi) {
51
- j(taggedTemplateExpressionPath).replaceWith([quasi]);
52
- }
53
- });
54
- };
55
- var handleClassNamesCXBehavior = function (j, objectPattern) {
56
- var cxIdentifierName = 'cx';
57
- var axIdentifierName = 'ax';
58
- var compiledRuntimePackageName = COMPILED_IMPORT_PATH + "/runtime";
59
- var cxObjectPropertyCollection = j(objectPattern)
60
- .find(j.ObjectProperty)
61
- .filter(function (objectPropertyPath) {
62
- return objectPropertyPath.node.key.type === 'Identifier' &&
63
- objectPropertyPath.node.key.name === cxIdentifierName;
64
- });
65
- cxObjectPropertyCollection.forEach(function (cxObjectPropertyPath) {
66
- addCommentBefore({
67
- j: j,
68
- collection: j(cxObjectPropertyPath.node),
69
- message: "Please replace \"" + cxIdentifierName + "\" with \"" + axIdentifierName + "\" from \"" + compiledRuntimePackageName + "\".\n Usage: import { " + axIdentifierName + " } from '" + compiledRuntimePackageName + "';\n\n NOTE: Both \"" + cxIdentifierName + "\" and \"" + axIdentifierName + "\" have some differences, so we have not replaced its usage.\n Please check the docs for \"" + axIdentifierName + "\" usage.\n\n In future, we will expose \"" + axIdentifierName + "\" directly from \"" + imports.emotionCoreImportNames.ClassNames + "\" props.\n\n Issue tracked on Github: https://github.com/atlassian-labs/compiled/issues/373",
70
- });
71
- });
72
- };
73
- var handleClassNamesStyleBehavior = function (j, objectPattern) {
74
- var styleIdentifierName = 'style';
75
- var hasStyleObjectProperty = j(objectPattern)
76
- .find(j.ObjectProperty)
77
- .some(function (objectPropertyPath) {
78
- return objectPropertyPath.node.key.type === 'Identifier' &&
79
- objectPropertyPath.node.key.name === styleIdentifierName;
80
- });
81
- if (!hasStyleObjectProperty) {
82
- var styleObjectProperty = j.objectProperty(j.identifier(styleIdentifierName), j.identifier(styleIdentifierName));
83
- objectPattern.properties.push(styleObjectProperty);
84
- addCommentBefore({
85
- j: j,
86
- collection: j(styleObjectProperty),
87
- message: "We have exported \"" + styleIdentifierName + "\" from \"" + imports.emotionCoreImportNames.ClassNames + "\" props.\n If you are using dynamic declarations, make sure to set the \"" + styleIdentifierName + "\"\n prop otherwise remove it.",
88
- });
89
- }
90
- };
91
- var handleClassNamesBehavior = function (j, collection) {
92
- var importDeclarationCollection = getImportDeclarationCollection({
93
- j: j,
94
- collection: collection,
95
- importPath: imports.emotionCorePackageName,
96
- });
97
- var name = findImportSpecifierName({
98
- j: j,
99
- importDeclarationCollection: importDeclarationCollection,
100
- importName: imports.emotionCoreImportNames.ClassNames,
101
- });
102
- if (name == null) {
103
- return;
104
- }
105
- collection
106
- .find(j.JSXElement)
107
- .filter(function (jsxElementPath) {
108
- return j(jsxElementPath)
109
- .find(j.JSXIdentifier)
110
- .some(function (jsxIdentifierPath) { return jsxIdentifierPath.node.name === name; });
111
- })
112
- .find(j.JSXExpressionContainer)
113
- .forEach(function (jsxExpressionContainer) {
114
- var expression = jsxExpressionContainer.node.expression;
115
- if (expression.type === 'FunctionExpression' ||
116
- expression.type === 'ArrowFunctionExpression') {
117
- if (expression.params.length && expression.params[0].type === 'ObjectPattern') {
118
- var objectPattern = expression.params[0];
119
- handleClassNamesStyleBehavior(j, objectPattern);
120
- handleClassNamesCXBehavior(j, objectPattern);
121
- }
122
- }
123
- });
124
- };
125
- var mergeCompiledImportSpecifiers = function (j, collection) {
126
- var allowedCompiledNames = __spreadArray([
127
- imports.compiledStyledImportName
128
- ], Object.values(imports.emotionCoreImportNames)).filter(function (name) {
129
- return ![imports.emotionCoreImportNames.jsx, imports.emotionCoreImportNames.css].includes(name);
130
- });
131
- mergeImportSpecifiersAlongWithTheirComments({
132
- j: j,
133
- collection: collection,
134
- filter: function (name) { return !!(name && allowedCompiledNames.includes(name)); },
135
- });
136
- };
137
- var transformer = function (fileInfo, _a, options) {
138
- var j = _a.jscodeshift;
139
- var source = fileInfo.source;
140
- var collection = j(source);
141
- var hasEmotionCoreImportDeclaration = hasImportDeclaration({
142
- j: j,
143
- collection: collection,
144
- importPath: imports.emotionCorePackageName,
145
- });
146
- var hasEmotionStyledImportDeclaration = hasImportDeclaration({
147
- j: j,
148
- collection: collection,
149
- importPath: imports.emotionStyledPackageName,
150
- });
151
- if (!hasEmotionCoreImportDeclaration && !hasEmotionStyledImportDeclaration) {
152
- return source;
153
- }
154
- if (hasEmotionStyledImportDeclaration) {
155
- convertDefaultImportToNamedImport({
156
- j: j,
157
- collection: collection,
158
- importPath: imports.emotionStyledPackageName,
159
- namedImport: imports.compiledStyledImportName,
160
- });
161
- }
162
- if (hasEmotionCoreImportDeclaration) {
163
- removeEmotionCoreJSXPragma(j, collection);
164
- addCommentForUnresolvedImportSpecifiers({
165
- j: j,
166
- collection: collection,
167
- importPath: imports.emotionCorePackageName,
168
- allowedImportSpecifierNames: Object.values(imports.emotionCoreImportNames),
169
- });
170
- replaceEmotionCoreCSSTaggedTemplateExpression(j, collection);
171
- handleClassNamesBehavior(j, collection);
172
- replaceImportDeclaration({ j: j, collection: collection, importPath: imports.emotionCorePackageName });
173
- }
174
- mergeCompiledImportSpecifiers(j, collection);
175
- return collection.toSource(options.printOptions || { quote: 'single' });
176
- };
177
- export default transformer;
178
- //# sourceMappingURL=emotion-to-compiled.js.map