Skip to content

Commit d4e7190

Browse files
committed
feat: compute wildcard path for array children
Wildcard path is required to lookup error messages
1 parent 9cd6336 commit d4e7190

20 files changed

+240
-0
lines changed

src/compiler/fields/array_field.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ export function createArrayField(parent: CompilerParent): CompilerField {
1515
? `${parent.fieldPathExpression} + '.' + ${parent.variableName}_i`
1616
: `${parent.variableName}_i`
1717

18+
const wildCardPath = parent.wildCardPath !== '' ? `${parent.wildCardPath}.*` : `*`
19+
1820
return {
1921
parentVariableName: `${parent.variableName}.value`,
2022
fieldNameExpression: `${parent.variableName}_i`,
2123
fieldPathExpression: fieldPathExpression,
24+
wildCardPath: wildCardPath,
2225
variableName: `${parent.variableName}_item`,
2326
valueExpression: `${parent.variableName}.value[${parent.variableName}_i]`,
2427
outputExpression: `${parent.outputExpression}[${parent.variableName}_i]`,

src/compiler/fields/object_field.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ export function createObjectField(
1919
? `${parent.fieldPathExpression} + '.' + '${node.fieldName}'`
2020
: `'${node.fieldName}'`
2121

22+
const wildCardPath =
23+
parent.wildCardPath !== '' ? `${parent.wildCardPath}.${node.fieldName}` : node.fieldName
24+
2225
return {
2326
parentVariableName: `${parent.variableName}.value`,
2427
fieldNameExpression: `'${node.fieldName}'`,
2528
fieldPathExpression: fieldPathExpression,
29+
wildCardPath: wildCardPath,
2630
variableName: `${node.propertyName}_${variablesCounter}`,
2731
valueExpression: `${parent.variableName}.value['${node.fieldName}']`,
2832
outputExpression: `${parent.outputExpression}['${node.propertyName}']`,

src/compiler/fields/record_field.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ export function createRecordField(parent: CompilerParent): CompilerField {
1515
? `${parent.fieldPathExpression} + '.' + ${parent.variableName}_i`
1616
: `${parent.variableName}_i`
1717

18+
const wildCardPath = parent.wildCardPath !== '' ? `${parent.wildCardPath}.*` : `*`
19+
1820
return {
1921
parentVariableName: `${parent.variableName}.value`,
2022
fieldNameExpression: `${parent.variableName}_i`,
2123
fieldPathExpression: fieldPathExpression,
24+
wildCardPath: wildCardPath,
2225
variableName: `${parent.variableName}_item`,
2326
valueExpression: `${parent.variableName}.value[${parent.variableName}_i]`,
2427
outputExpression: `${parent.outputExpression}[${parent.variableName}_i]`,

src/compiler/fields/root_field.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function createRootField(parent: CompilerParent): CompilerField {
1414
parentVariableName: parent.variableName,
1515
fieldNameExpression: `''`,
1616
fieldPathExpression: `''`,
17+
wildCardPath: '',
1718
variableName: `${parent.variableName}_item`,
1819
valueExpression: 'root',
1920
outputExpression: parent.outputExpression,

src/compiler/fields/tuple_field.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ export function createTupleField(
1818
? `${parent.fieldPathExpression} + '.' + '${node.fieldName}'`
1919
: `'${node.fieldName}'`
2020

21+
const wildCardPath = parent.wildCardPath !== '' ? `${parent.wildCardPath}.*` : `*`
22+
2123
return {
2224
parentVariableName: `${parent.variableName}.value`,
2325
fieldNameExpression: `${node.fieldName}`,
2426
fieldPathExpression: fieldPathExpression,
27+
wildCardPath: wildCardPath,
2528
variableName: `${parent.variableName}_item_${node.fieldName}`,
2629
valueExpression: `${parent.variableName}.value[${node.fieldName}]`,
2730
outputExpression: `${parent.outputExpression}[${node.propertyName}]`,

src/compiler/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export class Compiler {
9494
variableName: 'root',
9595
outputExpression: 'out',
9696
fieldPathExpression: 'out',
97+
wildCardPath: '',
9798
})
9899
}
99100

src/compiler/nodes/array.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class ArrayNodeCompiler extends BaseNode {
5050
fieldPathExpression: this.field.fieldPathExpression,
5151
outputExpression: this.field.outputExpression,
5252
variableName: this.field.variableName,
53+
wildCardPath: this.field.wildCardPath,
5354
})
5455

5556
const buffer = this.#buffer.child()

src/compiler/nodes/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export abstract class BaseNode {
4242
fieldPathExpression: this.field.fieldPathExpression,
4343
parentValueExpression: this.field.parentVariableName,
4444
isArrayMember: this.field.isArrayMember,
45+
wildCardPath: this.field.wildCardPath,
4546
})
4647
)
4748
}

src/compiler/nodes/object.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class ObjectNodeCompiler extends BaseNode {
7070
fieldPathExpression: this.field.fieldPathExpression,
7171
outputExpression: this.field.outputExpression,
7272
variableName: this.field.variableName,
73+
wildCardPath: this.field.wildCardPath,
7374
} as const
7475

7576
this.#node.properties.forEach((child) => this.#compiler.compileNode(child, buffer, parent))
@@ -86,6 +87,7 @@ export class ObjectNodeCompiler extends BaseNode {
8687
fieldPathExpression: this.field.fieldPathExpression,
8788
outputExpression: this.field.outputExpression,
8889
variableName: this.field.variableName,
90+
wildCardPath: this.field.wildCardPath,
8991
} as const
9092
this.#node.groups.forEach((group) => this.#compileObjectGroup(group, buffer, parent))
9193
return buffer.toString()

src/compiler/nodes/record.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class RecordNodeCompiler extends BaseNode {
5252
fieldPathExpression: this.field.fieldPathExpression,
5353
outputExpression: this.field.outputExpression,
5454
variableName: this.field.variableName,
55+
wildCardPath: this.field.wildCardPath,
5556
})
5657

5758
buffer.writeStatement(

0 commit comments

Comments
 (0)