Skip to content

Commit f35980c

Browse files
🎨 Combine iteration for deprecated and methods
1 parent 5cd17cc commit f35980c

1 file changed

Lines changed: 17 additions & 24 deletions

File tree

‎src/core/extractors.ts‎

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -222,31 +222,24 @@ export function decoratorExtractor(node: Node): RouteInfo[] {
222222
const pathArgNode = resolveArgNode(nonCommentArgs, 0, "path")
223223
const path = pathArgNode ? extractPathFromNode(pathArgNode) : ""
224224

225-
const deprecated =
226-
argumentsNode.namedChildren.some(
227-
(a) =>
228-
a.type === "keyword_argument" &&
229-
a.childForFieldName("name")?.text === "deprecated" &&
230-
a.childForFieldName("value")?.text === "True",
231-
) || undefined
232-
233-
// For api_route, extract methods from keyword argument
225+
let deprecated: boolean | undefined
234226
let resolvedMethod = methodNode.text
235-
if (isApiRoute) {
236-
resolvedMethod = "GET"
237-
for (const argNode of argumentsNode.namedChildren) {
238-
if (argNode.type !== "keyword_argument") continue
239-
const nameNode = argNode.childForFieldName("name")
240-
const valueNode = argNode.childForFieldName("value")
241-
if (nameNode?.text === "methods" && valueNode) {
242-
// Extract first method from list
243-
const listItems = valueNode.namedChildren
244-
const firstMethod =
245-
listItems.length > 0 ? extractStringValue(listItems[0]) : null
246-
if (firstMethod) {
247-
resolvedMethod = firstMethod
248-
}
249-
}
227+
if (isApiRoute) resolvedMethod = "GET"
228+
229+
for (const argNode of argumentsNode.namedChildren) {
230+
if (argNode.type !== "keyword_argument") continue
231+
const nameNode = argNode.childForFieldName("name")
232+
const valueNode = argNode.childForFieldName("value")
233+
if (nameNode?.text === "deprecated" && valueNode?.text === "True") {
234+
deprecated = true
235+
}
236+
if (isApiRoute && nameNode?.text === "methods" && valueNode) {
237+
// Extract first method from list
238+
const firstMethod =
239+
valueNode.namedChildren.length > 0
240+
? extractStringValue(valueNode.namedChildren[0])
241+
: null
242+
if (firstMethod) resolvedMethod = firstMethod
250243
}
251244
}
252245

0 commit comments

Comments
 (0)