From b14f2b72cecdc8a194bb75e4d4a24b866ddef528 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 26 Jul 2023 18:21:53 +0800 Subject: make minify and line rewriting work with Lua5.1 --- src/3rdParty/LuaMinify.h | 13 ++++++++++++- src/3rdParty/luaminify.lua | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/3rdParty/LuaMinify.h b/src/3rdParty/LuaMinify.h index 895f5a4..7ade925 100644 --- a/src/3rdParty/LuaMinify.h +++ b/src/3rdParty/LuaMinify.h @@ -1746,13 +1746,18 @@ local function Format_Mini(ast) return a.."\n"..b end]] sep = sep or ' ' + if sep == ';' then + local token = a:match("([%w_]+)%s*$") + if token == "then" or token == "do" then + sep = ' ' + end + end local aa, bb = a:sub(-1,-1), b:sub(1,1) if UpperChars[aa] or LowerChars[aa] or aa == '_' then if not (UpperChars[bb] or LowerChars[bb] or bb == '_' or Digits[bb]) then --bb is a symbol, can join without sep return a..b elseif bb == '(' then - print("==============>>>",aa,bb) --prevent ambiguous syntax return a..sep..b else @@ -2106,9 +2111,15 @@ local function FormatYue(ast, lineMap) break end end + aa = aa or '' sep = sep or ' ' if spaceSep then sep = '' + elseif sep == ';' then + local token = aa:match("([%w_]+)%s*$") + if token == "then" or token == "do" then + sep = ' ' + end end local bb = b:match("^%s*([^%s])") if UpperChars[aa] or LowerChars[aa] or aa == '_' then diff --git a/src/3rdParty/luaminify.lua b/src/3rdParty/luaminify.lua index 7f770ca..925af1e 100644 --- a/src/3rdParty/luaminify.lua +++ b/src/3rdParty/luaminify.lua @@ -1737,6 +1737,12 @@ local function Format_Mini(ast) return a.."\n"..b end]] sep = sep or ' ' + if sep == ';' then + local token = a:match("([%w_]+)%s*$") + if token == "then" or token == "do" then + sep = ' ' + end + end local aa, bb = a:sub(-1,-1), b:sub(1,1) if UpperChars[aa] or LowerChars[aa] or aa == '_' then if not (UpperChars[bb] or LowerChars[bb] or bb == '_' or Digits[bb]) then @@ -2094,9 +2100,15 @@ local function FormatYue(ast, lineMap) break end end + aa = aa or '' sep = sep or ' ' if spaceSep then sep = '' + elseif sep == ';' then + local token = aa:match("([%w_]+)%s*$") + if token == "then" or token == "do" then + sep = ' ' + end end local bb = b:match("^%s*([^%s])") if UpperChars[aa] or LowerChars[aa] or aa == '_' then -- cgit v1.2.3-55-g6feb