mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Cleanup build script comments and fix Closure Compiler bugs.
Former-commit-id: 84771ac79d6cfd7ec3b0d29586edf58d617d5577
This commit is contained in:
20
build.js
20
build.js
@@ -12,14 +12,14 @@
|
||||
/** The current working directory */
|
||||
var cwd = process.cwd();
|
||||
|
||||
/** Shortcut to native `Array.prototype` */
|
||||
var ArrayProto = Array.prototype;
|
||||
/** Used for array method references */
|
||||
var arrayRef = [];
|
||||
|
||||
/** Shortcut used to push arrays of values to an array */
|
||||
var push = ArrayProto.push;
|
||||
var push = arrayRef.push;
|
||||
|
||||
/** Shortcut used to convert array-like objects to arrays */
|
||||
var slice = ArrayProto.slice;
|
||||
var slice = arrayRef.slice;
|
||||
|
||||
/** Shortcut to the `stdout` object */
|
||||
var stdout = process.stdout;
|
||||
@@ -792,7 +792,7 @@
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Creates a debug and minified build, executing the `callback` for each.
|
||||
* Creates a debug and/or minified build, executing the `callback` for each.
|
||||
* The `callback` is invoked with two arguments; (filePath, outputSource).
|
||||
*
|
||||
* Note: For a list of commands see `displayHelp()` or run `lodash --help`.
|
||||
@@ -1065,7 +1065,7 @@
|
||||
' function difference(array) {',
|
||||
' var index = -1,',
|
||||
' length = array.length,',
|
||||
' flattened = concat.apply(ArrayProto, arguments),',
|
||||
' flattened = concat.apply(arrayRef, arguments),',
|
||||
' result = [];',
|
||||
'',
|
||||
' while (++index < length) {',
|
||||
@@ -1121,7 +1121,7 @@
|
||||
// replace `_.omit`
|
||||
source = source.replace(/^( +)function omit[\s\S]+?\n\1}/m, [
|
||||
' function omit(object) {',
|
||||
' var props = concat.apply(ArrayProto, arguments),',
|
||||
' var props = concat.apply(arrayRef, arguments),',
|
||||
' result = {};',
|
||||
'',
|
||||
' forIn(object, function(value, key) {',
|
||||
@@ -1137,7 +1137,7 @@
|
||||
source = source.replace(/^( +)function pick[\s\S]+?\n\1}/m, [
|
||||
' function pick(object) {',
|
||||
' var index = 0,',
|
||||
' props = concat.apply(ArrayProto, arguments),',
|
||||
' props = concat.apply(arrayRef, arguments),',
|
||||
' length = props.length,',
|
||||
' result = {};',
|
||||
'',
|
||||
@@ -1647,10 +1647,6 @@
|
||||
'isTemplate': isTemplate,
|
||||
'outputPath': outputPath,
|
||||
'onComplete': function(source) {
|
||||
// correct overly aggressive Closure Compiler minification
|
||||
if (!isTemplate) {
|
||||
source = source.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}');
|
||||
}
|
||||
// inject "use strict" directive
|
||||
if (isStrict) {
|
||||
source = source.replace(/^([\s\S]*?function[^{]+{)([^'"])/, '$1"use strict";$2');
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
postprocess = require('./post-compile'),
|
||||
uglifyJS = require('../vendor/uglifyjs/uglify-js');
|
||||
|
||||
/** Closure Compiler command-line options */
|
||||
/** The Closure Compiler command-line options */
|
||||
var closureOptions = [
|
||||
'--compilation_level=ADVANCED_OPTIMIZATIONS',
|
||||
'--warning_level=QUIET'
|
||||
@@ -135,7 +135,7 @@
|
||||
return value.replace(/^(--compilation_level)=.+$/, '$1=SIMPLE_OPTIMIZATIONS');
|
||||
});
|
||||
}
|
||||
// the standard error stream, standard output stream, and Closure Compiler process
|
||||
// the standard error stream, standard output stream, and the Closure Compiler process
|
||||
var error = '',
|
||||
output = '',
|
||||
compiler = spawn('java', ['-jar', closurePath].concat(options));
|
||||
@@ -348,7 +348,7 @@
|
||||
uglified = this.uglified;
|
||||
|
||||
// select the smallest gzipped file and use its minified counterpart as the
|
||||
// official minified release (ties go to Closure Compiler)
|
||||
// official minified release (ties go to the Closure Compiler)
|
||||
var min = Math.min(compiled.gzip.length, hybrid.gzip.length, uglified.gzip.length);
|
||||
|
||||
// pass the minified source to the minify instances "onComplete" callback
|
||||
|
||||
@@ -26,9 +26,17 @@
|
||||
* @returns {String} Returns the processed source.
|
||||
*/
|
||||
function postprocess(source) {
|
||||
// move vars exposed by Closure Compiler into the IIFE
|
||||
// move vars exposed by the Closure Compiler into the IIFE
|
||||
source = source.replace(/^((?:(['"])use strict\2;)?(?:var (?:[a-z]+=(?:!0|!1|null)[,;])+)?)([\s\S]*?function[^)]+\){)/, '$3$1');
|
||||
|
||||
// avoid bugs with the Closure Compiler
|
||||
source = source
|
||||
// correct overly aggressive Closure Compiler minification
|
||||
.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}')
|
||||
// restore `arrayRef` and `objectRef` values modified by pre-compile.js
|
||||
.replace(/= *Array.prototype/, '=[]')
|
||||
.replace(/= *Object.prototype/, '={}');
|
||||
|
||||
// unescape properties (i.e. foo["bar"] => foo.bar)
|
||||
source = source.replace(/(\w)\["([^."]+)"\]/g, function(match, left, right) {
|
||||
return /\W/.test(right) ? match : (left + '.' + right);
|
||||
|
||||
@@ -206,7 +206,7 @@
|
||||
source || (source = '');
|
||||
options || (options = {});
|
||||
|
||||
// remove unrecognized JSDoc tags so Closure Compiler won't complain
|
||||
// remove unrecognized JSDoc tags so the Closure Compiler won't complain
|
||||
source = source.replace(/@(?:alias|category)\b.*/g, '');
|
||||
|
||||
if (options.isTemplate) {
|
||||
@@ -216,7 +216,12 @@
|
||||
// remove copyright to add later in post-compile.js
|
||||
source = source.replace(/\/\*![\s\S]+?\*\//, '');
|
||||
|
||||
// add brackets to whitelisted properties so Closure Compiler won't mung them
|
||||
// replace `arrayRef` and `objectRef` values to avoid a bug in the Closure Compiler
|
||||
source = source
|
||||
.replace(/(arrayRef *= *)\[\]/, '$1Array.prototype')
|
||||
.replace(/(objectRef *= *)\{\}/, '$1Object.prototype');
|
||||
|
||||
// add brackets to whitelisted properties so the Closure Compiler won't mung them
|
||||
// http://code.google.com/closure/compiler/docs/api-tutorial3.html#export
|
||||
source = source.replace(RegExp('\\.(' + propWhitelist.join('|') + ')\\b', 'g'), "['$1']");
|
||||
|
||||
@@ -314,7 +319,7 @@
|
||||
isIteratorTemplate = /var iteratorTemplate\b/.test(snippet),
|
||||
modified = snippet;
|
||||
|
||||
// add brackets to whitelisted properties so Closure Compiler won't mung them
|
||||
// add brackets to whitelisted properties so the Closure Compiler won't mung them
|
||||
modified = modified.replace(RegExp('\\.(' + iteratorOptions.join('|') + ')\\b', 'g'), "['$1']");
|
||||
|
||||
if (isCreateIterator) {
|
||||
|
||||
Reference in New Issue
Block a user