From edff3e8d254adcf7f74e9227ea572a6d7a2a6958 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 2 Feb 2018 21:11:07 -0800 Subject: [PATCH] Bump to v4.17.5. --- README.md | 4 ++-- _baseClone.js | 20 +++++++++++++++++++- _baseMerge.js | 3 ++- _baseMergeDeep.js | 5 +++-- _initCloneArray.js | 2 +- _initCloneByTag.js | 11 ++++------- _isIndex.js | 7 +++++-- _safeGet.js | 15 +++++++++++++++ _stringToPath.js | 9 ++++----- _unicodeWords.js | 4 ++-- debounce.js | 6 ++++-- defaults.js | 44 ++++++++++++++++++++++++++++++++++++++------ invert.js | 15 +++++++++++++++ invertBy.js | 12 ++++++++++++ lodash.default.js | 2 +- package.json | 5 +++-- 16 files changed, 130 insertions(+), 34 deletions(-) create mode 100644 _safeGet.js diff --git a/README.md b/README.md index 0487f1ad0..b2f8a271a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-es v4.17.4 +# lodash-es v4.17.5 The [Lodash](https://lodash.com/) library exported as [ES](http://www.ecma-international.org/ecma-262/6.0/) modules. @@ -7,4 +7,4 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli): $ lodash modularize exports=es -o ./ ``` -See the [package source](https://github.com/lodash/lodash/tree/4.17.4-es) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.17.5-es) for more details. diff --git a/_baseClone.js b/_baseClone.js index 41959eb47..ad296197f 100644 --- a/_baseClone.js +++ b/_baseClone.js @@ -15,7 +15,9 @@ import initCloneByTag from './_initCloneByTag.js'; import initCloneObject from './_initCloneObject.js'; import isArray from './isArray.js'; import isBuffer from './isBuffer.js'; +import isMap from './isMap.js'; import isObject from './isObject.js'; +import isSet from './isSet.js'; import keys from './keys.js'; /** Used to compose bitmasks for cloning. */ @@ -123,7 +125,7 @@ function baseClone(value, bitmask, customizer, key, object, stack) { if (!cloneableTags[tag]) { return object ? value : {}; } - result = initCloneByTag(value, tag, baseClone, isDeep); + result = initCloneByTag(value, tag, isDeep); } } // Check for circular references and return its corresponding clone. @@ -134,6 +136,22 @@ function baseClone(value, bitmask, customizer, key, object, stack) { } stack.set(value, result); + if (isSet(value)) { + value.forEach(function(subValue) { + result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack)); + }); + + return result; + } + + if (isMap(value)) { + value.forEach(function(subValue, key) { + result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack)); + }); + + return result; + } + var keysFunc = isFull ? (isFlat ? getAllKeysIn : getAllKeys) : (isFlat ? keysIn : keys); diff --git a/_baseMerge.js b/_baseMerge.js index 37680f72f..151149859 100644 --- a/_baseMerge.js +++ b/_baseMerge.js @@ -4,6 +4,7 @@ import baseFor from './_baseFor.js'; import baseMergeDeep from './_baseMergeDeep.js'; import isObject from './isObject.js'; import keysIn from './keysIn.js'; +import safeGet from './_safeGet.js'; /** * The base implementation of `_.merge` without support for multiple sources. @@ -27,7 +28,7 @@ function baseMerge(object, source, srcIndex, customizer, stack) { } else { var newValue = customizer - ? customizer(object[key], srcValue, (key + ''), object, source, stack) + ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack) : undefined; if (newValue === undefined) { diff --git a/_baseMergeDeep.js b/_baseMergeDeep.js index a7962fbc7..2c2c65765 100644 --- a/_baseMergeDeep.js +++ b/_baseMergeDeep.js @@ -11,6 +11,7 @@ import isFunction from './isFunction.js'; import isObject from './isObject.js'; import isPlainObject from './isPlainObject.js'; import isTypedArray from './isTypedArray.js'; +import safeGet from './_safeGet.js'; import toPlainObject from './toPlainObject.js'; /** @@ -29,8 +30,8 @@ import toPlainObject from './toPlainObject.js'; * counterparts. */ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { - var objValue = object[key], - srcValue = source[key], + var objValue = safeGet(object, key), + srcValue = safeGet(source, key), stacked = stack.get(srcValue); if (stacked) { diff --git a/_initCloneArray.js b/_initCloneArray.js index 599732e03..67478a805 100644 --- a/_initCloneArray.js +++ b/_initCloneArray.js @@ -13,7 +13,7 @@ var hasOwnProperty = objectProto.hasOwnProperty; */ function initCloneArray(array) { var length = array.length, - result = array.constructor(length); + result = new array.constructor(length); // Add properties assigned by `RegExp#exec`. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { diff --git a/_initCloneByTag.js b/_initCloneByTag.js index f7f3eac58..0b03f8d09 100644 --- a/_initCloneByTag.js +++ b/_initCloneByTag.js @@ -1,8 +1,6 @@ import cloneArrayBuffer from './_cloneArrayBuffer.js'; import cloneDataView from './_cloneDataView.js'; -import cloneMap from './_cloneMap.js'; import cloneRegExp from './_cloneRegExp.js'; -import cloneSet from './_cloneSet.js'; import cloneSymbol from './_cloneSymbol.js'; import cloneTypedArray from './_cloneTypedArray.js'; @@ -32,16 +30,15 @@ var arrayBufferTag = '[object ArrayBuffer]', * Initializes an object clone based on its `toStringTag`. * * **Note:** This function only supports cloning values with tags of - * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. + * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`. * * @private * @param {Object} object The object to clone. * @param {string} tag The `toStringTag` of the object to clone. - * @param {Function} cloneFunc The function to clone values. * @param {boolean} [isDeep] Specify a deep clone. * @returns {Object} Returns the initialized clone. */ -function initCloneByTag(object, tag, cloneFunc, isDeep) { +function initCloneByTag(object, tag, isDeep) { var Ctor = object.constructor; switch (tag) { case arrayBufferTag: @@ -60,7 +57,7 @@ function initCloneByTag(object, tag, cloneFunc, isDeep) { return cloneTypedArray(object, isDeep); case mapTag: - return cloneMap(object, isDeep, cloneFunc); + return new Ctor; case numberTag: case stringTag: @@ -70,7 +67,7 @@ function initCloneByTag(object, tag, cloneFunc, isDeep) { return cloneRegExp(object); case setTag: - return cloneSet(object, isDeep, cloneFunc); + return new Ctor; case symbolTag: return cloneSymbol(object); diff --git a/_isIndex.js b/_isIndex.js index 0381ad086..b6cb47f3c 100644 --- a/_isIndex.js +++ b/_isIndex.js @@ -13,10 +13,13 @@ var reIsUint = /^(?:0|[1-9]\d*)$/; * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. */ function isIndex(value, length) { + var type = typeof value; length = length == null ? MAX_SAFE_INTEGER : length; + return !!length && - (typeof value == 'number' || reIsUint.test(value)) && - (value > -1 && value % 1 == 0 && value < length); + (type == 'number' || + (type != 'symbol' && reIsUint.test(value))) && + (value > -1 && value % 1 == 0 && value < length); } export default isIndex; diff --git a/_safeGet.js b/_safeGet.js new file mode 100644 index 000000000..be5bfc391 --- /dev/null +++ b/_safeGet.js @@ -0,0 +1,15 @@ +/** + * Gets the value at `key`, unless `key` is "__proto__". + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the property to get. + * @returns {*} Returns the property value. + */ +function safeGet(object, key) { + return key == '__proto__' + ? undefined + : object[key]; +} + +export default safeGet; diff --git a/_stringToPath.js b/_stringToPath.js index f0617e7de..acf73e026 100644 --- a/_stringToPath.js +++ b/_stringToPath.js @@ -1,8 +1,7 @@ import memoizeCapped from './_memoizeCapped.js'; /** Used to match property names within property paths. */ -var reLeadingDot = /^\./, - rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; +var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; /** Used to match backslashes in property paths. */ var reEscapeChar = /\\(\\)?/g; @@ -16,11 +15,11 @@ var reEscapeChar = /\\(\\)?/g; */ var stringToPath = memoizeCapped(function(string) { var result = []; - if (reLeadingDot.test(string)) { + if (string.charCodeAt(0) === 46 /* . */) { result.push(''); } - string.replace(rePropName, function(match, number, quote, string) { - result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match)); + string.replace(rePropName, function(match, number, quote, subString) { + result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match)); }); return result; }); diff --git a/_unicodeWords.js b/_unicodeWords.js index 99acbefc2..97b92ab71 100644 --- a/_unicodeWords.js +++ b/_unicodeWords.js @@ -38,8 +38,8 @@ var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', reOptMod = rsModifier + '?', rsOptVar = '[' + rsVarRange + ']?', rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', - rsOrdLower = '\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)', - rsOrdUpper = '\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)', + rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])', + rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])', rsSeq = rsOptVar + reOptMod + rsOptJoin, rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq; diff --git a/debounce.js b/debounce.js index 645754d54..c65962a83 100644 --- a/debounce.js +++ b/debounce.js @@ -108,9 +108,11 @@ function debounce(func, wait, options) { function remainingWait(time) { var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, - result = wait - timeSinceLastCall; + timeWaiting = wait - timeSinceLastCall; - return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result; + return maxing + ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) + : timeWaiting; } function shouldInvoke(time) { diff --git a/defaults.js b/defaults.js index b27d8818f..122908a47 100644 --- a/defaults.js +++ b/defaults.js @@ -1,7 +1,13 @@ -import apply from './_apply.js'; -import assignInWith from './assignInWith.js'; import baseRest from './_baseRest.js'; -import customDefaultsAssignIn from './_customDefaultsAssignIn.js'; +import eq from './eq.js'; +import isIterateeCall from './_isIterateeCall.js'; +import keysIn from './keysIn.js'; + +/** Used for built-in method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; /** * Assigns own and inherited enumerable string keyed properties of source @@ -24,9 +30,35 @@ import customDefaultsAssignIn from './_customDefaultsAssignIn.js'; * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); * // => { 'a': 1, 'b': 2 } */ -var defaults = baseRest(function(args) { - args.push(undefined, customDefaultsAssignIn); - return apply(assignInWith, undefined, args); +var defaults = baseRest(function(object, sources) { + object = Object(object); + + var index = -1; + var length = sources.length; + var guard = length > 2 ? sources[2] : undefined; + + if (guard && isIterateeCall(sources[0], sources[1], guard)) { + length = 1; + } + + while (++index < length) { + var source = sources[index]; + var props = keysIn(source); + var propsIndex = -1; + var propsLength = props.length; + + while (++propsIndex < propsLength) { + var key = props[propsIndex]; + var value = object[key]; + + if (value === undefined || + (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) { + object[key] = source[key]; + } + } + } + + return object; }); export default defaults; diff --git a/invert.js b/invert.js index 3ad074d87..4e938019b 100644 --- a/invert.js +++ b/invert.js @@ -2,6 +2,16 @@ import constant from './constant.js'; import createInverter from './_createInverter.js'; import identity from './identity.js'; +/** Used for built-in method references. */ +var objectProto = Object.prototype; + +/** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ +var nativeObjectToString = objectProto.toString; + /** * Creates an object composed of the inverted keys and values of `object`. * If `object` contains duplicate values, subsequent values overwrite @@ -21,6 +31,11 @@ import identity from './identity.js'; * // => { '1': 'c', '2': 'b' } */ var invert = createInverter(function(result, value, key) { + if (value != null && + typeof value.toString != 'function') { + value = nativeObjectToString.call(value); + } + result[value] = key; }, constant(identity)); diff --git a/invertBy.js b/invertBy.js index e29fc9d12..facffc5e0 100644 --- a/invertBy.js +++ b/invertBy.js @@ -7,6 +7,13 @@ var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; +/** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ +var nativeObjectToString = objectProto.toString; + /** * This method is like `_.invert` except that the inverted object is generated * from the results of running each element of `object` thru `iteratee`. The @@ -34,6 +41,11 @@ var hasOwnProperty = objectProto.hasOwnProperty; * // => { 'group1': ['a', 'c'], 'group2': ['b'] } */ var invertBy = createInverter(function(result, value, key) { + if (value != null && + typeof value.toString != 'function') { + value = nativeObjectToString.call(value); + } + if (hasOwnProperty.call(result, value)) { result[value].push(key); } else { diff --git a/lodash.default.js b/lodash.default.js index e920da753..c61abf998 100644 --- a/lodash.default.js +++ b/lodash.default.js @@ -45,7 +45,7 @@ import toInteger from './toInteger.js'; import lodash from './wrapperLodash.js'; /** Used as the semantic version number. */ -var VERSION = '4.17.4'; +var VERSION = '4.17.5'; /** Used to compose bitmasks for function metadata. */ var WRAP_BIND_KEY_FLAG = 2; diff --git a/package.json b/package.json index c49ea57f3..b0c4f555b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-es", - "version": "4.17.4", + "version": "4.17.5", "description": "Lodash exported as ES modules.", "keywords": "es6, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds", @@ -10,11 +10,12 @@ "jsnext:main": "lodash.js", "main": "lodash.js", "module": "lodash.js", + "sideEffects": false, "author": "John-David Dalton (http://allyoucanleet.com/)", "contributors": [ "John-David Dalton (http://allyoucanleet.com/)", "Blaine Bublitz (https://github.com/phated)", "Mathias Bynens (https://mathiasbynens.be/)" ], - "scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" } + "scripts": { "test": "echo \"See https://travis-ci.org/lodash-archive/lodash-cli for testing details.\"" } }