aboutsummaryrefslogtreecommitdiff
path: root/src/LuaMinify.h
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2020-06-22 16:50:40 +0800
committerLi Jin <dragon-fly@qq.com>2020-06-22 16:50:40 +0800
commitcd2b60b101a398cb9356d746364e70eaed1860f1 (patch)
treea1fe71b76faabc4883f16905a94164ce5c23e692 /src/LuaMinify.h
parent88c1052e700f38cf3d8ad82d469da4c487760b7e (diff)
downloadyuescript-cd2b60b101a398cb9356d746364e70eaed1860f1.tar.gz
yuescript-cd2b60b101a398cb9356d746364e70eaed1860f1.tar.bz2
yuescript-cd2b60b101a398cb9356d746364e70eaed1860f1.zip
add support for local variable declared with attribute 'close' and 'const' for Lua 5.4.
Diffstat (limited to '')
-rw-r--r--src/LuaMinify.h33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/LuaMinify.h b/src/LuaMinify.h
index 4990646..76d7759 100644
--- a/src/LuaMinify.h
+++ b/src/LuaMinify.h
@@ -298,8 +298,12 @@ local Scope = {
298 298
299 ObfuscateLocals = function(self, recommendedMaxLength, validNameChars) 299 ObfuscateLocals = function(self, recommendedMaxLength, validNameChars)
300 for i, var in pairs(self.Locals) do 300 for i, var in pairs(self.Locals) do
301 local id = GetUnique(self) 301 if var.Name == "_ENV" then
302 self:RenameLocal(var.Name, id) 302 self:RenameLocal(var.Name, "_ENV")
303 else
304 local id = GetUnique(self)
305 self:RenameLocal(var.Name, id)
306 end
303 end 307 end
304 end 308 end
305} 309}
@@ -1502,13 +1506,24 @@ R"lua_codes(
1502 1506
1503 elseif tok:ConsumeKeyword('local', tokenList) then 1507 elseif tok:ConsumeKeyword('local', tokenList) then
1504 if tok:Is('Ident') then 1508 if tok:Is('Ident') then
1505 local varList = { tok:Get(tokenList).Data } 1509 local varList, attrList = {}, {}
1506 while tok:ConsumeSymbol(',', tokenList) do 1510 repeat
1507 if not tok:Is('Ident') then 1511 if not tok:Is('Ident') then
1508 return false, GenerateError("local var name expected") 1512 return false, GenerateError("local var name expected")
1509 end 1513 end
1510 varList[#varList+1] = tok:Get(tokenList).Data 1514 varList[#varList+1] = tok:Get(tokenList).Data
1511 end 1515 if tok:ConsumeSymbol('<', tokenList) then
1516 if not tok:Is('Ident') then
1517 return false, GenerateError("attrib name expected")
1518 end
1519 attrList[#attrList+1] = tok:Get(tokenList).Data
1520 if not tok:ConsumeSymbol('>', tokenList) then
1521 return false, GenerateError("missing '>' to close attrib name")
1522 end
1523 else
1524 attrList[#attrList+1] = false
1525 end
1526 until not tok:ConsumeSymbol(',', tokenList)
1512 1527
1513 local initList = {} 1528 local initList = {}
1514 if tok:ConsumeSymbol('=', tokenList) then 1529 if tok:ConsumeSymbol('=', tokenList) then
@@ -1529,6 +1544,7 @@ R"lua_codes(
1529 local nodeLocal = {} 1544 local nodeLocal = {}
1530 nodeLocal.AstType = 'LocalStatement' 1545 nodeLocal.AstType = 'LocalStatement'
1531 nodeLocal.LocalList = varList 1546 nodeLocal.LocalList = varList
1547 nodeLocal.AttrList = attrList
1532 nodeLocal.InitList = initList 1548 nodeLocal.InitList = initList
1533 nodeLocal.Tokens = tokenList 1549 nodeLocal.Tokens = tokenList
1534 -- 1550 --
@@ -1923,8 +1939,11 @@ local function Format_Mini(ast)
1923 out = out.."local " 1939 out = out.."local "
1924 for i = 1, #statement.LocalList do 1940 for i = 1, #statement.LocalList do
1925 out = out..statement.LocalList[i].Name 1941 out = out..statement.LocalList[i].Name
1926 if i ~= #statement.LocalList then 1942 if statement.AttrList[i] then
1927 out = out.."," 1943 out = out.."<"..statement.AttrList[i]..">"
1944 if i == #statement.LocalList then
1945 out = out.." "
1946 end
1928 end 1947 end
1929 end 1948 end
1930 if #statement.InitList > 0 then 1949 if #statement.InitList > 0 then