@atlaskit/code 15.2.0 → 15.3.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 +653 -645
- package/__perf__/code-block-syntax-highlighting.tsx +4 -1
- package/__perf__/source-code-examples/100-line-example.tsx +52 -40
- package/codemods/13.0.0-remove-unnecessary-code-props.tsx +61 -75
- package/codemods/13.0.0-rename-imports.tsx +214 -251
- package/codemods/14.0.0-lite-mode.tsx +5 -9
- package/codemods/__tests__/13.0.0-remove-unnecessary-code-props.tsx +43 -43
- package/codemods/__tests__/13.0.0-rename-imports.tsx +143 -143
- package/codemods/__tests__/14.0.0-lite-mode/14.0.0-lite-mode.tsx +35 -35
- package/codemods/__tests__/14.0.0-lite-mode/remove-language.tsx +21 -21
- package/codemods/__tests__/14.0.0-lite-mode/text-to-child.tsx +35 -35
- package/codemods/migrations/14.0.0-lite-mode/remove-language.tsx +1 -6
- package/codemods/migrations/14.0.0-lite-mode/text-to-child.tsx +53 -61
- package/codemods/utils/helpers.tsx +161 -201
- package/dist/cjs/bidi-warning/ui/styled.js +7 -0
- package/dist/cjs/code-block.js +8 -1
- package/dist/cjs/code.js +5 -0
- package/dist/cjs/internal/theme/styles.js +3 -2
- package/dist/cjs/syntax-highlighter/types.js +1 -0
- package/dist/es2019/bidi-warning/ui/styled.js +7 -0
- package/dist/es2019/code-block.js +8 -1
- package/dist/es2019/code.js +6 -0
- package/dist/es2019/internal/theme/styles.js +4 -1
- package/dist/es2019/syntax-highlighter/types.js +3 -0
- package/dist/esm/bidi-warning/ui/styled.js +7 -0
- package/dist/esm/code-block.js +8 -1
- package/dist/esm/code.js +6 -0
- package/dist/esm/internal/theme/styles.js +4 -1
- package/dist/esm/syntax-highlighter/types.js +3 -0
- package/dist/types/bidi-warning/ui/index.d.ts +1 -1
- package/dist/types/bidi-warning/ui/styled.d.ts +4 -1
- package/dist/types/code.d.ts +3 -0
- package/dist/types/extract-react-types/code-block.d.ts +16 -16
- package/dist/types/internal/hooks/use-highlight.d.ts +1 -1
- package/dist/types/internal/utils/get-normalized-language.d.ts +1 -1
- package/dist/types/syntax-highlighter/async.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/highlight.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/create-line-element.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/create-line.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/flatten-code-tree.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/get-code-tree.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/get-inline-line-number.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/index.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/react-renderer/create-children.d.ts +2 -2
- package/dist/types/syntax-highlighter/lib/react-renderer/create-element.d.ts +2 -2
- package/dist/types/syntax-highlighter/lib/react-renderer/index.d.ts +1 -1
- package/dist/types/syntax-highlighter/types.d.ts +2 -2
- package/dist/types/types.d.ts +1 -1
- package/dist/types-ts4.5/bidi-warning/ui/index.d.ts +1 -1
- package/dist/types-ts4.5/bidi-warning/ui/styled.d.ts +4 -1
- package/dist/types-ts4.5/code.d.ts +3 -0
- package/dist/types-ts4.5/extract-react-types/code-block.d.ts +16 -16
- package/dist/types-ts4.5/internal/hooks/use-highlight.d.ts +1 -1
- package/dist/types-ts4.5/internal/utils/get-normalized-language.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/async.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/highlight.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/create-line-element.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/create-line.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/flatten-code-tree.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/get-code-tree.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/get-inline-line-number.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/index.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/create-children.d.ts +2 -2
- package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/create-element.d.ts +2 -2
- package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/index.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/types.d.ts +2 -2
- package/dist/types-ts4.5/types.d.ts +1 -1
- package/package.json +108 -110
- package/report.api.md +807 -807
|
@@ -1,285 +1,248 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
type API,
|
|
3
|
+
type ASTPath,
|
|
4
|
+
type FileInfo,
|
|
5
|
+
type Identifier,
|
|
6
|
+
type ImportSpecifier,
|
|
7
|
+
type JSCodeshift,
|
|
8
|
+
type Options,
|
|
9
9
|
} from 'jscodeshift';
|
|
10
|
-
import { Collection } from 'jscodeshift/src/Collection';
|
|
10
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
getDynamicImportCollection,
|
|
14
|
+
getImportDeclarationCollection,
|
|
15
|
+
getImportSpecifierCollection,
|
|
16
|
+
getImportSpecifierName,
|
|
17
|
+
hasDynamicImport,
|
|
18
|
+
hasImportDeclaration,
|
|
19
|
+
isClassDeclarationIdentifierPresent,
|
|
20
|
+
isFunctionDeclarationIdentifierPresent,
|
|
21
|
+
isImportDeclarationIdentifierPresent,
|
|
22
|
+
isVariableDeclaratorIdentifierPresent,
|
|
23
23
|
} from './utils/helpers';
|
|
24
24
|
|
|
25
25
|
const importPath = '@atlaskit/code';
|
|
26
26
|
const importsMapping = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
oldImports: {
|
|
28
|
+
Code: 'AkCode',
|
|
29
|
+
CodeBlock: 'AkCodeBlock',
|
|
30
|
+
},
|
|
31
|
+
newImports: {
|
|
32
|
+
Code: 'Code',
|
|
33
|
+
CodeBlock: 'CodeBlock',
|
|
34
|
+
},
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
function renameNamedImports(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
j: JSCodeshift,
|
|
39
|
+
collection: Collection<any>,
|
|
40
|
+
{
|
|
41
|
+
fromImportName,
|
|
42
|
+
toImportName,
|
|
43
|
+
}: {
|
|
44
|
+
fromImportName: string;
|
|
45
|
+
toImportName: string;
|
|
46
|
+
},
|
|
47
47
|
) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
j,
|
|
67
|
-
collection,
|
|
68
|
-
importSpecifierPath,
|
|
69
|
-
importSpecifierName,
|
|
70
|
-
{
|
|
71
|
-
fromImportName,
|
|
72
|
-
toImportName,
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
});
|
|
48
|
+
const importDeclarationCollection = getImportDeclarationCollection(j, collection, importPath);
|
|
49
|
+
const importSpecifierCollection = getImportSpecifierCollection(
|
|
50
|
+
j,
|
|
51
|
+
importDeclarationCollection,
|
|
52
|
+
fromImportName,
|
|
53
|
+
);
|
|
54
|
+
const importSpecifierName = getImportSpecifierName(importSpecifierCollection);
|
|
55
|
+
|
|
56
|
+
if (importSpecifierName === null) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
importSpecifierCollection.forEach((importSpecifierPath) => {
|
|
61
|
+
renameBasedOnImportAlias(j, collection, importSpecifierPath, importSpecifierName, {
|
|
62
|
+
fromImportName,
|
|
63
|
+
toImportName,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
76
66
|
}
|
|
77
67
|
|
|
78
68
|
function renameBasedOnImportAlias(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
69
|
+
j: JSCodeshift,
|
|
70
|
+
collection: Collection<any>,
|
|
71
|
+
importSpecifierPath: ASTPath<ImportSpecifier>,
|
|
72
|
+
importSpecifierName: string,
|
|
73
|
+
{
|
|
74
|
+
fromImportName,
|
|
75
|
+
toImportName,
|
|
76
|
+
}: {
|
|
77
|
+
fromImportName: string;
|
|
78
|
+
toImportName: string;
|
|
79
|
+
},
|
|
90
80
|
) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
81
|
+
const isImportAliasPresent = importSpecifierName !== fromImportName;
|
|
82
|
+
|
|
83
|
+
if (isImportAliasPresent) {
|
|
84
|
+
return renameOnlyImportName(j, importSpecifierPath, importSpecifierName, {
|
|
85
|
+
toImportName,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const isToImportNameIdentifierPresentInSourceCode =
|
|
90
|
+
isVariableDeclaratorIdentifierPresent(j, collection, toImportName) ||
|
|
91
|
+
isFunctionDeclarationIdentifierPresent(j, collection, toImportName) ||
|
|
92
|
+
isClassDeclarationIdentifierPresent(j, collection, toImportName) ||
|
|
93
|
+
isImportDeclarationIdentifierPresent(j, collection, toImportName);
|
|
94
|
+
|
|
95
|
+
if (isToImportNameIdentifierPresentInSourceCode) {
|
|
96
|
+
return renameOnlyImportNameWithAliasAddition(j, importSpecifierPath, {
|
|
97
|
+
fromImportName,
|
|
98
|
+
toImportName,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return renameImportNameWithItsUsage(j, collection, importSpecifierPath, {
|
|
103
|
+
fromImportName,
|
|
104
|
+
toImportName,
|
|
105
|
+
});
|
|
116
106
|
}
|
|
117
107
|
|
|
118
108
|
function renameOnlyImportName(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
109
|
+
j: JSCodeshift,
|
|
110
|
+
importSpecifierPath: ASTPath<ImportSpecifier>,
|
|
111
|
+
importSpecifierName: string,
|
|
112
|
+
{
|
|
113
|
+
toImportName,
|
|
114
|
+
}: {
|
|
115
|
+
toImportName: string;
|
|
116
|
+
},
|
|
127
117
|
) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
j.identifier(importSpecifierName),
|
|
132
|
-
),
|
|
133
|
-
);
|
|
118
|
+
j(importSpecifierPath).replaceWith(
|
|
119
|
+
j.importSpecifier(j.identifier(toImportName), j.identifier(importSpecifierName)),
|
|
120
|
+
);
|
|
134
121
|
}
|
|
135
122
|
|
|
136
123
|
function renameOnlyImportNameWithAliasAddition(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
124
|
+
j: JSCodeshift,
|
|
125
|
+
importSpecifierPath: ASTPath<ImportSpecifier>,
|
|
126
|
+
{
|
|
127
|
+
fromImportName,
|
|
128
|
+
toImportName,
|
|
129
|
+
}: {
|
|
130
|
+
fromImportName: string;
|
|
131
|
+
toImportName: string;
|
|
132
|
+
},
|
|
146
133
|
) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
134
|
+
j(importSpecifierPath).replaceWith(
|
|
135
|
+
j.importSpecifier(j.identifier(toImportName), j.identifier(fromImportName)),
|
|
136
|
+
);
|
|
150
137
|
}
|
|
151
138
|
|
|
152
139
|
function renameImportNameWithItsUsage(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
140
|
+
j: JSCodeshift,
|
|
141
|
+
collection: Collection<any>,
|
|
142
|
+
importSpecifierPath: ASTPath<ImportSpecifier>,
|
|
143
|
+
{
|
|
144
|
+
fromImportName,
|
|
145
|
+
toImportName,
|
|
146
|
+
}: {
|
|
147
|
+
fromImportName: string;
|
|
148
|
+
toImportName: string;
|
|
149
|
+
},
|
|
163
150
|
) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
collection.find(j.VariableDeclarator).forEach((variableDeclaratorPath) => {
|
|
195
|
-
const { init } = variableDeclaratorPath.node;
|
|
196
|
-
|
|
197
|
-
if (
|
|
198
|
-
init &&
|
|
199
|
-
init.type === 'Identifier' &&
|
|
200
|
-
(init as Identifier).name === fromImportName
|
|
201
|
-
) {
|
|
202
|
-
variableDeclaratorPath.node.init = j.identifier(toImportName);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
151
|
+
j(importSpecifierPath).replaceWith(
|
|
152
|
+
j.importSpecifier(j.identifier(toImportName), j.identifier(toImportName)),
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
collection
|
|
156
|
+
.find(j.JSXIdentifier)
|
|
157
|
+
.filter((jsxIdentifierPath) => jsxIdentifierPath.node.name === fromImportName)
|
|
158
|
+
.forEach((jsxIdentifierPath) => {
|
|
159
|
+
j(jsxIdentifierPath).replaceWith(j.identifier(toImportName));
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
collection.find(j.CallExpression).forEach((callExpressionPath) => {
|
|
163
|
+
const { arguments: callExpressionArguments } = callExpressionPath.node;
|
|
164
|
+
|
|
165
|
+
callExpressionPath.node.arguments = callExpressionArguments.map((argument) => {
|
|
166
|
+
if (argument.type === 'Identifier' && argument.name === fromImportName) {
|
|
167
|
+
return j.identifier(toImportName);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return argument;
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
collection.find(j.VariableDeclarator).forEach((variableDeclaratorPath) => {
|
|
175
|
+
const { init } = variableDeclaratorPath.node;
|
|
176
|
+
|
|
177
|
+
if (init && init.type === 'Identifier' && (init as Identifier).name === fromImportName) {
|
|
178
|
+
variableDeclaratorPath.node.init = j.identifier(toImportName);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
205
181
|
}
|
|
206
182
|
|
|
207
183
|
function addPromiseThenIdentifier(j: JSCodeshift, collection: Collection<any>) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
],
|
|
236
|
-
),
|
|
237
|
-
);
|
|
238
|
-
},
|
|
239
|
-
);
|
|
184
|
+
const thenArgument = 'module';
|
|
185
|
+
|
|
186
|
+
getDynamicImportCollection(j, collection, importPath).forEach((callExpressionPath) => {
|
|
187
|
+
j(callExpressionPath).replaceWith(
|
|
188
|
+
j.callExpression(j.memberExpression(callExpressionPath.node, j.identifier('then')), [
|
|
189
|
+
j.arrowFunctionExpression(
|
|
190
|
+
[j.identifier(thenArgument)],
|
|
191
|
+
j.objectExpression([
|
|
192
|
+
j.objectProperty(
|
|
193
|
+
j.identifier(importsMapping.oldImports.Code),
|
|
194
|
+
j.memberExpression(
|
|
195
|
+
j.identifier(thenArgument),
|
|
196
|
+
j.identifier(importsMapping.newImports.Code),
|
|
197
|
+
),
|
|
198
|
+
),
|
|
199
|
+
j.objectProperty(
|
|
200
|
+
j.identifier(importsMapping.oldImports.CodeBlock),
|
|
201
|
+
j.memberExpression(
|
|
202
|
+
j.identifier(thenArgument),
|
|
203
|
+
j.identifier(importsMapping.newImports.CodeBlock),
|
|
204
|
+
),
|
|
205
|
+
),
|
|
206
|
+
]),
|
|
207
|
+
),
|
|
208
|
+
]),
|
|
209
|
+
);
|
|
210
|
+
});
|
|
240
211
|
}
|
|
241
212
|
|
|
242
|
-
export default function transformer(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (hasDynamicImportCode) {
|
|
281
|
-
addPromiseThenIdentifier(j, collection);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return collection.toSource(options.printOptions || { quote: 'single' });
|
|
213
|
+
export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
|
|
214
|
+
const { source } = fileInfo;
|
|
215
|
+
const collection = j(source);
|
|
216
|
+
|
|
217
|
+
const hasCodeImportDeclaration = hasImportDeclaration(j, collection, importPath);
|
|
218
|
+
|
|
219
|
+
const hasDynamicImportCode = hasDynamicImport(j, collection, importPath);
|
|
220
|
+
|
|
221
|
+
if (!hasCodeImportDeclaration && !hasDynamicImportCode) {
|
|
222
|
+
return source;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (hasCodeImportDeclaration) {
|
|
226
|
+
[
|
|
227
|
+
{
|
|
228
|
+
fromImportName: importsMapping.oldImports.Code,
|
|
229
|
+
toImportName: importsMapping.newImports.Code,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
fromImportName: importsMapping.oldImports.CodeBlock,
|
|
233
|
+
toImportName: importsMapping.newImports.CodeBlock,
|
|
234
|
+
},
|
|
235
|
+
].forEach(({ fromImportName, toImportName }) => {
|
|
236
|
+
renameNamedImports(j, collection, {
|
|
237
|
+
fromImportName,
|
|
238
|
+
toImportName,
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (hasDynamicImportCode) {
|
|
244
|
+
addPromiseThenIdentifier(j, collection);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return collection.toSource(options.printOptions || { quote: 'single' });
|
|
285
248
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { JSCodeshift } from 'jscodeshift';
|
|
2
|
-
import { Collection } from 'jscodeshift/src/Collection';
|
|
1
|
+
import { type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
createTransformer,
|
|
6
|
-
hasImportDeclaration,
|
|
7
|
-
} from '@atlaskit/codemod-utils';
|
|
4
|
+
import { createTransformer, hasImportDeclaration } from '@atlaskit/codemod-utils';
|
|
8
5
|
|
|
9
6
|
import removeLanguage from './migrations/14.0.0-lite-mode/remove-language';
|
|
10
7
|
import textToChild from './migrations/14.0.0-lite-mode/text-to-child';
|
|
11
8
|
|
|
12
9
|
const transformer = createTransformer(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
hasImportDeclaration(j, source, '@atlaskit/code'),
|
|
10
|
+
[removeLanguage, textToChild],
|
|
11
|
+
(j: JSCodeshift, source: Collection<Node>) => hasImportDeclaration(j, source, '@atlaskit/code'),
|
|
16
12
|
);
|
|
17
13
|
|
|
18
14
|
export default transformer;
|
|
@@ -5,24 +5,24 @@ import transformer from '../13.0.0-remove-unnecessary-code-props';
|
|
|
5
5
|
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
6
6
|
|
|
7
7
|
const removePropsMapping = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
lineNumberContainerStyle: 'lineNumberContainerStyle',
|
|
9
|
+
showLineNumbers: 'lineNumberContainerStyle',
|
|
10
|
+
highlight: 'highlight',
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
describe('Remove props', () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
defineInlineTest(
|
|
15
|
+
{ default: transformer, parser: 'tsx' },
|
|
16
|
+
{},
|
|
17
|
+
`import React from 'react';`,
|
|
18
|
+
`import React from 'react';`,
|
|
19
|
+
'should not transform if imports are not present',
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
defineInlineTest(
|
|
23
|
+
{ default: transformer, parser: 'tsx' },
|
|
24
|
+
{},
|
|
25
|
+
`
|
|
26
26
|
import React from 'react';
|
|
27
27
|
import { Code } from '@atlaskit/code';
|
|
28
28
|
|
|
@@ -34,7 +34,7 @@ describe('Remove props', () => {
|
|
|
34
34
|
|
|
35
35
|
const element = <Code prop="abc" />;
|
|
36
36
|
`,
|
|
37
|
-
|
|
37
|
+
`
|
|
38
38
|
import React from 'react';
|
|
39
39
|
import { Code } from '@atlaskit/code';
|
|
40
40
|
|
|
@@ -46,14 +46,14 @@ describe('Remove props', () => {
|
|
|
46
46
|
|
|
47
47
|
const element = <Code prop="abc" />;
|
|
48
48
|
`,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
'should not transform if removable props are not preset',
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
describe('when only one prop present', () => {
|
|
53
|
+
defineInlineTest(
|
|
54
|
+
{ default: transformer, parser: 'tsx' },
|
|
55
|
+
{},
|
|
56
|
+
`
|
|
57
57
|
import React from 'react';
|
|
58
58
|
import { Code } from '@atlaskit/code';
|
|
59
59
|
|
|
@@ -65,7 +65,7 @@ describe('Remove props', () => {
|
|
|
65
65
|
|
|
66
66
|
const element = <Code prop="abc" ${removePropsMapping.lineNumberContainerStyle}={{ fontSize: '14px' }} />;
|
|
67
67
|
`,
|
|
68
|
-
|
|
68
|
+
`
|
|
69
69
|
import React from 'react';
|
|
70
70
|
import { Code } from '@atlaskit/code';
|
|
71
71
|
|
|
@@ -77,13 +77,13 @@ describe('Remove props', () => {
|
|
|
77
77
|
|
|
78
78
|
const element = <Code prop="abc" />;
|
|
79
79
|
`,
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
`removes "${removePropsMapping.lineNumberContainerStyle}" "JSXAttribute" prop`,
|
|
81
|
+
);
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
defineInlineTest(
|
|
84
|
+
{ default: transformer, parser: 'tsx' },
|
|
85
|
+
{},
|
|
86
|
+
`
|
|
87
87
|
import React from 'react';
|
|
88
88
|
import { Code } from '@atlaskit/code';
|
|
89
89
|
|
|
@@ -102,7 +102,7 @@ describe('Remove props', () => {
|
|
|
102
102
|
|
|
103
103
|
const Component3 = () => <Code prop="abc" {...foo} { ...{ ${removePropsMapping.lineNumberContainerStyle}: { fontSize: '24px' }, key: 'hello' } } {...bar} />;
|
|
104
104
|
`,
|
|
105
|
-
|
|
105
|
+
`
|
|
106
106
|
import React from 'react';
|
|
107
107
|
import { Code } from '@atlaskit/code';
|
|
108
108
|
|
|
@@ -120,14 +120,14 @@ describe('Remove props', () => {
|
|
|
120
120
|
key: 'hello'
|
|
121
121
|
} } {...bar} />;
|
|
122
122
|
`,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
`removes "${removePropsMapping.lineNumberContainerStyle}" "JSXSpreadAttribute" prop`,
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
defineInlineTest(
|
|
128
|
+
{ default: transformer, parser: 'tsx' },
|
|
129
|
+
{},
|
|
130
|
+
`
|
|
131
131
|
import React from 'react';
|
|
132
132
|
import { Code } from '@atlaskit/code';
|
|
133
133
|
|
|
@@ -165,7 +165,7 @@ describe('Remove props', () => {
|
|
|
165
165
|
|
|
166
166
|
const element = <Code prop="abc" ${removePropsMapping.lineNumberContainerStyle}={{ fontSize: '14px' }} ${removePropsMapping.highlight}="2-4" />;
|
|
167
167
|
`,
|
|
168
|
-
|
|
168
|
+
`
|
|
169
169
|
import React from 'react';
|
|
170
170
|
import { Code } from '@atlaskit/code';
|
|
171
171
|
|
|
@@ -196,6 +196,6 @@ describe('Remove props', () => {
|
|
|
196
196
|
|
|
197
197
|
const element = <Code prop="abc" />;
|
|
198
198
|
`,
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
'removes mixture of removable props',
|
|
200
|
+
);
|
|
201
201
|
});
|