Permalink
Browse files

YUI Compressor

  • Loading branch information...
0 parents commit 4acfc31323f73c252c3996d5a271449771eb4efe @jlecomte jlecomte committed Aug 9, 2007
@@ -0,0 +1,4 @@
+src.dir = src
+lib.dir = lib
+build.dir = build
+jar.name = yuicompressor.jar
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<project name="YUI Compressor" default="build.jar" basedir=".">
+
+ <target name="clean" depends="-load.properties">
+ <delete dir="${build.dir}" quiet="true"/>
+ </target>
+
+ <target name="-load.properties">
+ <property file="ant.properties"/>
+ </target>
+
+ <target name="-init" depends="-load.properties">
+ <mkdir dir="${build.dir}"/>
+ </target>
+
+ <target name="build.classes" depends="-init">
+ <mkdir dir="${build.dir}/classes"/>
+ <javac srcdir="${src.dir}"
+ destdir="${build.dir}/classes"
+ includes="**/*.java"
+ deprecation="off"
+ debug="on"
+ source="1.4">
+ <classpath>
+ <pathelement location="${lib.dir}/jargs-1.0.jar"/>
+ <pathelement location="${lib.dir}/rhino-1.6R6.jar"/>
+ </classpath>
+ </javac>
+ </target>
+
+ <target name="build.jar" depends="build.classes">
+ <mkdir dir="${build.dir}/jar"/>
+ <mkdir dir="${build.dir}/jar/lib"/>
+ <mkdir dir="${build.dir}/jar/main"/>
+ <unjar src="${lib.dir}/one-jar-boot-0.95.jar" dest="${build.dir}/jar">
+ <patternset>
+ <include name="**/*.class"/>
+ </patternset>
+ </unjar>
+ <!--<delete dir="${build.dir}/jar/META-INF"/>-->
+ <copy todir="${build.dir}/jar/lib">
+ <fileset dir="${lib.dir}">
+ <include name="jargs-1.0.jar"/>
+ <include name="rhino-1.6R6.jar"/>
+ </fileset>
+ </copy>
+ <copy file="${lib.dir}/one-jar-license.txt" todir="${build.dir}/jar"/>
+ <jar destfile="${build.dir}/jar/main/main.jar" basedir="${build.dir}/classes">
+ <manifest>
+ <attribute name="Main-Class" value="YUICompressor"/>
+ </manifest>
+ </jar>
+ <jar destfile="${build.dir}/${jar.name}" basedir="${build.dir}/jar">
+ <manifest>
+ <attribute name="Main-Class" value="com.simontuffs.onejar.Boot"/>
+ </manifest>
+ </jar>
+ </target>
+
+</project>
@@ -0,0 +1,59 @@
+==============================================================================
+YUI Compressor
+==============================================================================
+
+NAME
+
+ yuicompressor - The Yahoo! JavaScript Compressor
+
+SYNOPSIS
+
+ java -jar yuicompressor.jar
+ [-h, --help] [--warn] [--nomunge]
+ [--charset character-set] [-o outfile] infile
+
+DESCRIPTION
+
+ YUI Compressor is a JavaScript compressor which, in addition to minifying,
+ obfuscates local variables using the smallest possible variable name. This
+ obfuscation is safe, even when using constructs such as 'eval' or 'with'
+ (although the compression is not optimal is those cases) Compared to jsmin,
+ the average savings is around 20% (10% after gzipping)
+
+OPTIONS
+
+ -h, --help
+ Prints help on how to use the YUI Compressor
+
+ --warn
+ Prints additional warnings such as duplicate variable declarations,
+ missing variable declaration, unrecommended practices, etc.
+
+ --nomunge
+ Minify only. Do not obfuscate local symbols.
+
+ --charset character-set
+ If a supported character set is specified, the YUI Compressor will use it
+ to read the input file. Otherwise, it will assume that the platform's
+ default character set is being used. The output file is encoded using
+ the same character set.
+
+ -o outfile
+ Place output in file outfile. If not specified, the YUI Compressor will
+ place the output in a file which name is made of the input file name,
+ the "-min" suffix and the "js" extension.
+
+NOTES
+
+ YUI Compressor requires Java version >= 1.4.
+
+AUTHOR
+
+ The YUI Compressor was written and is maintained by:
+ Julien Lecomte <jlecomte@yahoo-inc.com>
+
+COPYRIGHT
+
+ Copyright (c) 2007, Yahoo! Inc. All rights reserved.
+ Code licensed under the BSD License:
+ http://developer.yahoo.net/yui/license.txt
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2004, P. Simon Tuffs (simon@simontuffs.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of P. Simon Tuffs nor the names of any contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
Binary file not shown.
@@ -0,0 +1,35 @@
+/*
+ * YUI Compressor
+ * Author: Julien Lecomte <jlecomte@yahoo-inc.com>
+ * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://developer.yahoo.net/yui/license.txt
+ */
+
+import org.mozilla.javascript.Token;
+
+/**
+ * Identifier represents a variable/function identifier.
+ */
+class Identifier extends JavaScriptToken {
+
+ private String mungedValue;
+ private ScriptOrFnScope declaredScope;
+
+ Identifier(String value, ScriptOrFnScope declaredScope) {
+ super(Token.NAME, value);
+ this.declaredScope = declaredScope;
+ }
+
+ ScriptOrFnScope getDeclaredScope() {
+ return declaredScope;
+ }
+
+ void setMungedValue(String value) {
+ mungedValue = value;
+ }
+
+ String getMungedValue() {
+ return mungedValue;
+ }
+}
@@ -0,0 +1,56 @@
+/*
+ * YUI Compressor
+ * Author: Julien Lecomte <jlecomte@yahoo-inc.com>
+ * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://developer.yahoo.net/yui/license.txt
+ */
+
+import org.mozilla.javascript.ErrorReporter;
+import org.mozilla.javascript.EvaluatorException;
+
+import java.io.PrintStream;
+
+class JavaScriptErrorReporter implements ErrorReporter {
+
+ private boolean reportWarnings;
+ private PrintStream err;
+ private String filename;
+
+ JavaScriptErrorReporter(PrintStream err, String filename, boolean reportWarnings) {
+ this.err = err;
+ this.filename = filename;
+ this.reportWarnings = reportWarnings;
+ }
+
+ public void warning(String message, String sourceName,
+ int line, String lineSource, int lineOffset) {
+ if (reportWarnings) {
+ reportMessage(message, sourceName, line, lineSource, lineOffset);
+ }
+ }
+
+ public EvaluatorException runtimeError(String message, String sourceName,
+ int line, String lineSource, int lineOffset) {
+ error(message, sourceName, line, lineSource, lineOffset);
+ return new EvaluatorException(message);
+ }
+
+ public void error(String message, String sourceName,
+ int line, String lineSource, int lineOffset) {
+ reportMessage(message, sourceName, line, lineSource, lineOffset);
+ }
+
+ private void reportMessage(String message, String sourceName,
+ int line, String lineSource, int lineOffset) {
+ if (line < 0) {
+ if (message.length() == 0) {
+ err.println("An unknown error occurred while checking " + this.filename);
+ } else {
+ err.println(this.filename + ':' + message);
+ }
+ } else {
+ err.println(this.filename + ':' + line + ':' + lineOffset + ':' + message);
+ }
+ }
+}
@@ -0,0 +1,26 @@
+/*
+ * YUI Compressor
+ * Author: Julien Lecomte <jlecomte@yahoo-inc.com>
+ * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://developer.yahoo.net/yui/license.txt
+ */
+
+public class JavaScriptToken {
+
+ private int type;
+ private String value;
+
+ JavaScriptToken(int type, String value) {
+ this.type = type;
+ this.value = value;
+ }
+
+ int getType() {
+ return type;
+ }
+
+ String getValue() {
+ return value;
+ }
+}
Oops, something went wrong.

0 comments on commit 4acfc31

Please sign in to comment.