JRS: In article <
[email protected]>, dated
Sun, 14 Aug 2005 21:17:43, seen in JDS
I can't. But a beter question is, why bother? Is your javascript stuff
really so huge that taking out the whitespace will matter that much?
Very probably. Though the percentage of superfluous material is as
important as the overall hugeness.
I wrote a tool to indent Pascal; that work enables me to realise some of
the problems. One must be able to recognise, reliably, whether one is
in string or in comment, even though strings may contain comment markers
and comment may contain string quotes and quotes may be escaped.
For a worst(?)-case, consider
eval("X = 3 /* rhubarb's nice \" *" + "/ + 4")
in which the comment closer does not appear in the source file.
It would be easier if the author used a subset of javascript : for
example, no eval, no literal // in a string (use /\/ instead).
It might be better if some comment were preserved : say /** ... **/ .
Then an author could put /** (c) Fred 1984 **/ without losing it.
Then there's probably little to gain from removing superfluous
whitespace within a line, especially if it is consistently-sized and
therefore compressible (I remove trailing whitespace from all my pages
automatically as part of the checking process, using MiniTrue).
One should check javascript-specific editors; a tool that understands
the language should be able to omit superfluities. Something like what
AMAYA and HTML-kit can (potentially?) do for HTML.
Another approach would be to remove all //-to-line-end, then all /** ...
**/ comment, then all leading and trailing whitespace, then all blank
lines. An author writing code to be so processed would probably get
over 95% of possible reduction. AFAICS, MiniTrue could easily do that,
though it might require four passes.