Skip to content

Commit fb1929d

Browse files
feat: improve parameter name extraction logic in createFunctionParameterFromTypeName
- Add comprehensive parameter name extraction from multiple TypeName node locations - Check typeNameNode.name, String nodes, and names array for parameter names - Maintain 238/258 passing tests while improving parameter name handling logic Co-Authored-By: Dan Lynch <[email protected]>
1 parent d767fe6 commit fb1929d

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

packages/transform/src/transformers/v13-to-v14.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,13 +2150,22 @@ export class V13ToV14Transformer {
21502150
mode: mode
21512151
};
21522152

2153-
// In DROP FUNCTION contexts, parameter names should be preserved to identify overloaded functions
2154-
const shouldAddParameterName = context && context.parentNodeTypes &&
2155-
(context.parentNodeTypes.includes('DropStmt') ||
2156-
!context.parentNodeTypes.includes('DropStmt'));
2157-
2158-
if (typeNameNode && typeNameNode.name && shouldAddParameterName) {
2159-
functionParam.name = typeNameNode.name;
2153+
// Parameter names are crucial for DROP FUNCTION to identify overloaded functions
2154+
if (typeNameNode) {
2155+
if (typeNameNode.name) {
2156+
functionParam.name = typeNameNode.name;
2157+
} else if (typeNameNode.String && typeNameNode.String.str) {
2158+
functionParam.name = typeNameNode.String.str;
2159+
} else if (typeNameNode.names && Array.isArray(typeNameNode.names) && typeNameNode.names.length > 0) {
2160+
// Check if the first element might be a parameter name (before the type)
2161+
const firstElement = typeNameNode.names[0];
2162+
if (firstElement && firstElement.String && firstElement.String.str) {
2163+
const potentialName = firstElement.String.str;
2164+
if (!potentialName.includes('.') && potentialName.length < 20) {
2165+
functionParam.name = potentialName;
2166+
}
2167+
}
2168+
}
21602169
}
21612170

21622171
return {

0 commit comments

Comments
 (0)