remove the advanced_optimizations concessions and the advanced_optimizations rake task. Simple will do.

This commit is contained in:
Jeremy Ashkenas
2010-02-24 12:16:45 -05:00
parent 69bb3490b3
commit 2c8fbe7875
2 changed files with 48 additions and 80 deletions

View File

@@ -8,20 +8,3 @@ task :build do
File.open('underscore-min.js', 'w') {|f| f.write(min) } File.open('underscore-min.js', 'w') {|f| f.write(min) }
end end
task :build_advanced do
js = File.read('underscore.js')
# remove wrapping anonymous function as this messes with closure compiler
# see
# http://groups.google.com/group/closure-compiler-discuss/browse_thread/thread/b59b54c1a0073aa5
js.sub!('(function() {', '').chomp!("_.initWrapper();\n})();\n")
compiler = Closure::Compiler.new \
:compilation_level => 'ADVANCED_OPTIMIZATIONS',
:formatting => 'PRETTY_PRINT'
min = compiler.compile(js)
File.open('underscore-min2.js', 'w') {|f| f.write(min) }
#
original_size = js.length
minimized_size = min.length
puts original_size, minimized_size
end

View File

@@ -45,8 +45,13 @@
nativeIsArray = Array.isArray, nativeIsArray = Array.isArray,
nativeKeys = Object.keys; nativeKeys = Object.keys;
// If Underscore is called as a function, it returns a wrapped object that
// can be used OO-style. This wrapper holds altered versions of all the
// underscore functions. Wrapped objects may be chained.
var wrapper = function(obj) { this._wrapped = obj; };
// Create a safe reference to the Underscore object for reference below. // Create a safe reference to the Underscore object for reference below.
var _ = function(obj) { return _.buildWrapper(obj); }; var _ = function(obj) { return new wrapper(obj); };
// Export the Underscore object for CommonJS. // Export the Underscore object for CommonJS.
if (typeof exports !== 'undefined') exports._ = _; if (typeof exports !== 'undefined') exports._ = _;
@@ -643,22 +648,6 @@
_.methods = _.functions; _.methods = _.functions;
// ------------------------ Setup the OOP Wrapper: -------------------------- // ------------------------ Setup the OOP Wrapper: --------------------------
_.buildWrapper = function() { throw "Call _.initWrapper() to enable OO wrapping"; };
_.initWrapper = function() {
if (_._wrapper) return; // Already initialized
// If Underscore is called as a function, it returns a wrapped object that
// can be used OO-style. This wrapper holds altered versions of all the
// underscore functions. Wrapped objects may be chained.
var wrapper = function(obj) { this._wrapped = obj; };
// Make wrapper object public so user code can extend it.
// Otherwise, there is no way to modify its prototype
_._wrapper = wrapper;
// Overwrite method called from _()
_.buildWrapper = function (obj) { return new wrapper(obj); };
// Helper function to continue chaining intermediate results. // Helper function to continue chaining intermediate results.
var result = function(obj, chain) { var result = function(obj, chain) {
@@ -702,9 +691,5 @@
wrapper.prototype.value = function() { wrapper.prototype.value = function() {
return this._wrapped; return this._wrapped;
}; };
};
// For backwards compatability, init the OO wrapper
// the advanced minifying rake task will strip this out
_.initWrapper();
})(); })();