
Originally Posted by
wqweto
Just for the experiment I just impl a VbPeg based JS tokenizer w/ the requirements of the RE "competition" but also one that strips whitespace outside of string literals (minifies JS) and it turned quite fast
Nice...
FWIW, here's a performance-improvement for the ActiveScript-JSCode based replacements
(which also corrects a few errors in the reg-expressions):
Code:
With New_c.StringBuilder
.AppendNL "'use strict';"
.AppendNL "var regCmtSngLine1 = /(^\/\/.*?(\r|\n))/gm ;"
.AppendNL "var regCmtSngLine2 = /(?!([""']([^\\[""']]*).*[""'])).(\/\/.*?(\r|\n))/g ;"
.AppendNL "var regCmtMultiLine = /(\/\*[\w\'\s\r\n\*]*\*\/)/g ;"
.AppendNL "var regLet = /^\s*[\{\(]*let \b/gm ;"
.AppendNL "var regEmptyLines = /^\s*[\r\n]/gm ;"
.AppendNL "function CompressJavaScript(code){"
.AppendNL " return code"
.AppendNL " .replace(regCmtSngLine1,'')"
.AppendNL " .replace(regCmtSngLine2,'')"
.AppendNL " .replace(regCmtMultiLine,'')"
.AppendNL " .replace(regLet,'var ')"
.AppendNL " .replace(regEmptyLines,'')"
.AppendNL "}"
mSC.AddCode .ToString
End With
With these changes it is now faster than the (VB)Scripting-Regex-Code -
(also note, that "JScript" works - surprisingly - a bit faster than the newer "JScript9" engine).
Olaf