@atlaskit/form 15.5.2 → 15.5.4
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 +15 -0
- package/codemods/migrate-data-testid-to-testid-prop.tsx +5 -7
- package/codemods/utils/add-jsx-attribute-to-jsx-element.tsx +21 -0
- package/codemods/utils/create-remove-func-for.tsx +30 -0
- package/codemods/utils/get-dynamic-import-collection.tsx +40 -0
- package/codemods/utils/get-import-declaration-collection.tsx +12 -0
- package/codemods/utils/get-import-default-specifier-collection.tsx +9 -0
- package/codemods/utils/get-import-default-specifier-name.tsx +12 -0
- package/codemods/utils/get-import-specifier-collection.tsx +12 -0
- package/codemods/utils/get-import-specifier-name.tsx +12 -0
- package/codemods/utils/get-jsx-attribute-by-name.tsx +15 -0
- package/codemods/utils/get-jsx-attributes-by-name.tsx +17 -0
- package/codemods/utils/get-jsx-attributes.tsx +5 -0
- package/codemods/utils/get-jsx-spread-identifier-attributes-by-name.tsx +37 -0
- package/codemods/utils/get-jsx-spread-object-expression-attributes-by-name.tsx +19 -0
- package/codemods/utils/has-dynamic-import.tsx +12 -0
- package/codemods/utils/has-import-declaration.tsx +12 -0
- package/codemods/utils/is-class-declaration-identifier-present.tsx +14 -0
- package/codemods/utils/is-function-declaration-identifier-present.tsx +14 -0
- package/codemods/utils/is-import-declaration-identifier-present.tsx +13 -0
- package/codemods/utils/is-variable-declarator-identifier-present.tsx +17 -0
- package/codemods/utils/remove-jsx-attribute-by-name.tsx +16 -0
- package/codemods/utils/remove-jsx-attribute-object-property-by-name.tsx +58 -0
- package/package.json +18 -10
- package/codemods/utils/helpers.tsx +0 -353
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/form
|
|
2
2
|
|
|
3
|
+
## 15.5.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 15.5.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`02483200273ec`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/02483200273ec) -
|
|
14
|
+
Enrol all Design System UI packages into the React Compiler with platform gating via
|
|
15
|
+
isReactCompilerActivePlatform.
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 15.5.2
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -7,13 +7,11 @@ import {
|
|
|
7
7
|
} from 'jscodeshift';
|
|
8
8
|
import { type Collection } from 'jscodeshift/src/Collection';
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
hasImportDeclaration,
|
|
16
|
-
} from './utils/helpers';
|
|
10
|
+
import { addJSXAttributeToJSXElement } from './utils/add-jsx-attribute-to-jsx-element';
|
|
11
|
+
import { getImportDeclarationCollection } from './utils/get-import-declaration-collection';
|
|
12
|
+
import { getImportDefaultSpecifierCollection } from './utils/get-import-default-specifier-collection';
|
|
13
|
+
import { getImportDefaultSpecifierName } from './utils/get-import-default-specifier-name';
|
|
14
|
+
import { hasImportDeclaration } from './utils/has-import-declaration';
|
|
17
15
|
|
|
18
16
|
const importPath = '@atlaskit/form';
|
|
19
17
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ASTPath, type JSCodeshift, type JSXAttribute, type JSXElement } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
export const addJSXAttributeToJSXElement: (
|
|
4
|
+
j: JSCodeshift,
|
|
5
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
6
|
+
jsxAttribute: JSXAttribute,
|
|
7
|
+
limit?: number,
|
|
8
|
+
) => void = (
|
|
9
|
+
j: JSCodeshift,
|
|
10
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
11
|
+
jsxAttribute: JSXAttribute,
|
|
12
|
+
limit?: number,
|
|
13
|
+
) => {
|
|
14
|
+
j(jsxElementPath)
|
|
15
|
+
.find(j.JSXOpeningElement)
|
|
16
|
+
.forEach((openingElement, i) => {
|
|
17
|
+
if (!limit || i < limit) {
|
|
18
|
+
openingElement.node.attributes?.push(jsxAttribute);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
import { addCommentToStartOfFile, getNamedSpecifier } from '@atlaskit/codemod-utils';
|
|
5
|
+
|
|
6
|
+
import { getJSXAttributesByName } from './get-jsx-attributes-by-name';
|
|
7
|
+
|
|
8
|
+
export const createRemoveFuncFor: (
|
|
9
|
+
component: string,
|
|
10
|
+
importName: string,
|
|
11
|
+
prop: string,
|
|
12
|
+
comment?: string,
|
|
13
|
+
) => (j: JSCodeshift, source: Collection<Node>) => void =
|
|
14
|
+
(component: string, importName: string, prop: string, comment?: string) =>
|
|
15
|
+
(j: JSCodeshift, source: Collection<Node>) => {
|
|
16
|
+
const specifier = getNamedSpecifier(j, source, component, importName);
|
|
17
|
+
|
|
18
|
+
if (!specifier) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
source.findJSXElements(specifier).forEach((element) => {
|
|
23
|
+
getJSXAttributesByName(j, element, prop).forEach((attribute: any) => {
|
|
24
|
+
j(attribute).remove();
|
|
25
|
+
if (comment) {
|
|
26
|
+
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type CallExpression, type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
function isCallExpressionCalleeImportType(callee: CallExpression['callee']) {
|
|
5
|
+
return callee && callee.type === 'Import';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function isCallExpressionArgumentStringLiteralType(
|
|
9
|
+
callExpressionArguments: CallExpression['arguments'],
|
|
10
|
+
) {
|
|
11
|
+
return (
|
|
12
|
+
callExpressionArguments &&
|
|
13
|
+
callExpressionArguments.length &&
|
|
14
|
+
callExpressionArguments[0].type === 'StringLiteral'
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isCallExpressionArgumentValueMatches(
|
|
19
|
+
callExpressionArgument: CallExpression['arguments'][0],
|
|
20
|
+
j: JSCodeshift,
|
|
21
|
+
value: string,
|
|
22
|
+
) {
|
|
23
|
+
return j(callExpressionArgument).some((path) => path.node.value === value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getDynamicImportCollection(
|
|
27
|
+
j: JSCodeshift,
|
|
28
|
+
collection: Collection<any>,
|
|
29
|
+
importPath: string,
|
|
30
|
+
): Collection<CallExpression> {
|
|
31
|
+
return collection.find(j.CallExpression).filter((callExpressionPath) => {
|
|
32
|
+
const { callee, arguments: callExpressionArguments } = callExpressionPath.node;
|
|
33
|
+
|
|
34
|
+
return !!(
|
|
35
|
+
isCallExpressionCalleeImportType(callee) &&
|
|
36
|
+
isCallExpressionArgumentStringLiteralType(callExpressionArguments) &&
|
|
37
|
+
isCallExpressionArgumentValueMatches(callExpressionArguments[0], j, importPath)
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ImportDeclaration, type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function getImportDeclarationCollection(
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
collection: Collection<any>,
|
|
7
|
+
importPath: string,
|
|
8
|
+
): Collection<ImportDeclaration> {
|
|
9
|
+
return collection
|
|
10
|
+
.find(j.ImportDeclaration)
|
|
11
|
+
.filter((importDeclarationPath) => importDeclarationPath.node.source.value === importPath);
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ImportDeclaration, type ImportDefaultSpecifier, type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function getImportDefaultSpecifierCollection(
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
importDeclarationCollection: Collection<ImportDeclaration>,
|
|
7
|
+
): Collection<ImportDefaultSpecifier> {
|
|
8
|
+
return importDeclarationCollection.find(j.ImportDefaultSpecifier);
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ImportDefaultSpecifier } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function getImportDefaultSpecifierName(
|
|
5
|
+
importSpecifierCollection: Collection<ImportDefaultSpecifier>,
|
|
6
|
+
): string | null {
|
|
7
|
+
if (importSpecifierCollection.length === 0) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return importSpecifierCollection.nodes()[0]!.local!.name;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ImportDeclaration, type ImportSpecifier, type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function getImportSpecifierCollection(
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
importDeclarationCollection: Collection<ImportDeclaration>,
|
|
7
|
+
importName: string,
|
|
8
|
+
): Collection<ImportSpecifier> {
|
|
9
|
+
return importDeclarationCollection
|
|
10
|
+
.find(j.ImportSpecifier)
|
|
11
|
+
.filter((importSpecifierPath) => importSpecifierPath.node.imported.name === importName);
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ImportSpecifier } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function getImportSpecifierName(
|
|
5
|
+
importSpecifierCollection: Collection<ImportSpecifier>,
|
|
6
|
+
): string | null {
|
|
7
|
+
if (importSpecifierCollection.length === 0) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return importSpecifierCollection.nodes()[0]!.local!.name;
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ASTPath, type JSCodeshift, type JSXAttribute, type JSXElement } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
export const getJSXAttributeByName: (
|
|
4
|
+
j: JSCodeshift,
|
|
5
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
6
|
+
attributeName: string,
|
|
7
|
+
) => JSXAttribute | undefined = (
|
|
8
|
+
j: JSCodeshift,
|
|
9
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
10
|
+
attributeName: string,
|
|
11
|
+
): JSXAttribute | undefined => {
|
|
12
|
+
const attributes: JSXAttribute[] = j(jsxElementPath).find(j.JSXAttribute).nodes();
|
|
13
|
+
|
|
14
|
+
return attributes?.find((attr) => attr.name && attr.name.name === attributeName);
|
|
15
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ASTPath, type JSCodeshift, type JSXAttribute, type JSXElement } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function getJSXAttributesByName(
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
7
|
+
attributeName: string,
|
|
8
|
+
): Collection<JSXAttribute> {
|
|
9
|
+
return j(jsxElementPath)
|
|
10
|
+
.find(j.JSXOpeningElement)
|
|
11
|
+
.find(j.JSXAttribute)
|
|
12
|
+
.filter((jsxAttributePath) =>
|
|
13
|
+
j(jsxAttributePath)
|
|
14
|
+
.find(j.JSXIdentifier)
|
|
15
|
+
.some((jsxIdentifierPath) => jsxIdentifierPath.node.name === attributeName),
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ASTPath, type JSXAttribute, type JSXElement } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
export const getJSXAttributes: (jsxElementPath: ASTPath<JSXElement>) => JSXAttribute[] = (
|
|
4
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
5
|
+
) => jsxElementPath.node.openingElement.attributes as JSXAttribute[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ASTPath, type JSCodeshift, type JSXElement, type ObjectProperty } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function getJSXSpreadIdentifierAttributesByName(
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
collection: Collection<any>,
|
|
7
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
8
|
+
attributeName: string,
|
|
9
|
+
): Collection<ObjectProperty> | null {
|
|
10
|
+
const identifierCollection = j(jsxElementPath)
|
|
11
|
+
.find(j.JSXOpeningElement)
|
|
12
|
+
.find(j.JSXSpreadAttribute)
|
|
13
|
+
.filter((jsxSpreadAttributePath) => jsxSpreadAttributePath.node.argument.type === 'Identifier')
|
|
14
|
+
.find(j.Identifier);
|
|
15
|
+
|
|
16
|
+
if (identifierCollection.length === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return collection
|
|
21
|
+
.find(j.VariableDeclarator)
|
|
22
|
+
.filter((variableDeclaratorPath) => {
|
|
23
|
+
const { id } = variableDeclaratorPath.node;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
id.type === 'Identifier' &&
|
|
27
|
+
identifierCollection.some((identifierPath) => identifierPath.node.name === id.name)
|
|
28
|
+
);
|
|
29
|
+
})
|
|
30
|
+
.find(j.ObjectExpression)
|
|
31
|
+
.find(j.ObjectProperty)
|
|
32
|
+
.filter((objectPropertyPath) =>
|
|
33
|
+
j(objectPropertyPath)
|
|
34
|
+
.find(j.Identifier)
|
|
35
|
+
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ASTPath, type JSCodeshift, type JSXElement, type ObjectProperty } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function getJSXSpreadObjectExpressionAttributesByName(
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
7
|
+
attributeName: string,
|
|
8
|
+
): Collection<ObjectProperty> {
|
|
9
|
+
return j(jsxElementPath)
|
|
10
|
+
.find(j.JSXOpeningElement)
|
|
11
|
+
.find(j.JSXSpreadAttribute)
|
|
12
|
+
.find(j.ObjectExpression)
|
|
13
|
+
.find(j.ObjectProperty)
|
|
14
|
+
.filter((objectPropertyPath) =>
|
|
15
|
+
j(objectPropertyPath)
|
|
16
|
+
.find(j.Identifier)
|
|
17
|
+
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
import { getDynamicImportCollection } from './get-dynamic-import-collection';
|
|
5
|
+
|
|
6
|
+
export function hasDynamicImport(
|
|
7
|
+
j: JSCodeshift,
|
|
8
|
+
collection: Collection<any>,
|
|
9
|
+
importPath: string,
|
|
10
|
+
): boolean {
|
|
11
|
+
return getDynamicImportCollection(j, collection, importPath).length > 0;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
import { getImportDeclarationCollection } from './get-import-declaration-collection';
|
|
5
|
+
|
|
6
|
+
export function hasImportDeclaration(
|
|
7
|
+
j: JSCodeshift,
|
|
8
|
+
collection: Collection<any>,
|
|
9
|
+
importPath: string,
|
|
10
|
+
): boolean {
|
|
11
|
+
return getImportDeclarationCollection(j, collection, importPath).length > 0;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Identifier, type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function isClassDeclarationIdentifierPresent(
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
collection: Collection<any>,
|
|
7
|
+
variableName: string,
|
|
8
|
+
): boolean {
|
|
9
|
+
return collection.find(j.ClassDeclaration).some((classDeclarationPath) => {
|
|
10
|
+
const { id } = classDeclarationPath.node;
|
|
11
|
+
|
|
12
|
+
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Identifier, type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function isFunctionDeclarationIdentifierPresent(
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
collection: Collection<any>,
|
|
7
|
+
variableName: string,
|
|
8
|
+
): boolean {
|
|
9
|
+
return collection.find(j.FunctionDeclaration).some((functionDeclarationPath) => {
|
|
10
|
+
const { id } = functionDeclarationPath.node;
|
|
11
|
+
|
|
12
|
+
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function isImportDeclarationIdentifierPresent(
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
collection: Collection<any>,
|
|
7
|
+
variableName: string,
|
|
8
|
+
): boolean {
|
|
9
|
+
return collection
|
|
10
|
+
.find(j.ImportDeclaration)
|
|
11
|
+
.find(j.Identifier)
|
|
12
|
+
.some((identifierPath) => identifierPath.node.name === variableName);
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Identifier, type JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
+
|
|
4
|
+
export function isVariableDeclaratorIdentifierPresent(
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
collection: Collection<any>,
|
|
7
|
+
variableName: string,
|
|
8
|
+
): boolean {
|
|
9
|
+
return collection
|
|
10
|
+
.find(j.VariableDeclaration)
|
|
11
|
+
.find(j.VariableDeclarator)
|
|
12
|
+
.some((variableDeclaratorPath) => {
|
|
13
|
+
const { id } = variableDeclaratorPath.node;
|
|
14
|
+
|
|
15
|
+
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ASTPath, type JSCodeshift, type JSXElement } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
import { getJSXAttributeByName } from './get-jsx-attribute-by-name';
|
|
4
|
+
import { getJSXAttributes } from './get-jsx-attributes';
|
|
5
|
+
|
|
6
|
+
export const removeJSXAttributeByName: (
|
|
7
|
+
j: JSCodeshift,
|
|
8
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
9
|
+
attrName: string,
|
|
10
|
+
) => void = (j: JSCodeshift, jsxElementPath: ASTPath<JSXElement>, attrName: string) => {
|
|
11
|
+
const attributes = getJSXAttributes(jsxElementPath);
|
|
12
|
+
const attr = getJSXAttributeByName(j, jsxElementPath, attrName);
|
|
13
|
+
if (attr) {
|
|
14
|
+
attributes?.splice(attributes.indexOf(attr), 1);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ASTPath,
|
|
3
|
+
type Identifier,
|
|
4
|
+
type JSCodeshift,
|
|
5
|
+
type JSXElement,
|
|
6
|
+
type StringLiteral,
|
|
7
|
+
} from 'jscodeshift';
|
|
8
|
+
|
|
9
|
+
import { getJSXAttributeByName } from './get-jsx-attribute-by-name';
|
|
10
|
+
import { getJSXAttributesByName } from './get-jsx-attributes-by-name';
|
|
11
|
+
import { removeJSXAttributeByName } from './remove-jsx-attribute-by-name';
|
|
12
|
+
|
|
13
|
+
export const removeJSXAttributeObjectPropertyByName: (
|
|
14
|
+
j: JSCodeshift,
|
|
15
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
16
|
+
attrName: string,
|
|
17
|
+
propertyToRemove: string,
|
|
18
|
+
) => void = (
|
|
19
|
+
j: JSCodeshift,
|
|
20
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
21
|
+
attrName: string,
|
|
22
|
+
propertyToRemove: string,
|
|
23
|
+
) => {
|
|
24
|
+
const attr = getJSXAttributeByName(j, jsxElementPath, attrName);
|
|
25
|
+
|
|
26
|
+
if (!attr) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const attrCollection = getJSXAttributesByName(j, jsxElementPath, attrName);
|
|
31
|
+
|
|
32
|
+
const removeMatchingNodes = (p: ASTPath<Identifier | StringLiteral>) => {
|
|
33
|
+
const name = p.node.type === 'Identifier' ? p.node?.name : p.node?.value;
|
|
34
|
+
// Need to account for quoted properties
|
|
35
|
+
const nameMatches = propertyToRemove.match(new RegExp(`['"]?${name}['"]?`));
|
|
36
|
+
// This will otherwise try to remove values of properties since they are literals
|
|
37
|
+
const isKey = p.parent.value?.type === 'ObjectProperty';
|
|
38
|
+
// Sorry about all the parents. This is the easiest way to get the name
|
|
39
|
+
// of the attribute name. And I always know the depth of the object
|
|
40
|
+
// property here.
|
|
41
|
+
const parentNameMatches = attrName === p.parent.parent.parent.parent.node?.name?.name;
|
|
42
|
+
if (isKey && nameMatches && parentNameMatches) {
|
|
43
|
+
j(p.parent).remove();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Remove all the now migrated object properties
|
|
48
|
+
const objectProperties = attrCollection.find(j.ObjectProperty);
|
|
49
|
+
objectProperties.find(j.Identifier).forEach(removeMatchingNodes);
|
|
50
|
+
objectProperties.find(j.StringLiteral).forEach(removeMatchingNodes);
|
|
51
|
+
|
|
52
|
+
// @ts-ignore -- Property 'expression' does not exist on type 'LiteralKind | JSXElement | JSXExpressionContainer | JSXFragment'. Property 'expression' does not exist on type 'Literal'.
|
|
53
|
+
const attrProperties = attr.value?.expression.properties;
|
|
54
|
+
|
|
55
|
+
if (attrProperties && attrProperties?.length === 0) {
|
|
56
|
+
removeJSXAttributeByName(j, jsxElementPath, attrName);
|
|
57
|
+
}
|
|
58
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/form",
|
|
3
|
-
"version": "15.5.
|
|
3
|
+
"version": "15.5.4",
|
|
4
4
|
"description": "A form allows people to input information.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -18,6 +18,13 @@
|
|
|
18
18
|
"atlaskit:src": "src/index.tsx",
|
|
19
19
|
"atlaskit:designLink": "https://atlassian.design/patterns/forms",
|
|
20
20
|
"atlassian": {
|
|
21
|
+
"react-compiler": {
|
|
22
|
+
"enabled": true,
|
|
23
|
+
"gating": {
|
|
24
|
+
"source": "@atlassian/react-compiler-gating",
|
|
25
|
+
"importSpecifierName": "isReactCompilerActivePlatform"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
21
28
|
"team": "Design System Team",
|
|
22
29
|
"website": {
|
|
23
30
|
"name": "Form",
|
|
@@ -26,12 +33,12 @@
|
|
|
26
33
|
},
|
|
27
34
|
"dependencies": {
|
|
28
35
|
"@atlaskit/css": "^0.19.0",
|
|
29
|
-
"@atlaskit/ds-lib": "^
|
|
30
|
-
"@atlaskit/heading": "^5.
|
|
36
|
+
"@atlaskit/ds-lib": "^7.0.0",
|
|
37
|
+
"@atlaskit/heading": "^5.4.0",
|
|
31
38
|
"@atlaskit/icon": "^34.0.0",
|
|
32
39
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
33
40
|
"@atlaskit/primitives": "^18.1.0",
|
|
34
|
-
"@atlaskit/tokens": "^
|
|
41
|
+
"@atlaskit/tokens": "^12.0.0",
|
|
35
42
|
"@atlaskit/visually-hidden": "^3.0.0",
|
|
36
43
|
"@babel/runtime": "^7.0.0",
|
|
37
44
|
"@compiled/react": "^0.20.0",
|
|
@@ -48,22 +55,23 @@
|
|
|
48
55
|
"@af/suppress-react-warnings": "workspace:^",
|
|
49
56
|
"@af/visual-regression": "workspace:^",
|
|
50
57
|
"@atlaskit/banner": "^14.0.0",
|
|
51
|
-
"@atlaskit/button": "^23.
|
|
58
|
+
"@atlaskit/button": "^23.11.0",
|
|
52
59
|
"@atlaskit/checkbox": "^17.3.0",
|
|
53
60
|
"@atlaskit/codemod-utils": "^4.2.0",
|
|
54
61
|
"@atlaskit/datetime-picker": "^17.6.0",
|
|
55
62
|
"@atlaskit/docs": "^11.7.0",
|
|
56
|
-
"@atlaskit/link": "^3.
|
|
63
|
+
"@atlaskit/link": "^3.4.0",
|
|
57
64
|
"@atlaskit/lozenge": "^13.5.0",
|
|
58
|
-
"@atlaskit/modal-dialog": "^14.
|
|
59
|
-
"@atlaskit/radio": "^8.
|
|
65
|
+
"@atlaskit/modal-dialog": "^14.15.0",
|
|
66
|
+
"@atlaskit/radio": "^8.5.0",
|
|
60
67
|
"@atlaskit/range": "^10.0.0",
|
|
61
68
|
"@atlaskit/section-message": "^8.12.0",
|
|
62
69
|
"@atlaskit/select": "^21.10.0",
|
|
63
70
|
"@atlaskit/textarea": "^8.2.0",
|
|
64
|
-
"@atlaskit/textfield": "^8.
|
|
65
|
-
"@atlaskit/toggle": "^15.
|
|
71
|
+
"@atlaskit/textfield": "^8.3.0",
|
|
72
|
+
"@atlaskit/toggle": "^15.4.0",
|
|
66
73
|
"@atlassian/feature-flags-test-utils": "^1.0.0",
|
|
74
|
+
"@atlassian/react-compiler-gating": "workspace:^",
|
|
67
75
|
"@atlassian/ssr-tests": "workspace:^",
|
|
68
76
|
"@atlassian/structured-docs-types": "workspace:^",
|
|
69
77
|
"@atlassian/testing-library": "^0.5.0",
|
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ASTPath,
|
|
3
|
-
CallExpression,
|
|
4
|
-
default as core,
|
|
5
|
-
Identifier,
|
|
6
|
-
ImportDeclaration,
|
|
7
|
-
ImportDefaultSpecifier,
|
|
8
|
-
ImportSpecifier,
|
|
9
|
-
JSCodeshift,
|
|
10
|
-
JSXAttribute,
|
|
11
|
-
JSXElement,
|
|
12
|
-
ObjectProperty,
|
|
13
|
-
StringLiteral,
|
|
14
|
-
} from 'jscodeshift';
|
|
15
|
-
import { type Collection } from 'jscodeshift/src/Collection';
|
|
16
|
-
|
|
17
|
-
import { addCommentToStartOfFile, getNamedSpecifier } from '@atlaskit/codemod-utils';
|
|
18
|
-
|
|
19
|
-
export function hasImportDeclaration(
|
|
20
|
-
j: JSCodeshift,
|
|
21
|
-
collection: Collection<any>,
|
|
22
|
-
importPath: string,
|
|
23
|
-
): boolean {
|
|
24
|
-
return getImportDeclarationCollection(j, collection, importPath).length > 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getImportDeclarationCollection(
|
|
28
|
-
j: JSCodeshift,
|
|
29
|
-
collection: Collection<any>,
|
|
30
|
-
importPath: string,
|
|
31
|
-
): Collection<ImportDeclaration> {
|
|
32
|
-
return collection
|
|
33
|
-
.find(j.ImportDeclaration)
|
|
34
|
-
.filter((importDeclarationPath) => importDeclarationPath.node.source.value === importPath);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function hasDynamicImport(
|
|
38
|
-
j: JSCodeshift,
|
|
39
|
-
collection: Collection<any>,
|
|
40
|
-
importPath: string,
|
|
41
|
-
): boolean {
|
|
42
|
-
return getDynamicImportCollection(j, collection, importPath).length > 0;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function getDynamicImportCollection(
|
|
46
|
-
j: JSCodeshift,
|
|
47
|
-
collection: Collection<any>,
|
|
48
|
-
importPath: string,
|
|
49
|
-
): Collection<CallExpression> {
|
|
50
|
-
return collection.find(j.CallExpression).filter((callExpressionPath) => {
|
|
51
|
-
const { callee, arguments: callExpressionArguments } = callExpressionPath.node;
|
|
52
|
-
|
|
53
|
-
return !!(
|
|
54
|
-
isCallExpressionCalleeImportType(callee) &&
|
|
55
|
-
isCallExpressionArgumentStringLiteralType(callExpressionArguments) &&
|
|
56
|
-
isCallExpressionArgumentValueMatches(callExpressionArguments[0], j, importPath)
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function isCallExpressionCalleeImportType(callee: CallExpression['callee']) {
|
|
61
|
-
return callee && callee.type === 'Import';
|
|
62
|
-
}
|
|
63
|
-
function isCallExpressionArgumentStringLiteralType(
|
|
64
|
-
callExpressionArguments: CallExpression['arguments'],
|
|
65
|
-
) {
|
|
66
|
-
return (
|
|
67
|
-
callExpressionArguments &&
|
|
68
|
-
callExpressionArguments.length &&
|
|
69
|
-
callExpressionArguments[0].type === 'StringLiteral'
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
function isCallExpressionArgumentValueMatches(
|
|
73
|
-
callExpressionArgument: CallExpression['arguments'][0],
|
|
74
|
-
j: JSCodeshift,
|
|
75
|
-
value: string,
|
|
76
|
-
) {
|
|
77
|
-
return j(callExpressionArgument).some((path) => path.node.value === value);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function getImportDefaultSpecifierCollection(
|
|
81
|
-
j: JSCodeshift,
|
|
82
|
-
importDeclarationCollection: Collection<ImportDeclaration>,
|
|
83
|
-
): Collection<ImportDefaultSpecifier> {
|
|
84
|
-
return importDeclarationCollection.find(j.ImportDefaultSpecifier);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function getImportSpecifierCollection(
|
|
88
|
-
j: JSCodeshift,
|
|
89
|
-
importDeclarationCollection: Collection<ImportDeclaration>,
|
|
90
|
-
importName: string,
|
|
91
|
-
): Collection<ImportSpecifier> {
|
|
92
|
-
return importDeclarationCollection
|
|
93
|
-
.find(j.ImportSpecifier)
|
|
94
|
-
.filter((importSpecifierPath) => importSpecifierPath.node.imported.name === importName);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function getImportDefaultSpecifierName(
|
|
98
|
-
importSpecifierCollection: Collection<ImportDefaultSpecifier>,
|
|
99
|
-
): string | null {
|
|
100
|
-
if (importSpecifierCollection.length === 0) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return importSpecifierCollection.nodes()[0]!.local!.name;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function getImportSpecifierName(
|
|
108
|
-
importSpecifierCollection: Collection<ImportSpecifier>,
|
|
109
|
-
): string | null {
|
|
110
|
-
if (importSpecifierCollection.length === 0) {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return importSpecifierCollection.nodes()[0]!.local!.name;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function isVariableDeclaratorIdentifierPresent(
|
|
118
|
-
j: JSCodeshift,
|
|
119
|
-
collection: Collection<any>,
|
|
120
|
-
variableName: string,
|
|
121
|
-
): boolean {
|
|
122
|
-
return collection
|
|
123
|
-
.find(j.VariableDeclaration)
|
|
124
|
-
.find(j.VariableDeclarator)
|
|
125
|
-
.some((variableDeclaratorPath) => {
|
|
126
|
-
const { id } = variableDeclaratorPath.node;
|
|
127
|
-
|
|
128
|
-
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function isFunctionDeclarationIdentifierPresent(
|
|
133
|
-
j: JSCodeshift,
|
|
134
|
-
collection: Collection<any>,
|
|
135
|
-
variableName: string,
|
|
136
|
-
): boolean {
|
|
137
|
-
return collection.find(j.FunctionDeclaration).some((functionDeclarationPath) => {
|
|
138
|
-
const { id } = functionDeclarationPath.node;
|
|
139
|
-
|
|
140
|
-
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function isClassDeclarationIdentifierPresent(
|
|
145
|
-
j: JSCodeshift,
|
|
146
|
-
collection: Collection<any>,
|
|
147
|
-
variableName: string,
|
|
148
|
-
): boolean {
|
|
149
|
-
return collection.find(j.ClassDeclaration).some((classDeclarationPath) => {
|
|
150
|
-
const { id } = classDeclarationPath.node;
|
|
151
|
-
|
|
152
|
-
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function isImportDeclarationIdentifierPresent(
|
|
157
|
-
j: JSCodeshift,
|
|
158
|
-
collection: Collection<any>,
|
|
159
|
-
variableName: string,
|
|
160
|
-
): boolean {
|
|
161
|
-
return collection
|
|
162
|
-
.find(j.ImportDeclaration)
|
|
163
|
-
.find(j.Identifier)
|
|
164
|
-
.some((identifierPath) => identifierPath.node.name === variableName);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export function getJSXAttributesByName(
|
|
168
|
-
j: JSCodeshift,
|
|
169
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
170
|
-
attributeName: string,
|
|
171
|
-
): Collection<JSXAttribute> {
|
|
172
|
-
return j(jsxElementPath)
|
|
173
|
-
.find(j.JSXOpeningElement)
|
|
174
|
-
.find(j.JSXAttribute)
|
|
175
|
-
.filter((jsxAttributePath) =>
|
|
176
|
-
j(jsxAttributePath)
|
|
177
|
-
.find(j.JSXIdentifier)
|
|
178
|
-
.some((jsxIdentifierPath) => jsxIdentifierPath.node.name === attributeName),
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function getJSXSpreadIdentifierAttributesByName(
|
|
183
|
-
j: JSCodeshift,
|
|
184
|
-
collection: Collection<any>,
|
|
185
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
186
|
-
attributeName: string,
|
|
187
|
-
): Collection<ObjectProperty> | null {
|
|
188
|
-
const identifierCollection = j(jsxElementPath)
|
|
189
|
-
.find(j.JSXOpeningElement)
|
|
190
|
-
.find(j.JSXSpreadAttribute)
|
|
191
|
-
.filter((jsxSpreadAttributePath) => jsxSpreadAttributePath.node.argument.type === 'Identifier')
|
|
192
|
-
.find(j.Identifier);
|
|
193
|
-
|
|
194
|
-
if (identifierCollection.length === 0) {
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return collection
|
|
199
|
-
.find(j.VariableDeclarator)
|
|
200
|
-
.filter((variableDeclaratorPath) => {
|
|
201
|
-
const { id } = variableDeclaratorPath.node;
|
|
202
|
-
|
|
203
|
-
return (
|
|
204
|
-
id.type === 'Identifier' &&
|
|
205
|
-
identifierCollection.some((identifierPath) => identifierPath.node.name === id.name)
|
|
206
|
-
);
|
|
207
|
-
})
|
|
208
|
-
.find(j.ObjectExpression)
|
|
209
|
-
.find(j.ObjectProperty)
|
|
210
|
-
.filter((objectPropertyPath) =>
|
|
211
|
-
j(objectPropertyPath)
|
|
212
|
-
.find(j.Identifier)
|
|
213
|
-
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export function getJSXSpreadObjectExpressionAttributesByName(
|
|
218
|
-
j: JSCodeshift,
|
|
219
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
220
|
-
attributeName: string,
|
|
221
|
-
): Collection<ObjectProperty> {
|
|
222
|
-
return j(jsxElementPath)
|
|
223
|
-
.find(j.JSXOpeningElement)
|
|
224
|
-
.find(j.JSXSpreadAttribute)
|
|
225
|
-
.find(j.ObjectExpression)
|
|
226
|
-
.find(j.ObjectProperty)
|
|
227
|
-
.filter((objectPropertyPath) =>
|
|
228
|
-
j(objectPropertyPath)
|
|
229
|
-
.find(j.Identifier)
|
|
230
|
-
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export const createRemoveFuncFor: (
|
|
235
|
-
component: string,
|
|
236
|
-
importName: string,
|
|
237
|
-
prop: string,
|
|
238
|
-
comment?: string,
|
|
239
|
-
) => (j: core.JSCodeshift, source: Collection<Node>) => void =
|
|
240
|
-
(component: string, importName: string, prop: string, comment?: string) =>
|
|
241
|
-
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
242
|
-
const specifier = getNamedSpecifier(j, source, component, importName);
|
|
243
|
-
|
|
244
|
-
if (!specifier) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
source.findJSXElements(specifier).forEach((element) => {
|
|
249
|
-
getJSXAttributesByName(j, element, prop).forEach((attribute: any) => {
|
|
250
|
-
j(attribute).remove();
|
|
251
|
-
if (comment) {
|
|
252
|
-
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
export const getJSXAttributeByName: (
|
|
259
|
-
j: JSCodeshift,
|
|
260
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
261
|
-
attributeName: string,
|
|
262
|
-
) => JSXAttribute | undefined = (
|
|
263
|
-
j: JSCodeshift,
|
|
264
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
265
|
-
attributeName: string,
|
|
266
|
-
): JSXAttribute | undefined => {
|
|
267
|
-
const attributes: JSXAttribute[] = j(jsxElementPath).find(j.JSXAttribute).nodes();
|
|
268
|
-
|
|
269
|
-
return attributes?.find((attr) => attr.name && attr.name.name === attributeName);
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
export const addJSXAttributeToJSXElement: (
|
|
273
|
-
j: JSCodeshift,
|
|
274
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
275
|
-
jsxAttribute: JSXAttribute,
|
|
276
|
-
limit?: number,
|
|
277
|
-
) => void = (
|
|
278
|
-
j: JSCodeshift,
|
|
279
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
280
|
-
jsxAttribute: JSXAttribute,
|
|
281
|
-
limit?: number,
|
|
282
|
-
) => {
|
|
283
|
-
j(jsxElementPath)
|
|
284
|
-
.find(j.JSXOpeningElement)
|
|
285
|
-
.forEach((openingElement, i) => {
|
|
286
|
-
if (!limit || i < limit) {
|
|
287
|
-
openingElement.node.attributes?.push(jsxAttribute);
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
export const removeJSXAttributeByName: (
|
|
293
|
-
j: JSCodeshift,
|
|
294
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
295
|
-
attrName: string,
|
|
296
|
-
) => void = (j: JSCodeshift, jsxElementPath: ASTPath<JSXElement>, attrName: string) => {
|
|
297
|
-
const attributes = getJSXAttributes(jsxElementPath);
|
|
298
|
-
const attr = getJSXAttributeByName(j, jsxElementPath, attrName);
|
|
299
|
-
if (attr) {
|
|
300
|
-
attributes?.splice(attributes.indexOf(attr), 1);
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
export const getJSXAttributes: (jsxElementPath: ASTPath<JSXElement>) => JSXAttribute[] = (
|
|
305
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
306
|
-
) => jsxElementPath.node.openingElement.attributes as JSXAttribute[];
|
|
307
|
-
|
|
308
|
-
export const removeJSXAttributeObjectPropertyByName: (
|
|
309
|
-
j: JSCodeshift,
|
|
310
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
311
|
-
attrName: string,
|
|
312
|
-
propertyToRemove: string,
|
|
313
|
-
) => void = (
|
|
314
|
-
j: JSCodeshift,
|
|
315
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
316
|
-
attrName: string,
|
|
317
|
-
propertyToRemove: string,
|
|
318
|
-
) => {
|
|
319
|
-
const attr = getJSXAttributeByName(j, jsxElementPath, attrName);
|
|
320
|
-
|
|
321
|
-
if (!attr) {
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
const attrCollection = getJSXAttributesByName(j, jsxElementPath, attrName);
|
|
326
|
-
|
|
327
|
-
const removeMatchingNodes = (p: ASTPath<Identifier | StringLiteral>) => {
|
|
328
|
-
const name = p.node.type === 'Identifier' ? p.node?.name : p.node?.value;
|
|
329
|
-
// Need to account for quoted properties
|
|
330
|
-
const nameMatches = propertyToRemove.match(new RegExp(`['"]?${name}['"]?`));
|
|
331
|
-
// This will otherwise try to remove values of properties since they are literals
|
|
332
|
-
const isKey = p.parent.value?.type === 'ObjectProperty';
|
|
333
|
-
// Sorry about all the parents. This is the easiest way to get the name
|
|
334
|
-
// of the attribute name. And I always know the depth of the object
|
|
335
|
-
// property here.
|
|
336
|
-
const parentNameMatches = attrName === p.parent.parent.parent.parent.node?.name?.name;
|
|
337
|
-
if (isKey && nameMatches && parentNameMatches) {
|
|
338
|
-
j(p.parent).remove();
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
// Remove all the now migrated object properties
|
|
343
|
-
const objectProperties = attrCollection.find(j.ObjectProperty);
|
|
344
|
-
objectProperties.find(j.Identifier).forEach(removeMatchingNodes);
|
|
345
|
-
objectProperties.find(j.StringLiteral).forEach(removeMatchingNodes);
|
|
346
|
-
|
|
347
|
-
// @ts-ignore -- Property 'expression' does not exist on type 'LiteralKind | JSXElement | JSXExpressionContainer | JSXFragment'. Property 'expression' does not exist on type 'Literal'.
|
|
348
|
-
const attrProperties = attr.value?.expression.properties;
|
|
349
|
-
|
|
350
|
-
if (attrProperties && attrProperties?.length === 0) {
|
|
351
|
-
removeJSXAttributeByName(j, jsxElementPath, attrName);
|
|
352
|
-
}
|
|
353
|
-
};
|