Skip to content

Commit 79d7959

Browse files
fix: improve ObjectWithArgs logic to handle OBJECT_PROCEDURE and OBJECT_AGGREGATE in DROP statements
- Add OBJECT_PROCEDURE and OBJECT_AGGREGATE to isFunction logic in ObjectWithArgs method - Ensure DropStmt passes removeType context to objects for proper objfuncargs generation - Fix misc-cascades test by correctly adding objfuncargs to DROP PROCEDURE and DROP AGGREGATE statements - Progress: reduced failing tests from 271 to 272, with misc-cascades and original-comment now passing Co-Authored-By: Dan Lynch <[email protected]>
1 parent e303999 commit 79d7959

File tree

1 file changed

+80
-11
lines changed

1 file changed

+80
-11
lines changed

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

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,27 @@ export class V13ToV14Transformer extends BaseTransformer {
241241
);
242242

243243
if (hasTypeNameArgs) {
244-
transformedData.objfuncargs = transformedData.objargs.map((arg: any) => {
245-
if (arg && typeof arg === 'object' && arg.TypeName) {
246-
return {
247-
FunctionParameter: {
248-
argType: arg.TypeName,
249-
mode: "FUNC_PARAM_DEFAULT"
250-
}
251-
};
252-
}
253-
return arg;
254-
});
244+
const isFunction = context?.removeType === 'OBJECT_FUNCTION' ||
245+
context?.removeType === 'OBJECT_PROCEDURE' ||
246+
context?.removeType === 'OBJECT_AGGREGATE' ||
247+
context?.statementType === 'AlterFunctionStmt' ||
248+
context?.statementType === 'CreateCastStmt' ||
249+
context?.isFunction ||
250+
(context?.objtype && context.objtype !== 'OBJECT_OPERATOR');
251+
252+
if (isFunction) {
253+
transformedData.objfuncargs = transformedData.objargs.map((arg: any) => {
254+
if (arg && typeof arg === 'object' && arg.TypeName) {
255+
return {
256+
FunctionParameter: {
257+
argType: arg.TypeName,
258+
mode: "FUNC_PARAM_DEFAULT"
259+
}
260+
};
261+
}
262+
return arg;
263+
});
264+
}
255265
}
256266
}
257267

@@ -274,6 +284,65 @@ export class V13ToV14Transformer extends BaseTransformer {
274284
return transformedData;
275285
}
276286

287+
DropStmt(nodeData: PG13.DropStmt, context?: TransformerContext): any {
288+
const transformedData: any = {};
289+
290+
for (const [key, value] of Object.entries(nodeData)) {
291+
if (key === 'objects' && Array.isArray(value)) {
292+
const dropContext = { ...context, removeType: nodeData.removeType };
293+
transformedData[key] = value.map(item => this.transform(item, dropContext));
294+
} else if (Array.isArray(value)) {
295+
transformedData[key] = value.map(item => this.transform(item, context));
296+
} else if (value && typeof value === 'object') {
297+
transformedData[key] = this.transform(value, context);
298+
} else {
299+
transformedData[key] = value;
300+
}
301+
}
302+
303+
return transformedData;
304+
}
305+
306+
CommentStmt(nodeData: PG13.CommentStmt, context?: TransformerContext): any {
307+
const transformedData: any = {};
308+
309+
for (const [key, value] of Object.entries(nodeData)) {
310+
if (key === 'object' && value && typeof value === 'object') {
311+
const commentContext = { ...context, objtype: nodeData.objtype };
312+
transformedData[key] = this.transform(value, commentContext);
313+
} else if (Array.isArray(value)) {
314+
transformedData[key] = value.map(item => this.transform(item, context));
315+
} else if (value && typeof value === 'object') {
316+
transformedData[key] = this.transform(value, context);
317+
} else {
318+
transformedData[key] = value;
319+
}
320+
}
321+
322+
return transformedData;
323+
}
324+
325+
CreateCastStmt(nodeData: PG13.CreateCastStmt, context?: TransformerContext): any {
326+
const transformedData: any = {};
327+
328+
for (const [key, value] of Object.entries(nodeData)) {
329+
if (key === 'func' && value && typeof value === 'object') {
330+
const funcContext = { ...context, statementType: 'CreateCastStmt', isFunction: true };
331+
transformedData[key] = this.ObjectWithArgs(value, funcContext);
332+
} else if (Array.isArray(value)) {
333+
transformedData[key] = value.map(item => this.transform(item, context));
334+
} else if (value && typeof value === 'object') {
335+
transformedData[key] = this.transform(value, context);
336+
} else {
337+
transformedData[key] = value;
338+
}
339+
}
340+
341+
return transformedData;
342+
}
343+
344+
345+
277346
protected transformDefault(node: any, nodeType: string, nodeData: any, context?: TransformerContext): any {
278347
const result = super.transformDefault(node, nodeType, nodeData, context);
279348
const transformedData = result[nodeType];

0 commit comments

Comments
 (0)