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" ;
9
3
10
4
const getRenameComment = ( keyName : string , newKeyName : string ) =>
11
5
` The key ${ keyName } is renamed to ${ newKeyName } .` ;
@@ -31,42 +25,37 @@ export const getObjectWithUpdatedAwsConfigKeys = (
31
25
32
26
// Add properties from awsGlobalConfig
33
27
for ( const property of awsGlobalConfig . properties ) {
34
- if ( ! OBJECT_PROPERTY_TYPE_LIST . includes ( property . type ) ) {
28
+ if ( property . type !== "Property" && property . type !== "ObjectProperty" ) {
35
29
propertiesToUpdate . push ( property ) ;
36
30
continue ;
37
31
}
38
32
39
- const propertyKey = ( property as Property | ObjectProperty ) . key ;
40
- if ( propertyKey . type !== "Identifier" ) {
33
+ if ( property . key . type !== "Identifier" ) {
41
34
propertiesToUpdate . push ( property ) ;
42
35
continue ;
43
36
}
44
37
45
- const propertyKeyName = propertyKey . name ;
38
+ const propertyKeyName = property . key . name ;
46
39
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
+ } )
58
47
) {
59
48
propertiesToUpdate . push ( property ) ;
60
49
}
61
50
}
62
51
63
52
const updatedProperties = propertiesToUpdate
64
53
. map ( ( property ) => {
65
- if ( ! OBJECT_PROPERTY_TYPE_LIST . includes ( property . type ) ) {
54
+ if ( property . type !== "Property" && property . type !== "ObjectProperty" ) {
66
55
return property ;
67
56
}
68
57
69
- const propertyKey = ( property as Property | ObjectProperty ) . key ;
58
+ const propertyKey = property . key ;
70
59
if ( propertyKey . type !== "Identifier" ) {
71
60
return property ;
72
61
}
0 commit comments