Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/luamin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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 = ""
}
Expand Down Expand Up @@ -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;
}
}

Expand Down