Skip to content

Commit ef2ebf0

Browse files
committed
chore: remove type assertion in getObjectWithUpdatedAwsConfigKeys
1 parent 9381cfc commit ef2ebf0

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

src/transforms/v2-to-v3/client-instances/getObjectWithUpdatedAwsConfigKeys.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import type {
2-
Identifier,
3-
JSCodeshift,
4-
ObjectExpression,
5-
ObjectProperty,
6-
Property,
7-
} from "jscodeshift";
8-
import { AWS_CONFIG_KEY_MAP, OBJECT_PROPERTY_TYPE_LIST } from "../config";
1+
import type { JSCodeshift, ObjectExpression } from "jscodeshift";
2+
import { AWS_CONFIG_KEY_MAP } from "../config";
93

104
const getRenameComment = (keyName: string, newKeyName: string) =>
115
` The key ${keyName} is renamed to ${newKeyName}.`;
@@ -31,42 +25,37 @@ export const getObjectWithUpdatedAwsConfigKeys = (
3125

3226
// Add properties from awsGlobalConfig
3327
for (const property of awsGlobalConfig.properties) {
34-
if (!OBJECT_PROPERTY_TYPE_LIST.includes(property.type)) {
28+
if (property.type !== "Property" && property.type !== "ObjectProperty") {
3529
propertiesToUpdate.push(property);
3630
continue;
3731
}
3832

39-
const propertyKey = (property as Property | ObjectProperty).key;
40-
if (propertyKey.type !== "Identifier") {
33+
if (property.key.type !== "Identifier") {
4134
propertiesToUpdate.push(property);
4235
continue;
4336
}
4437

45-
const propertyKeyName = propertyKey.name;
38+
const propertyKeyName = property.key.name;
4639
if (
47-
!propertiesToUpdate
48-
.filter((propertyToUpdate) => OBJECT_PROPERTY_TYPE_LIST.includes(propertyToUpdate.type))
49-
.filter(
50-
(propertyToUpdate) =>
51-
(propertyToUpdate as Property | ObjectProperty).key.type === "Identifier"
52-
)
53-
.some(
54-
(propertyToUpdate) =>
55-
((propertyToUpdate as Property | ObjectProperty).key as Identifier).name ===
56-
propertyKeyName
57-
)
40+
!propertiesToUpdate.some((propertyToUpdate) => {
41+
if (propertyToUpdate.type === "Property" || propertyToUpdate.type === "ObjectProperty") {
42+
if (propertyToUpdate.key.type === "Identifier") {
43+
return propertyToUpdate.key.name === propertyKeyName;
44+
}
45+
}
46+
})
5847
) {
5948
propertiesToUpdate.push(property);
6049
}
6150
}
6251

6352
const updatedProperties = propertiesToUpdate
6453
.map((property) => {
65-
if (!OBJECT_PROPERTY_TYPE_LIST.includes(property.type)) {
54+
if (property.type !== "Property" && property.type !== "ObjectProperty") {
6655
return property;
6756
}
6857

69-
const propertyKey = (property as Property | ObjectProperty).key;
58+
const propertyKey = property.key;
7059
if (propertyKey.type !== "Identifier") {
7160
return property;
7261
}

0 commit comments

Comments
 (0)