Skip to content

Commit e06371c

Browse files
Fix arrayBounds Integer transformation and add context propagation
- Handle empty Integer objects {} -> {ival: -1} in arrayBounds contexts - Add proper context passing for A_Const, TypeName, A_Indices, DefElem - Preserve A_Indices contexts as empty (exclude from transformation) - Current pass rate: 71.3% (184/258 tests) - Still need to fix A_Const ival preservation for non-empty values Co-Authored-By: Dan Lynch <[email protected]>
1 parent 4ec73ab commit e06371c

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

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

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ export class V15ToV16Transformer {
523523
if (val.String && val.String.str !== undefined) {
524524
result.sval = val.String.str;
525525
delete result.val;
526-
} else if (val.Integer && val.Integer.ival !== undefined) {
527-
result.ival = val.Integer.ival;
526+
} else if (val.Integer !== undefined) {
527+
result.ival = val.Integer;
528528
delete result.val;
529529
} else if (val.Float && val.Float.str !== undefined) {
530530
result.fval = val.Float.str;
@@ -538,7 +538,20 @@ export class V15ToV16Transformer {
538538
}
539539

540540
if (result.ival !== undefined) {
541-
result.ival = this.transform(result.ival as any, context);
541+
const childContext: TransformerContext = {
542+
...context,
543+
parentNodeTypes: [...(context.parentNodeTypes || []), 'A_Const']
544+
};
545+
546+
if (typeof result.ival === 'object' && result.ival !== null) {
547+
if (Object.keys(result.ival).length === 0) {
548+
const wrappedIval = { Integer: result.ival };
549+
const transformedWrapped = this.transform(wrappedIval as any, childContext);
550+
result.ival = transformedWrapped.Integer;
551+
}
552+
} else {
553+
result.ival = this.transform(result.ival as any, childContext);
554+
}
542555
}
543556

544557
return { A_Const: result };
@@ -592,9 +605,13 @@ export class V15ToV16Transformer {
592605
}
593606

594607
if (node.arrayBounds !== undefined) {
608+
const childContext: TransformerContext = {
609+
...context,
610+
parentNodeTypes: [...(context.parentNodeTypes || []), 'TypeName', 'arrayBounds']
611+
};
595612
result.arrayBounds = Array.isArray(node.arrayBounds)
596-
? node.arrayBounds.map((item: any) => this.transform(item as any, context))
597-
: this.transform(node.arrayBounds as any, context);
613+
? node.arrayBounds.map((item: any) => this.transform(item as any, childContext))
614+
: this.transform(node.arrayBounds as any, childContext);
598615
}
599616

600617
if (node.location !== undefined) {
@@ -674,11 +691,19 @@ export class V15ToV16Transformer {
674691
}
675692

676693
if (node.lidx !== undefined) {
677-
result.lidx = this.transform(node.lidx as any, context);
694+
const childContext: TransformerContext = {
695+
...context,
696+
parentNodeTypes: [...(context.parentNodeTypes || []), 'A_Indices']
697+
};
698+
result.lidx = this.transform(node.lidx as any, childContext);
678699
}
679700

680701
if (node.uidx !== undefined) {
681-
result.uidx = this.transform(node.uidx as any, context);
702+
const childContext: TransformerContext = {
703+
...context,
704+
parentNodeTypes: [...(context.parentNodeTypes || []), 'A_Indices']
705+
};
706+
result.uidx = this.transform(node.uidx as any, childContext);
682707
}
683708

684709
return { A_Indices: result };
@@ -863,6 +888,18 @@ export class V15ToV16Transformer {
863888

864889
Integer(node: PG15.Integer, context: TransformerContext): { Integer: PG16.Integer } {
865890
const result: any = { ...node };
891+
892+
if (Object.keys(result).length === 0) {
893+
const parentTypes = context.parentNodeTypes || [];
894+
895+
const shouldTransform =
896+
parentTypes.includes('arrayBounds') && !parentTypes.includes('A_Indices');
897+
898+
if (shouldTransform) {
899+
result.ival = -1;
900+
}
901+
}
902+
866903
return { Integer: result };
867904
}
868905

@@ -2815,7 +2852,11 @@ export class V15ToV16Transformer {
28152852
}
28162853

28172854
if (node.arg !== undefined) {
2818-
result.arg = this.transform(node.arg as any, context);
2855+
const childContext: TransformerContext = {
2856+
...context,
2857+
parentNodeTypes: [...(context.parentNodeTypes || []), 'DefElem']
2858+
};
2859+
result.arg = this.transform(node.arg as any, childContext);
28192860
}
28202861

28212862
if (node.defaction !== undefined) {

0 commit comments

Comments
 (0)