diff options
author | Li Jin <dragon-fly@qq.com> | 2023-07-26 18:21:53 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-07-26 18:21:53 +0800 |
commit | b14f2b72cecdc8a194bb75e4d4a24b866ddef528 (patch) | |
tree | 21a45a1e82df1229ef2df33d8a7b214a3ec39fd5 /src/3rdParty/LuaMinify.h | |
parent | dd55e092906123232f521b5d3ff2b848806ec67a (diff) | |
download | yuescript-b14f2b72cecdc8a194bb75e4d4a24b866ddef528.tar.gz yuescript-b14f2b72cecdc8a194bb75e4d4a24b866ddef528.tar.bz2 yuescript-b14f2b72cecdc8a194bb75e4d4a24b866ddef528.zip |
make minify and line rewriting work with Lua5.1
Diffstat (limited to 'src/3rdParty/LuaMinify.h')
-rw-r--r-- | src/3rdParty/LuaMinify.h | 13 |
1 files changed, 12 insertions, 1 deletions
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) | |||
1746 | return a.."\n"..b | 1746 | return a.."\n"..b |
1747 | end]] | 1747 | end]] |
1748 | sep = sep or ' ' | 1748 | sep = sep or ' ' |
1749 | if sep == ';' then | ||
1750 | local token = a:match("([%w_]+)%s*$") | ||
1751 | if token == "then" or token == "do" then | ||
1752 | sep = ' ' | ||
1753 | end | ||
1754 | end | ||
1749 | local aa, bb = a:sub(-1,-1), b:sub(1,1) | 1755 | local aa, bb = a:sub(-1,-1), b:sub(1,1) |
1750 | if UpperChars[aa] or LowerChars[aa] or aa == '_' then | 1756 | if UpperChars[aa] or LowerChars[aa] or aa == '_' then |
1751 | if not (UpperChars[bb] or LowerChars[bb] or bb == '_' or Digits[bb]) then | 1757 | if not (UpperChars[bb] or LowerChars[bb] or bb == '_' or Digits[bb]) then |
1752 | --bb is a symbol, can join without sep | 1758 | --bb is a symbol, can join without sep |
1753 | return a..b | 1759 | return a..b |
1754 | elseif bb == '(' then | 1760 | elseif bb == '(' then |
1755 | print("==============>>>",aa,bb) | ||
1756 | --prevent ambiguous syntax | 1761 | --prevent ambiguous syntax |
1757 | return a..sep..b | 1762 | return a..sep..b |
1758 | else | 1763 | else |
@@ -2106,9 +2111,15 @@ local function FormatYue(ast, lineMap) | |||
2106 | break | 2111 | break |
2107 | end | 2112 | end |
2108 | end | 2113 | end |
2114 | aa = aa or '' | ||
2109 | sep = sep or ' ' | 2115 | sep = sep or ' ' |
2110 | if spaceSep then | 2116 | if spaceSep then |
2111 | sep = '' | 2117 | sep = '' |
2118 | elseif sep == ';' then | ||
2119 | local token = aa:match("([%w_]+)%s*$") | ||
2120 | if token == "then" or token == "do" then | ||
2121 | sep = ' ' | ||
2122 | end | ||
2112 | end | 2123 | end |
2113 | local bb = b:match("^%s*([^%s])") | 2124 | local bb = b:match("^%s*([^%s])") |
2114 | if UpperChars[aa] or LowerChars[aa] or aa == '_' then | 2125 | if UpperChars[aa] or LowerChars[aa] or aa == '_' then |