Permalink
Browse files

Use Uglify-JS2 for minification

  • Loading branch information...
1 parent b15ea77 commit 0ad26539088355392787843644d78e1ccc61cde7 @laktek committed Jan 5, 2013
Showing with 11 additions and 26 deletions.
  1. +4 −7 lib/minifiers/uglify.js
  2. +1 −1 package.json
  3. +6 −18 spec/minifiers/uglify.spec.js
View
@@ -1,5 +1,4 @@
-var jsp = require("uglify-js").parser;
-var pro = require("uglify-js").uglify;
+var uglifyJS = require("uglify-js");
module.exports = {
compiler_options: {},
@@ -11,11 +10,9 @@ module.exports = {
var output, err;
try {
- var ast = jsp.parse(input); // 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
- output = pro.gen_code(ast); // compressed code here
- output = output.replace(/;*$/, ";"); //add a semi-colon to the end
+ output = uglifyJS.minify(input, {
+ fromString: true
+ }).code;
} catch(error) {
err = error;
}
View
@@ -37,7 +37,7 @@
"marked": ">= 0.2.5",
"mime": ">= 1.2.5",
"mustache": ">0.7.0 || >=0.5.2 <0.7.0",
- "uglify-js": ">= 1.3.3",
+ "uglify-js": ">= 2.2.3",
"underscore": ">= 1.4.2"
},
"devDependencies": {
@@ -1,24 +1,12 @@
-var jsp = require("uglify-js").parser;
-var pro = require("uglify-js").uglify;
+var uglifyJS = require("uglify-js");
var uglify_minifier = require("../../lib/minifiers/uglify");
describe("calling minify", function() {
- it("calls the callback with the result", function(){
- spyOn(jsp, "parse").andCallFake(function(input){
- return "initial ast";
- });
-
- spyOn(pro, "ast_mangle").andCallFake(function(input){
- return "initial ast";
- });
-
- spyOn(pro, "ast_squeeze").andCallFake(function(input){
- return "initial ast";
- });
+ it("call the callback with the result", function(){
- spyOn(pro, "gen_code").andCallFake(function(input){
- return "{ function(){} };";
+ spyOn(uglifyJS, "minify").andCallFake(function(input){
+ return { code: "{ function(){} };", map: null };
});
var spyCallback = jasmine.createSpy();
@@ -27,8 +15,8 @@ describe("calling minify", function() {
expect(spyCallback).toHaveBeenCalledWith(undefined, "{ function(){} };");
});
- it("calls the callback with the error", function(){
- spyOn(jsp, "parse").andCallFake(function(input){
+ it("call the callback with the error", function(){
+ spyOn(uglifyJS, "minify").andCallFake(function(input){
throw "error";
});

0 comments on commit 0ad2653

Please sign in to comment.