Skip to content

Commit 85971d4

Browse files
feat: improve v13-to-v14 transformer with funcformat detection and objfuncargs refinement
- Add context-sensitive funcformat detection (COERCE_SQL_SYNTAX for pg_catalog functions) - Fix FunctionParameter mode conversion from FUNC_PARAM_IN to FUNC_PARAM_DEFAULT - Refine objfuncargs preservation logic to be more restrictive - Improve test pass rate from 28.7% to 40.3% (104/258 passing tests) Co-Authored-By: Dan Lynch <[email protected]>
1 parent 6ede0eb commit 85971d4

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ export class V13ToV14Transformer {
155155
result.location = node.location;
156156
}
157157

158+
if (result.funcformat === undefined) {
159+
const hasPgCatalogPrefix = result.funcname &&
160+
Array.isArray(result.funcname) &&
161+
result.funcname.length >= 2 &&
162+
result.funcname[0] &&
163+
typeof result.funcname[0] === 'object' &&
164+
'String' in result.funcname[0] &&
165+
result.funcname[0].String.str === 'pg_catalog';
166+
167+
if (hasPgCatalogPrefix) {
168+
result.funcformat = "COERCE_SQL_SYNTAX";
169+
} else {
170+
result.funcformat = "COERCE_EXPLICIT_CALL";
171+
}
172+
}
173+
158174
return { FuncCall: result };
159175
}
160176

@@ -220,7 +236,11 @@ export class V13ToV14Transformer {
220236
}
221237

222238
if (node.mode !== undefined) {
223-
result.mode = node.mode;
239+
if (node.mode === 'FUNC_PARAM_IN') {
240+
result.mode = 'FUNC_PARAM_DEFAULT';
241+
} else {
242+
result.mode = node.mode;
243+
}
224244
}
225245

226246
return { FunctionParameter: result };
@@ -924,16 +944,19 @@ export class V13ToV14Transformer {
924944

925945
private shouldPreserveObjfuncargs(context: TransformerContext): boolean {
926946
if (!context.parentNodeTypes || context.parentNodeTypes.length === 0) {
927-
return true;
947+
return false; // Default to not preserving objfuncargs
928948
}
929949

930950
for (const parentType of context.parentNodeTypes) {
951+
if (parentType === 'CreateCastStmt') {
952+
return true; // CreateCastStmt needs objfuncargs preserved
953+
}
931954
if (parentType === 'AlterFunctionStmt') {
932-
return false;
955+
return false; // AlterFunctionStmt should not have objfuncargs
933956
}
934957
}
935958

936-
return true;
959+
return false; // Default to removing objfuncargs unless specifically needed
937960
}
938961

939962
private isVariadicAggregateContext(context: TransformerContext): boolean {

0 commit comments

Comments
 (0)