webpack 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +39 -63
  2. package/lib/APIPlugin.js +2 -8
  3. package/lib/AsyncDependenciesBlock.js +46 -55
  4. package/lib/ChunkTemplate.js +25 -26
  5. package/lib/CompatibilityPlugin.js +49 -46
  6. package/lib/Compilation.js +279 -138
  7. package/lib/ConstPlugin.js +2 -6
  8. package/lib/DefinePlugin.js +9 -27
  9. package/lib/EnvironmentPlugin.js +25 -9
  10. package/lib/EvalDevToolModulePlugin.js +15 -10
  11. package/lib/EvalSourceMapDevToolPlugin.js +24 -18
  12. package/lib/ExtendedAPIPlugin.js +1 -6
  13. package/lib/FlagDependencyExportsPlugin.js +72 -79
  14. package/lib/FlagInitialModulesAsUsedPlugin.js +17 -13
  15. package/lib/FunctionModulePlugin.js +17 -11
  16. package/lib/HotModuleReplacementPlugin.js +3 -13
  17. package/lib/HotUpdateChunkTemplate.js +21 -22
  18. package/lib/JsonpTemplatePlugin.js +15 -11
  19. package/lib/LoaderTargetPlugin.js +14 -10
  20. package/lib/MainTemplate.js +193 -191
  21. package/lib/MultiWatching.js +16 -14
  22. package/lib/NoEmitOnErrorsPlugin.js +14 -11
  23. package/lib/NodeStuffPlugin.js +6 -30
  24. package/lib/NormalModuleFactory.js +2 -2
  25. package/lib/NormalModuleReplacementPlugin.js +36 -31
  26. package/lib/Parser.js +8 -7
  27. package/lib/ParserHelpers.js +19 -5
  28. package/lib/ProvidePlugin.js +2 -6
  29. package/lib/RequestShortener.js +49 -47
  30. package/lib/RequireJsStuffPlugin.js +5 -20
  31. package/lib/RuleSet.js +28 -20
  32. package/lib/Template.js +133 -132
  33. package/lib/compareLocations.js +9 -8
  34. package/lib/dependencies/AMDPlugin.js +111 -115
  35. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +157 -154
  36. package/lib/dependencies/CommonJsPlugin.js +81 -85
  37. package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +73 -75
  38. package/lib/dependencies/ContextDependencyTemplateAsId.js +21 -18
  39. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +23 -29
  40. package/lib/dependencies/CriticalDependencyWarning.js +13 -8
  41. package/lib/dependencies/{HarmonyCompatiblilityDependency.js → HarmonyCompatibilityDependency.js} +3 -3
  42. package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
  43. package/lib/dependencies/HarmonyModulesPlugin.js +51 -49
  44. package/lib/dependencies/ImportParserPlugin.js +31 -28
  45. package/lib/dependencies/ImportPlugin.js +28 -24
  46. package/lib/dependencies/LocalModule.js +17 -13
  47. package/lib/dependencies/ModuleDependencyTemplateAsId.js +15 -17
  48. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +15 -17
  49. package/lib/dependencies/RequireContextPlugin.js +59 -57
  50. package/lib/dependencies/RequireEnsurePlugin.js +22 -26
  51. package/lib/dependencies/RequireIncludePlugin.js +18 -23
  52. package/lib/dependencies/RequireResolveDependencyParserPlugin.js +59 -56
  53. package/lib/dependencies/SystemPlugin.js +34 -36
  54. package/lib/dependencies/WebpackMissingModule.js +10 -18
  55. package/lib/node/NodeTargetPlugin.js +8 -5
  56. package/lib/node/NodeWatchFileSystem.js +54 -53
  57. package/lib/optimize/CommonsChunkPlugin.js +163 -166
  58. package/lib/optimize/RemoveParentModulesPlugin.js +36 -27
  59. package/lib/validateSchema.js +18 -18
  60. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +22 -20
  61. package/package.json +12 -6
@@ -29,6 +29,21 @@ function byId(a, b) {
29
29
  return 0;
30
30
  }
31
31
 
32
+ function iterationBlockVariable(variables, fn) {
33
+ for(var indexVariable = 0; indexVariable < variables.length; indexVariable++) {
34
+ var varDep = variables[indexVariable].dependencies;
35
+ for(var indexVDep = 0; indexVDep < varDep.length; indexVDep++) {
36
+ fn(varDep[indexVDep]);
37
+ }
38
+ }
39
+ }
40
+
41
+ function iterationOfArrayCallback(arr, fn) {
42
+ for(var index = 0; index < arr.length; index++) {
43
+ fn(arr[index]);
44
+ }
45
+ }
46
+
32
47
  class Compilation extends Tapable {
33
48
  constructor(compiler) {
34
49
  super();
@@ -73,13 +88,13 @@ class Compilation extends Tapable {
73
88
  }
74
89
 
75
90
  addModule(module, cacheGroup) {
76
- cacheGroup = cacheGroup || "m";
77
91
  const identifier = module.identifier();
78
92
  if(this._modules[identifier]) {
79
93
  return false;
80
94
  }
81
- if(this.cache && this.cache[cacheGroup + identifier]) {
82
- const cacheModule = this.cache[cacheGroup + identifier];
95
+ const cacheName = (cacheGroup || "m") + identifier;
96
+ if(this.cache && this.cache[cacheName]) {
97
+ const cacheModule = this.cache[cacheName];
83
98
 
84
99
  let rebuild = true;
85
100
  if(!cacheModule.error && cacheModule.cacheable && this.fileTimestamps && this.contextTimestamps) {
@@ -100,7 +115,7 @@ class Compilation extends Tapable {
100
115
  module.unbuild();
101
116
  this._modules[identifier] = module;
102
117
  if(this.cache) {
103
- this.cache[cacheGroup + identifier] = module;
118
+ this.cache[cacheName] = module;
104
119
  }
105
120
  this.modules.push(module);
106
121
  return true;
@@ -124,24 +139,29 @@ class Compilation extends Tapable {
124
139
  module.building = undefined;
125
140
  building.forEach(cb => cb(err));
126
141
  }
127
- module.build(this.options, this, this.resolvers.normal, this.inputFileSystem, (err) => {
128
- module.errors.forEach(err => {
142
+ module.build(this.options, this, this.resolvers.normal, this.inputFileSystem, (error) => {
143
+ var errors = module.errors;
144
+ for(var indexError = 0; indexError < errors.length; indexError++) {
145
+ var err = errors[indexError];
129
146
  err.origin = origin;
130
147
  err.dependencies = dependencies;
131
148
  if(optional)
132
149
  this.warnings.push(err);
133
150
  else
134
151
  this.errors.push(err);
135
- }, this);
136
- module.warnings.forEach(err => {
137
- err.origin = origin;
138
- err.dependencies = dependencies;
139
- this.warnings.push(err);
140
- }, this);
152
+ }
153
+
154
+ var warnings = module.warnings;
155
+ for(var indexWarning = 0; indexWarning < warnings.length; indexWarning++) {
156
+ var war = warnings[indexWarning];
157
+ war.origin = origin;
158
+ war.dependencies = dependencies;
159
+ this.warnings.push(war);
160
+ }
141
161
  module.dependencies.sort(Dependency.compare);
142
- if(err) {
143
- this.applyPlugins2("failed-module", module, err);
144
- return callback(err);
162
+ if(error) {
163
+ this.applyPlugins2("failed-module", module, error);
164
+ return callback(error);
145
165
  }
146
166
  this.applyPlugins1("succeed-module", module);
147
167
  return callback();
@@ -162,13 +182,13 @@ class Compilation extends Tapable {
162
182
 
163
183
  function addDependenciesBlock(block) {
164
184
  if(block.dependencies) {
165
- block.dependencies.forEach(addDependency);
185
+ iterationOfArrayCallback(block.dependencies, addDependency);
166
186
  }
167
187
  if(block.blocks) {
168
- block.blocks.forEach(addDependenciesBlock);
188
+ iterationOfArrayCallback(block.blocks, addDependenciesBlock);
169
189
  }
170
190
  if(block.variables) {
171
- block.variables.forEach(v => v.dependencies.forEach(addDependency));
191
+ iterationBlockVariable(block.variables, addDependency);
172
192
  }
173
193
  }
174
194
  addDependenciesBlock(module);
@@ -226,6 +246,15 @@ class Compilation extends Tapable {
226
246
  return errorAndCallback(err);
227
247
  }
228
248
  }
249
+
250
+ function iterationDependencies(depend) {
251
+ for(var index = 0; index < depend.length; index++) {
252
+ var dep = depend[index];
253
+ dep.module = dependentModule;
254
+ dependentModule.addReason(module, dep);
255
+ }
256
+ }
257
+
229
258
  if(err) {
230
259
  return errorOrWarningAndCallback(new ModuleNotFoundError(module, err, dependencies));
231
260
  }
@@ -250,10 +279,7 @@ class Compilation extends Tapable {
250
279
  dependentModule.optional = isOptional();
251
280
  }
252
281
 
253
- dependencies.forEach(dep => {
254
- dep.module = dependentModule;
255
- dependentModule.addReason(module, dep);
256
- });
282
+ iterationDependencies(dependencies);
257
283
 
258
284
  if(_this.profile) {
259
285
  if(!module.profile) {
@@ -277,10 +303,7 @@ class Compilation extends Tapable {
277
303
  newModule.issuer = dependentModule.issuer;
278
304
  dependentModule = newModule;
279
305
 
280
- dependencies.forEach(dep => {
281
- dep.module = dependentModule;
282
- dependentModule.addReason(module, dep);
283
- });
306
+ iterationDependencies(dependencies);
284
307
 
285
308
  if(_this.profile) {
286
309
  const afterBuilding = +new Date();
@@ -296,10 +319,7 @@ class Compilation extends Tapable {
296
319
 
297
320
  dependentModule.optional = isOptional();
298
321
 
299
- dependencies.forEach(dep => {
300
- dep.module = dependentModule;
301
- dependentModule.addReason(module, dep);
302
- });
322
+ iterationDependencies(dependencies);
303
323
 
304
324
  _this.buildModule(dependentModule, isOptional(), module, dependencies, err => {
305
325
  if(err) {
@@ -498,8 +518,13 @@ class Compilation extends Tapable {
498
518
  }
499
519
 
500
520
  finish() {
501
- this.applyPlugins1("finish-modules", this.modules);
502
- this.modules.forEach(m => this.reportDependencyErrorsAndWarnings(m, [m]));
521
+ var modules = this.modules;
522
+ this.applyPlugins1("finish-modules", modules);
523
+
524
+ for(var index = 0; index < modules.length; index++) {
525
+ var module = modules[index];
526
+ this.reportDependencyErrorsAndWarnings(module, [module]);
527
+ }
503
528
  }
504
529
 
505
530
  unseal() {
@@ -628,25 +653,35 @@ class Compilation extends Tapable {
628
653
  }
629
654
 
630
655
  reportDependencyErrorsAndWarnings(module, blocks) {
631
- blocks.forEach(block => {
632
- block.dependencies.forEach(d => {
656
+ for(var indexBlock = 0; indexBlock < blocks.length; indexBlock++) {
657
+ var block = blocks[indexBlock];
658
+ var dependencies = block.dependencies;
659
+
660
+ for(var indexDep = 0; indexDep < dependencies.length; indexDep++) {
661
+ var d = dependencies[indexDep];
662
+
633
663
  const warnings = d.getWarnings();
634
664
  if(warnings) {
635
- warnings.forEach(w => {
636
- const warning = new ModuleDependencyWarning(module, w, d.loc);
665
+ for(var indexWar = 0; indexWar < warnings.length; indexWar++) {
666
+ var w = warnings[indexWar];
667
+
668
+ var warning = new ModuleDependencyWarning(module, w, d.loc);
637
669
  this.warnings.push(warning);
638
- });
670
+ }
639
671
  }
640
672
  const errors = d.getErrors();
641
673
  if(errors) {
642
- errors.forEach(w => {
643
- const warning = new ModuleDependencyError(module, w, d.loc);
644
- this.errors.push(warning);
645
- });
674
+ for(var indexErr = 0; indexErr < errors.length; indexErr++) {
675
+ var e = errors[indexErr];
676
+
677
+ var error = new ModuleDependencyError(module, e, d.loc);
678
+ this.errors.push(error);
679
+ }
646
680
  }
647
- });
681
+ }
682
+
648
683
  this.reportDependencyErrorsAndWarnings(module, block.blocks);
649
- });
684
+ }
650
685
  }
651
686
 
652
687
  addChunk(name, module, loc) {
@@ -671,6 +706,14 @@ class Compilation extends Tapable {
671
706
  assignIndex(module) {
672
707
  const _this = this;
673
708
 
709
+ const queue = [() => {
710
+ assignIndexToModule(module);
711
+ }];
712
+
713
+ const iteratorAllDependencies = d => {
714
+ queue.push(() => assignIndexToDependency(d));
715
+ };
716
+
674
717
  function assignIndexToModule(module) {
675
718
  // enter module
676
719
  if(typeof module.index !== "number") {
@@ -691,7 +734,7 @@ class Compilation extends Tapable {
691
734
  }
692
735
 
693
736
  function assignIndexToDependencyBlock(block) {
694
- const allDependencies = [];
737
+ var allDependencies = [];
695
738
 
696
739
  function iteratorDependency(d) {
697
740
  allDependencies.push(d);
@@ -702,22 +745,26 @@ class Compilation extends Tapable {
702
745
  }
703
746
 
704
747
  if(block.variables) {
705
- block.variables.forEach(v => v.dependencies.forEach(iteratorDependency));
748
+ iterationBlockVariable(block.variables, iteratorDependency);
706
749
  }
750
+
707
751
  if(block.dependencies) {
708
- block.dependencies.forEach(iteratorDependency);
752
+ iterationOfArrayCallback(block.dependencies, iteratorDependency);
709
753
  }
710
754
  if(block.blocks) {
711
- block.blocks.slice().reverse().forEach(iteratorBlock, this);
755
+ var blocks = block.blocks;
756
+ var indexBlock = blocks.length;
757
+ while(indexBlock--) {
758
+ iteratorBlock(blocks[indexBlock]);
759
+ }
712
760
  }
713
761
 
714
- allDependencies.reverse();
715
- allDependencies.forEach(d => queue.push(() => assignIndexToDependency(d)));
762
+ var indexAll = allDependencies.length;
763
+ while(indexAll--) {
764
+ iteratorAllDependencies(allDependencies[indexAll]);
765
+ }
716
766
  }
717
767
 
718
- const queue = [() => {
719
- assignIndexToModule(module);
720
- }];
721
768
  while(queue.length) {
722
769
  queue.pop()();
723
770
  }
@@ -749,13 +796,15 @@ class Compilation extends Tapable {
749
796
  }
750
797
 
751
798
  if(block.variables) {
752
- block.variables.forEach(v => v.dependencies.forEach(iteratorDependency, this));
799
+ iterationBlockVariable(block.variables, iteratorDependency);
753
800
  }
801
+
754
802
  if(block.dependencies) {
755
- block.dependencies.forEach(iteratorDependency);
803
+ iterationOfArrayCallback(block.dependencies, iteratorDependency);
756
804
  }
805
+
757
806
  if(block.blocks) {
758
- block.blocks.forEach(iteratorBlock, this);
807
+ iterationOfArrayCallback(block.blocks, iteratorBlock);
759
808
  }
760
809
  }
761
810
 
@@ -768,25 +817,7 @@ class Compilation extends Tapable {
768
817
  }
769
818
 
770
819
  processDependenciesBlockForChunk(block, chunk) {
771
- const queue = [
772
- [block, chunk]
773
- ];
774
- while(queue.length) {
775
- const queueItem = queue.pop();
776
- block = queueItem[0];
777
- chunk = queueItem[1];
778
- if(block.variables) {
779
- block.variables.forEach(v => v.dependencies.forEach(iteratorDependency, this));
780
- }
781
- if(block.dependencies) {
782
- block.dependencies.forEach(iteratorDependency, this);
783
- }
784
- if(block.blocks) {
785
- block.blocks.forEach(iteratorBlock, this);
786
- }
787
- }
788
-
789
- function iteratorBlock(b) {
820
+ const iteratorBlock = b => {
790
821
  let c;
791
822
  if(!b.chunks) {
792
823
  c = this.addChunk(b.chunkName, b.module, b.loc);
@@ -798,9 +829,9 @@ class Compilation extends Tapable {
798
829
  chunk.addChunk(c);
799
830
  c.addParent(chunk);
800
831
  queue.push([b, c]);
801
- }
832
+ };
802
833
 
803
- function iteratorDependency(d) {
834
+ const iteratorDependency = d => {
804
835
  if(!d.module) {
805
836
  return;
806
837
  }
@@ -811,19 +842,33 @@ class Compilation extends Tapable {
811
842
  d.module.addChunk(chunk);
812
843
  queue.push([d.module, chunk]);
813
844
  }
845
+ };
846
+
847
+ const queue = [
848
+ [block, chunk]
849
+ ];
850
+
851
+ while(queue.length) {
852
+ var queueItem = queue.pop();
853
+ block = queueItem[0];
854
+ chunk = queueItem[1];
855
+
856
+ if(block.variables) {
857
+ iterationBlockVariable(block.variables, iteratorDependency);
858
+ }
859
+
860
+ if(block.dependencies) {
861
+ iterationOfArrayCallback(block.dependencies, iteratorDependency);
862
+ }
863
+
864
+ if(block.blocks) {
865
+ iterationOfArrayCallback(block.blocks, iteratorBlock);
866
+ }
814
867
  }
815
868
  }
816
869
 
817
870
  removeChunkFromDependencies(block, chunk) {
818
- block.blocks.forEach(b => {
819
- b.chunks.forEach(c => {
820
- chunk.removeChunk(c);
821
- c.removeParent(chunk);
822
- this.removeChunkFromDependencies(b, c);
823
- });
824
- });
825
-
826
- function iteratorDependency(d) {
871
+ const iteratorDependency = d => {
827
872
  if(!d.module) {
828
873
  return;
829
874
  }
@@ -832,64 +877,121 @@ class Compilation extends Tapable {
832
877
  this.removeChunkFromDependencies(d.module, chunk);
833
878
  }
834
879
  }
880
+ };
881
+
882
+ var blocks = block.blocks;
883
+ for(var indexBlock = 0; indexBlock < blocks.length; indexBlock++) {
884
+ var chunks = blocks[indexBlock].chunks;
885
+ for(var indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
886
+ var blockChunk = chunks[indexChunk];
887
+ chunk.removeChunk(blockChunk);
888
+ blockChunk.removeParent(chunk);
889
+ this.removeChunkFromDependencies(chunks, blockChunk);
890
+ }
891
+ }
892
+
893
+ if(block.dependencies) {
894
+ iterationOfArrayCallback(block.dependencies, iteratorDependency);
895
+ }
896
+
897
+ if(block.variables) {
898
+ iterationBlockVariable(block.variables, iteratorDependency);
835
899
  }
836
- block.dependencies.forEach(iteratorDependency, this);
837
- block.variables.forEach(v => v.dependencies.forEach(iteratorDependency, this));
838
900
  }
839
901
 
840
902
  applyModuleIds() {
841
- const unusedIds = [];
842
- let nextFreeModuleId = 0;
843
- const usedIds = [];
844
- const usedIdMap = {};
903
+ var unusedIds = [];
904
+ var nextFreeModuleId = 0;
905
+ var usedIds = [];
906
+ // TODO consider Map when performance has improved https://gist.github.com/sokra/234c077e1299b7369461f1708519c392
907
+ var usedIdMap = Object.create(null);
845
908
  if(this.usedModuleIds) {
846
909
  Object.keys(this.usedModuleIds).forEach(key => {
847
910
  const id = this.usedModuleIds[key];
848
- if(typeof usedIdMap[id] === "undefined") {
911
+ if(!usedIdMap[id]) {
849
912
  usedIds.push(id);
850
- usedIdMap[id] = id;
913
+ usedIdMap[id] = true;
851
914
  }
852
915
  });
853
916
  }
854
- this.modules.forEach(module => {
855
- if(module.id !== null && typeof usedIdMap[module.id] === "undefined") {
856
- usedIds.push(module.id);
857
- usedIdMap[module.id] = module.id;
917
+
918
+ var modules1 = this.modules;
919
+ for(var indexModule1 = 0; indexModule1 < modules1.length; indexModule1++) {
920
+ var module1 = modules1[indexModule1];
921
+ if(module1.id && !usedIdMap[module1.id]) {
922
+ usedIds.push(module1.id);
923
+ usedIdMap[module1.id] = true;
858
924
  }
859
- });
925
+ }
926
+
860
927
  if(usedIds.length > 0) {
861
- const usedNumberIds = usedIds.filter(id => typeof id === "number");
862
- nextFreeModuleId = usedNumberIds.reduce((a, b) => Math.max(a, b), -1) + 1;
863
- for(let i = 0; i < nextFreeModuleId; i++) {
864
- if(usedIdMap[i] !== i)
865
- unusedIds.push(i);
928
+ var usedIdMax = -1;
929
+ for(var index = 0; index < usedIds.length; index++) {
930
+ var usedIdKey = usedIds[index];
931
+
932
+ if(typeof usedIdKey !== "number") {
933
+ continue;
934
+ }
935
+
936
+ usedIdMax = Math.max(usedIdMax, usedIdKey);
937
+ }
938
+
939
+ var lengthFreeModules = nextFreeModuleId = usedIdMax + 1;
940
+
941
+ while(lengthFreeModules--) {
942
+ if(!usedIdMap[lengthFreeModules]) {
943
+ unusedIds.push(lengthFreeModules);
944
+ }
866
945
  }
867
- unusedIds.reverse();
868
946
  }
869
- this.modules.forEach(module => {
870
- if(module.id === null) {
947
+
948
+ var modules2 = this.modules;
949
+ for(var indexModule2 = 0; indexModule2 < modules2.length; indexModule2++) {
950
+ var module2 = modules2[indexModule2];
951
+ if(module2.id === null) {
871
952
  if(unusedIds.length > 0)
872
- module.id = unusedIds.pop();
953
+ module2.id = unusedIds.pop();
873
954
  else
874
- module.id = nextFreeModuleId++;
955
+ module2.id = nextFreeModuleId++;
875
956
  }
876
- });
957
+ }
877
958
  }
878
959
 
879
960
  applyChunkIds() {
880
961
  const unusedIds = [];
881
962
  let nextFreeChunkId = 0;
963
+
964
+ function getNextFreeChunkId(usedChunkIds) {
965
+ var keyChunks = Object.keys(usedChunkIds);
966
+ var result = -1;
967
+
968
+ for(var index = 0; index < keyChunks.length; index++) {
969
+ var usedIdKey = keyChunks[index];
970
+ var usedIdValue = usedChunkIds[usedIdKey];
971
+
972
+ if(typeof usedIdValue !== "number") {
973
+ continue;
974
+ }
975
+
976
+ result = Math.max(result, usedIdValue);
977
+ }
978
+
979
+ return result;
980
+ }
981
+
882
982
  if(this.usedChunkIds) {
883
- const usedIds = Object.keys(this.usedChunkIds).map(key => this.usedChunkIds[key]).sort();
884
- const usedNumberIds = usedIds.filter(id => typeof id === "number");
885
- nextFreeChunkId = usedNumberIds.reduce((a, b) => Math.max(a, b), -1) + 1;
886
- for(let i = 0; i < nextFreeChunkId; i++) {
887
- if(this.usedChunkIds[i] !== i)
888
- unusedIds.push(i);
983
+ nextFreeChunkId = getNextFreeChunkId(this.usedChunkIds) + 1;
984
+ var index = nextFreeChunkId;
985
+ while(index--) {
986
+ if(this.usedChunkIds[index] !== index) {
987
+ unusedIds.push(index);
988
+ }
889
989
  }
890
- unusedIds.reverse();
891
990
  }
892
- this.chunks.forEach(chunk => {
991
+
992
+ var chunks = this.chunks;
993
+ for(var indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
994
+ var chunk = chunks[indexChunk];
893
995
  if(chunk.id === null) {
894
996
  if(unusedIds.length > 0)
895
997
  chunk.id = unusedIds.pop();
@@ -899,19 +1001,35 @@ class Compilation extends Tapable {
899
1001
  if(!chunk.ids) {
900
1002
  chunk.ids = [chunk.id];
901
1003
  }
902
- });
1004
+ }
903
1005
  }
904
1006
 
905
1007
  sortItemsWithModuleIds() {
906
1008
  this.modules.sort(byId);
907
- this.modules.forEach(module => module.sortItems());
908
- this.chunks.forEach(chunk => chunk.sortItems());
1009
+
1010
+ var modules = this.modules;
1011
+ for(var indexModule = 0; indexModule < modules.length; indexModule++) {
1012
+ modules[indexModule].sortItems();
1013
+ }
1014
+
1015
+ var chunks = this.chunks;
1016
+ for(var indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
1017
+ chunks[indexChunk].sortItems();
1018
+ }
909
1019
  }
910
1020
 
911
1021
  sortItemsWithChunkIds() {
912
1022
  this.chunks.sort(byId);
913
- this.modules.forEach(module => module.sortItems());
914
- this.chunks.forEach(chunk => chunk.sortItems());
1023
+
1024
+ var modules = this.modules;
1025
+ for(var indexModule = 0; indexModule < modules.length; indexModule++) {
1026
+ modules[indexModule].sortItems();
1027
+ }
1028
+
1029
+ var chunks = this.chunks;
1030
+ for(var indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
1031
+ chunks[indexChunk].sortItems();
1032
+ }
915
1033
  }
916
1034
 
917
1035
  summarizeDependencies() {
@@ -926,19 +1044,33 @@ class Compilation extends Tapable {
926
1044
  this.fileDependencies = (this.compilationDependencies || []).slice();
927
1045
  this.contextDependencies = [];
928
1046
  this.missingDependencies = [];
929
- this.children.forEach(child => {
1047
+
1048
+ var children = this.children;
1049
+ for(var indexChildren = 0; indexChildren < children.length; indexChildren++) {
1050
+ var child = children[indexChildren];
1051
+
930
1052
  this.fileDependencies = this.fileDependencies.concat(child.fileDependencies);
931
1053
  this.contextDependencies = this.contextDependencies.concat(child.contextDependencies);
932
1054
  this.missingDependencies = this.missingDependencies.concat(child.missingDependencies);
933
- });
934
- this.modules.forEach(module => {
1055
+ }
1056
+
1057
+ var modules = this.modules;
1058
+ for(var indexModule = 0; indexModule < modules.length; indexModule++) {
1059
+ var module = modules[indexModule];
1060
+
935
1061
  if(module.fileDependencies) {
936
- module.fileDependencies.forEach(item => this.fileDependencies.push(item));
1062
+ var fileDependencies = module.fileDependencies;
1063
+ for(var indexFileDep = 0; indexFileDep < fileDependencies.length; indexFileDep++) {
1064
+ this.fileDependencies.push(fileDependencies[indexFileDep]);
1065
+ }
937
1066
  }
938
1067
  if(module.contextDependencies) {
939
- module.contextDependencies.forEach(item => this.contextDependencies.push(item));
1068
+ var contextDependencies = module.contextDependencies;
1069
+ for(var indexContextDep = 0; indexContextDep < contextDependencies.length; indexContextDep++) {
1070
+ this.contextDependencies.push(contextDependencies[indexContextDep]);
1071
+ }
940
1072
  }
941
- });
1073
+ }
942
1074
  this.errors.forEach(error => {
943
1075
  if(Array.isArray(error.missing)) {
944
1076
  error.missing.forEach(item => this.missingDependencies.push(item));
@@ -1046,8 +1178,9 @@ class Compilation extends Tapable {
1046
1178
  try {
1047
1179
  const useChunkHash = !chunk.hasRuntime() || (this.mainTemplate.useChunkHash && this.mainTemplate.useChunkHash(chunk));
1048
1180
  const usedHash = useChunkHash ? chunkHash : this.fullHash;
1049
- if(this.cache && this.cache[`c${chunk.id}`] && this.cache[`c${chunk.id}`].hash === usedHash) {
1050
- source = this.cache[`c${chunk.id}`].source;
1181
+ const cacheName = "c" + chunk.id;
1182
+ if(this.cache && this.cache[cacheName] && this.cache[cacheName].hash === usedHash) {
1183
+ source = this.cache[cacheName].source;
1051
1184
  } else {
1052
1185
  if(chunk.hasRuntime()) {
1053
1186
  source = this.mainTemplate.render(this.hash, chunk, this.moduleTemplate, this.dependencyTemplates);
@@ -1055,7 +1188,7 @@ class Compilation extends Tapable {
1055
1188
  source = this.chunkTemplate.render(chunk, this.moduleTemplate, this.dependencyTemplates);
1056
1189
  }
1057
1190
  if(this.cache) {
1058
- this.cache[`c${chunk.id}`] = {
1191
+ this.cache[cacheName] = {
1059
1192
  hash: usedHash,
1060
1193
  source: source = (source instanceof CachedSource ? source : new CachedSource(source))
1061
1194
  };
@@ -1092,15 +1225,23 @@ class Compilation extends Tapable {
1092
1225
 
1093
1226
  checkConstraints() {
1094
1227
  const usedIds = {};
1095
- this.modules.forEach(module => {
1096
- if(usedIds[module.id])
1097
- throw new Error(`checkConstraints: duplicate module id ${module.id}`);
1098
- });
1099
- this.chunks.forEach((chunk, idx) => {
1100
- if(this.chunks.indexOf(chunk) !== idx)
1228
+
1229
+ var modules = this.modules;
1230
+ for(var indexModule = 0; indexModule < modules.length; indexModule++) {
1231
+ var moduleId = modules[indexModule].id;
1232
+
1233
+ if(usedIds[moduleId])
1234
+ throw new Error(`checkConstraints: duplicate module id ${moduleId}`);
1235
+ }
1236
+
1237
+ var chunks = this.chunks;
1238
+ for(var indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
1239
+ var chunk = chunks[indexChunk];
1240
+
1241
+ if(chunks.indexOf(chunk) !== indexChunk)
1101
1242
  throw new Error(`checkConstraints: duplicate chunk in compilation ${chunk.debugId}`);
1102
1243
  chunk.checkConstraints();
1103
- });
1244
+ }
1104
1245
  }
1105
1246
  }
1106
1247
 
@@ -3,10 +3,9 @@
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
5
  "use strict";
6
-
7
6
  const ConstDependency = require("./dependencies/ConstDependency");
8
- const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
9
7
  const NullFactory = require("./NullFactory");
8
+ const ParserHelpers = require("./ParserHelpers");
10
9
 
11
10
  const getQuery = (request) => {
12
11
  const i = request.indexOf("?");
@@ -46,10 +45,7 @@ class ConstPlugin {
46
45
  });
47
46
  parser.plugin("evaluate Identifier __resourceQuery", function(expr) {
48
47
  if(!this.state.module) return;
49
- const res = new BasicEvaluatedExpression();
50
- res.setString(getQuery(this.state.module.resource));
51
- res.setRange(expr.range);
52
- return res;
48
+ return ParserHelpers.evaluateToString(getQuery(this.state.module.resource))(expr);
53
49
  });
54
50
  parser.plugin("expression __resourceQuery", function() {
55
51
  if(!this.state.module) return;