ember-codemod-add-component-signatures 5.4.5 → 5.5.0
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/dist/src/utils/analyze-project/find-arguments.js +16 -11
- package/dist/src/utils/analyze-project/find-blocks.js +3 -2
- package/dist/src/utils/create-registries/create-registry.js +3 -3
- package/dist/src/utils/create-registries/rename-component/update-references.js +1 -0
- package/dist/src/utils/create-signatures/create-signature/builders.js +2 -9
- package/dist/src/utils/create-signatures/create-signature/pass-signature-to-base-component.js +74 -34
- package/dist/src/utils/update-signatures/update-signature/builders.js +4 -7
- package/dist/src/utils/update-signatures/update-signature.js +4 -5
- package/package.json +10 -10
|
@@ -8,29 +8,29 @@ function analyzeClass(file) {
|
|
|
8
8
|
// We know that the file is in TypeScript
|
|
9
9
|
const traverse = ASTJavaScript.traverse(true);
|
|
10
10
|
traverse(file, {
|
|
11
|
-
visitMemberExpression(
|
|
12
|
-
this.traverse(
|
|
13
|
-
if (node.
|
|
14
|
-
node.
|
|
15
|
-
node.
|
|
11
|
+
visitMemberExpression(path) {
|
|
12
|
+
this.traverse(path);
|
|
13
|
+
if (path.node.object.type !== 'MemberExpression' ||
|
|
14
|
+
path.node.object.property.type !== 'Identifier' ||
|
|
15
|
+
path.node.object.property.name !== 'args') {
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
|
-
switch (node.
|
|
18
|
+
switch (path.node.property.type) {
|
|
19
19
|
// Matches the pattern `this.args.someArgument`
|
|
20
20
|
case 'Identifier': {
|
|
21
|
-
args.add(node.
|
|
21
|
+
args.add(path.node.property.name);
|
|
22
22
|
break;
|
|
23
23
|
}
|
|
24
24
|
// Matches the pattern `this.args['someArgument']`
|
|
25
25
|
case 'StringLiteral': {
|
|
26
|
-
args.add(node.
|
|
26
|
+
args.add(path.node.property.value);
|
|
27
27
|
break;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
return false;
|
|
31
31
|
},
|
|
32
|
-
visitVariableDeclarator(
|
|
33
|
-
const { id: leftHandSide, init: rightHandSide } = node
|
|
32
|
+
visitVariableDeclarator(path) {
|
|
33
|
+
const { id: leftHandSide, init: rightHandSide } = path.node;
|
|
34
34
|
let isValid = false;
|
|
35
35
|
switch (rightHandSide?.type) {
|
|
36
36
|
// Matches the pattern `const { someArgument } = this.args;`
|
|
@@ -58,8 +58,13 @@ function analyzeClass(file) {
|
|
|
58
58
|
if (!isValid) {
|
|
59
59
|
return false;
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
if (leftHandSide.type !== 'ObjectPattern') {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
62
64
|
leftHandSide.properties.forEach((property) => {
|
|
65
|
+
if (property.type !== 'ObjectProperty') {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
63
68
|
switch (property.key.type) {
|
|
64
69
|
case 'Identifier': {
|
|
65
70
|
args.add(property.key.name);
|
|
@@ -12,8 +12,9 @@ export function findBlocks(templateFile) {
|
|
|
12
12
|
const toArgument = node.hash.pairs.find(({ key }) => {
|
|
13
13
|
return key === 'to';
|
|
14
14
|
});
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const blockName = normalizeBlockName(
|
|
16
|
+
// @ts-expect-error: Incorrect type
|
|
17
|
+
toArgument?.value?.original);
|
|
17
18
|
const positionalArgumentTypes = node.params.map(({ type: recastType }) => {
|
|
18
19
|
return getBlockParameterType(recastType);
|
|
19
20
|
});
|
|
@@ -2,8 +2,6 @@ import { AST } from '@codemod-utils/ast-javascript';
|
|
|
2
2
|
export function createRegistry(file, data) {
|
|
3
3
|
const traverse = AST.traverse(true);
|
|
4
4
|
const ast = traverse(file);
|
|
5
|
-
// @ts-expect-error: Assume that types from external packages are correct
|
|
6
|
-
const nodes = ast.program.body;
|
|
7
5
|
const registryEntries = AST.builders.tsInterfaceBody([
|
|
8
6
|
AST.builders.tsPropertySignature(AST.builders.stringLiteral(data.entity.doubleColonizedName), AST.builders.tsTypeAnnotation(AST.builders.tsTypeQuery(AST.builders.identifier(data.entity.pascalizedName)))),
|
|
9
7
|
AST.builders.tsPropertySignature(AST.builders.stringLiteral(data.entity.name), AST.builders.tsTypeAnnotation(AST.builders.tsTypeQuery(AST.builders.identifier(data.entity.pascalizedName)))),
|
|
@@ -12,6 +10,8 @@ export function createRegistry(file, data) {
|
|
|
12
10
|
AST.builders.exportDefaultDeclaration(AST.builders.tsInterfaceDeclaration(AST.builders.identifier('Registry'), registryEntries)),
|
|
13
11
|
]));
|
|
14
12
|
registryNode.declare = true;
|
|
15
|
-
|
|
13
|
+
// @ts-expect-error: Incorrect type
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
15
|
+
ast.program.body.push(registryNode);
|
|
16
16
|
return AST.print(ast);
|
|
17
17
|
}
|
|
@@ -14,6 +14,7 @@ export function updateReferences(file, options) {
|
|
|
14
14
|
AST.builders.noop(),
|
|
15
15
|
AST.builders.exportDefaultDeclaration(AST.builders.identifier(data.entity.pascalizedName)),
|
|
16
16
|
];
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
17
18
|
path.parentPath.value.push(...nodesToAdd);
|
|
18
19
|
return AST.builders.variableDeclaration('const', [
|
|
19
20
|
AST.builders.variableDeclarator(AST.builders.identifier(data.entity.pascalizedName), path.node.declaration),
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { AST } from '@codemod-utils/ast-javascript';
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
3
2
|
export function builderConvertArgsToSignature(nodes = []) {
|
|
4
3
|
return [
|
|
5
|
-
AST.builders.tsPropertySignature(AST.builders.identifier('Args'),
|
|
6
|
-
// @ts-expect-error: Assume that types from external packages are correct
|
|
7
|
-
AST.builders.tsTypeAnnotation(AST.builders.tsTypeLiteral(nodes)), false),
|
|
4
|
+
AST.builders.tsPropertySignature(AST.builders.identifier('Args'), AST.builders.tsTypeAnnotation(AST.builders.tsTypeLiteral(nodes)), false),
|
|
8
5
|
];
|
|
9
6
|
}
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
11
7
|
export function builderCreateSignature(identifier, members) {
|
|
12
|
-
return AST.builders.tsInterfaceDeclaration(AST.builders.identifier(identifier),
|
|
13
|
-
// @ts-expect-error: Assume that types from external packages are correct
|
|
14
|
-
AST.builders.tsInterfaceBody(members));
|
|
8
|
+
return AST.builders.tsInterfaceDeclaration(AST.builders.identifier(identifier), AST.builders.tsInterfaceBody(members));
|
|
15
9
|
}
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
17
10
|
export function builderPassSignature(identifier) {
|
|
18
11
|
return AST.builders.tsTypeParameterInstantiation([
|
|
19
12
|
AST.builders.tsTypeReference(AST.builders.identifier(identifier)),
|
package/dist/src/utils/create-signatures/create-signature/pass-signature-to-base-component.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AST } from '@codemod-utils/ast-javascript';
|
|
2
2
|
import { builderConvertArgsToSignature, builderCreateSignature, builderPassSignature, } from './builders.js';
|
|
3
3
|
import { isSignature } from './is-signature.js';
|
|
4
|
-
const MARKER = 'template_fd9b2463e5f141cfb5666b64daa1f11a';
|
|
5
4
|
export function passSignatureToBaseComponent(file, options) {
|
|
6
5
|
const traverse = AST.traverse(true);
|
|
7
6
|
const { baseComponentName, data } = options;
|
|
@@ -14,19 +13,24 @@ export function passSignatureToBaseComponent(file, options) {
|
|
|
14
13
|
let typeParameters;
|
|
15
14
|
switch (path.node.callee.name) {
|
|
16
15
|
case 'templateOnlyComponent': {
|
|
17
|
-
// @ts-expect-error:
|
|
16
|
+
// @ts-expect-error: Incorrect type
|
|
18
17
|
typeParameters = path.node.typeParameters;
|
|
19
18
|
break;
|
|
20
19
|
}
|
|
21
|
-
case
|
|
22
|
-
|
|
20
|
+
case 'template_fd9b2463e5f141cfb5666b64daa1f11a': {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
22
|
+
const parentPath = path.parentPath;
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
24
|
+
const type = parentPath.value.type;
|
|
23
25
|
if (type === 'TSSatisfiesExpression') {
|
|
24
26
|
typeParameters =
|
|
25
|
-
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
28
|
+
parentPath.value.typeAnnotation.typeParameters;
|
|
26
29
|
}
|
|
27
30
|
else if (type === 'VariableDeclarator') {
|
|
28
31
|
typeParameters =
|
|
29
|
-
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
33
|
+
parentPath.value.id.typeAnnotation.typeAnnotation
|
|
30
34
|
.typeParameters;
|
|
31
35
|
}
|
|
32
36
|
break;
|
|
@@ -39,20 +43,29 @@ export function passSignatureToBaseComponent(file, options) {
|
|
|
39
43
|
// When the interface is missing
|
|
40
44
|
if (!typeParameters) {
|
|
41
45
|
const members = builderConvertArgsToSignature();
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
42
47
|
switch (path.parentPath.node.type) {
|
|
43
48
|
case 'ExportDefaultDeclaration': {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
50
|
+
const parentPath = path.parentPath;
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
52
|
+
const index = parentPath.name;
|
|
44
53
|
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// @ts-expect-error:
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
55
|
+
parentPath.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
56
|
+
// @ts-expect-error: Incorrect type
|
|
48
57
|
path.node.typeParameters = builderPassSignature(identifier);
|
|
49
58
|
break;
|
|
50
59
|
}
|
|
51
60
|
case 'VariableDeclarator': {
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
62
|
+
const parentPath = path.parentPath.parentPath.parentPath;
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
64
|
+
const index = parentPath.name;
|
|
52
65
|
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// @ts-expect-error:
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
67
|
+
parentPath.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
68
|
+
// @ts-expect-error: Incorrect type
|
|
56
69
|
path.node.typeParameters = builderPassSignature(identifier);
|
|
57
70
|
break;
|
|
58
71
|
}
|
|
@@ -66,20 +79,29 @@ export function passSignatureToBaseComponent(file, options) {
|
|
|
66
79
|
const members = isSignature(typeParameter.members)
|
|
67
80
|
? typeParameter.members
|
|
68
81
|
: builderConvertArgsToSignature(typeParameter.members);
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
69
83
|
switch (path.parentPath.node.type) {
|
|
70
84
|
case 'ExportDefaultDeclaration': {
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
86
|
+
const parentPath = path.parentPath;
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
88
|
+
const index = parentPath.name;
|
|
71
89
|
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// @ts-expect-error:
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
91
|
+
parentPath.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
92
|
+
// @ts-expect-error: Incorrect type
|
|
75
93
|
path.node.typeParameters = builderPassSignature(identifier);
|
|
76
94
|
break;
|
|
77
95
|
}
|
|
78
96
|
case 'VariableDeclarator': {
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
98
|
+
const parentPath = path.parentPath.parentPath.parentPath;
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
100
|
+
const index = parentPath.name;
|
|
79
101
|
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// @ts-expect-error:
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
103
|
+
parentPath.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
104
|
+
// @ts-expect-error: Incorrect type
|
|
83
105
|
path.node.typeParameters = builderPassSignature(identifier);
|
|
84
106
|
break;
|
|
85
107
|
}
|
|
@@ -88,9 +110,11 @@ export function passSignatureToBaseComponent(file, options) {
|
|
|
88
110
|
}
|
|
89
111
|
// When the interface is defined "outside"
|
|
90
112
|
case 'TSTypeReference': {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
113
|
+
if (typeParameter.typeName.type === 'Identifier') {
|
|
114
|
+
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
115
|
+
interfaceName = typeParameter.typeName.name;
|
|
116
|
+
typeParameter.typeName.name = identifier;
|
|
117
|
+
}
|
|
94
118
|
return false;
|
|
95
119
|
}
|
|
96
120
|
}
|
|
@@ -106,17 +130,21 @@ export function passSignatureToBaseComponent(file, options) {
|
|
|
106
130
|
// When the interface is missing
|
|
107
131
|
if (!typeParameters) {
|
|
108
132
|
const members = builderConvertArgsToSignature();
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
109
134
|
switch (path.parentPath.node.type) {
|
|
110
135
|
case 'ExportDefaultDeclaration': {
|
|
111
|
-
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
112
137
|
const index = path.parentPath.name;
|
|
138
|
+
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
113
140
|
path.parentPath.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
114
141
|
path.node.superTypeParameters = builderPassSignature(identifier);
|
|
115
142
|
break;
|
|
116
143
|
}
|
|
117
144
|
case 'Program': {
|
|
118
|
-
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
119
145
|
const index = path.name;
|
|
146
|
+
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
120
148
|
path.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
121
149
|
path.node.superTypeParameters = builderPassSignature(identifier);
|
|
122
150
|
break;
|
|
@@ -128,12 +156,16 @@ export function passSignatureToBaseComponent(file, options) {
|
|
|
128
156
|
switch (typeParameter.type) {
|
|
129
157
|
// When the interface is directly passed to the component
|
|
130
158
|
case 'TSTypeLiteral': {
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
160
|
+
const parentPath = path.parentPath;
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
162
|
+
const index = parentPath.name;
|
|
163
|
+
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
131
164
|
const members = isSignature(typeParameter.members)
|
|
132
165
|
? typeParameter.members
|
|
133
166
|
: builderConvertArgsToSignature(typeParameter.members);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
path.parentPath.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
168
|
+
parentPath.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
137
169
|
path.node.superTypeParameters = builderPassSignature(identifier);
|
|
138
170
|
return false;
|
|
139
171
|
}
|
|
@@ -151,19 +183,23 @@ export function passSignatureToBaseComponent(file, options) {
|
|
|
151
183
|
return false;
|
|
152
184
|
},
|
|
153
185
|
visitClassExpression(path) {
|
|
154
|
-
if (
|
|
155
|
-
path.node.superClass.type !== 'Identifier' ||
|
|
186
|
+
if (path.node.superClass?.type !== 'Identifier' ||
|
|
156
187
|
path.node.superClass.name !== baseComponentName) {
|
|
157
188
|
return false;
|
|
158
189
|
}
|
|
159
190
|
const typeParameters = path.node.superTypeParameters;
|
|
160
191
|
if (!typeParameters) {
|
|
161
|
-
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
162
193
|
switch (path.parentPath.node.type) {
|
|
163
194
|
case 'VariableDeclarator': {
|
|
195
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
196
|
+
const parentPath = path.parentPath.parentPath.parentPath;
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
198
|
+
const index = parentPath.name;
|
|
164
199
|
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
165
|
-
const
|
|
166
|
-
|
|
200
|
+
const members = builderConvertArgsToSignature();
|
|
201
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
202
|
+
parentPath.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
167
203
|
path.node.superTypeParameters = builderPassSignature(identifier);
|
|
168
204
|
break;
|
|
169
205
|
}
|
|
@@ -174,12 +210,16 @@ export function passSignatureToBaseComponent(file, options) {
|
|
|
174
210
|
switch (typeParameter.type) {
|
|
175
211
|
// When the interface is directly passed to the component
|
|
176
212
|
case 'TSTypeLiteral': {
|
|
213
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
214
|
+
const parentPath = path.parentPath.parentPath.parentPath;
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
216
|
+
const index = parentPath.name;
|
|
217
|
+
const identifier = `${data.entity.pascalizedName}Signature`;
|
|
177
218
|
const members = isSignature(typeParameter.members)
|
|
178
219
|
? typeParameter.members
|
|
179
220
|
: builderConvertArgsToSignature(typeParameter.members);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
path.parentPath.parentPath.parentPath.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
222
|
+
parentPath.parentPath.value.splice(index, 0, builderCreateSignature(identifier, members));
|
|
183
223
|
path.node.superTypeParameters = builderPassSignature(identifier);
|
|
184
224
|
return false;
|
|
185
225
|
}
|
|
@@ -26,7 +26,6 @@ function builderConvertTsTypeToKeyword(tsType) {
|
|
|
26
26
|
function needsQuotations(key) {
|
|
27
27
|
return key.includes('-');
|
|
28
28
|
}
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
30
29
|
export function builderCreateArgsNode(signature) {
|
|
31
30
|
const members = [];
|
|
32
31
|
(signature.Args ?? []).forEach((argumentName) => {
|
|
@@ -35,13 +34,12 @@ export function builderCreateArgsNode(signature) {
|
|
|
35
34
|
: AST.builders.identifier(argumentName), AST.builders.tsTypeAnnotation(AST.builders.tsUnknownKeyword())));
|
|
36
35
|
});
|
|
37
36
|
return AST.builders.tsPropertySignature(AST.builders.identifier('Args'),
|
|
38
|
-
// @ts-expect-error:
|
|
37
|
+
// @ts-expect-error: Incorrect type
|
|
39
38
|
AST.builders.tsTypeAnnotation(AST.builders.tsTypeLiteral(members)), false);
|
|
40
39
|
}
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
42
40
|
export function builderCreateBlocksNode(signature) {
|
|
43
41
|
if (signature.Blocks === undefined) {
|
|
44
|
-
return;
|
|
42
|
+
return undefined;
|
|
45
43
|
}
|
|
46
44
|
const members = [];
|
|
47
45
|
signature.Blocks.forEach((positionalArgumentTypes, blockName) => {
|
|
@@ -50,13 +48,12 @@ export function builderCreateBlocksNode(signature) {
|
|
|
50
48
|
: AST.builders.identifier(blockName), AST.builders.tsTypeAnnotation(AST.builders.tsTupleType(positionalArgumentTypes.map(builderConvertTsTypeToKeyword)))));
|
|
51
49
|
});
|
|
52
50
|
return AST.builders.tsPropertySignature(AST.builders.identifier('Blocks'),
|
|
53
|
-
// @ts-expect-error:
|
|
51
|
+
// @ts-expect-error: Incorrect type
|
|
54
52
|
AST.builders.tsTypeAnnotation(AST.builders.tsTypeLiteral(members)), false);
|
|
55
53
|
}
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
57
54
|
export function builderCreateElementNode(signature) {
|
|
58
55
|
if (signature.Element === undefined) {
|
|
59
|
-
return;
|
|
56
|
+
return undefined;
|
|
60
57
|
}
|
|
61
58
|
return AST.builders.tsPropertySignature(AST.builders.identifier('Element'), AST.builders.tsTypeAnnotation(AST.builders.tsUnionType(signature.Element.map((htmlInterface) => {
|
|
62
59
|
return AST.builders.tsTypeReference(AST.builders.identifier(htmlInterface));
|
|
@@ -2,8 +2,6 @@ import { AST } from '@codemod-utils/ast-javascript';
|
|
|
2
2
|
import { builderCreateArgsNode, builderCreateBlocksNode, builderCreateElementNode, } from './update-signature/builders.js';
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
4
4
|
function getBodyNode(node, key) {
|
|
5
|
-
// @ts-expect-error: Assume that types from external packages are correct
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
7
5
|
return node.body.body.find((node) => {
|
|
8
6
|
if (node.type !== 'TSPropertySignature' || node.key.type !== 'Identifier') {
|
|
9
7
|
return false;
|
|
@@ -21,8 +19,7 @@ export function updateSignature(file, data) {
|
|
|
21
19
|
return false;
|
|
22
20
|
}
|
|
23
21
|
const argsNode = getBodyNode(path.node, 'Args');
|
|
24
|
-
const isArgsKnown = argsNode &&
|
|
25
|
-
argsNode.typeAnnotation.typeAnnotation.type === 'TSTypeLiteral' &&
|
|
22
|
+
const isArgsKnown = argsNode?.typeAnnotation?.typeAnnotation?.type === 'TSTypeLiteral' &&
|
|
26
23
|
argsNode.typeAnnotation.typeAnnotation.members.length > 0;
|
|
27
24
|
const ArgsNode = isArgsKnown
|
|
28
25
|
? argsNode
|
|
@@ -31,7 +28,9 @@ export function updateSignature(file, data) {
|
|
|
31
28
|
builderCreateBlocksNode(data.signature);
|
|
32
29
|
const ElementNode = getBodyNode(path.node, 'Element') ??
|
|
33
30
|
builderCreateElementNode(data.signature);
|
|
34
|
-
return AST.builders.tsInterfaceDeclaration(AST.builders.identifier(identifier), AST.builders.tsInterfaceBody([ArgsNode, BlocksNode, ElementNode].filter(
|
|
31
|
+
return AST.builders.tsInterfaceDeclaration(AST.builders.identifier(identifier), AST.builders.tsInterfaceBody([ArgsNode, BlocksNode, ElementNode].filter((node) => {
|
|
32
|
+
return node !== undefined;
|
|
33
|
+
})));
|
|
35
34
|
},
|
|
36
35
|
});
|
|
37
36
|
return AST.print(ast);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-codemod-add-component-signatures",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "Codemod to add component signatures",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -27,27 +27,27 @@
|
|
|
27
27
|
"@codemod-utils/ast-javascript": "^3.0.1",
|
|
28
28
|
"@codemod-utils/ast-template": "^3.0.1",
|
|
29
29
|
"@codemod-utils/ast-template-tag": "^2.1.0",
|
|
30
|
-
"@codemod-utils/blueprints": "^3.0
|
|
30
|
+
"@codemod-utils/blueprints": "^3.1.0",
|
|
31
31
|
"@codemod-utils/ember": "^4.1.1",
|
|
32
32
|
"@codemod-utils/files": "^4.0.1",
|
|
33
|
-
"@codemod-utils/package-json": "^4.0.
|
|
33
|
+
"@codemod-utils/package-json": "^4.0.2",
|
|
34
34
|
"@codemod-utils/threads": "^1.0.0",
|
|
35
35
|
"yargs": "^18.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@changesets/cli": "^2.
|
|
39
|
-
"@codemod-utils/tests": "^3.0.
|
|
40
|
-
"@ijlee2-frontend-configs/changesets": "^2.1.
|
|
41
|
-
"@ijlee2-frontend-configs/eslint-config-node": "^3.
|
|
42
|
-
"@ijlee2-frontend-configs/prettier": "^3.0
|
|
38
|
+
"@changesets/cli": "^2.31.0",
|
|
39
|
+
"@codemod-utils/tests": "^3.0.2",
|
|
40
|
+
"@ijlee2-frontend-configs/changesets": "^2.1.1",
|
|
41
|
+
"@ijlee2-frontend-configs/eslint-config-node": "^3.3.0",
|
|
42
|
+
"@ijlee2-frontend-configs/prettier": "^3.1.0",
|
|
43
43
|
"@sondr3/minitest": "^0.1.2",
|
|
44
44
|
"@tsconfig/node22": "^22.0.5",
|
|
45
45
|
"@tsconfig/strictest": "^2.0.8",
|
|
46
|
-
"@types/node": "^22.19.
|
|
46
|
+
"@types/node": "^22.19.17",
|
|
47
47
|
"@types/yargs": "^17.0.35",
|
|
48
48
|
"concurrently": "^9.2.1",
|
|
49
49
|
"eslint": "^9.39.4",
|
|
50
|
-
"prettier": "^3.8.
|
|
50
|
+
"prettier": "^3.8.3",
|
|
51
51
|
"typescript": "^5.9.3"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|