Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Edge case for luamin and short-ifs #11
luamin collapses space between non-word characters and keywords. This is mostly correct except it breaks edge cases involving Pico-8's short-if. This feature is invisibly implemented by Pico-8 as a preprocessor replacement, and does not match the "if" if it has a non-word non-space character to its left.
which would be correct if the "if" were expanded to its long form, but Pico-8 fails to expand it.
The workaround is to either avoid short-if, or to make sure that the previous line to a short-if ends in a word char.
luamin should either recognize short-if and preserve the leading space or just always preserve the leading space of the "if" keyword.
I submitted a quick fix to always insert a space between closing brackets and names/tokens. The luamin command currently uses a tokens-only approach, so I can't do something more sophisticated like inserting spaces before statements specifically. (There's an AST-based minifier in the code but I gave up on it temporarily because it wasn't producing better results than a tokens-only minifier.) The quick fix should handle the common problem cases, and might actually be a complete fix but I'm not sure. :)