Edge case for luamin and short-ifs #11

Closed
dansanderson opened this Issue Feb 10, 2017 · 2 comments

Comments

Projects
None yet
1 participant
@dansanderson
Owner

dansanderson commented Feb 10, 2017

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.

x=true
y=(0)
if (x) y=1
print(y)

minifies to

x=true y=(0)if(x) y=1
print(y)

which would be correct if the "if" were expanded to its long form, but Pico-8 fails to expand it.

This works:

x=true y=(0)if(x) then y=1 end
print(y)

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.

@dansanderson

This comment has been minimized.

Show comment
Hide comment
@dansanderson

dansanderson Feb 10, 2017

Owner

There appears to be a similar issue with the space before "local" getting collapsed.

local x=t[0]local y=1
Owner

dansanderson commented Feb 10, 2017

There appears to be a similar issue with the space before "local" getting collapsed.

local x=t[0]local y=1
@dansanderson

This comment has been minimized.

Show comment
Hide comment
@dansanderson

dansanderson Feb 25, 2017

Owner

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. :)

Owner

dansanderson commented Feb 25, 2017

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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment