Stedi / prettier-plugin-jsonata

prettier-plugin-jsonata
MIT License
11 stars 2 forks source link

Filter and grouping expression results in invalid jsonata #462

Closed dushyantbangal closed 10 months ago

dushyantbangal commented 10 months ago

Whenever I provide an expression with filter ([]) and grouping in it, the output is invalid. It ends up swapping the position of the filter and grouping expression.

Input:

$myvar[value ="Placeholder"]{value : $}

Output:

$myvar{ value: $ }[value = "Placeholder"]

Error given by JSONata evaluation:

A predicate cannot follow a grouping expression in a step

Code:

var jsonata = require("jsonata");
var serializeJsonata = require("@stedi/prettier-plugin-jsonata/dist/lib").serializeJsonata;

async function serialize(ugly) {
  const jsonataAST = jsonata(ugly).ast();
  const pretty = await serializeJsonata(jsonataAST);
  console.log(pretty)
}

serialize('$myvar[value ="Placeholder"]{value : $}')