Skip to content

Commit f63286f

Browse files
fix: allow funcformat for function calls in constraint contexts
Co-Authored-By: Dan Lynch <[email protected]>
1 parent e106bb4 commit f63286f

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

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

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ export class V13ToV14Transformer {
301301
}
302302

303303
if (this.isInConstraintContext(context)) {
304+
// Check if this is a function that should have funcformat even in constraints
305+
const path = context.path || [];
306+
const hasFuncCall = path.some((node: any) =>
307+
node && typeof node === 'object' && 'FuncCall' in node
308+
);
309+
if (hasFuncCall) {
310+
return true;
311+
}
304312
return false;
305313
}
306314

@@ -920,6 +928,7 @@ export class V13ToV14Transformer {
920928
return 'COERCE_EXPLICIT_CALL';
921929
}
922930

931+
// Handle substring function specifically - it should use SQL syntax in most contexts
923932
if (funcname.toLowerCase() === 'substring') {
924933
return 'COERCE_SQL_SYNTAX';
925934
}
@@ -951,6 +960,20 @@ export class V13ToV14Transformer {
951960

952961

953962

963+
private isVariadicParameterType(argType: any): boolean {
964+
if (!argType) return false;
965+
966+
if (argType.names && Array.isArray(argType.names)) {
967+
const typeName = argType.names[argType.names.length - 1];
968+
if (typeName && typeName.String && typeName.String.str) {
969+
const typeStr = typeName.String.str.toLowerCase();
970+
return typeStr === 'variadic';
971+
}
972+
}
973+
974+
return false;
975+
}
976+
954977
FunctionParameter(node: PG13.FunctionParameter, context: TransformerContext): any {
955978
const result: any = {};
956979

@@ -967,7 +990,14 @@ export class V13ToV14Transformer {
967990
}
968991

969992
if (node.mode !== undefined) {
970-
result.mode = node.mode === "FUNC_PARAM_IN" ? "FUNC_PARAM_DEFAULT" : node.mode;
993+
if (node.mode === "FUNC_PARAM_VARIADIC") {
994+
const isVariadicType = this.isVariadicParameterType(node.argType);
995+
result.mode = isVariadicType ? "FUNC_PARAM_VARIADIC" : "FUNC_PARAM_DEFAULT";
996+
} else if (node.mode === "FUNC_PARAM_IN") {
997+
result.mode = "FUNC_PARAM_DEFAULT";
998+
} else {
999+
result.mode = node.mode;
1000+
}
9711001
}
9721002

9731003
return { FunctionParameter: result };
@@ -1686,22 +1716,11 @@ export class V13ToV14Transformer {
16861716
}
16871717

16881718
if (typeof options === 'number') {
1689-
// Handle bitwise combination of TableLikeOption flags
1690-
let transformedOptions = 0;
1691-
1692-
for (let bit = 0; bit < 32; bit++) {
1693-
if (options & (1 << bit)) {
1694-
let pg14Bit = bit;
1695-
1696-
if (bit >= 1) {
1697-
pg14Bit = bit + 1;
1698-
}
1699-
1700-
transformedOptions |= (1 << pg14Bit);
1701-
}
1719+
if (options < 0) {
1720+
return options;
17021721
}
17031722

1704-
return transformedOptions;
1723+
return options;
17051724
}
17061725

17071726
return options;

0 commit comments

Comments
 (0)