@atlaskit/code 15.7.1 → 15.7.3
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 +14 -0
- package/package.json +3 -4
- package/codemods/13.0.0-remove-unnecessary-code-props.tsx +0 -84
- package/codemods/13.0.0-rename-imports.tsx +0 -248
- package/codemods/14.0.0-lite-mode.tsx +0 -14
- package/codemods/__tests__/13.0.0-remove-unnecessary-code-props.tsx +0 -201
- package/codemods/__tests__/13.0.0-rename-imports.tsx +0 -365
- package/codemods/__tests__/14.0.0-lite-mode/14.0.0-lite-mode.tsx +0 -216
- package/codemods/__tests__/14.0.0-lite-mode/remove-language.tsx +0 -131
- package/codemods/__tests__/14.0.0-lite-mode/text-to-child.tsx +0 -203
- package/codemods/migrations/14.0.0-lite-mode/remove-language.tsx +0 -13
- package/codemods/migrations/14.0.0-lite-mode/text-to-child.tsx +0 -67
- package/codemods/utils/helpers.tsx +0 -226
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { createTransformer } from '@atlaskit/codemod-utils';
|
|
2
|
-
|
|
3
|
-
import textToChild from '../../migrations/14.0.0-lite-mode/text-to-child';
|
|
4
|
-
|
|
5
|
-
const transformer = createTransformer([textToChild]);
|
|
6
|
-
|
|
7
|
-
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
8
|
-
|
|
9
|
-
describe('make the test prop a child', () => {
|
|
10
|
-
defineInlineTest(
|
|
11
|
-
{ default: transformer, parser: 'tsx' },
|
|
12
|
-
{},
|
|
13
|
-
`
|
|
14
|
-
import React from 'react';
|
|
15
|
-
|
|
16
|
-
import { Code } from '@atlaskit/code';
|
|
17
|
-
|
|
18
|
-
export default function CodeDefaultExample() {
|
|
19
|
-
return (
|
|
20
|
-
<p>
|
|
21
|
-
To start creating a changeset, run{' '}
|
|
22
|
-
<Code text="yarn changeset" />. Then you will be prompted
|
|
23
|
-
to select packages for release.
|
|
24
|
-
</p>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
`,
|
|
28
|
-
`
|
|
29
|
-
import React from 'react';
|
|
30
|
-
|
|
31
|
-
import { Code } from '@atlaskit/code';
|
|
32
|
-
|
|
33
|
-
export default function CodeDefaultExample() {
|
|
34
|
-
return (
|
|
35
|
-
<p>
|
|
36
|
-
To start creating a changeset, run{' '}
|
|
37
|
-
<Code>yarn changeset</Code>. Then you will be prompted
|
|
38
|
-
to select packages for release.
|
|
39
|
-
</p>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
`,
|
|
43
|
-
'should make the text prop a child if it is a string',
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
defineInlineTest(
|
|
47
|
-
{ default: transformer, parser: 'tsx' },
|
|
48
|
-
{},
|
|
49
|
-
`
|
|
50
|
-
import React from 'react';
|
|
51
|
-
|
|
52
|
-
import { Code } from '@atlaskit/code';
|
|
53
|
-
|
|
54
|
-
const text = "yarn changeset";
|
|
55
|
-
|
|
56
|
-
export default function CodeDefaultExample() {
|
|
57
|
-
return (
|
|
58
|
-
<p>
|
|
59
|
-
To start creating a changeset, run{' '}
|
|
60
|
-
<Code text={text} />. Then you will be prompted
|
|
61
|
-
to select packages for release.
|
|
62
|
-
</p>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
`,
|
|
66
|
-
`
|
|
67
|
-
import React from 'react';
|
|
68
|
-
|
|
69
|
-
import { Code } from '@atlaskit/code';
|
|
70
|
-
|
|
71
|
-
const text = "yarn changeset";
|
|
72
|
-
|
|
73
|
-
export default function CodeDefaultExample() {
|
|
74
|
-
return (
|
|
75
|
-
<p>
|
|
76
|
-
To start creating a changeset, run{' '}
|
|
77
|
-
<Code>{text}</Code>. Then you will be prompted
|
|
78
|
-
to select packages for release.
|
|
79
|
-
</p>
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
`,
|
|
83
|
-
'should make the text prop a child if it is a variable',
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
defineInlineTest(
|
|
87
|
-
{ default: transformer, parser: 'tsx' },
|
|
88
|
-
{},
|
|
89
|
-
`
|
|
90
|
-
import React from 'react';
|
|
91
|
-
|
|
92
|
-
import { Code } from '@atlaskit/code';
|
|
93
|
-
|
|
94
|
-
export default function CodeDefaultExample() {
|
|
95
|
-
return (
|
|
96
|
-
<p>
|
|
97
|
-
To start creating a changeset, run{' '}
|
|
98
|
-
<Code testId="hello!" text="yarn changeset" />. Then you will be prompted
|
|
99
|
-
to select packages for release.
|
|
100
|
-
</p>
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
`,
|
|
104
|
-
`
|
|
105
|
-
import React from 'react';
|
|
106
|
-
|
|
107
|
-
import { Code } from '@atlaskit/code';
|
|
108
|
-
|
|
109
|
-
export default function CodeDefaultExample() {
|
|
110
|
-
return (
|
|
111
|
-
<p>
|
|
112
|
-
To start creating a changeset, run{' '}
|
|
113
|
-
<Code testId="hello!">yarn changeset</Code>. Then you will be prompted
|
|
114
|
-
to select packages for release.
|
|
115
|
-
</p>
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
`,
|
|
119
|
-
'should retain other props when converting to children',
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
defineInlineTest(
|
|
123
|
-
{ default: transformer, parser: 'tsx' },
|
|
124
|
-
{},
|
|
125
|
-
`
|
|
126
|
-
import React from 'react';
|
|
127
|
-
|
|
128
|
-
import { Code } from '@atlaskit/code';
|
|
129
|
-
|
|
130
|
-
import codeProps from './code-props';
|
|
131
|
-
|
|
132
|
-
export default function CodeDefaultExample() {
|
|
133
|
-
return (
|
|
134
|
-
<p>
|
|
135
|
-
To start creating a changeset, run{' '}
|
|
136
|
-
<Code {...codeProps} text="yarn changeset" />. Then you will be prompted
|
|
137
|
-
to select packages for release.
|
|
138
|
-
</p>
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
`,
|
|
142
|
-
`
|
|
143
|
-
import React from 'react';
|
|
144
|
-
|
|
145
|
-
import { Code } from '@atlaskit/code';
|
|
146
|
-
|
|
147
|
-
import codeProps from './code-props';
|
|
148
|
-
|
|
149
|
-
export default function CodeDefaultExample() {
|
|
150
|
-
return (
|
|
151
|
-
<p>
|
|
152
|
-
To start creating a changeset, run{' '}
|
|
153
|
-
<Code {...codeProps}>yarn changeset</Code>. Then you will be prompted
|
|
154
|
-
to select packages for release.
|
|
155
|
-
</p>
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
`,
|
|
159
|
-
'should retain other props that are spread when converting to children',
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
defineInlineTest(
|
|
163
|
-
{ default: transformer, parser: 'tsx' },
|
|
164
|
-
{},
|
|
165
|
-
`
|
|
166
|
-
import React from 'react';
|
|
167
|
-
|
|
168
|
-
import { Code } from '@atlaskit/code';
|
|
169
|
-
|
|
170
|
-
const text = "yarn changeset" ;
|
|
171
|
-
|
|
172
|
-
export default function CodeDefaultExample() {
|
|
173
|
-
return (
|
|
174
|
-
<p>
|
|
175
|
-
To start creating a changeset, run{' '}
|
|
176
|
-
<Code text={text} />. Then you will be prompted
|
|
177
|
-
to select packages for release.
|
|
178
|
-
If you wanna run <Code text="rm -rf"/> you can for fun
|
|
179
|
-
</p>
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
`,
|
|
183
|
-
`
|
|
184
|
-
import React from 'react';
|
|
185
|
-
|
|
186
|
-
import { Code } from '@atlaskit/code';
|
|
187
|
-
|
|
188
|
-
const text = "yarn changeset" ;
|
|
189
|
-
|
|
190
|
-
export default function CodeDefaultExample() {
|
|
191
|
-
return (
|
|
192
|
-
<p>
|
|
193
|
-
To start creating a changeset, run{' '}
|
|
194
|
-
<Code>{text}</Code>. Then you will be prompted
|
|
195
|
-
to select packages for release.
|
|
196
|
-
If you wanna run <Code>rm -rf</Code> you can for fun
|
|
197
|
-
</p>
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
`,
|
|
201
|
-
'should make the text prop a child with 2 usages',
|
|
202
|
-
);
|
|
203
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createRemoveFuncFor } from '../../utils/helpers';
|
|
2
|
-
|
|
3
|
-
const comment = `
|
|
4
|
-
We could not automatically convert this code to the new API.
|
|
5
|
-
|
|
6
|
-
This file uses \`Code\`’s \`language\` prop. The support for syntax highlighting has
|
|
7
|
-
been removed to make \`Code\` lighter, quicker and more composable. If you need syntax
|
|
8
|
-
highlighting it is still available in \`CodeBlock\`.
|
|
9
|
-
`;
|
|
10
|
-
|
|
11
|
-
const removeLanguageProp = createRemoveFuncFor('@atlaskit/code', 'Code', 'language', comment);
|
|
12
|
-
|
|
13
|
-
export default removeLanguageProp;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { ASTPath, default as core, JSXAttribute, JSXElement } from 'jscodeshift';
|
|
2
|
-
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
-
|
|
4
|
-
import { getJSXAttributesByName, getNamedSpecifier } from '@atlaskit/codemod-utils';
|
|
5
|
-
|
|
6
|
-
const textToChild = (j: core.JSCodeshift, source: Collection<Node>) => {
|
|
7
|
-
const specifier = getNamedSpecifier(j, source, '@atlaskit/code', 'Code');
|
|
8
|
-
|
|
9
|
-
if (!specifier) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
source.findJSXElements(specifier).forEach((element: ASTPath<JSXElement>) => {
|
|
14
|
-
getJSXAttributesByName(j, element, 'text').forEach((attribute: ASTPath<JSXAttribute>) => {
|
|
15
|
-
const { value } = attribute.node;
|
|
16
|
-
if (!value) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let codeChild = value;
|
|
21
|
-
switch (value.type) {
|
|
22
|
-
// case when object value is provided
|
|
23
|
-
case 'JSXExpressionContainer':
|
|
24
|
-
const { expression } = value;
|
|
25
|
-
|
|
26
|
-
// case when string is provided inside JSX expression
|
|
27
|
-
// e.g.: text={"rm -rf"}
|
|
28
|
-
if (expression.type === 'StringLiteral') {
|
|
29
|
-
codeChild = j.jsxText(expression.value);
|
|
30
|
-
}
|
|
31
|
-
// case when a variable is provided as value
|
|
32
|
-
// e.g.: text={someVariable}
|
|
33
|
-
else {
|
|
34
|
-
codeChild = j.jsxExpressionContainer(expression);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
break;
|
|
38
|
-
|
|
39
|
-
// case when string value is provided
|
|
40
|
-
// e.g.: text="rm -rf"
|
|
41
|
-
case 'StringLiteral':
|
|
42
|
-
codeChild = j.jsxText(value.value);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Remove text prop
|
|
46
|
-
j(attribute).remove();
|
|
47
|
-
|
|
48
|
-
j(element)
|
|
49
|
-
.find(j.JSXOpeningElement)
|
|
50
|
-
.forEach((openingElement) => {
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
if (openingElement.value.name.name === specifier) {
|
|
53
|
-
// Create opening and closing tag with the text content as a child
|
|
54
|
-
j(openingElement).replaceWith(
|
|
55
|
-
j.jsxElement(
|
|
56
|
-
j.jsxOpeningElement(j.jsxIdentifier(specifier), openingElement.value.attributes),
|
|
57
|
-
j.jsxClosingElement(j.jsxIdentifier(specifier)),
|
|
58
|
-
[codeChild],
|
|
59
|
-
),
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export default textToChild;
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ASTPath,
|
|
3
|
-
CallExpression,
|
|
4
|
-
default as core,
|
|
5
|
-
Identifier,
|
|
6
|
-
ImportDeclaration,
|
|
7
|
-
ImportSpecifier,
|
|
8
|
-
JSCodeshift,
|
|
9
|
-
JSXAttribute,
|
|
10
|
-
JSXElement,
|
|
11
|
-
ObjectProperty,
|
|
12
|
-
} from 'jscodeshift';
|
|
13
|
-
import { type Collection } from 'jscodeshift/src/Collection';
|
|
14
|
-
|
|
15
|
-
import { addCommentToStartOfFile, getNamedSpecifier } from '@atlaskit/codemod-utils';
|
|
16
|
-
|
|
17
|
-
export function hasImportDeclaration(
|
|
18
|
-
j: JSCodeshift,
|
|
19
|
-
collection: Collection<any>,
|
|
20
|
-
importPath: string,
|
|
21
|
-
) {
|
|
22
|
-
return getImportDeclarationCollection(j, collection, importPath).length > 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function getImportDeclarationCollection(
|
|
26
|
-
j: JSCodeshift,
|
|
27
|
-
collection: Collection<any>,
|
|
28
|
-
importPath: string,
|
|
29
|
-
) {
|
|
30
|
-
return collection
|
|
31
|
-
.find(j.ImportDeclaration)
|
|
32
|
-
.filter((importDeclarationPath) => importDeclarationPath.node.source.value === importPath);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function hasDynamicImport(j: JSCodeshift, collection: Collection<any>, importPath: string) {
|
|
36
|
-
return getDynamicImportCollection(j, collection, importPath).length > 0;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function getDynamicImportCollection(
|
|
40
|
-
j: JSCodeshift,
|
|
41
|
-
collection: Collection<any>,
|
|
42
|
-
importPath: string,
|
|
43
|
-
) {
|
|
44
|
-
return collection.find(j.CallExpression).filter((callExpressionPath) => {
|
|
45
|
-
const { callee, arguments: callExpressionArguments } = callExpressionPath.node;
|
|
46
|
-
|
|
47
|
-
return !!(
|
|
48
|
-
isCallExpressionCalleeImportType(callee) &&
|
|
49
|
-
isCallExpressionArgumentStringLiteralType(callExpressionArguments) &&
|
|
50
|
-
isCallExpressionArgumentValueMatches(callExpressionArguments[0], j, importPath)
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function isCallExpressionCalleeImportType(callee: CallExpression['callee']) {
|
|
55
|
-
return callee && callee.type === 'Import';
|
|
56
|
-
}
|
|
57
|
-
function isCallExpressionArgumentStringLiteralType(
|
|
58
|
-
callExpressionArguments: CallExpression['arguments'],
|
|
59
|
-
) {
|
|
60
|
-
return (
|
|
61
|
-
callExpressionArguments &&
|
|
62
|
-
callExpressionArguments.length &&
|
|
63
|
-
callExpressionArguments[0].type === 'StringLiteral'
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
function isCallExpressionArgumentValueMatches(
|
|
67
|
-
callExpressionArgument: CallExpression['arguments'][0],
|
|
68
|
-
j: JSCodeshift,
|
|
69
|
-
value: string,
|
|
70
|
-
) {
|
|
71
|
-
return j(callExpressionArgument).some((path) => path.node.value === value);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function getImportSpecifierCollection(
|
|
75
|
-
j: JSCodeshift,
|
|
76
|
-
importDeclarationCollection: Collection<ImportDeclaration>,
|
|
77
|
-
importName: string,
|
|
78
|
-
) {
|
|
79
|
-
return importDeclarationCollection
|
|
80
|
-
.find(j.ImportSpecifier)
|
|
81
|
-
.filter((importSpecifierPath) => importSpecifierPath.node.imported.name === importName);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function getImportSpecifierName(importSpecifierCollection: Collection<ImportSpecifier>) {
|
|
85
|
-
if (importSpecifierCollection.length === 0) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return importSpecifierCollection.nodes()[0]!.local!.name;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function isVariableDeclaratorIdentifierPresent(
|
|
93
|
-
j: JSCodeshift,
|
|
94
|
-
collection: Collection<any>,
|
|
95
|
-
variableName: string,
|
|
96
|
-
) {
|
|
97
|
-
return collection
|
|
98
|
-
.find(j.VariableDeclaration)
|
|
99
|
-
.find(j.VariableDeclarator)
|
|
100
|
-
.some((variableDeclaratorPath) => {
|
|
101
|
-
const { id } = variableDeclaratorPath.node;
|
|
102
|
-
|
|
103
|
-
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function isFunctionDeclarationIdentifierPresent(
|
|
108
|
-
j: JSCodeshift,
|
|
109
|
-
collection: Collection<any>,
|
|
110
|
-
variableName: string,
|
|
111
|
-
) {
|
|
112
|
-
return collection.find(j.FunctionDeclaration).some((functionDeclarationPath) => {
|
|
113
|
-
const { id } = functionDeclarationPath.node;
|
|
114
|
-
|
|
115
|
-
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function isClassDeclarationIdentifierPresent(
|
|
120
|
-
j: JSCodeshift,
|
|
121
|
-
collection: Collection<any>,
|
|
122
|
-
variableName: string,
|
|
123
|
-
) {
|
|
124
|
-
return collection.find(j.ClassDeclaration).some((classDeclarationPath) => {
|
|
125
|
-
const { id } = classDeclarationPath.node;
|
|
126
|
-
|
|
127
|
-
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function isImportDeclarationIdentifierPresent(
|
|
132
|
-
j: JSCodeshift,
|
|
133
|
-
collection: Collection<any>,
|
|
134
|
-
variableName: string,
|
|
135
|
-
) {
|
|
136
|
-
return collection
|
|
137
|
-
.find(j.ImportDeclaration)
|
|
138
|
-
.find(j.Identifier)
|
|
139
|
-
.some((identifierPath) => identifierPath.node.name === variableName);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function getJSXAttributesByName(
|
|
143
|
-
j: JSCodeshift,
|
|
144
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
145
|
-
attributeName: string,
|
|
146
|
-
): Collection<JSXAttribute> {
|
|
147
|
-
return j(jsxElementPath)
|
|
148
|
-
.find(j.JSXOpeningElement)
|
|
149
|
-
.find(j.JSXAttribute)
|
|
150
|
-
.filter((jsxAttributePath) =>
|
|
151
|
-
j(jsxAttributePath)
|
|
152
|
-
.find(j.JSXIdentifier)
|
|
153
|
-
.some((jsxIdentifierPath) => jsxIdentifierPath.node.name === attributeName),
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function getJSXSpreadIdentifierAttributesByName(
|
|
158
|
-
j: JSCodeshift,
|
|
159
|
-
collection: Collection<any>,
|
|
160
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
161
|
-
attributeName: string,
|
|
162
|
-
): Collection<ObjectProperty> | null {
|
|
163
|
-
const identifierCollection = j(jsxElementPath)
|
|
164
|
-
.find(j.JSXOpeningElement)
|
|
165
|
-
.find(j.JSXSpreadAttribute)
|
|
166
|
-
.filter((jsxSpreadAttributePath) => jsxSpreadAttributePath.node.argument.type === 'Identifier')
|
|
167
|
-
.find(j.Identifier);
|
|
168
|
-
|
|
169
|
-
if (identifierCollection.length === 0) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return collection
|
|
174
|
-
.find(j.VariableDeclarator)
|
|
175
|
-
.filter((variableDeclaratorPath) => {
|
|
176
|
-
const { id } = variableDeclaratorPath.node;
|
|
177
|
-
|
|
178
|
-
return (
|
|
179
|
-
id.type === 'Identifier' &&
|
|
180
|
-
identifierCollection.some((identifierPath) => identifierPath.node.name === id.name)
|
|
181
|
-
);
|
|
182
|
-
})
|
|
183
|
-
.find(j.ObjectExpression)
|
|
184
|
-
.find(j.ObjectProperty)
|
|
185
|
-
.filter((objectPropertyPath) =>
|
|
186
|
-
j(objectPropertyPath)
|
|
187
|
-
.find(j.Identifier)
|
|
188
|
-
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export function getJSXSpreadObjectExpressionAttributesByName(
|
|
193
|
-
j: JSCodeshift,
|
|
194
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
195
|
-
attributeName: string,
|
|
196
|
-
) {
|
|
197
|
-
return j(jsxElementPath)
|
|
198
|
-
.find(j.JSXOpeningElement)
|
|
199
|
-
.find(j.JSXSpreadAttribute)
|
|
200
|
-
.find(j.ObjectExpression)
|
|
201
|
-
.find(j.ObjectProperty)
|
|
202
|
-
.filter((objectPropertyPath) =>
|
|
203
|
-
j(objectPropertyPath)
|
|
204
|
-
.find(j.Identifier)
|
|
205
|
-
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export const createRemoveFuncFor =
|
|
210
|
-
(component: string, importName: string, prop: string, comment?: string) =>
|
|
211
|
-
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
212
|
-
const specifier = getNamedSpecifier(j, source, component, importName);
|
|
213
|
-
|
|
214
|
-
if (!specifier) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
source.findJSXElements(specifier).forEach((element) => {
|
|
219
|
-
getJSXAttributesByName(j, element, prop).forEach((attribute: any) => {
|
|
220
|
-
j(attribute).remove();
|
|
221
|
-
if (comment) {
|
|
222
|
-
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
};
|