diff --git a/src/luamin.js b/src/luamin.js index 8e694bb..e00e32f 100644 --- a/src/luamin.js +++ b/src/luamin.js @@ -34,6 +34,9 @@ const assert = function(a,b) { function parseFloat(str, radix) { if (!str) return 0; + if (!radix || radix === 10) { + return Number(str.toString()); + } var parts = str.toString().split("."); if (parts.length > 1) { return parseInt(parts[0], radix) + parseInt(parts[1], radix) / Math.pow(radix, parts[1].length); @@ -2600,9 +2603,14 @@ function FormatAst(ast, indentation) { padToken(expr.Token_Op) //} } else if(expr.Type == "UnopExpr") { - //padToken(expr.Token_Op) formatExpr(expr.Rhs) - padToken(expr.Rhs.GetFirstToken()) + // Only add a space if the operator is a word like 'not' + if (expr.Token_Op.Source === 'not') { + padToken(expr.Rhs.GetFirstToken()) + } else { + // Otherwise, squish them together for '-' and '#' + trimToken(expr.Rhs.GetFirstToken()) + } } else if(expr.Type == "NumberLiteral" || expr.Type == "StringLiteral" || expr.Type == "NilLiteral" || expr.Type == "BooleanLiteral" || expr.Type == "VargLiteral" || expr.Type == 'HashLiteral') @@ -3008,7 +3016,12 @@ function StripAst(ast) { let firstCh = (typeof tokenB.Source == 'string' ? tokenB.Source : tokenB.Source.toString()).substr(0,1) if ((lastCh == "-" && firstCh == "-") || (AllIdentChars.includes(lastCh) && AllIdentChars.includes(firstCh)) || (shit && lastCh == ')' && firstCh == '(')) { - tokenB.LeadingWhite = shit ? ';' : ' ' + // Only force a semicolon if it's the specific ')( ' edge case + if (shit && lastCh == ')' && firstCh == '(') { + tokenB.LeadingWhite = ';'; + } else { + tokenB.LeadingWhite = ' '; + } } else { tokenB.LeadingWhite = "" } @@ -3177,10 +3190,9 @@ function StripAst(ast) { } if (stat.SemicolonList[i-1]) { - let lastS = lastChStat.GetLastToken().Source - let firstS = chStat.GetFirstToken().Source - if (bannedCombos[lastS] === null || bannedCombos[lastS] === undefined || !bannedCombos[lastS].includes(firstS)) { - stat.SemicolonList[i-1] = null + let firstS = chStat.GetFirstToken().Source; + if (firstS !== '(' && firstS !== '[') { + stat.SemicolonList[i-1] = null; } }