diff --git a/build/post-compile.js b/build/post-compile.js index 4bd6d1999..f324f5f9c 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -6,11 +6,15 @@ var fs = require('fs'); /** The minimal license/copyright template */ - var licenseTemplate = - '/*!\n' + - ' Lo-Dash @VERSION lodash.com/license\n' + - ' Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE\n' + - '*/'; + var licenseTemplate = { + 'lodash': + '/*!\n' + + ' Lo-Dash @VERSION lodash.com/license\n' + + ' Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE\n' + + '*/', + 'underscore': + '/*! Underscore.js @VERSION github.com/documentcloud/underscore/blob/master/LICENSE */' + }; /*--------------------------------------------------------------------------*/ @@ -29,7 +33,9 @@ } // set the version - var license = licenseTemplate.replace('@VERSION', snippet[2]); + var license = ( + snippet ? licenseTemplate[/lodash/i.test(source) ? 'lodash' : 'underscore'] : '' + ).replace('@VERSION', snippet[2]); // move vars exposed by Closure Compiler into the IIFE source = source.replace(/^([^(\n]+)\s*(\(function[^)]+\){)/, '$2$1'); diff --git a/build/pre-compile.js b/build/pre-compile.js index 8fa56e471..3a218c606 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -231,7 +231,11 @@ 'where', 'without', 'wrap', - 'zip' + 'zip', + + // properties used by underscore.js + '_chain', + '_wrapped' ]; /*--------------------------------------------------------------------------*/ @@ -272,6 +276,9 @@ // remove brackets from `_.escape()` in `_.template` source = source.replace(/__e *= *_\['escape']/g, '__e=_.escape'); + // remove brackets from `_.escape()` in underscore.js `_.template` + source = source.replace(/_\['escape'\]\(__t'/g, '_.escape(__t'); + // remove brackets from `collection.indexOf` in `_.contains` source = source.replace("collection['indexOf'](target)", 'collection.indexOf(target)'); @@ -286,6 +293,9 @@ }); }); + // add newline to `+"__p+='"` in underscore.js `_.template` + source = source.replace(/\+"__p\+='"/g, '+"\\n__p+=\'"'); + // remove whitespace from `_.template` related regexes source = source.replace(/(?:reDelimiterCode\w+|reEmptyString\w+|reInsertVariable) *=.+/g, function(match) { return match.replace(/ |\\n/g, '');