From 3ced9d494759d37559a7dde0c1dd4c43bcec1e52 Mon Sep 17 00:00:00 2001
From: Sam Stephenson
Date: Sun, 20 Feb 2011 14:25:34 -0600
Subject: [PATCH 1/7] Move index.js into lib
---
bin/uglifyjs | 2 +-
index.js | 2 --
lib/index.js | 2 ++
package.json | 2 +-
test/unit/scripts.js | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
delete mode 100644 index.js
create mode 100644 lib/index.js
diff --git a/bin/uglifyjs b/bin/uglifyjs
index ca6869fb..0e915ded 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -3,7 +3,7 @@
global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
var fs = require("fs");
-var uglify = require("uglify-js"), // symlink ~/.node_libraries/uglify-js.js to ../uglify-js.js
+var uglify = require("uglify-js"), // `npm link` or symlink ../lib to ~/.node_libraries/uglify-js
jsp = uglify.parser,
pro = uglify.uglify;
diff --git a/index.js b/index.js
deleted file mode 100644
index 1a0fc323..00000000
--- a/index.js
+++ /dev/null
@@ -1,2 +0,0 @@
-exports.parser = require("./lib/parse-js");
-exports.uglify = require("./lib/process");
diff --git a/lib/index.js b/lib/index.js
new file mode 100644
index 00000000..7144c32f
--- /dev/null
+++ b/lib/index.js
@@ -0,0 +1,2 @@
+exports.parser = require("./parse-js");
+exports.uglify = require("./process");
diff --git a/package.json b/package.json
index c267382f..08ae8239 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{"name" : "uglify-js",
"author" : "Mihai Bazon - http://github.com/mishoo",
"version" : "0.0.1",
- "main" : "index.js",
+ "main" : "./lib/index.js",
"bin" : { "uglifyjs" : "./bin/uglifyjs" },
}
diff --git a/test/unit/scripts.js b/test/unit/scripts.js
index 94a4cddc..dc7499f4 100644
--- a/test/unit/scripts.js
+++ b/test/unit/scripts.js
@@ -1,5 +1,5 @@
var fs = require('fs'),
- uglify = require('uglify-js'),
+ uglify = require('../../lib'),
jsp = uglify.parser,
nodeunit = require('nodeunit'),
path = require('path'),
From d4d8111ff36be661d832e971bb9119fbcdf968e1 Mon Sep 17 00:00:00 2001
From: Sam Stephenson
Date: Sun, 20 Feb 2011 14:31:30 -0600
Subject: [PATCH 2/7] Add license and repository info to package.json
---
LICENSE | 28 ++++++++++++++++++++++++++++
README.html | 2 +-
package.json | 18 +++++++++++++-----
3 files changed, 42 insertions(+), 6 deletions(-)
create mode 100644 LICENSE
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..ee8561b5
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,28 @@
+Copyright (c) 2011 Mihai Bazon
+Based on parse-js (http://marijn.haverbeke.nl/parse-js/).
+
+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.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “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 HOLDER 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.
diff --git a/README.html b/README.html
index 4cd70115..2be0394f 100644
--- a/README.html
+++ b/README.html
@@ -707,7 +707,7 @@ 1.6 License
-Copyright 2010 (c) Mihai Bazon <mihai.bazon@gmail.com>
+Copyright (c) 2011 Mihai Bazon <mihai.bazon@gmail.com>
Based on parse-js (http://marijn.haverbeke.nl/parse-js/).
Redistribution and use in source and binary forms, with or without
diff --git a/package.json b/package.json
index 08ae8239..8c7eefd3 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,14 @@
-{"name" : "uglify-js",
- "author" : "Mihai Bazon - http://github.com/mishoo",
- "version" : "0.0.1",
- "main" : "./lib/index.js",
- "bin" : { "uglifyjs" : "./bin/uglifyjs" },
+{ "name" : "uglify-js"
+, "author" : "Mihai Bazon - http://github.com/mishoo"
+, "version" : "0.0.1"
+, "main" : "./lib/index.js"
+, "bin" : { "uglifyjs" : "./bin/uglifyjs" }
+, "licenses" : [
+ { "type" : "BSD"
+ , "url" : "http://github.com/mishoo/raw/master/LICENSE"
+ }]
+, "repository" :
+ { "type" : "git"
+ , "url" : "http://github.com/mishoo/UglifyJS.git"
+ }
}
From 1065c3ed1f5bde9993cef5f4d10d68190875cb6b Mon Sep 17 00:00:00 2001
From: Sam Stephenson
Date: Sun, 20 Feb 2011 14:41:11 -0600
Subject: [PATCH 3/7] `make dist` generates dist/uglify.js for non-CommonJS
environments
---
.gitignore | 3 ++-
Makefile | 10 ++++++++++
build.js | 29 +++++++++++++++++++++++++++++
3 files changed, 41 insertions(+), 1 deletion(-)
create mode 100644 Makefile
create mode 100755 build.js
diff --git a/.gitignore b/.gitignore
index d97eaa09..da080d93 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.DS_Store
.tmp*~
*.local.*
-.pinf-*
\ No newline at end of file
+.pinf-*
+/dist
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..003cf9c6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,10 @@
+all: dist
+
+dist: dist/uglify.js
+
+dist/uglify.js: lib/*
+ mkdir -p dist
+ ./build.js > dist/uglify.js
+
+clean:
+ rm -f dist/uglify.js
diff --git a/build.js b/build.js
new file mode 100755
index 00000000..5b23413a
--- /dev/null
+++ b/build.js
@@ -0,0 +1,29 @@
+#!/usr/bin/env node
+
+var fs = require("fs");
+var UglifyJS = require("./lib");
+var stitch = require("stitch");
+var package = stitch.createPackage({ paths: [__dirname + "/lib"] });
+var metadata = JSON.parse(fs.readFileSync(__dirname + "/package.json"));
+
+package.compile(function(err, source) {
+ if (err) throw err;
+ var uglify = UglifyJS.uglify;
+
+ var ast = UglifyJS.parser.parse(
+ "(function(window) {" + source + ";" +
+ "window.UglifyJS = this.require('.')" +
+ "}).call({}, this)"
+ );
+
+ process.stdout.write(
+ "/*! UglifyJS v" + metadata.version + "\n" +
+ " * http://github.com/mishoo/UglifyJS/\n" +
+ " *\n" +
+ " * (c) 2011 Mihai Bazon\n" +
+ " * Released under the BSD License\n" +
+ " */\n" +
+ uglify.gen_code(uglify.ast_squeeze(uglify.ast_mangle(ast))) +
+ ";\n"
+ );
+});
From c5ba60c5c079f05b6588d5f07c74211dc5ff8570 Mon Sep 17 00:00:00 2001
From: Sam Stephenson
Date: Sun, 20 Feb 2011 14:50:44 -0600
Subject: [PATCH 4/7] Add test targets
---
Makefile | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 003cf9c6..23c7ab1a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,18 @@
-all: dist
+all: dist test
dist: dist/uglify.js
-dist/uglify.js: lib/*
+dist/uglify.js: lib/*.js
mkdir -p dist
./build.js > dist/uglify.js
+test: test/testparser.js test/unit
+
+test/testparser.js: lib/*.js
+ test/testparser.js
+
+test/unit: test/unit/scripts.js test/unit/compress/expected/*.js test/unit/compress/test/*.js lib/*.js
+ nodeunit test/unit/scripts.js
+
clean:
rm -f dist/uglify.js
From 43b71dad13f5fb397312852880df44fd2ec8cb27 Mon Sep 17 00:00:00 2001
From: Sam Stephenson
Date: Sun, 20 Feb 2011 15:08:08 -0600
Subject: [PATCH 5/7] Update documentation for node 0.4/npm 0.3 compatibility
---
README.html | 101 ++++++++++++++++++++++++++++------------------------
README.org | 28 +++++++--------
2 files changed, 69 insertions(+), 60 deletions(-)
diff --git a/README.html b/README.html
index 2be0394f..44c228a0 100644
--- a/README.html
+++ b/README.html
@@ -7,7 +7,7 @@
UglifyJS -- a JavaScript parser/compressor/beautifier
-
+
@@ -21,6 +21,9 @@
.target { }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
+ .right {margin-left:auto; margin-right:0px; text-align:right;}
+ .left {margin-left:0px; margin-right:auto; text-align:left;}
+ .center {margin-left:auto; margin-right:auto; text-align:center;}
p.verse { margin-left: 3% }
pre {
border: 1pt solid #AEBDCC;
@@ -31,7 +34,13 @@
overflow:auto;
}
table { border-collapse: collapse; }
- td, th { vertical-align: top; }
+ td, th { vertical-align: top; }
+ th.right { text-align:center; }
+ th.left { text-align:center; }
+ th.center { text-align:center; }
+ td.right { text-align:right; }
+ td.left { text-align:left; }
+ td.center { text-align:center; }
dt { font-weight: bold; }
div.figure { padding: 0.5em; }
div.figure p { text-align: center; }
@@ -250,10 +259,10 @@ 1.1.1 Calls involving t
-new Array(1, 2, 3, 4) => [1,2,3,4]
+new Array(1, 2, 3, 4) => [1,2,3,4]
Array(a, b, c) => [a,b,c]
-new Array(5) => Array(5)
-new Array(a) => Array(a)
+new Array(5) => Array(5)
+new Array(a) => Array(a)
@@ -271,38 +280,38 @@ 1.1.1 Calls involving t
-// case 1. globally declared variable
- var Array;
- new Array(1, 2, 3);
+// case 1. globally declared variable
+ var Array;
+ new Array(1, 2, 3);
Array(a, b);
- // or (can be declared later)
- new Array(1, 2, 3);
- var Array;
+ // or (can be declared later)
+ new Array(1, 2, 3);
+ var Array;
- // or (can be a function)
- new Array(1, 2, 3);
- function Array() { ... }
+ // or (can be a function)
+ new Array(1, 2, 3);
+ function Array() { ... }
-// case 2. declared in a function
- (function(){
- a = new Array(1, 2, 3);
+// case 2. declared in a function
+ (function(){
+ a = new Array(1, 2, 3);
b = Array(5, 6);
- var Array;
+ var Array;
})();
- // or
- (function(Array){
- return Array(5, 6, 7);
+ // or
+ (function(Array){
+ return Array(5, 6, 7);
})();
- // or
- (function(){
- return new Array(1, 2, 3, 4);
- function Array() { ... }
+ // or
+ (function(){
+ return new Array(1, 2, 3, 4);
+ function Array() { ... }
})();
- // etc.
+ // etc.
@@ -455,20 +464,20 @@ 1.2.1 API
-Symlink the lib directory as ~/.node_libraries/uglifyjs, so that the
-require calls in the following sample will work:
+Symlink the lib
directory as ~/.node_libraries/uglify-js
(or run
+npm link
) so that the require calls in the following sample will work:
-var jsp = require("uglifyjs/parse-js");
-var pro = require("uglifyjs/process");
+var UglifyJS = require("uglify-js");
+var parser = UglifyJS.parser, uglify = UglifyJS.uglify;
-var orig_code = "... JS code here";
-var ast = jsp.parse(orig_code); // parse code and get the initial AST
-ast = pro.ast_mangle(ast); // get a new AST with mangled names
-ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
-var final_code = pro.gen_code(ast); // compressed code here
+var orig_code = "... JS code here";
+var ast = parser.parse(orig_code); // parse code and get the initial AST
+ast = uglify.ast_mangle(ast); // get a new AST with mangled names
+ast = uglify.ast_squeeze(ast); // get an AST with compression optimizations
+var final_code = uglify.gen_code(ast); // compressed code here
@@ -478,14 +487,14 @@ 1.2.1 API
can see, there are a sequence of steps which you can apply. For example if
you want compressed output but for some reason you don't want to mangle
variable names, you would simply skip the line that calls
-pro.ast_mangle(ast)
.
+uglify.ast_mangle(ast)
.
Some of these functions take optional arguments. Here's a description:
-
-
jsp.parse(code, strict_semicolons)
– parses JS code and returns an AST.
+parser.parse(code, strict_semicolons)
– parses JS code and returns an AST.
strict_semicolons
is optional and defaults to false
. If you pass
true
then the parser will throw an error when it expects a semicolon and
it doesn't find it. For most JS code you don't want that, but it's useful
@@ -493,7 +502,7 @@ 1.2.1 API
-
-
pro.ast_mangle(ast, options)
– generates a new AST containing mangled
+uglify.ast_mangle(ast, options)
– generates a new AST containing mangled
(compressed) variable and function names. It supports the following
options:
@@ -508,7 +517,7 @@ 1.2.1 API
-pro.ast_squeeze(ast, options)
– employs further optimizations designed
+uglify.ast_squeeze(ast, options)
– employs further optimizations designed
to reduce the size of the code that gen_code
would generate from the
AST. Returns a new AST. options
can be a hash; the supported options
are:
@@ -526,7 +535,7 @@ 1.2.1 API
-pro.gen_code(ast, beautify)
– generates JS code from the AST. By
+uglify.gen_code(ast, beautify)
– generates JS code from the AST. By
default it's minified, but if you pass true
for the second argument it
will be nicely formatted and indented. Additionally, you can control the
behavior by passing a hash for beautify
, where the following options are
@@ -606,14 +615,14 @@ 1.3 Compression – h
-
+
-Library | Orig. size | UglifyJS | YUI | GCL |
+Library | Orig. size | UglifyJS | YUI | GCL |
-DynarchLIB | 636896 | 241441 | 246452 (+5011) | 240439 (-1002) (buggy) |
-jQuery | 163855 | 72006 | 79702 (+7696) | 71858 (-148) |
+DynarchLIB | 636896 | 241441 | 246452 (+5011) | 240439 (-1002) (buggy) |
+jQuery | 163855 | 72006 | 79702 (+7696) | 71858 (-148) |
@@ -754,8 +763,8 @@
Author: Mihai Bazon
-
Date: 2011-02-19 11:12:48 EET
-
HTML generated by org-mode 7.01trans in emacs 23
+
Date: 2011-02-20 15:10:05 CST
+
HTML generated by org-mode 7.4 in emacs 24