@atlaskit/datetime-picker 17.6.2 → 17.6.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/14.0.0-remove-duplicate-and-unused-props.tsx +18 -61
- package/codemods/__tests__/next-remove-duplicate-and-unused-props.tsx +6 -6
- package/codemods/utils/add-jsx-attribute-to-jsx-element.tsx +13 -0
- package/codemods/utils/create-remove-func-for.tsx +30 -0
- package/codemods/utils/dtp-props-to-move-into-picker-props.tsx +23 -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-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/codemods/utils/select-props-to-move-into-props.tsx +23 -0
- package/package.json +17 -9
- package/codemods/utils/helpers.tsx +0 -327
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/datetime-picker
|
|
2
2
|
|
|
3
|
+
## 17.6.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 17.6.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
|
## 17.6.2
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1,78 +1,35 @@
|
|
|
1
1
|
import { type API, type FileInfo, type JSCodeshift, type Options } from 'jscodeshift';
|
|
2
2
|
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
3
|
|
|
4
|
+
import { addJSXAttributeToJSXElement } from './utils/add-jsx-attribute-to-jsx-element';
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from './utils/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type FromPickerFormula = {
|
|
22
|
-
source: string[];
|
|
23
|
-
newPropName: string;
|
|
24
|
-
};
|
|
6
|
+
dtpPropsToMoveIntoPickerProps,
|
|
7
|
+
type ToPickerFormula,
|
|
8
|
+
} from './utils/dtp-props-to-move-into-picker-props';
|
|
9
|
+
import { getImportDeclarationCollection } from './utils/get-import-declaration-collection';
|
|
10
|
+
import { getImportSpecifierCollection } from './utils/get-import-specifier-collection';
|
|
11
|
+
import { getImportSpecifierName } from './utils/get-import-specifier-name';
|
|
12
|
+
import { getJSXAttributeByName } from './utils/get-jsx-attribute-by-name';
|
|
13
|
+
import { getJSXAttributesByName } from './utils/get-jsx-attributes-by-name';
|
|
14
|
+
import { hasImportDeclaration } from './utils/has-import-declaration';
|
|
15
|
+
import { removeJSXAttributeByName } from './utils/remove-jsx-attribute-by-name';
|
|
16
|
+
import { removeJSXAttributeObjectPropertyByName } from './utils/remove-jsx-attribute-object-property-by-name';
|
|
17
|
+
import {
|
|
18
|
+
type FromPickerFormula,
|
|
19
|
+
selectPropsToMoveIntoProps,
|
|
20
|
+
} from './utils/select-props-to-move-into-props';
|
|
25
21
|
|
|
26
22
|
const importPath = '@atlaskit/datetime-picker';
|
|
27
23
|
|
|
28
24
|
const dateTimePickerImportName = 'DateTimePicker';
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
const datePickerImportName = 'DatePicker';
|
|
26
|
+
const timePickerImportName = 'TimePicker';
|
|
31
27
|
|
|
32
28
|
const pickerAndSelectPropNames = [
|
|
33
29
|
['datePickerSelectProps', 'datePickerProps'],
|
|
34
30
|
['timePickerSelectProps', 'timePickerProps'],
|
|
35
31
|
];
|
|
36
32
|
|
|
37
|
-
export const dtpPropsToMoveIntoPickerProps: ToPickerFormula[] = [
|
|
38
|
-
{
|
|
39
|
-
oldPropName: 'dateFormat',
|
|
40
|
-
destination: ['datePickerProps', 'dateFormat'],
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
oldPropName: 'times',
|
|
44
|
-
destination: ['timePickerProps', 'times'],
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
oldPropName: 'timeFormat',
|
|
48
|
-
destination: ['timePickerProps', 'timeFormat'],
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
oldPropName: 'timeIsEditable',
|
|
52
|
-
destination: ['timePickerProps', 'timeIsEditable'],
|
|
53
|
-
},
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
// For the pickers, not for DTP
|
|
57
|
-
export const selectPropsToMoveIntoProps: FromPickerFormula[] = [
|
|
58
|
-
{
|
|
59
|
-
source: ['selectProps', 'aria-describedby'],
|
|
60
|
-
newPropName: 'aria-describedby',
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
source: ['selectProps', 'aria-label'],
|
|
64
|
-
newPropName: 'label',
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
source: ['selectProps', 'inputId'],
|
|
68
|
-
newPropName: 'id',
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
source: ['selectProps', 'placeholder'],
|
|
72
|
-
newPropName: 'placeholder',
|
|
73
|
-
},
|
|
74
|
-
];
|
|
75
|
-
|
|
76
33
|
/**
|
|
77
34
|
* Move *pickerSelectProps into their respectice *pickerProps as a property
|
|
78
35
|
* named `selectProps`.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
jest.autoMockOff();
|
|
2
2
|
|
|
3
|
-
import transformer
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
selectPropsToMoveIntoProps,
|
|
7
|
-
timePickerImportName,
|
|
8
|
-
} from '../14.0.0-remove-duplicate-and-unused-props';
|
|
3
|
+
import transformer from '../14.0.0-remove-duplicate-and-unused-props';
|
|
4
|
+
import { dtpPropsToMoveIntoPickerProps } from '../utils/dtp-props-to-move-into-picker-props';
|
|
5
|
+
import { selectPropsToMoveIntoProps } from '../utils/select-props-to-move-into-props';
|
|
9
6
|
|
|
10
7
|
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
11
8
|
|
|
9
|
+
const datePickerImportName = 'DatePicker';
|
|
10
|
+
const timePickerImportName = 'TimePicker';
|
|
11
|
+
|
|
12
12
|
defineInlineTest(
|
|
13
13
|
{ default: transformer, parser: 'tsx' },
|
|
14
14
|
{},
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
) => void = (j: JSCodeshift, jsxElementPath: ASTPath<JSXElement>, jsxAttribute: JSXAttribute) => {
|
|
8
|
+
j(jsxElementPath)
|
|
9
|
+
.find(j.JSXOpeningElement)
|
|
10
|
+
.forEach((openingElement) => {
|
|
11
|
+
openingElement.node.attributes?.push(jsxAttribute);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -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,23 @@
|
|
|
1
|
+
export type ToPickerFormula = {
|
|
2
|
+
oldPropName: string;
|
|
3
|
+
destination: string[];
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const dtpPropsToMoveIntoPickerProps: ToPickerFormula[] = [
|
|
7
|
+
{
|
|
8
|
+
oldPropName: 'dateFormat',
|
|
9
|
+
destination: ['datePickerProps', 'dateFormat'],
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
oldPropName: 'times',
|
|
13
|
+
destination: ['timePickerProps', 'times'],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
oldPropName: 'timeFormat',
|
|
17
|
+
destination: ['timePickerProps', 'timeFormat'],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
oldPropName: 'timeIsEditable',
|
|
21
|
+
destination: ['timePickerProps', 'timeIsEditable'],
|
|
22
|
+
},
|
|
23
|
+
];
|
|
@@ -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,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
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type FromPickerFormula = {
|
|
2
|
+
source: string[];
|
|
3
|
+
newPropName: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const selectPropsToMoveIntoProps: FromPickerFormula[] = [
|
|
7
|
+
{
|
|
8
|
+
source: ['selectProps', 'aria-describedby'],
|
|
9
|
+
newPropName: 'aria-describedby',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
source: ['selectProps', 'aria-label'],
|
|
13
|
+
newPropName: 'label',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
source: ['selectProps', 'inputId'],
|
|
17
|
+
newPropName: 'id',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
source: ['selectProps', 'placeholder'],
|
|
21
|
+
newPropName: 'placeholder',
|
|
22
|
+
},
|
|
23
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/datetime-picker",
|
|
3
|
-
"version": "17.6.
|
|
3
|
+
"version": "17.6.4",
|
|
4
4
|
"description": "A date time picker allows the user to select an associated date and time.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -25,6 +25,13 @@
|
|
|
25
25
|
],
|
|
26
26
|
"atlaskit:src": "src/index.tsx",
|
|
27
27
|
"atlassian": {
|
|
28
|
+
"react-compiler": {
|
|
29
|
+
"enabled": true,
|
|
30
|
+
"gating": {
|
|
31
|
+
"source": "@atlassian/react-compiler-gating",
|
|
32
|
+
"importSpecifierName": "isReactCompilerActivePlatform"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
28
35
|
"team": "Design System Team",
|
|
29
36
|
"website": {
|
|
30
37
|
"name": "Date time picker",
|
|
@@ -33,10 +40,10 @@
|
|
|
33
40
|
},
|
|
34
41
|
"dependencies": {
|
|
35
42
|
"@atlaskit/analytics-next": "^11.2.0",
|
|
36
|
-
"@atlaskit/button": "^23.
|
|
43
|
+
"@atlaskit/button": "^23.11.0",
|
|
37
44
|
"@atlaskit/calendar": "^17.2.0",
|
|
38
45
|
"@atlaskit/css": "^0.19.0",
|
|
39
|
-
"@atlaskit/ds-lib": "^
|
|
46
|
+
"@atlaskit/ds-lib": "^7.0.0",
|
|
40
47
|
"@atlaskit/icon": "^34.0.0",
|
|
41
48
|
"@atlaskit/layering": "^3.6.0",
|
|
42
49
|
"@atlaskit/locale": "^3.0.0",
|
|
@@ -44,7 +51,7 @@
|
|
|
44
51
|
"@atlaskit/popper": "^7.1.0",
|
|
45
52
|
"@atlaskit/primitives": "^18.1.0",
|
|
46
53
|
"@atlaskit/select": "^21.10.0",
|
|
47
|
-
"@atlaskit/tokens": "^
|
|
54
|
+
"@atlaskit/tokens": "^12.0.0",
|
|
48
55
|
"@babel/runtime": "^7.0.0",
|
|
49
56
|
"@compiled/react": "^0.20.0",
|
|
50
57
|
"date-fns": "^2.17.0"
|
|
@@ -60,15 +67,16 @@
|
|
|
60
67
|
"@atlaskit/codemod-utils": "^4.2.0",
|
|
61
68
|
"@atlaskit/docs": "^11.7.0",
|
|
62
69
|
"@atlaskit/form": "^15.5.0",
|
|
63
|
-
"@atlaskit/heading": "^5.
|
|
64
|
-
"@atlaskit/link": "^3.
|
|
65
|
-
"@atlaskit/modal-dialog": "^14.
|
|
70
|
+
"@atlaskit/heading": "^5.4.0",
|
|
71
|
+
"@atlaskit/link": "^3.4.0",
|
|
72
|
+
"@atlaskit/modal-dialog": "^14.15.0",
|
|
66
73
|
"@atlaskit/popup": "^4.16.0",
|
|
67
74
|
"@atlaskit/range": "^10.0.0",
|
|
68
75
|
"@atlaskit/section-message": "^8.12.0",
|
|
69
|
-
"@atlaskit/textfield": "^8.
|
|
70
|
-
"@atlaskit/toggle": "^15.
|
|
76
|
+
"@atlaskit/textfield": "^8.3.0",
|
|
77
|
+
"@atlaskit/toggle": "^15.4.0",
|
|
71
78
|
"@atlassian/feature-flags-test-utils": "^1.0.0",
|
|
79
|
+
"@atlassian/react-compiler-gating": "workspace:^",
|
|
72
80
|
"@atlassian/ssr-tests": "workspace:^",
|
|
73
81
|
"@atlassian/structured-docs-types": "workspace:^",
|
|
74
82
|
"@testing-library/react": "^16.3.0",
|
|
@@ -1,327 +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
|
-
StringLiteral,
|
|
13
|
-
} from 'jscodeshift';
|
|
14
|
-
import { type Collection } from 'jscodeshift/src/Collection';
|
|
15
|
-
|
|
16
|
-
import { addCommentToStartOfFile, getNamedSpecifier } from '@atlaskit/codemod-utils';
|
|
17
|
-
|
|
18
|
-
export function hasImportDeclaration(
|
|
19
|
-
j: JSCodeshift,
|
|
20
|
-
collection: Collection<any>,
|
|
21
|
-
importPath: string,
|
|
22
|
-
): boolean {
|
|
23
|
-
return getImportDeclarationCollection(j, collection, importPath).length > 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function getImportDeclarationCollection(
|
|
27
|
-
j: JSCodeshift,
|
|
28
|
-
collection: Collection<any>,
|
|
29
|
-
importPath: string,
|
|
30
|
-
): Collection<ImportDeclaration> {
|
|
31
|
-
return collection
|
|
32
|
-
.find(j.ImportDeclaration)
|
|
33
|
-
.filter((importDeclarationPath) => importDeclarationPath.node.source.value === importPath);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function hasDynamicImport(
|
|
37
|
-
j: JSCodeshift,
|
|
38
|
-
collection: Collection<any>,
|
|
39
|
-
importPath: string,
|
|
40
|
-
): boolean {
|
|
41
|
-
return getDynamicImportCollection(j, collection, importPath).length > 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function getDynamicImportCollection(
|
|
45
|
-
j: JSCodeshift,
|
|
46
|
-
collection: Collection<any>,
|
|
47
|
-
importPath: string,
|
|
48
|
-
): Collection<CallExpression> {
|
|
49
|
-
return collection.find(j.CallExpression).filter((callExpressionPath) => {
|
|
50
|
-
const { callee, arguments: callExpressionArguments } = callExpressionPath.node;
|
|
51
|
-
|
|
52
|
-
return !!(
|
|
53
|
-
isCallExpressionCalleeImportType(callee) &&
|
|
54
|
-
isCallExpressionArgumentStringLiteralType(callExpressionArguments) &&
|
|
55
|
-
isCallExpressionArgumentValueMatches(callExpressionArguments[0], j, importPath)
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function isCallExpressionCalleeImportType(callee: CallExpression['callee']) {
|
|
60
|
-
return callee && callee.type === 'Import';
|
|
61
|
-
}
|
|
62
|
-
function isCallExpressionArgumentStringLiteralType(
|
|
63
|
-
callExpressionArguments: CallExpression['arguments'],
|
|
64
|
-
) {
|
|
65
|
-
return (
|
|
66
|
-
callExpressionArguments &&
|
|
67
|
-
callExpressionArguments.length &&
|
|
68
|
-
callExpressionArguments[0].type === 'StringLiteral'
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
function isCallExpressionArgumentValueMatches(
|
|
72
|
-
callExpressionArgument: CallExpression['arguments'][0],
|
|
73
|
-
j: JSCodeshift,
|
|
74
|
-
value: string,
|
|
75
|
-
) {
|
|
76
|
-
return j(callExpressionArgument).some((path) => path.node.value === value);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function getImportSpecifierCollection(
|
|
80
|
-
j: JSCodeshift,
|
|
81
|
-
importDeclarationCollection: Collection<ImportDeclaration>,
|
|
82
|
-
importName: string,
|
|
83
|
-
): Collection<ImportSpecifier> {
|
|
84
|
-
return importDeclarationCollection
|
|
85
|
-
.find(j.ImportSpecifier)
|
|
86
|
-
.filter((importSpecifierPath) => importSpecifierPath.node.imported.name === importName);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function getImportSpecifierName(
|
|
90
|
-
importSpecifierCollection: Collection<ImportSpecifier>,
|
|
91
|
-
): string | null {
|
|
92
|
-
if (importSpecifierCollection.length === 0) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return importSpecifierCollection.nodes()[0]!.local!.name;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function isVariableDeclaratorIdentifierPresent(
|
|
100
|
-
j: JSCodeshift,
|
|
101
|
-
collection: Collection<any>,
|
|
102
|
-
variableName: string,
|
|
103
|
-
): boolean {
|
|
104
|
-
return collection
|
|
105
|
-
.find(j.VariableDeclaration)
|
|
106
|
-
.find(j.VariableDeclarator)
|
|
107
|
-
.some((variableDeclaratorPath) => {
|
|
108
|
-
const { id } = variableDeclaratorPath.node;
|
|
109
|
-
|
|
110
|
-
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function isFunctionDeclarationIdentifierPresent(
|
|
115
|
-
j: JSCodeshift,
|
|
116
|
-
collection: Collection<any>,
|
|
117
|
-
variableName: string,
|
|
118
|
-
): boolean {
|
|
119
|
-
return collection.find(j.FunctionDeclaration).some((functionDeclarationPath) => {
|
|
120
|
-
const { id } = functionDeclarationPath.node;
|
|
121
|
-
|
|
122
|
-
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function isClassDeclarationIdentifierPresent(
|
|
127
|
-
j: JSCodeshift,
|
|
128
|
-
collection: Collection<any>,
|
|
129
|
-
variableName: string,
|
|
130
|
-
): boolean {
|
|
131
|
-
return collection.find(j.ClassDeclaration).some((classDeclarationPath) => {
|
|
132
|
-
const { id } = classDeclarationPath.node;
|
|
133
|
-
|
|
134
|
-
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function isImportDeclarationIdentifierPresent(
|
|
139
|
-
j: JSCodeshift,
|
|
140
|
-
collection: Collection<any>,
|
|
141
|
-
variableName: string,
|
|
142
|
-
): boolean {
|
|
143
|
-
return collection
|
|
144
|
-
.find(j.ImportDeclaration)
|
|
145
|
-
.find(j.Identifier)
|
|
146
|
-
.some((identifierPath) => identifierPath.node.name === variableName);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function getJSXAttributesByName(
|
|
150
|
-
j: JSCodeshift,
|
|
151
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
152
|
-
attributeName: string,
|
|
153
|
-
): Collection<JSXAttribute> {
|
|
154
|
-
return j(jsxElementPath)
|
|
155
|
-
.find(j.JSXOpeningElement)
|
|
156
|
-
.find(j.JSXAttribute)
|
|
157
|
-
.filter((jsxAttributePath) =>
|
|
158
|
-
j(jsxAttributePath)
|
|
159
|
-
.find(j.JSXIdentifier)
|
|
160
|
-
.some((jsxIdentifierPath) => jsxIdentifierPath.node.name === attributeName),
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function getJSXSpreadIdentifierAttributesByName(
|
|
165
|
-
j: JSCodeshift,
|
|
166
|
-
collection: Collection<any>,
|
|
167
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
168
|
-
attributeName: string,
|
|
169
|
-
): Collection<ObjectProperty> | null {
|
|
170
|
-
const identifierCollection = j(jsxElementPath)
|
|
171
|
-
.find(j.JSXOpeningElement)
|
|
172
|
-
.find(j.JSXSpreadAttribute)
|
|
173
|
-
.filter((jsxSpreadAttributePath) => jsxSpreadAttributePath.node.argument.type === 'Identifier')
|
|
174
|
-
.find(j.Identifier);
|
|
175
|
-
|
|
176
|
-
if (identifierCollection.length === 0) {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return collection
|
|
181
|
-
.find(j.VariableDeclarator)
|
|
182
|
-
.filter((variableDeclaratorPath) => {
|
|
183
|
-
const { id } = variableDeclaratorPath.node;
|
|
184
|
-
|
|
185
|
-
return (
|
|
186
|
-
id.type === 'Identifier' &&
|
|
187
|
-
identifierCollection.some((identifierPath) => identifierPath.node.name === id.name)
|
|
188
|
-
);
|
|
189
|
-
})
|
|
190
|
-
.find(j.ObjectExpression)
|
|
191
|
-
.find(j.ObjectProperty)
|
|
192
|
-
.filter((objectPropertyPath) =>
|
|
193
|
-
j(objectPropertyPath)
|
|
194
|
-
.find(j.Identifier)
|
|
195
|
-
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export function getJSXSpreadObjectExpressionAttributesByName(
|
|
200
|
-
j: JSCodeshift,
|
|
201
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
202
|
-
attributeName: string,
|
|
203
|
-
): Collection<ObjectProperty> {
|
|
204
|
-
return j(jsxElementPath)
|
|
205
|
-
.find(j.JSXOpeningElement)
|
|
206
|
-
.find(j.JSXSpreadAttribute)
|
|
207
|
-
.find(j.ObjectExpression)
|
|
208
|
-
.find(j.ObjectProperty)
|
|
209
|
-
.filter((objectPropertyPath) =>
|
|
210
|
-
j(objectPropertyPath)
|
|
211
|
-
.find(j.Identifier)
|
|
212
|
-
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export const createRemoveFuncFor: (
|
|
217
|
-
component: string,
|
|
218
|
-
importName: string,
|
|
219
|
-
prop: string,
|
|
220
|
-
comment?: string,
|
|
221
|
-
) => (j: core.JSCodeshift, source: Collection<Node>) => void =
|
|
222
|
-
(component: string, importName: string, prop: string, comment?: string) =>
|
|
223
|
-
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
224
|
-
const specifier = getNamedSpecifier(j, source, component, importName);
|
|
225
|
-
|
|
226
|
-
if (!specifier) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
source.findJSXElements(specifier).forEach((element) => {
|
|
231
|
-
getJSXAttributesByName(j, element, prop).forEach((attribute: any) => {
|
|
232
|
-
j(attribute).remove();
|
|
233
|
-
if (comment) {
|
|
234
|
-
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
export const getJSXAttributeByName: (
|
|
241
|
-
j: JSCodeshift,
|
|
242
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
243
|
-
attributeName: string,
|
|
244
|
-
) => JSXAttribute | undefined = (
|
|
245
|
-
j: JSCodeshift,
|
|
246
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
247
|
-
attributeName: string,
|
|
248
|
-
): JSXAttribute | undefined => {
|
|
249
|
-
const attributes: JSXAttribute[] = j(jsxElementPath).find(j.JSXAttribute).nodes();
|
|
250
|
-
|
|
251
|
-
return attributes?.find((attr) => attr.name && attr.name.name === attributeName);
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
export const addJSXAttributeToJSXElement: (
|
|
255
|
-
j: JSCodeshift,
|
|
256
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
257
|
-
jsxAttribute: JSXAttribute,
|
|
258
|
-
) => void = (j: JSCodeshift, jsxElementPath: ASTPath<JSXElement>, jsxAttribute: JSXAttribute) => {
|
|
259
|
-
j(jsxElementPath)
|
|
260
|
-
.find(j.JSXOpeningElement)
|
|
261
|
-
.forEach((openingElement) => {
|
|
262
|
-
openingElement.node.attributes?.push(jsxAttribute);
|
|
263
|
-
});
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
export const removeJSXAttributeByName: (
|
|
267
|
-
j: JSCodeshift,
|
|
268
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
269
|
-
attrName: string,
|
|
270
|
-
) => void = (j: JSCodeshift, jsxElementPath: ASTPath<JSXElement>, attrName: string) => {
|
|
271
|
-
const attributes = getJSXAttributes(jsxElementPath);
|
|
272
|
-
const attr = getJSXAttributeByName(j, jsxElementPath, attrName);
|
|
273
|
-
if (attr) {
|
|
274
|
-
attributes?.splice(attributes.indexOf(attr), 1);
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
export const getJSXAttributes: (jsxElementPath: ASTPath<JSXElement>) => JSXAttribute[] = (
|
|
279
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
280
|
-
) => jsxElementPath.node.openingElement.attributes as JSXAttribute[];
|
|
281
|
-
|
|
282
|
-
export const removeJSXAttributeObjectPropertyByName: (
|
|
283
|
-
j: JSCodeshift,
|
|
284
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
285
|
-
attrName: string,
|
|
286
|
-
propertyToRemove: string,
|
|
287
|
-
) => void = (
|
|
288
|
-
j: JSCodeshift,
|
|
289
|
-
jsxElementPath: ASTPath<JSXElement>,
|
|
290
|
-
attrName: string,
|
|
291
|
-
propertyToRemove: string,
|
|
292
|
-
) => {
|
|
293
|
-
const attr = getJSXAttributeByName(j, jsxElementPath, attrName);
|
|
294
|
-
|
|
295
|
-
if (!attr) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const attrCollection = getJSXAttributesByName(j, jsxElementPath, attrName);
|
|
300
|
-
|
|
301
|
-
const removeMatchingNodes = (p: ASTPath<Identifier | StringLiteral>) => {
|
|
302
|
-
const name = p.node.type === 'Identifier' ? p.node?.name : p.node?.value;
|
|
303
|
-
// Need to account for quoted properties
|
|
304
|
-
const nameMatches = propertyToRemove.match(new RegExp(`['"]?${name}['"]?`));
|
|
305
|
-
// This will otherwise try to remove values of properties since they are literals
|
|
306
|
-
const isKey = p.parent.value?.type === 'ObjectProperty';
|
|
307
|
-
// Sorry about all the parents. This is the easiest way to get the name
|
|
308
|
-
// of the attribute name. And I always know the depth of the object
|
|
309
|
-
// property here.
|
|
310
|
-
const parentNameMatches = attrName === p.parent.parent.parent.parent.node?.name?.name;
|
|
311
|
-
if (isKey && nameMatches && parentNameMatches) {
|
|
312
|
-
j(p.parent).remove();
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
// Remove all the now migrated object properties
|
|
317
|
-
const objectProperties = attrCollection.find(j.ObjectProperty);
|
|
318
|
-
objectProperties.find(j.Identifier).forEach(removeMatchingNodes);
|
|
319
|
-
objectProperties.find(j.StringLiteral).forEach(removeMatchingNodes);
|
|
320
|
-
|
|
321
|
-
// @ts-ignore -- Property 'expression' does not exist on type 'LiteralKind | JSXElement | JSXExpressionContainer | JSXFragment'. Property 'expression' does not exist on type 'Literal'.
|
|
322
|
-
const attrProperties = attr.value?.expression.properties;
|
|
323
|
-
|
|
324
|
-
if (attrProperties && attrProperties?.length === 0) {
|
|
325
|
-
removeJSXAttributeByName(j, jsxElementPath, attrName);
|
|
326
|
-
}
|
|
327
|
-
};
|