Skip to content

Commit 29d7d85

Browse files
feat: add ObjectWithArgs objfuncargs transformation for CommentStmt contexts
- Create objfuncargs from objargs in CommentStmt contexts for PG14 compatibility - Add shouldCreateObjfuncargsFromObjargs helper method - Add createFunctionParameterFromTypeName helper to convert TypeName to FunctionParameter - Transform objargs into FunctionParameter objects with mode FUNC_PARAM_DEFAULT This addresses test failures where PG14 expects objfuncargs array in CommentStmt ObjectWithArgs nodes. Co-Authored-By: Dan Lynch <[email protected]>
1 parent 5a420d5 commit 29d7d85

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,10 +1195,15 @@ export class V13ToV14Transformer {
11951195
// Handle objfuncargs based on context
11961196
const shouldCreateObjfuncargs = this.shouldCreateObjfuncargs(context);
11971197
const shouldPreserveObjfuncargs = this.shouldPreserveObjfuncargs(context);
1198+
const shouldCreateObjfuncargsFromObjargs = this.shouldCreateObjfuncargsFromObjargs(context);
11981199

11991200
if (shouldCreateObjfuncargs) {
12001201
// For CreateCastStmt contexts, always set empty objfuncargs (override any existing content)
12011202
result.objfuncargs = [];
1203+
} else if (shouldCreateObjfuncargsFromObjargs && result.objargs) {
1204+
result.objfuncargs = Array.isArray(result.objargs)
1205+
? result.objargs.map((arg: any) => this.createFunctionParameterFromTypeName(arg))
1206+
: [this.createFunctionParameterFromTypeName(result.objargs)];
12021207
} else if (result.objfuncargs !== undefined) {
12031208
if (shouldPreserveObjfuncargs) {
12041209
result.objfuncargs = Array.isArray(result.objfuncargs)
@@ -1243,6 +1248,31 @@ export class V13ToV14Transformer {
12431248
return true;
12441249
}
12451250

1251+
private shouldCreateObjfuncargsFromObjargs(context: TransformerContext): boolean {
1252+
if (!context.parentNodeTypes || context.parentNodeTypes.length === 0) {
1253+
return false;
1254+
}
1255+
1256+
for (const parentType of context.parentNodeTypes) {
1257+
if (parentType === 'CommentStmt') {
1258+
return true;
1259+
}
1260+
}
1261+
1262+
return false;
1263+
}
1264+
1265+
private createFunctionParameterFromTypeName(typeNameNode: any): any {
1266+
const transformedTypeName = this.transform(typeNameNode, { parentNodeTypes: [] });
1267+
1268+
return {
1269+
FunctionParameter: {
1270+
argType: transformedTypeName,
1271+
mode: "FUNC_PARAM_DEFAULT"
1272+
}
1273+
};
1274+
}
1275+
12461276
private isVariadicAggregateContext(context: TransformerContext): boolean {
12471277
let parent = context.parent;
12481278
while (parent) {

0 commit comments

Comments
 (0)