Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitespaces are significant #609

Open
xzfc opened this issue Jan 30, 2025 · 1 comment
Open

Whitespaces are significant #609

xzfc opened this issue Jan 30, 2025 · 1 comment

Comments

@xzfc
Copy link

xzfc commented Jan 30, 2025

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:

{
"type": "switch_body",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "switch_case",
"named": true
},
{
"type": "switch_default",
"named": true
}
]
}
},

But it's not an issue for, e.g., an array:

{
"type": "array",
"named": true,
"fields": {
"elements": {
"multiple": true,
"required": false,
"types": [
{
"type": ",",
"named": false
},
{
"type": "expression",
"named": true
},
{
"type": "spread_element",
"named": true
}
]
}
}
},

Workaround?

In the meantime, what workaround/quick fixes available to run multi-line migrations? I need some guidance.

  • Fix grammar.js and *-node-types.json to use "fields"?
  • Rewrite my rules using ast nodes instead of snippets?
  • Somehow fix spacing for "children"?
@morgante
Copy link
Contributor

The easiest solution is changing grammar.js but ideally we would fix spacing for children as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants