seaofvoices / darklua

A command line tool that transforms Lua code
https://darklua.com/
MIT License
71 stars 9 forks source link

`remove_compound_assignment` copying comments/newlines in between statements #174

Closed 1enu closed 6 months ago

1enu commented 6 months ago

How to replicate:

  1. Go to https://darklua.com/try-it/
  2. Use the following rule below:
    {
    rules: [
    'remove_compound_assignment',
    ],
    }

    Results:

Input Output Expected
```lua local x = 0 x += 1-- this is ok local y = 0 print(y) y += 1-- this is ok local y = 0 y += 1-- one newline appears local z = 0 --duplicate z += 1--it copies the comments local a = 0 --copies --all --comments --in between a += 1 ``` ```lua local x = 0 x =x +1-- this is ok local y = 0 print(y) y =y +1-- this is ok local y = 0 y = y +1-- one newline appears local z = 0 --duplicate z =--duplicate z +1--it copies the comments local a = 0 --copies --all --comments --in between a =--copies --all --comments --in between a +1 ``` ```lua local x = 0 x =x +1-- this is ok local y = 0 print(y) y =y +1-- this is ok local y = 0 y =y +1-- one newline appears local z = 0 --duplicate z =z +1--it copies the comments local a = 0 --copies --all --comments --in between a =a +1 ```
jeparlefrancais commented 6 months ago

Thank you for the detailed report, I can already see the fix for this issue. The rule is cloning the variable with all its token information. If it just cleared the tokens it'd probably fix all of this 🚀