mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Rework "strict" build option and fix typo in test-ui.js.
Former-commit-id: e06045546bea43bbe1fff78d6c948036ad98a88c
This commit is contained in:
31
build.js
31
build.js
@@ -784,12 +784,12 @@
|
||||
* @returns {String} Returns the modified source.
|
||||
*/
|
||||
function setUseStrictOption(source, value) {
|
||||
// remove `isStrictFast` assignment
|
||||
return removeVar(source, 'isStrictFast')
|
||||
// replace `useStrict` branch in `value` with hard-coded option
|
||||
.replace(/(?: *\/\/.*\n)*(\s*)' *<%.+?useStrict.+/, value ? "$1'\\'use strict\\';\\n' +" : '')
|
||||
// remove `useStrict` from iterator options
|
||||
.replace(/(?:,\s*'useStrict':[^,]+?\n| *'useStrict':[^,]+,\n)/g, '');
|
||||
// inject "use strict"
|
||||
if (value) {
|
||||
source = source.replace(/^[\s\S]*?function[^{]+{/, "$&\n 'use strict';");
|
||||
}
|
||||
// replace `useStrict` branch in `value` with hard-coded option
|
||||
return source.replace(/(?: *\/\/.*\n)*(\s*)' *<%.+?useStrict.+/, value ? "$1'\\'use strict\\';\\n' +" : '');
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -940,9 +940,6 @@
|
||||
// the lodash.js source
|
||||
var source = fs.readFileSync(path.join(__dirname, 'lodash.js'), 'utf8');
|
||||
|
||||
// flag used to specify if the build should include the "use strict" directive
|
||||
var useStrict = isStrict || !(isLegacy || isMobile);
|
||||
|
||||
// flag used to specify replacing Lo-Dash's `_.clone` with Underscore's
|
||||
var useUnderscoreClone = isUnderscore;
|
||||
|
||||
@@ -1037,17 +1034,10 @@
|
||||
'setTimeout': setTimeout
|
||||
});
|
||||
|
||||
if (isStrict) {
|
||||
source = setUseStrictOption(source, true);
|
||||
} else {
|
||||
// remove "use strict" directive
|
||||
source = source.replace(/(["'])use strict\1;( *\n)?/, '');
|
||||
if (!useStrict) {
|
||||
source = setUseStrictOption(source, false);
|
||||
}
|
||||
}
|
||||
source = setUseStrictOption(source, isStrict);
|
||||
|
||||
if (isLegacy) {
|
||||
_.each(['getPrototypeOf', 'isBindFast', 'isKeysFast', 'isStrictFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'], function(varName) {
|
||||
_.each(['getPrototypeOf', 'isBindFast', 'isKeysFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'], function(varName) {
|
||||
source = replaceVar(source, varName, 'false');
|
||||
});
|
||||
|
||||
@@ -1607,7 +1597,6 @@
|
||||
}
|
||||
if (isRemoved(source, 'createIterator', 'bind')) {
|
||||
source = removeVar(source, 'isBindFast');
|
||||
source = removeVar(source, 'isStrictFast');
|
||||
source = removeVar(source, 'nativeBind');
|
||||
}
|
||||
if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'isPlainObject', 'keys')) {
|
||||
@@ -1668,7 +1657,7 @@
|
||||
}
|
||||
// inject "use strict" directive
|
||||
if (isStrict) {
|
||||
source = source.replace(/^(\/\*![\s\S]+?\*\/\n;\(function[^)]+\){)([^'"])/, '$1"use strict";$2');
|
||||
source = source.replace(/^([\s\S]*?function[^{]+{)([^'"])/, '$1"use strict";$2');
|
||||
}
|
||||
if (isStdOut) {
|
||||
stdout.write(source);
|
||||
|
||||
@@ -574,9 +574,9 @@
|
||||
QUnit.module('strict modifier');
|
||||
|
||||
(function() {
|
||||
var object = Object.create(Object.prototype, {
|
||||
'a': { 'value': _.identify },
|
||||
'b': { 'value': null }
|
||||
var object = Object.freeze({
|
||||
'a': _.identity,
|
||||
'b': null
|
||||
});
|
||||
|
||||
['non-strict', 'strict'].forEach(function(strictMode, index) {
|
||||
@@ -589,20 +589,26 @@
|
||||
}
|
||||
build(commands, function(source, filePath) {
|
||||
var basename = path.basename(filePath, '.js'),
|
||||
context = createContext(),
|
||||
pass = !index;
|
||||
context = createContext();
|
||||
|
||||
vm.runInContext(source, context);
|
||||
var lodash = context._;
|
||||
|
||||
try {
|
||||
lodash.bindAll(object);
|
||||
lodash.extend(object, { 'a': 1 });
|
||||
lodash.defaults(object, { 'b': 2 });
|
||||
} catch(e) {
|
||||
pass = !!index;
|
||||
}
|
||||
equal(pass, true, basename);
|
||||
var actual = _.every([
|
||||
function() { lodash.bindAll(object); },
|
||||
function() { lodash.extend(object, { 'a': 1 }); },
|
||||
function() { lodash.defaults(object, { 'b': 2 }); }
|
||||
], function(fn) {
|
||||
var pass = !index;
|
||||
try {
|
||||
fn();
|
||||
} catch(e) {
|
||||
pass = !!index;
|
||||
}
|
||||
return pass;
|
||||
});
|
||||
|
||||
equal(actual, true, basename);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
case 'lodash-prod': return 'lodash.min.js';
|
||||
case 'lodash-underscore': return 'lodash.underscore.min.js';
|
||||
case 'lodash-custom': return 'lodash.custom.min.js';
|
||||
case 'lodash-custom-debug': return 'lodash.custom'.js;
|
||||
case 'lodash-custom-debug': return 'lodash.custom.js';
|
||||
}
|
||||
return 'lodash.js';
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user