Skip to content

Commit

Permalink
avoid shortforming an if/while when its condition has shortforms too
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismypassport committed Nov 4, 2024
1 parent 091376a commit 5bde644
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pico_minify.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ def analyze_node_post(node):
if not to_short and not has_elseif:
has_empties, starts_with_do = False, False
allow_shorthand = allow_parent_shorthands(node)

# now check the children
if not allow_child_shorthands(node, node.cond):
allow_shorthand = False

for i, body in enumerate(get_node_bodies(node)):
if not allow_child_shorthands(node, body):
allow_shorthand = False
Expand Down
2 changes: 1 addition & 1 deletion shrinko.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from picotron_cart import write_cart64_compressed_size, write_cart64_version
import argparse

k_version = 'v1.2.3'
k_version = 'v1.2.3b'

def SplitBySeps(val):
return k_hint_split_re.split(val)
Expand Down
6 changes: 6 additions & 0 deletions test_compare/short-lines.p8
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ end
?"bla",1,2,3,4
n=print"bla"
n,l=print"bla2"
if(function()?"hello 1"
return true
end)
()do?"hello 2"
end
if(print"hello 1")?"hello 2"
8 changes: 8 additions & 0 deletions test_compare/short-spaces.p8
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ end
?"bla",1,2,3,4
n = print"bla"
n, l = print"bla2"

if (function() ?"hello 1"
return true
end)
() do ?"hello 2"
end

if (print"hello 1") ?"hello 2"
4 changes: 3 additions & 1 deletion test_compare/short.p8
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ end?((function()if e==0do e=1end end)())
?"bla"
?"bla",1,2,3,4
?"bla",1,2,3,4
n=print"bla"n,l=print"bla2"
n=print"bla"n,l=print"bla2"if(function()?"hello 1"
return true end)()do?"hello 2"
end if(print"hello 1")?"hello 2"
12 changes: 12 additions & 0 deletions test_input/short.p8
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ end
print("bla");print("bla",1,2,3,4);print("bla",1,2,3,4)
prout = print("bla")
prout, prout2 = print("bla2")

if (function()
print"hello 1"
return true
end)
() then
print"hello 2"
end

if print"hello 1" then
print"hello 2"
end

0 comments on commit 5bde644

Please sign in to comment.