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 | |
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')
-rw-r--r-- | src/3rdParty/LuaMinify.h | 13 | ||||
-rw-r--r-- | src/3rdParty/luaminify.lua | 12 |
2 files changed, 24 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 |
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) | |||
1737 | return a.."\n"..b | 1737 | return a.."\n"..b |
1738 | end]] | 1738 | end]] |
1739 | sep = sep or ' ' | 1739 | sep = sep or ' ' |
1740 | if sep == ';' then | ||
1741 | local token = a:match("([%w_]+)%s*$") | ||
1742 | if token == "then" or token == "do" then | ||
1743 | sep = ' ' | ||
1744 | end | ||
1745 | end | ||
1740 | local aa, bb = a:sub(-1,-1), b:sub(1,1) | 1746 | local aa, bb = a:sub(-1,-1), b:sub(1,1) |
1741 | if UpperChars[aa] or LowerChars[aa] or aa == '_' then | 1747 | if UpperChars[aa] or LowerChars[aa] or aa == '_' then |
1742 | if not (UpperChars[bb] or LowerChars[bb] or bb == '_' or Digits[bb]) then | 1748 | if not (UpperChars[bb] or LowerChars[bb] or bb == '_' or Digits[bb]) then |
@@ -2094,9 +2100,15 @@ local function FormatYue(ast, lineMap) | |||
2094 | break | 2100 | break |
2095 | end | 2101 | end |
2096 | end | 2102 | end |
2103 | aa = aa or '' | ||
2097 | sep = sep or ' ' | 2104 | sep = sep or ' ' |
2098 | if spaceSep then | 2105 | if spaceSep then |
2099 | sep = '' | 2106 | sep = '' |
2107 | elseif sep == ';' then | ||
2108 | local token = aa:match("([%w_]+)%s*$") | ||
2109 | if token == "then" or token == "do" then | ||
2110 | sep = ' ' | ||
2111 | end | ||
2100 | end | 2112 | end |
2101 | local bb = b:match("^%s*([^%s])") | 2113 | local bb = b:match("^%s*([^%s])") |
2102 | if UpperChars[aa] or LowerChars[aa] or aa == '_' then | 2114 | if UpperChars[aa] or LowerChars[aa] or aa == '_' then |