gritql
gritql copied to clipboard
Whitespaces are significant
Example
This pattern:
language js
`switch(a){ }`
matches only the second line:
switch(a){} // 1: no match
switch(a){ } // 2: match
switch(a){ } // 3: no match
Which is highly inconvenient when doing multi-line migrations as rules need to have precisely the same indentations as the code.
Clue
As I can see, this happen for node types that capture their descendants via "children" rather than "fields". E.g. it's an issue for switch_body:
https://github.com/getgrit/gritql/blob/5af841f57592f287bdd736a87ec4008c77d88603/resources/node-types/javascript-node-types.json#L3157-L3175
But it's not an issue for, e.g., an array:
https://github.com/getgrit/gritql/blob/5af841f57592f287bdd736a87ec4008c77d88603/resources/node-types/javascript-node-types.json#L308-L331
Workaround?
In the meantime, what workaround/quick fixes available to run multi-line migrations? I need some guidance.
- Fix
grammar.jsand*-node-types.jsonto use"fields"? - Rewrite my rules using ast nodes instead of snippets?
- Somehow fix spacing for
"children"?
The easiest solution is changing grammar.js but ideally we would fix spacing for children as well.