aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/LuaMinify.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdParty/LuaMinify.h')
-rw-r--r--src/3rdParty/LuaMinify.h48
1 files changed, 23 insertions, 25 deletions
diff --git a/src/3rdParty/LuaMinify.h b/src/3rdParty/LuaMinify.h
index c68097b..895f5a4 100644
--- a/src/3rdParty/LuaMinify.h
+++ b/src/3rdParty/LuaMinify.h
@@ -2,7 +2,7 @@ R"lua_codes(
2--[[ 2--[[
3The MIT License (MIT) 3The MIT License (MIT)
4 4
5Copyright (c) 2012-2013 5Copyright (c) 2012-2013 Mark Langen, modified by Li Jin 2023
6 6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 8
@@ -2087,7 +2087,7 @@ R"lua_codes(
2087local function FormatYue(ast, lineMap) 2087local function FormatYue(ast, lineMap)
2088 local currentLine = 1 2088 local currentLine = 1
2089 local formatStatlist, formatExpr 2089 local formatStatlist, formatExpr
2090 2090
2091 local function joinStatementsSafe(out, b, sep) 2091 local function joinStatementsSafe(out, b, sep)
2092 if #out < 1 then 2092 if #out < 1 then
2093 return '' 2093 return ''
@@ -2148,21 +2148,6 @@ local function FormatYue(ast, lineMap)
2148 2148
2149 formatExpr = function(expr) 2149 formatExpr = function(expr)
2150 local out = {string.rep('(', expr.ParenCount or 0)} 2150 local out = {string.rep('(', expr.ParenCount or 0)}
2151 if expr.Tokens then
2152 local line = expr.Tokens[1].Line
2153 local targetLine = lineMap[line]
2154 if targetLine and currentLine < targetLine then
2155 out[#out + 1] = string.rep('\n', targetLine - currentLine)
2156 currentLine = targetLine
2157 end
2158 elseif expr.Value then
2159 local line = expr.Value.Line
2160 local targetLine = lineMap[line]
2161 if targetLine and currentLine < targetLine then
2162 out[#out + 1] = string.rep('\n', targetLine - currentLine)
2163 currentLine = targetLine
2164 end
2165 end
2166 if expr.AstType == 'VarExpr' then 2151 if expr.AstType == 'VarExpr' then
2167 if expr.Variable then 2152 if expr.Variable then
2168 out[#out + 1] = expr.Variable.Name 2153 out[#out + 1] = expr.Variable.Name
@@ -2226,6 +2211,11 @@ local function FormatYue(ast, lineMap)
2226 2211
2227 elseif expr.AstType == 'MemberExpr' then 2212 elseif expr.AstType == 'MemberExpr' then
2228 out[#out + 1] = formatExpr(expr.Base) 2213 out[#out + 1] = formatExpr(expr.Base)
2214 local targetLine = lineMap[expr.Ident.Line]
2215 if targetLine and currentLine < targetLine then
2216 out[#out + 1] = string.rep('\n', targetLine - currentLine)
2217 currentLine = targetLine
2218 end
2229 out[#out + 1] = expr.Indexer 2219 out[#out + 1] = expr.Indexer
2230 out[#out + 1] = expr.Ident.Data 2220 out[#out + 1] = expr.Ident.Data
2231 2221
@@ -2276,19 +2266,19 @@ local function FormatYue(ast, lineMap)
2276 2266
2277 end 2267 end
2278 out[#out + 1] = string.rep(')', expr.ParenCount or 0) 2268 out[#out + 1] = string.rep(')', expr.ParenCount or 0)
2279 return table.concat(out) 2269 if expr.Tokens and expr.Tokens[1] then
2280 end 2270 local line = expr.Tokens[1].Line
2281
2282 local formatStatement = function(statement)
2283 local out = {""}
2284 if statement.Tokens and statement.Tokens[1] then
2285 local line = statement.Tokens[1].Line
2286 local targetLine = lineMap[line] 2271 local targetLine = lineMap[line]
2287 if targetLine and currentLine < targetLine then 2272 if targetLine and currentLine < targetLine then
2288 out[#out + 1] = string.rep('\n', targetLine - currentLine) 2273 table.insert(out, 1, string.rep('\n', targetLine - currentLine))
2289 currentLine = targetLine 2274 currentLine = targetLine
2290 end 2275 end
2291 end 2276 end
2277 return table.concat(out)
2278 end
2279
2280 local formatStatement = function(statement)
2281 local out = {""}
2292 if statement.AstType == 'AssignmentStatement' then 2282 if statement.AstType == 'AssignmentStatement' then
2293 for i = 1, #statement.Lhs do 2283 for i = 1, #statement.Lhs do
2294 out[#out + 1] = formatExpr(statement.Lhs[i]) 2284 out[#out + 1] = formatExpr(statement.Lhs[i])
@@ -2443,6 +2433,14 @@ local function FormatYue(ast, lineMap)
2443 else 2433 else
2444 print("Unknown AST Type: ", statement.AstType) 2434 print("Unknown AST Type: ", statement.AstType)
2445 end 2435 end
2436 if statement.Tokens and statement.Tokens[1] then
2437 local line = statement.Tokens[1].Line
2438 local targetLine = lineMap[line]
2439 if targetLine and currentLine < targetLine then
2440 table.insert(out, 1, string.rep('\n', targetLine - currentLine))
2441 currentLine = targetLine
2442 end
2443 end
2446 return table.concat(out) 2444 return table.concat(out)
2447 end 2445 end
2448 2446