Skip to content

Commit

Permalink
fix: reverse translator
Browse files Browse the repository at this point in the history
  • Loading branch information
koladilip committed Jun 19, 2024
1 parent d83876a commit 6d91b87
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 287 deletions.
2 changes: 1 addition & 1 deletion src/reverse_translator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('reverse_translator', () => {
]),
);
expect(template).toEqual(
'{\n "user": {\n "id": $.userId\n },\n "events": [{\n "items": $.products{.category}.({\n "discount": $.discount,\n "product_id":.id,\n "options":.variations[*].({\n "s":.size\n })[],\n "value":.price *.quantity * (1 - $.discount / 100)\n })[],\n "name": $.events[0],\n "revenue": $.products{.category}.(.price *.quantity * (1 - $.discount / 100)).sum()\n }]\n}',
'{\n "user": {\n "id": $.userId\n },\n "events": [{\n "items": $.products{.category}.({\n "discount": $.discount,\n "product_id": .id,\n "options": .variations[*].({\n "s": .size\n })[],\n "value": .price * .quantity * (1 - $.discount / 100)\n })[],\n "name": $.events[0],\n "revenue": $.products{.category}.(.price * .quantity * (1 - $.discount / 100)).sum()\n }]\n}',
);
});
});
6 changes: 3 additions & 3 deletions src/reverse_translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class JsonTemplateReverseTranslator {
translate(expr: Expression): string {
let code: string = this.translateExpression(expr);
code = code.replace(/\.\s+\./g, '.');
code = code.replace(/\s+\./g, '.');
// code = code.replace(/\s+\./g, '.');
if (this.options?.defaultPathType === PathType.JSON) {
code = code.replace(/\^/g, '$');
}
Expand Down Expand Up @@ -262,12 +262,12 @@ export class JsonTemplateReverseTranslator {
if (expr.object) {
code.push(this.translateExpression(expr.object));
if (expr.id) {
code.push(` .${expr.id}`);
code.push(`.${expr.id}`);
}
} else if (expr.parent) {
code.push(this.translatePathRootString(expr.parent, PathType.SIMPLE));
if (expr.id) {
code.push(` .${expr.id}`);
code.push(`.${expr.id}`);
}
} else if (expr.id) {
code.push(expr.id.replace(BINDINGS_PARAM_KEY, '$'));
Expand Down
283 changes: 0 additions & 283 deletions test/test_engine.ts

This file was deleted.

0 comments on commit 6d91b87

Please sign in to comment.