Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit21217df

Browse files
committed
ReducecreateIterator.
Former-commit-id: 8c27ca8e4d1f71b2727dd988bc62194510a850dc
1 parent25ba18e commit21217df

File tree

4 files changed

+28
-38
lines changed

4 files changed

+28
-38
lines changed

‎build.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@
684684
// remove `isKeysFast` from `inLoop.object` of `mapIteratorOptions`, `invoke`, `pairs`, `pluck`, and `sortBy`
685685
.replace(/'\s*\+\s*\(isKeysFast[^)]+?\)\s*\+\s*'/g,'.push')
686686
// remove data object property assignment in `createIterator`
687-
.replace(/\s*.+?\.isKeysFast*=.+/,'');
687+
.replace(/*'isKeysFast':.+\n/,'');
688688
}
689689

690690
/**
@@ -795,10 +795,8 @@
795795
.replace(/(?:*\/\/.*\n)*(\s*)'*<%*if*\(useStrict\).+/,value ?"$1'\\'use strict\\';\\n' +" :'')
796796
// remove `useStrict` from iterator options
797797
.replace(/*'useStrict':*false,\n/g,'')
798-
// remove `useStrict` variable assignment in `createIterator`
799-
.replace(/,\s*useStrict*=[^;]+/,'')
800798
// remove `useStrict` data object property assignment in `createIterator`
801-
.replace(/\s*.+?\.useStrict*=.+/,'');
799+
.replace(/*'useStrict':.+\n/,'');
802800
}
803801

804802
/*--------------------------------------------------------------------------*/

‎build/pre-compile.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
'createCallback',
1616
'ctor',
1717
'hasOwnProperty',
18-
'identity',
1918
'index',
2019
'iteratee',
2120
'length',

‎lodash.js‎

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@
482482

483483
/** Reusable iterator options for `invoke`, `map`, `pluck`, and `sortBy` */
484484
varmapIteratorOptions={
485-
'init':'',
485+
'init':false,
486486
'beforeLoop':{
487487
'array':'result = Array(length)',
488488
'object':'result = '+(isKeysFast ?'Array(length)' :'[]')
@@ -672,8 +672,7 @@
672672
* useStrict - A boolean to specify whether or not to include the ES5
673673
* "use strict" directive.
674674
*
675-
* args - A string of comma separated arguments the iteration function will
676-
* accept.
675+
* args - A string of comma separated arguments the iteration function will accept.
677676
*
678677
* init - A string to specify the initial value of the `result` variable.
679678
*
@@ -691,31 +690,35 @@
691690
*@returns {Function} Returns the compiled function.
692691
*/
693692
functioncreateIterator(){
694-
varobject,
695-
prop,
696-
value,
697-
index=-1,
693+
varindex=-1,
698694
length=arguments.length;
699695

700696
// merge options into a template data object
701697
vardata={
702698
'bottom':'',
699+
'hasDontEnumBug':hasDontEnumBug,
700+
'isKeysFast':isKeysFast,
701+
'noArgsEnum':noArgsEnum,
702+
'noCharByIndex':noCharByIndex,
703+
'shadowed':shadowed,
703704
'top':'',
704-
'arrayBranch':{'beforeLoop':''},
705-
'objectBranch':{'beforeLoop':''}
705+
'useHas':true,
706+
'useStrict':isStrictFast,
707+
'arrayBranch':{},
708+
'objectBranch':{}
706709
};
707710

708711
while(++index<length){
709-
object=arguments[index];
710-
for(propinobject){
711-
value=(value=object[prop])==null ?'' :value;
712+
varobject=arguments[index];
713+
for(varpropinobject){
714+
varvalue=object[prop];
712715
// keep this regexp explicit for the build pre-process
713716
if(/beforeLoop|inLoop/.test(prop)){
714717
if(typeofvalue=='string'){
715718
value={'array':value,'object':value};
716719
}
717-
data.arrayBranch[prop]=value.array||'';
718-
data.objectBranch[prop]=value.object||'';
720+
data.arrayBranch[prop]=value.array;
721+
data.objectBranch[prop]=value.object;
719722
}else{
720723
data[prop]=value;
721724
}
@@ -724,28 +727,18 @@
724727
// set additional template `data` values
725728
varargs=data.args,
726729
firstArg=/^[^,]+/.exec(args)[0],
727-
init=data.init,
728-
useStrict=data.useStrict;
730+
init=data.init;
729731

730732
data.firstArg=firstArg;
731-
data.hasDontEnumBug=hasDontEnumBug;
732733
data.init=init==null ?firstArg :init;
733-
data.isKeysFast=isKeysFast;
734-
data.noArgsEnum=noArgsEnum;
735-
data.shadowed=shadowed;
736-
data.useHas=data.useHas!==false;
737-
data.useStrict=useStrict==null ?isStrictFast :useStrict;
738-
739-
if(data.noCharByIndex==null){
740-
data.noCharByIndex=noCharByIndex;
741-
}
734+
742735
if(firstArg!='collection'||!data.arrayBranch.inLoop){
743736
data.arrayBranch=null;
744737
}
745738
// create the function factory
746739
varfactory=Function(
747740
'arrayLikeClasses, ArrayProto, bind, compareAscending, concat, createCallback, '+
748-
'forIn, hasOwnProperty,identity,indexOf, isArguments, isArray, isFunction, '+
741+
'forIn, hasOwnProperty, indexOf, isArguments, isArray, isFunction, '+
749742
'isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, '+
750743
'slice, stringClass, toString, undefined',
751744
'var callee = function('+args+') {\n'+iteratorTemplate(data)+'\n};\n'+
@@ -754,7 +747,7 @@
754747
// return the compiled function
755748
returnfactory(
756749
arrayLikeClasses,ArrayProto,bind,compareAscending,concat,createCallback,
757-
forIn,hasOwnProperty,identity,indexOf,isArguments,isArray,isFunction,
750+
forIn,hasOwnProperty,indexOf,isArguments,isArray,isFunction,
758751
isPlainObject,objectClass,objectTypes,nativeKeys,propertyIsEnumerable,
759752
slice,stringClass,toString
760753
);
@@ -846,7 +839,7 @@
846839
// fallback for browsers that can't detect `arguments` objects by [[Class]]
847840
if(noArgsClass){
848841
isArguments=function(value){
849-
return!!(value&&hasOwnProperty.call(value,'callee'));
842+
returnvalue?hasOwnProperty.call(value,'callee') :false;
850843
};
851844
}
852845

@@ -1996,7 +1989,7 @@
19961989
* // => 2
19971990
*/
19981991
varfind=createIterator(baseIteratorOptions,forEachIteratorOptions,{
1999-
'init':'',
1992+
'init':false,
20001993
'inLoop':'if (callback(value, index, collection)) return value'
20011994
});
20021995

@@ -3194,8 +3187,8 @@
31943187
' return result\n'+
31953188
'}',
31963189
'inLoop':
3197-
'if (isFunction(result[index])) {\n'+
3198-
' result[index] = bind(result[index], result)\n'+
3190+
'if (isFunction(value)) {\n'+
3191+
' result[index] = bind(value, result)\n'+
31993192
'}'
32003193
});
32013194

‎test/test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@
395395
}else{
396396
func(object,{'a':1});
397397
}
398-
}catch(e){console.log(e);
398+
}catch(e){
399399
pass=false;
400400
}
401401
ok(pass);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp