8000 Optimize method compilation with/without strict mode. · lodash/lodash@a266552 · GitHub
[go: up one dir, main page]

Skip to content

Commit a266552

Browse files
committed
Optimize method compilation with/without strict mode.
Former-commit-id: 05e4d9282116987b53a817b406c82c140a25c761
1 parent 8d35d78 commit a266552

File tree

4 files changed

+151
-142
lines changed

4 files changed

+151
-142
lines changed

build.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@
5050

5151
if (isStrict) {
5252
source = setUseStrictOption(source, true);
53-
}
54-
else if (!useStrict) {
53+
} else {
5554
source = removeUseStrictDirective(source);
56-
source = setUseStrictOption(source, false);
55+
if (!useStrict) {
56+
source = setUseStrictOption(source, false);
57+
}
5758
}
5859

5960
if (isLegacy) {
6061
source = replaceVar(source, 'noArgsClass', 'true');
61-
['isBindFast', 'isKeysFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'].forEach(function(varName) {
62+
['isBindFast', 'isKeysFast', 'isStrictFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'].forEach(function(varName) {
6263
source = replaceVar(source, varName, 'false');
6364
});
6465
}
@@ -686,11 +687,14 @@
686687
* @returns {String} Returns the modified source.
687688
*/
688689
function setUseStrictOption(source, value) {
689-
return source
690+
// remove `isStrictFast` assignment
691+
return removeVar(source, 'isStrictFast')
690692
// replace `useStrict` branch in `value` with hard-coded option
691693
.replace(/(?: *\/\/.*\n)*(\s*)' *<% *if *\(useStrict\).+/, value ? "$1'\\'use strict\\';\\n' +" : '')
692694
// remove `useStrict` from iterator options
693695
.replace(/ *'useStrict': *false,\n/g, '')
696+
// remove `useStrict` variable assignment in `createIterator`
697+
.replace(/,\s*useStrict *=[^;]+/, '')
694698
// remove `useStrict` data object property assignment in `createIterator`
695699
.replace(/\s*.+?\.useStrict *=.+/, '');
696700
}
@@ -708,7 +712,7 @@
708712
source = source.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}');
709713

710714
// re-remove "use strict" added by the minifier
711-
if (!useStrict) {
715+
if (!isStrict) {
712716
source = removeUseStrictDirective(source);
713717
}
714718
fs.writeFileSync(path.join(cwd, filename), source);
@@ -1057,10 +1061,6 @@
10571061
debugSource = source;
10581062

10591063
// remove associated functions, variables, and code snippets that the minifier may miss
1060-
if (isRemoved(source, 'bind')) {
1061-
source = removeVar(source, 'nativeBind');
1062-
source = removeVar(source, 'isBindFast');
1063-
}
10641064
if (isRemoved(source, 'isArray')) {
10651065
source = removeVar(source, 'nativeIsArray');
10661066
}
@@ -1087,6 +1087,11 @@
10871087
source = removeFunction(source, 'createIterator');
10881088
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var noArgsEnum;|.+?noArgsEnum *=.+/g, '');
10891089
}
1090+
if (isRemoved(source, 'createIterator', 'bind')) {
1091+
source = removeVar(source, 'isBindFast');
1092+
source = removeVar(source, 'isStrictFast');
1093+
source = removeVar(source, 'nativeBind');
1094+
}
10901095
if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) {
10911096
source = removeVar(source, 'reNative');
10921097
}

0 commit comments

Comments
 (0)
0