@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.
- package/CHANGELOG.md +68 -1
- package/dist/browser/class-names/index.d.ts +2 -2
- package/dist/browser/class-names/index.js.flow +45 -0
- package/dist/browser/class-names/index.js.map +1 -1
- package/dist/browser/css/index.d.ts +16 -3
- package/dist/browser/css/index.js +1 -13
- package/dist/browser/css/index.js.flow +35 -0
- package/dist/browser/css/index.js.map +1 -1
- package/dist/browser/index.d.ts +15 -23
- package/dist/browser/index.js +4 -0
- package/dist/browser/index.js.flow +15 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/browser/jsx/jsx-dev-runtime.js +4 -0
- package/dist/browser/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/browser/jsx/jsx-local-namespace.d.ts +40 -0
- package/dist/browser/jsx/jsx-local-namespace.js +2 -0
- package/dist/browser/jsx/jsx-local-namespace.js.map +1 -0
- package/dist/browser/jsx/jsx-runtime.d.ts +2 -0
- package/dist/browser/jsx/jsx-runtime.js +4 -0
- package/dist/browser/jsx/jsx-runtime.js.map +1 -0
- package/dist/browser/keyframes/index.js.flow +54 -0
- package/dist/browser/runtime/ax.js.flow +27 -0
- package/dist/browser/runtime/css-custom-property.d.ts +1 -1
- package/dist/browser/runtime/css-custom-property.js.flow +19 -0
- package/dist/browser/runtime/css-custom-property.js.map +1 -1
- package/dist/browser/runtime/dev-warnings.d.ts +0 -1
- package/dist/browser/runtime/dev-warnings.js +1 -1
- package/dist/browser/runtime/dev-warnings.js.flow +7 -0
- package/dist/browser/runtime/dev-warnings.js.map +1 -1
- package/dist/browser/runtime/index.js.flow +10 -0
- package/dist/browser/runtime/is-node.js.flow +19 -0
- package/dist/browser/runtime/sheet.d.ts +1 -1
- package/dist/browser/runtime/sheet.js.flow +36 -0
- package/dist/browser/runtime/style-cache.d.ts +1 -1
- package/dist/browser/runtime/style-cache.js.flow +19 -0
- package/dist/browser/runtime/style-cache.js.map +1 -1
- package/dist/browser/runtime/style.d.ts +1 -1
- package/dist/browser/runtime/style.js +2 -2
- package/dist/browser/runtime/style.js.flow +17 -0
- package/dist/browser/runtime/style.js.map +1 -1
- package/dist/browser/runtime/types.js.flow +23 -0
- package/dist/browser/runtime.js.flow +7 -0
- package/dist/browser/styled/index.d.ts +6 -9
- package/dist/browser/styled/index.js.flow +69 -0
- package/dist/browser/styled/index.js.map +1 -1
- package/dist/browser/types.d.ts +6 -3
- package/dist/browser/types.js.flow +29 -0
- package/dist/browser/utils/error.js.flow +7 -0
- package/dist/cjs/class-names/index.d.ts +2 -2
- package/dist/cjs/class-names/index.js.flow +45 -0
- package/dist/cjs/class-names/index.js.map +1 -1
- package/dist/cjs/css/index.d.ts +16 -3
- package/dist/cjs/css/index.js +1 -13
- package/dist/cjs/css/index.js.flow +35 -0
- package/dist/cjs/css/index.js.map +1 -1
- package/dist/cjs/index.d.ts +15 -23
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.flow +15 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/cjs/jsx/jsx-dev-runtime.js +16 -0
- package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/cjs/jsx/jsx-local-namespace.d.ts +40 -0
- package/dist/cjs/jsx/jsx-local-namespace.js +3 -0
- package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -0
- package/dist/cjs/jsx/jsx-runtime.d.ts +2 -0
- package/dist/cjs/jsx/jsx-runtime.js +16 -0
- package/dist/cjs/jsx/jsx-runtime.js.map +1 -0
- package/dist/cjs/keyframes/index.js.flow +54 -0
- package/dist/cjs/runtime/ax.js.flow +27 -0
- package/dist/cjs/runtime/css-custom-property.d.ts +1 -1
- package/dist/cjs/runtime/css-custom-property.js.flow +19 -0
- package/dist/cjs/runtime/css-custom-property.js.map +1 -1
- package/dist/cjs/runtime/dev-warnings.d.ts +0 -1
- package/dist/cjs/runtime/dev-warnings.js +2 -3
- package/dist/cjs/runtime/dev-warnings.js.flow +7 -0
- package/dist/cjs/runtime/dev-warnings.js.map +1 -1
- package/dist/cjs/runtime/index.js.flow +10 -0
- package/dist/cjs/runtime/is-node.js.flow +19 -0
- package/dist/cjs/runtime/sheet.d.ts +1 -1
- package/dist/cjs/runtime/sheet.js.flow +36 -0
- package/dist/cjs/runtime/style-cache.d.ts +1 -1
- package/dist/cjs/runtime/style-cache.js.flow +19 -0
- package/dist/cjs/runtime/style-cache.js.map +1 -1
- package/dist/cjs/runtime/style.d.ts +1 -1
- package/dist/cjs/runtime/style.js +2 -2
- package/dist/cjs/runtime/style.js.flow +17 -0
- package/dist/cjs/runtime/style.js.map +1 -1
- package/dist/cjs/runtime/types.js.flow +23 -0
- package/dist/cjs/runtime.js.flow +7 -0
- package/dist/cjs/styled/index.d.ts +6 -9
- package/dist/cjs/styled/index.js.flow +69 -0
- package/dist/cjs/styled/index.js.map +1 -1
- package/dist/cjs/types.d.ts +6 -3
- package/dist/cjs/types.js.flow +29 -0
- package/dist/cjs/utils/error.js.flow +7 -0
- package/dist/esm/class-names/index.d.ts +2 -2
- package/dist/esm/class-names/index.js.flow +45 -0
- package/dist/esm/class-names/index.js.map +1 -1
- package/dist/esm/css/index.d.ts +16 -3
- package/dist/esm/css/index.js +1 -13
- package/dist/esm/css/index.js.flow +35 -0
- package/dist/esm/css/index.js.map +1 -1
- package/dist/esm/index.d.ts +15 -23
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.flow +15 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/esm/jsx/jsx-dev-runtime.js +4 -0
- package/dist/esm/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/esm/jsx/jsx-local-namespace.d.ts +40 -0
- package/dist/esm/jsx/jsx-local-namespace.js +2 -0
- package/dist/esm/jsx/jsx-local-namespace.js.map +1 -0
- package/dist/esm/jsx/jsx-runtime.d.ts +2 -0
- package/dist/esm/jsx/jsx-runtime.js +4 -0
- package/dist/esm/jsx/jsx-runtime.js.map +1 -0
- package/dist/esm/keyframes/index.js.flow +54 -0
- package/dist/esm/runtime/ax.js.flow +27 -0
- package/dist/esm/runtime/css-custom-property.d.ts +1 -1
- package/dist/esm/runtime/css-custom-property.js.flow +19 -0
- package/dist/esm/runtime/css-custom-property.js.map +1 -1
- package/dist/esm/runtime/dev-warnings.d.ts +0 -1
- package/dist/esm/runtime/dev-warnings.js +1 -1
- package/dist/esm/runtime/dev-warnings.js.flow +7 -0
- package/dist/esm/runtime/dev-warnings.js.map +1 -1
- package/dist/esm/runtime/index.js.flow +10 -0
- package/dist/esm/runtime/is-node.js.flow +19 -0
- package/dist/esm/runtime/sheet.d.ts +1 -1
- package/dist/esm/runtime/sheet.js.flow +36 -0
- package/dist/esm/runtime/style-cache.d.ts +1 -1
- package/dist/esm/runtime/style-cache.js.flow +19 -0
- package/dist/esm/runtime/style-cache.js.map +1 -1
- package/dist/esm/runtime/style.d.ts +1 -1
- package/dist/esm/runtime/style.js +2 -2
- package/dist/esm/runtime/style.js.flow +17 -0
- package/dist/esm/runtime/style.js.map +1 -1
- package/dist/esm/runtime/types.js.flow +23 -0
- package/dist/esm/runtime.js.flow +7 -0
- package/dist/esm/styled/index.d.ts +6 -9
- package/dist/esm/styled/index.js.flow +69 -0
- package/dist/esm/styled/index.js.map +1 -1
- package/dist/esm/types.d.ts +6 -3
- package/dist/esm/types.js.flow +29 -0
- package/dist/esm/utils/error.js.flow +7 -0
- package/jsx-dev-runtime/package.json +6 -0
- package/jsx-runtime/package.json +6 -0
- package/package.json +41 -15
- package/src/__tests__/browser.test.tsx +5 -5
- package/src/__tests__/jest-matcher.test.tsx +197 -0
- package/src/__tests__/server-side-hydrate.test.tsx +1 -0
- package/src/__tests__/ssr.test.tsx +2 -2
- package/src/class-names/__tests__/index.test.tsx +1 -1
- package/src/class-names/__tests__/types.test.js.flow +28 -0
- package/src/class-names/index.js.flow +45 -0
- package/src/class-names/index.tsx +3 -2
- package/src/css/__tests__/index.test.tsx +40 -0
- package/src/css/__tests__/types.test.js.flow +17 -0
- package/src/css/index.js.flow +35 -0
- package/src/css/index.tsx +27 -3
- package/src/index.js.flow +15 -0
- package/src/index.tsx +20 -26
- package/src/jsx/__tests__/index.test.tsx +1 -2
- package/src/jsx/__tests__/jsx-import-source-pragma.test.tsx +37 -0
- package/src/jsx/__tests__/jsx-pragma.test.tsx +39 -0
- package/src/jsx/jsx-dev-runtime.tsx +5 -0
- package/src/jsx/jsx-local-namespace.tsx +49 -0
- package/src/jsx/jsx-runtime.tsx +5 -0
- package/src/keyframes/__tests__/index.test.tsx +2 -1
- package/src/keyframes/__tests__/types.test.js.flow +31 -0
- package/src/keyframes/index.js.flow +54 -0
- package/src/runtime/__perf__/ax.test.ts +42 -0
- package/src/runtime/__perf__/cs.test.tsx +111 -0
- package/src/runtime/__perf__/sheet.test.ts +61 -0
- package/src/runtime/__perf__/utils/cs.tsx +60 -0
- package/src/runtime/__perf__/utils/sheet.tsx +151 -0
- package/src/runtime/__tests__/style-ssr.test.tsx +1 -0
- package/src/runtime/__tests__/style.test.tsx +92 -58
- package/src/runtime/ax.js.flow +27 -0
- package/src/runtime/css-custom-property.js.flow +19 -0
- package/src/runtime/css-custom-property.tsx +1 -1
- package/src/runtime/dev-warnings.js.flow +7 -0
- package/src/runtime/dev-warnings.tsx +1 -1
- package/src/runtime/index.js.flow +10 -0
- package/src/runtime/is-node.js.flow +19 -0
- package/src/runtime/sheet.js.flow +36 -0
- package/src/runtime/sheet.tsx +1 -1
- package/src/runtime/style-cache.js.flow +19 -0
- package/src/runtime/style-cache.tsx +2 -1
- package/src/runtime/style.js.flow +17 -0
- package/src/runtime/style.tsx +4 -3
- package/src/runtime/types.js.flow +23 -0
- package/src/runtime.js.flow +7 -0
- package/src/styled/__tests__/index.test.tsx +3 -3
- package/src/styled/__tests__/types.test.js.flow +30 -0
- package/src/styled/index.js.flow +69 -0
- package/src/styled/index.tsx +7 -10
- package/src/types.js.flow +29 -0
- package/src/types.tsx +7 -3
- package/src/utils/error.js.flow +7 -0
- package/dist/browser/codemods/codemods-helpers.d.ts +0 -60
- package/dist/browser/codemods/codemods-helpers.js +0 -201
- package/dist/browser/codemods/codemods-helpers.js.map +0 -1
- package/dist/browser/codemods/constants.d.ts +0 -3
- package/dist/browser/codemods/constants.js +0 -4
- package/dist/browser/codemods/constants.js.map +0 -1
- package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
- package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
- package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
- package/dist/browser/codemods/emotion-to-compiled/index.d.ts +0 -1
- package/dist/browser/codemods/emotion-to-compiled/index.js +0 -2
- package/dist/browser/codemods/emotion-to-compiled/index.js.map +0 -1
- package/dist/browser/codemods/styled-components-to-compiled/index.d.ts +0 -1
- package/dist/browser/codemods/styled-components-to-compiled/index.js +0 -2
- package/dist/browser/codemods/styled-components-to-compiled/index.js.map +0 -1
- package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
- package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
- package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
- package/dist/cjs/codemods/codemods-helpers.d.ts +0 -60
- package/dist/cjs/codemods/codemods-helpers.js +0 -217
- package/dist/cjs/codemods/codemods-helpers.js.map +0 -1
- package/dist/cjs/codemods/constants.d.ts +0 -3
- package/dist/cjs/codemods/constants.js +0 -7
- package/dist/cjs/codemods/constants.js.map +0 -1
- package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
- package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -180
- package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
- package/dist/cjs/codemods/emotion-to-compiled/index.d.ts +0 -1
- package/dist/cjs/codemods/emotion-to-compiled/index.js +0 -9
- package/dist/cjs/codemods/emotion-to-compiled/index.js.map +0 -1
- package/dist/cjs/codemods/styled-components-to-compiled/index.d.ts +0 -1
- package/dist/cjs/codemods/styled-components-to-compiled/index.js +0 -9
- package/dist/cjs/codemods/styled-components-to-compiled/index.js.map +0 -1
- package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
- package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -35
- package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
- package/dist/esm/codemods/codemods-helpers.d.ts +0 -60
- package/dist/esm/codemods/codemods-helpers.js +0 -201
- package/dist/esm/codemods/codemods-helpers.js.map +0 -1
- package/dist/esm/codemods/constants.d.ts +0 -3
- package/dist/esm/codemods/constants.js +0 -4
- package/dist/esm/codemods/constants.js.map +0 -1
- package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
- package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
- package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
- package/dist/esm/codemods/emotion-to-compiled/index.d.ts +0 -1
- package/dist/esm/codemods/emotion-to-compiled/index.js +0 -2
- package/dist/esm/codemods/emotion-to-compiled/index.js.map +0 -1
- package/dist/esm/codemods/styled-components-to-compiled/index.d.ts +0 -1
- package/dist/esm/codemods/styled-components-to-compiled/index.js +0 -2
- package/dist/esm/codemods/styled-components-to-compiled/index.js.map +0 -1
- package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
- package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
- package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
- package/src/codemods/README.md +0 -8
- package/src/codemods/codemods-helpers.tsx +0 -369
- package/src/codemods/constants.tsx +0 -3
- package/src/codemods/emotion-to-compiled/README.md +0 -71
- package/src/codemods/emotion-to-compiled/__tests__/emotion-to-compiled.test.tsx +0 -526
- package/src/codemods/emotion-to-compiled/emotion-to-compiled.tsx +0 -249
- package/src/codemods/emotion-to-compiled/index.tsx +0 -1
- package/src/codemods/styled-components-to-compiled/README.md +0 -37
- package/src/codemods/styled-components-to-compiled/__tests__/styled-components-to-compiled.test.tsx +0 -109
- package/src/codemods/styled-components-to-compiled/index.tsx +0 -1
- package/src/codemods/styled-components-to-compiled/styled-components-to-compiled.tsx +0 -45
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
JSCodeshift,
|
|
3
|
-
ImportDeclaration,
|
|
4
|
-
ImportDefaultSpecifier,
|
|
5
|
-
ImportSpecifier,
|
|
6
|
-
Program,
|
|
7
|
-
Identifier,
|
|
8
|
-
JSXIdentifier,
|
|
9
|
-
TSTypeParameter,
|
|
10
|
-
Node,
|
|
11
|
-
ImportNamespaceSpecifier,
|
|
12
|
-
Collection,
|
|
13
|
-
} from 'jscodeshift';
|
|
14
|
-
import { COMPILED_IMPORT_PATH, REACT_IMPORT_PATH, REACT_IMPORT_NAME } from './constants';
|
|
15
|
-
|
|
16
|
-
type Identifiers = Array<Identifier | JSXIdentifier | TSTypeParameter>;
|
|
17
|
-
|
|
18
|
-
export const getImportDeclarationCollection = ({
|
|
19
|
-
j,
|
|
20
|
-
collection,
|
|
21
|
-
importPath,
|
|
22
|
-
}: {
|
|
23
|
-
j: JSCodeshift;
|
|
24
|
-
collection: Collection<any>;
|
|
25
|
-
importPath: string;
|
|
26
|
-
}): Collection<ImportDeclaration> => {
|
|
27
|
-
const found: Collection<ImportDeclaration> = collection
|
|
28
|
-
.find(j.ImportDeclaration)
|
|
29
|
-
.filter((importDeclarationPath) => importDeclarationPath.node.source.value === importPath);
|
|
30
|
-
|
|
31
|
-
return found;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const hasImportDeclaration = ({
|
|
35
|
-
j,
|
|
36
|
-
collection,
|
|
37
|
-
importPath,
|
|
38
|
-
}: {
|
|
39
|
-
j: JSCodeshift;
|
|
40
|
-
collection: Collection<any>;
|
|
41
|
-
importPath: string;
|
|
42
|
-
}): boolean => {
|
|
43
|
-
const result: Collection<ImportDeclaration> = getImportDeclarationCollection({
|
|
44
|
-
j,
|
|
45
|
-
collection,
|
|
46
|
-
importPath,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return result.length > 0;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const getImportDefaultSpecifierName = (
|
|
53
|
-
importDefaultSpecifierCollection: Collection<ImportDefaultSpecifier>
|
|
54
|
-
): string => {
|
|
55
|
-
const name = importDefaultSpecifierCollection.nodes()[0]!.local!.name;
|
|
56
|
-
if (!name) {
|
|
57
|
-
throw new Error('Name should exist.');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return name;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const getImportSpecifierName = (
|
|
64
|
-
importSpecifierCollection: Collection<ImportSpecifier>
|
|
65
|
-
): string | undefined => importSpecifierCollection.nodes()[0]!.local!.name;
|
|
66
|
-
|
|
67
|
-
export const getAllImportSpecifiers = ({
|
|
68
|
-
j,
|
|
69
|
-
importDeclarationCollection,
|
|
70
|
-
}: {
|
|
71
|
-
j: JSCodeshift;
|
|
72
|
-
importDeclarationCollection: Collection<ImportDeclaration>;
|
|
73
|
-
}): Identifiers => {
|
|
74
|
-
const importSpecifiersImportedNodes: Identifiers = [];
|
|
75
|
-
|
|
76
|
-
importDeclarationCollection.find(j.ImportSpecifier).forEach((importSpecifierPath) => {
|
|
77
|
-
const node = importSpecifierPath.node.imported;
|
|
78
|
-
|
|
79
|
-
if (node) {
|
|
80
|
-
importSpecifiersImportedNodes.push(node);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return importSpecifiersImportedNodes;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export const findImportSpecifierName = ({
|
|
88
|
-
j,
|
|
89
|
-
importDeclarationCollection,
|
|
90
|
-
importName,
|
|
91
|
-
}: {
|
|
92
|
-
j: JSCodeshift;
|
|
93
|
-
importDeclarationCollection: Collection<ImportDeclaration>;
|
|
94
|
-
importName: string;
|
|
95
|
-
}): string | null | undefined => {
|
|
96
|
-
const importSpecifierCollection: Collection<ImportSpecifier> = importDeclarationCollection
|
|
97
|
-
.find(j.ImportSpecifier)
|
|
98
|
-
.filter((importSpecifierPath) => importSpecifierPath.node.imported.name === importName);
|
|
99
|
-
|
|
100
|
-
if (importSpecifierCollection.length === 0) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return getImportSpecifierName(importSpecifierCollection);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const convertDefaultImportToNamedImport = ({
|
|
108
|
-
j,
|
|
109
|
-
collection,
|
|
110
|
-
importPath,
|
|
111
|
-
namedImport,
|
|
112
|
-
}: {
|
|
113
|
-
j: JSCodeshift;
|
|
114
|
-
collection: Collection<any>;
|
|
115
|
-
importPath: string;
|
|
116
|
-
namedImport: string;
|
|
117
|
-
}): void => {
|
|
118
|
-
const importDeclarationCollection: Collection<ImportDeclaration> = getImportDeclarationCollection(
|
|
119
|
-
{
|
|
120
|
-
j,
|
|
121
|
-
collection,
|
|
122
|
-
importPath,
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
importDeclarationCollection.forEach((importDeclarationPath) => {
|
|
127
|
-
const importDefaultSpecifierCollection = j(importDeclarationPath).find(
|
|
128
|
-
j.ImportDefaultSpecifier
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
if (importDefaultSpecifierCollection.length > 0) {
|
|
132
|
-
const oldNode = importDeclarationPath.node;
|
|
133
|
-
const { comments } = oldNode;
|
|
134
|
-
|
|
135
|
-
j(importDeclarationPath).replaceWith([
|
|
136
|
-
j.importDeclaration(
|
|
137
|
-
[
|
|
138
|
-
j.importSpecifier(
|
|
139
|
-
j.identifier(namedImport),
|
|
140
|
-
j.identifier(getImportDefaultSpecifierName(importDefaultSpecifierCollection))
|
|
141
|
-
),
|
|
142
|
-
],
|
|
143
|
-
j.literal(COMPILED_IMPORT_PATH)
|
|
144
|
-
),
|
|
145
|
-
]);
|
|
146
|
-
|
|
147
|
-
const newNode = importDeclarationPath.node;
|
|
148
|
-
|
|
149
|
-
if (newNode !== oldNode) {
|
|
150
|
-
newNode.comments = comments;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// not replacing newlines (which \s does)
|
|
157
|
-
const spacesAndTabs = /[ \t]{2,}/g;
|
|
158
|
-
const lineStartWithSpaces = /^[ \t]*/gm;
|
|
159
|
-
|
|
160
|
-
const clean = (value: string) =>
|
|
161
|
-
value
|
|
162
|
-
.replace(spacesAndTabs, ' ')
|
|
163
|
-
.replace(lineStartWithSpaces, '')
|
|
164
|
-
// using .trim() to clear the any newlines before the first text and after last text
|
|
165
|
-
.trim();
|
|
166
|
-
|
|
167
|
-
export const addCommentBefore = ({
|
|
168
|
-
j,
|
|
169
|
-
collection,
|
|
170
|
-
message,
|
|
171
|
-
}: {
|
|
172
|
-
j: JSCodeshift;
|
|
173
|
-
collection: Collection<Program>;
|
|
174
|
-
message: string;
|
|
175
|
-
}): void => {
|
|
176
|
-
const content = ` TODO(${COMPILED_IMPORT_PATH} codemod): ${clean(message)} `;
|
|
177
|
-
collection.forEach((path) => {
|
|
178
|
-
path.value.comments = path.value.comments || [];
|
|
179
|
-
|
|
180
|
-
const exists = path.value.comments.find((comment) => comment.value === content);
|
|
181
|
-
|
|
182
|
-
// avoiding duplicates of the same comment
|
|
183
|
-
if (exists) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
path.value.comments.push(j.commentBlock(content));
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export const addCommentToStartOfFile = ({
|
|
192
|
-
j,
|
|
193
|
-
collection,
|
|
194
|
-
message,
|
|
195
|
-
}: {
|
|
196
|
-
j: JSCodeshift;
|
|
197
|
-
collection: Collection<Node>;
|
|
198
|
-
message: string;
|
|
199
|
-
}): void => {
|
|
200
|
-
addCommentBefore({
|
|
201
|
-
j,
|
|
202
|
-
collection: collection.find(j.Program),
|
|
203
|
-
message,
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
export const addCommentForUnresolvedImportSpecifiers = ({
|
|
208
|
-
j,
|
|
209
|
-
collection,
|
|
210
|
-
importPath,
|
|
211
|
-
allowedImportSpecifierNames,
|
|
212
|
-
}: {
|
|
213
|
-
j: JSCodeshift;
|
|
214
|
-
collection: Collection<Node>;
|
|
215
|
-
importPath: string;
|
|
216
|
-
allowedImportSpecifierNames: string[];
|
|
217
|
-
}): void => {
|
|
218
|
-
const importDeclarationCollection: Collection<ImportDeclaration> = getImportDeclarationCollection(
|
|
219
|
-
{
|
|
220
|
-
j,
|
|
221
|
-
collection,
|
|
222
|
-
importPath,
|
|
223
|
-
}
|
|
224
|
-
);
|
|
225
|
-
const importSpecifiers: Identifiers = getAllImportSpecifiers({
|
|
226
|
-
j,
|
|
227
|
-
importDeclarationCollection,
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
importSpecifiers
|
|
231
|
-
.filter((identifierPath) => !allowedImportSpecifierNames.includes(identifierPath.name))
|
|
232
|
-
.forEach((importSpecifierPath) => {
|
|
233
|
-
addCommentToStartOfFile({
|
|
234
|
-
j,
|
|
235
|
-
collection,
|
|
236
|
-
message: `"${importSpecifierPath.name}" is not exported from "${COMPILED_IMPORT_PATH}" at the moment. Please find an alternative for it.`,
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
export const addReactIdentifier = ({
|
|
242
|
-
j,
|
|
243
|
-
collection,
|
|
244
|
-
}: {
|
|
245
|
-
j: JSCodeshift;
|
|
246
|
-
collection: Collection<Node>;
|
|
247
|
-
}): void => {
|
|
248
|
-
const hasReactImportDeclaration: boolean = hasImportDeclaration({
|
|
249
|
-
j,
|
|
250
|
-
collection,
|
|
251
|
-
importPath: REACT_IMPORT_PATH,
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
if (!hasReactImportDeclaration) {
|
|
255
|
-
collection.find(j.Program).forEach((programPath) => {
|
|
256
|
-
programPath.node.body.unshift(
|
|
257
|
-
j.importDeclaration(
|
|
258
|
-
[j.importNamespaceSpecifier(j.identifier(REACT_IMPORT_NAME))],
|
|
259
|
-
j.literal(REACT_IMPORT_PATH)
|
|
260
|
-
)
|
|
261
|
-
);
|
|
262
|
-
});
|
|
263
|
-
} else {
|
|
264
|
-
const importDeclarationCollection: Collection<ImportDeclaration> = getImportDeclarationCollection(
|
|
265
|
-
{
|
|
266
|
-
j,
|
|
267
|
-
collection,
|
|
268
|
-
importPath: REACT_IMPORT_PATH,
|
|
269
|
-
}
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
importDeclarationCollection.forEach((importDeclarationPath) => {
|
|
273
|
-
const importDefaultSpecifierCollection: Collection<ImportDefaultSpecifier> = j(
|
|
274
|
-
importDeclarationPath
|
|
275
|
-
).find(j.ImportDefaultSpecifier);
|
|
276
|
-
const importNamespaceSpecifierCollection: Collection<ImportNamespaceSpecifier> = j(
|
|
277
|
-
importDeclarationPath
|
|
278
|
-
).find(j.ImportNamespaceSpecifier);
|
|
279
|
-
|
|
280
|
-
const hasNoDefaultReactImportDeclaration = importDefaultSpecifierCollection.length === 0;
|
|
281
|
-
const hasNoNamespaceReactImportDeclaration = importNamespaceSpecifierCollection.length === 0;
|
|
282
|
-
|
|
283
|
-
if (
|
|
284
|
-
hasNoDefaultReactImportDeclaration &&
|
|
285
|
-
hasNoNamespaceReactImportDeclaration &&
|
|
286
|
-
importDeclarationPath.node.specifiers
|
|
287
|
-
) {
|
|
288
|
-
importDeclarationPath.node.specifiers.unshift(
|
|
289
|
-
j.importDefaultSpecifier(j.identifier(REACT_IMPORT_NAME))
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
export const replaceImportDeclaration = ({
|
|
297
|
-
j,
|
|
298
|
-
collection,
|
|
299
|
-
importPath,
|
|
300
|
-
}: {
|
|
301
|
-
j: JSCodeshift;
|
|
302
|
-
collection: Collection<Node>;
|
|
303
|
-
importPath: string;
|
|
304
|
-
}): void => {
|
|
305
|
-
const importDeclarationCollection: Collection<ImportDeclaration> = getImportDeclarationCollection(
|
|
306
|
-
{
|
|
307
|
-
j,
|
|
308
|
-
collection,
|
|
309
|
-
importPath,
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
importDeclarationCollection.forEach((importDeclarationPath) => {
|
|
314
|
-
importDeclarationPath.node.source.value = COMPILED_IMPORT_PATH;
|
|
315
|
-
});
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
export const mergeImportSpecifiersAlongWithTheirComments = ({
|
|
319
|
-
j,
|
|
320
|
-
collection,
|
|
321
|
-
filter = (_) => true,
|
|
322
|
-
}: {
|
|
323
|
-
j: JSCodeshift;
|
|
324
|
-
collection: Collection<Node>;
|
|
325
|
-
filter?: (name: string | undefined) => boolean;
|
|
326
|
-
}): void => {
|
|
327
|
-
const importDeclarationCollection: Collection<ImportDeclaration> = getImportDeclarationCollection(
|
|
328
|
-
{
|
|
329
|
-
j,
|
|
330
|
-
collection,
|
|
331
|
-
importPath: COMPILED_IMPORT_PATH,
|
|
332
|
-
}
|
|
333
|
-
);
|
|
334
|
-
|
|
335
|
-
const importSpecifiers: ImportSpecifier[] = [];
|
|
336
|
-
|
|
337
|
-
importDeclarationCollection
|
|
338
|
-
.find(j.ImportSpecifier)
|
|
339
|
-
.filter((importSpecifierPath) => filter(importSpecifierPath.node.imported.name))
|
|
340
|
-
.forEach((importSpecifierPath) => {
|
|
341
|
-
importSpecifiers.push(importSpecifierPath.node);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
const importDeclarationCollectionLength = importDeclarationCollection.length;
|
|
345
|
-
const importDeclarationComments: Node['comments'] = [];
|
|
346
|
-
|
|
347
|
-
importDeclarationCollection.forEach((importDeclarationPath, index) => {
|
|
348
|
-
const oldNode = importDeclarationPath.node;
|
|
349
|
-
const { comments } = oldNode;
|
|
350
|
-
|
|
351
|
-
if (comments) {
|
|
352
|
-
importDeclarationComments.push(...comments);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
if (index === importDeclarationCollectionLength - 1) {
|
|
356
|
-
j(importDeclarationPath).replaceWith([
|
|
357
|
-
j.importDeclaration(importSpecifiers, j.literal(COMPILED_IMPORT_PATH)),
|
|
358
|
-
]);
|
|
359
|
-
|
|
360
|
-
const newNode = importDeclarationPath.node;
|
|
361
|
-
|
|
362
|
-
if (newNode !== oldNode) {
|
|
363
|
-
newNode.comments = importDeclarationComments;
|
|
364
|
-
}
|
|
365
|
-
} else {
|
|
366
|
-
j(importDeclarationPath).remove();
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# emotion-to-compiled
|
|
2
|
-
|
|
3
|
-
> Codemod for easy migration from emotion.
|
|
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
|
-
/** @jsx jsx */
|
|
18
|
-
import styled from '@emotion/styled';
|
|
19
|
-
import { css, jsx } from '@emotion/core';
|
|
20
|
-
|
|
21
|
-
const Component = (props) => (
|
|
22
|
-
<>
|
|
23
|
-
<div
|
|
24
|
-
css={css`
|
|
25
|
-
color: red;
|
|
26
|
-
background-color: #000;
|
|
27
|
-
`}
|
|
28
|
-
/>
|
|
29
|
-
<span
|
|
30
|
-
css={css`
|
|
31
|
-
color: blue;
|
|
32
|
-
`}
|
|
33
|
-
/>
|
|
34
|
-
</>
|
|
35
|
-
);
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Is transformed to:
|
|
39
|
-
|
|
40
|
-
```javascript
|
|
41
|
-
import { styled } from '@compiled/react';
|
|
42
|
-
|
|
43
|
-
const Component = (props) => (
|
|
44
|
-
<>
|
|
45
|
-
<div
|
|
46
|
-
css={`
|
|
47
|
-
color: red;
|
|
48
|
-
background-color: #000;
|
|
49
|
-
`}
|
|
50
|
-
/>
|
|
51
|
-
<span
|
|
52
|
-
css={`
|
|
53
|
-
color: blue;
|
|
54
|
-
`}
|
|
55
|
-
/>
|
|
56
|
-
</>
|
|
57
|
-
);
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## Updating Instructions
|
|
61
|
-
|
|
62
|
-
When wanting to update to a later version make sure `@compiled/cli` is being ran with the same version.
|
|
63
|
-
|
|
64
|
-
> Watch out for it being cached!
|
|
65
|
-
|
|
66
|
-
For example when upgrading `@compiled/react` to `v0.6.0` where you've already used the CLI,
|
|
67
|
-
on your next run explicitly set the version number:
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
npx @compiled/cli@0.6.0 --preset codemods
|
|
71
|
-
```
|