diff --git a/src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java b/src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java index 03362036..102247cc 100755 --- a/src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java +++ b/src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java @@ -313,6 +313,22 @@ private static ArrayList parse(Reader in, ErrorReporter reporter) env.setLanguageVersion(Context.VERSION_1_7); Parser parser = new Parser(env, reporter); parser.parse(in, null, 1); + return parse(parser); + } + + private static ArrayList parse(String script, ErrorReporter reporter) + throws EvaluatorException { + + CompilerEnvirons env = new CompilerEnvirons(); + env.setLanguageVersion(Context.VERSION_1_7); + Parser parser = new Parser(env, reporter); + parser.parse(script, null, 1); + return parse(parser); + } + + private static ArrayList parse(Parser parser) + throws EvaluatorException { + String source = parser.getEncodedSource(); int offset = 0; @@ -539,15 +555,32 @@ public JavaScriptCompressor(Reader in, ErrorReporter reporter) this.logger = reporter; this.tokens = parse(in, reporter); } + + public JavaScriptCompressor(String script, ErrorReporter reporter) + throws IOException, EvaluatorException { + + this.logger = reporter; + this.tokens = parse(script, reporter); + } + public void compress(Writer out, int linebreak, boolean munge, boolean verbose, - boolean preserveAllSemiColons, boolean disableOptimizations) + boolean preserveAllSemiColons, boolean disableOptimizations) throws IOException { - compress(out, null, linebreak, munge, verbose, preserveAllSemiColons, - disableOptimizations, false); + compress(out, null, null, linebreak, munge, verbose, preserveAllSemiColons, + disableOptimizations, false); } + public void compress(Writer out, Writer mungemap, int linebreak, boolean munge, boolean verbose, boolean preserveAllSemiColons, boolean disableOptimizations, boolean preserveUnknownHints) throws IOException { + compress(out, mungemap, null, linebreak, munge, verbose, preserveAllSemiColons, + disableOptimizations, preserveUnknownHints); + } + + public void compress(Writer out, Writer mungemap, StringBuffer writerBuffer, int linebreak, boolean munge, + boolean verbose, boolean preserveAllSemiColons, + boolean disableOptimizations, boolean preserveUnknownHints) + throws IOException { this.munge = munge; this.verbose = verbose; @@ -565,11 +598,17 @@ public void compress(Writer out, Writer mungemap, int linebreak, boolean munge, mungeSymboltree(); StringBuffer sb = printSymbolTree(linebreak, preserveAllSemiColons); - out.write(sb.toString()); + if (out != null) { + out.write(sb.toString()); + } if (mungemap != null) { printMungeMapping(mungemap); } + + if (writerBuffer != null) { + writerBuffer.append(sb.toString()); + } } private ScriptOrFnScope getCurrentScope() {