Minify boolean and numeric literals in obfuscated mode#10291
Minify boolean and numeric literals in obfuscated mode#10291zbynek wants to merge 4 commits intogwtproject:mainfrom
Conversation
a569b03 to
eb7f316
Compare
| if (spaceReturn(expr)) { | ||
| _space(); | ||
| } else { | ||
| _spaceOpt(); | ||
| } |
There was a problem hiding this comment.
I don't have a great solution for this, but I just wanted to call out briefly that this seems gross - we have to toString the child node twice, so that we know how to concat them together. Perf-wise (though probably not logic-wise) it would seem better to just go ahead and not accept(expr) if we know it is a literal, but append directly.
Better still would be to signal to the TextOutput "hey you already know if space is optional or not... I just finished writing a keyword, make sure the next token gets a space if it needs it". Then, when the next token is written, TextOutput decides if it needs a space?
One missing case in the current impl is to do with parens - in the terser sample you showed me, there are some cases of extra parens being required in order to maintain operator precedence:
return(t=h.h>>19)!=(u=n.h>>19)?...
There was a problem hiding this comment.
Perf-wise (though probably not logic-wise) it would seem better to just go ahead and not accept(expr) if we know it is a literal
That's implemented in my last commit.
One missing case in the current impl is to do with parens
I don't have a good solution for that -- would it be OK to leave that for another time?
There was a problem hiding this comment.
Yeah, I think we wait, rethink that as we implement other size enhancements.
There was a problem hiding this comment.
Uh, so we need to accept the literal node so that subclasses can handle it (for billing). For now I reverted to the duplicated serialization -- we could introduce a flag that lets us accept the node without printing, but it's not obvious if that can save time.
Fixes #10281
Also cleans up some minor code style issues in the modified files.
Does NOT implement