seaofvoices / darklua

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

Remove compound assignment rule #78

Closed jeparlefrancais closed 1 year ago

jeparlefrancais commented 1 year ago

Closes #53

This adds a new rule remove_compound_assignment. It will expand:

local counter = 0
counter += 1

Into:

local counter = 0
counter = counter + 1

To preserve the appropriate potential side effects, the rule will define new variables to hold the temporary values.

object[getProp()] += 1
-- converts to 
local __DARKLUA_VAR = getProp()
object[__DARKLUA_VAR] = object[__DARKLUA_VAR] + 1

This rule is not enabled by default.