From 68858316432fa8b2c74e8ce76ad78443c3838747 Mon Sep 17 00:00:00 2001 From: Isaac Shapira Date: Sat, 16 Mar 2013 15:55:55 -0600 Subject: [PATCH] option added to allow user to turn mangling off --- lib/snockets.js | 15 ++++++++++----- src/snockets.coffee | 7 ++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/snockets.js b/lib/snockets.js index 7aee668..5d8325e 100644 --- a/lib/snockets.js +++ b/lib/snockets.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.3.3 +// Generated by CoffeeScript 1.4.0 (function() { var CoffeeScript, DIRECTIVE, DepGraph, EXPLICIT_PATH, HEADER, HoldingQueue, Snockets, compilers, fs, jsExts, minify, parseDirectives, path, stripExt, timeEq, uglify, _, __slice = [].slice, @@ -19,7 +19,7 @@ module.exports = Snockets = (function() { function Snockets(options) { - var _base, _base1, _ref, _ref1; + var _base, _base1, _base2, _ref, _ref1, _ref2; this.options = options != null ? options : {}; if ((_ref = (_base = this.options).src) == null) { _base.src = '.'; @@ -27,6 +27,9 @@ if ((_ref1 = (_base1 = this.options).async) == null) { _base1.async = true; } + if ((_ref2 = (_base2 = this.options).mangle) == null) { + _base2.mangle = true; + } this.cache = {}; this.concatCache = {}; this.depGraph = new DepGraph; @@ -173,7 +176,7 @@ result = _this.concatCache[filePath].minifiedData.toString('utf8'); concatenationChanged = false; } else { - result = minify(concatenation); + result = minify(concatenation, _this.options.mangle); _this.concatCache[filePath].minifiedData = new Buffer(result); } } else { @@ -541,12 +544,14 @@ })()).concat('.js'); }; - minify = function(js) { + minify = function(js, mangle) { var ast, jsp, pro; jsp = uglify.parser; pro = uglify.uglify; ast = jsp.parse(js); - ast = pro.ast_mangle(ast); + if (mangle) { + ast = pro.ast_mangle(ast); + } ast = pro.ast_squeeze(ast); return pro.gen_code(ast); }; diff --git a/src/snockets.coffee b/src/snockets.coffee index fb98cba..f4f41be 100644 --- a/src/snockets.coffee +++ b/src/snockets.coffee @@ -12,6 +12,7 @@ module.exports = class Snockets constructor: (@options = {}) -> @options.src ?= '.' @options.async ?= true + @options.mangle ?= true @cache = {} @concatCache = {} @depGraph = new DepGraph @@ -85,7 +86,7 @@ module.exports = class Snockets result = @concatCache[filePath].minifiedData.toString 'utf8' concatenationChanged = false else - result = minify concatenation + result = minify concatenation, @options.mangle @concatCache[filePath].minifiedData = new Buffer(result) else result = concatenation @@ -312,11 +313,11 @@ stripExt = (filePath) -> jsExts = -> (".#{ext}" for ext of compilers).concat '.js' -minify = (js) -> +minify = (js, mangle) -> jsp = uglify.parser pro = uglify.uglify ast = jsp.parse js - ast = pro.ast_mangle ast + ast = pro.ast_mangle ast if mangle ast = pro.ast_squeeze ast pro.gen_code ast