Skip to content

Commit f6f555f

Browse files
feat: implement boolean TypeCast to A_Const boolval transformation
- Enhanced TypeCast method to detect boolean casts and convert to A_Const with boolval - Handle both pre-transformation (PG14) and post-transformation (PG15) A_Const structures - Improved test coverage from 145/258 to 151/258 tests passing (+6 tests) - Boolean strings 't'/'f' now correctly convert to boolval objects with proper boolean values Progress: 151/258 tests now passing, representing continued improvement in transformer functionality Co-Authored-By: Dan Lynch <[email protected]>
1 parent 879ea70 commit f6f555f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,56 @@ export class V14ToV15Transformer {
279279
}
280280

281281
TypeCast(node: PG14.TypeCast, context: TransformerContext): any {
282+
// First transform the node using standard transformation
282283
const result = this.transformGenericNode(node, context);
284+
285+
// Handle both pre-transformation (PG14) and post-transformation (PG15) A_Const structures
286+
if (result.arg &&
287+
typeof result.arg === 'object' &&
288+
'A_Const' in result.arg &&
289+
result.arg.A_Const &&
290+
result.typeName &&
291+
result.typeName.names &&
292+
Array.isArray(result.typeName.names)) {
293+
294+
let isBoolean = false;
295+
let boolValue = false;
296+
297+
if (result.arg.A_Const.sval &&
298+
result.arg.A_Const.sval.sval &&
299+
(result.arg.A_Const.sval.sval === 't' || result.arg.A_Const.sval.sval === 'f')) {
300+
isBoolean = true;
301+
boolValue = result.arg.A_Const.sval.sval === 't';
302+
}
303+
else if (result.arg.A_Const.val &&
304+
typeof result.arg.A_Const.val === 'object' &&
305+
'String' in result.arg.A_Const.val &&
306+
result.arg.A_Const.val.String &&
307+
(result.arg.A_Const.val.String.str === 't' || result.arg.A_Const.val.String.str === 'f')) {
308+
isBoolean = true;
309+
boolValue = result.arg.A_Const.val.String.str === 't';
310+
}
311+
312+
if (isBoolean) {
313+
const isBoolType = result.typeName.names.some((name: any) =>
314+
name && typeof name === 'object' &&
315+
(('String' in name && name.String && name.String.sval === 'bool') ||
316+
('String' in name && name.String && name.String.str === 'bool'))
317+
);
318+
319+
if (isBoolType) {
320+
return {
321+
A_Const: {
322+
boolval: {
323+
boolval: boolValue
324+
},
325+
location: result.arg.A_Const.location
326+
}
327+
};
328+
}
329+
}
330+
}
331+
283332
return { TypeCast: result };
284333
}
285334

0 commit comments

Comments
 (0)