webpack 4.10.1 → 4.12.0

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 (118) hide show
  1. package/lib/AmdMainTemplatePlugin.js +3 -1
  2. package/lib/AsyncDependencyToInitialChunkError.js +4 -4
  3. package/lib/BannerPlugin.js +3 -1
  4. package/lib/BasicEvaluatedExpression.js +14 -11
  5. package/lib/CachePlugin.js +12 -5
  6. package/lib/CaseSensitiveModulesWarning.js +41 -45
  7. package/lib/Chunk.js +56 -19
  8. package/lib/ChunkGroup.js +14 -6
  9. package/lib/CommentCompilationWarning.js +22 -0
  10. package/lib/Compilation.js +72 -29
  11. package/lib/Compiler.js +22 -10
  12. package/lib/ConstPlugin.js +25 -9
  13. package/lib/ContextModule.js +88 -36
  14. package/lib/ContextModuleFactory.js +18 -7
  15. package/lib/ContextReplacementPlugin.js +14 -7
  16. package/lib/DefinePlugin.js +15 -6
  17. package/lib/DependenciesBlock.js +3 -1
  18. package/lib/DependenciesBlockVariable.js +2 -1
  19. package/lib/DllPlugin.js +4 -2
  20. package/lib/DynamicEntryPlugin.js +4 -2
  21. package/lib/EntryModuleNotFoundError.js +21 -22
  22. package/lib/ErrorHelpers.js +5 -2
  23. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  24. package/lib/FlagDependencyUsagePlugin.js +11 -5
  25. package/lib/FunctionModuleTemplatePlugin.js +8 -6
  26. package/lib/HarmonyLinkingError.js +1 -2
  27. package/lib/HotModuleReplacement.runtime.js +13 -4
  28. package/lib/HotModuleReplacementPlugin.js +13 -6
  29. package/lib/JavascriptGenerator.js +2 -1
  30. package/lib/JavascriptModulesPlugin.js +4 -9
  31. package/lib/JsonParser.js +2 -1
  32. package/lib/LibraryTemplatePlugin.js +2 -1
  33. package/lib/LoaderOptionsPlugin.js +2 -1
  34. package/lib/MainTemplate.js +2 -1
  35. package/lib/Module.js +13 -5
  36. package/lib/ModuleBuildError.js +22 -12
  37. package/lib/ModuleDependencyError.js +4 -4
  38. package/lib/ModuleDependencyWarning.js +4 -4
  39. package/lib/ModuleError.js +13 -5
  40. package/lib/ModuleFilenameHelpers.js +20 -8
  41. package/lib/ModuleNotFoundError.js +23 -26
  42. package/lib/ModuleParseError.js +27 -14
  43. package/lib/ModuleWarning.js +13 -7
  44. package/lib/MultiCompiler.js +19 -7
  45. package/lib/MultiModule.js +5 -2
  46. package/lib/NodeStuffPlugin.js +2 -1
  47. package/lib/NormalModule.js +80 -16
  48. package/lib/NormalModuleFactory.js +67 -24
  49. package/lib/OptionsDefaulter.js +7 -3
  50. package/lib/Parser.js +182 -75
  51. package/lib/ParserHelpers.js +6 -3
  52. package/lib/ProgressPlugin.js +17 -2
  53. package/lib/RawModule.js +4 -2
  54. package/lib/RecordIdsPlugin.js +77 -9
  55. package/lib/RemovedPluginError.js +1 -3
  56. package/lib/RequestShortener.js +15 -6
  57. package/lib/RuleSet.js +51 -18
  58. package/lib/RuntimeTemplate.js +21 -10
  59. package/lib/SourceMapDevToolPlugin.js +4 -3
  60. package/lib/Stats.js +74 -31
  61. package/lib/Template.js +7 -4
  62. package/lib/TemplatedPathPlugin.js +6 -3
  63. package/lib/UmdMainTemplatePlugin.js +8 -3
  64. package/lib/UnsupportedFeatureWarning.js +22 -21
  65. package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
  66. package/lib/Watching.js +3 -2
  67. package/lib/WebpackOptionsApply.js +51 -23
  68. package/lib/WebpackOptionsDefaulter.js +15 -9
  69. package/lib/WebpackOptionsValidationError.js +63 -34
  70. package/lib/debug/ProfilingPlugin.js +11 -2
  71. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
  72. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -4
  73. package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -2
  74. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -3
  75. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -3
  76. package/lib/dependencies/ImportParserPlugin.js +42 -11
  77. package/lib/dependencies/LoaderPlugin.js +12 -7
  78. package/lib/dependencies/LocalModulesHelpers.js +13 -6
  79. package/lib/dependencies/RequireContextPlugin.js +4 -2
  80. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +8 -4
  81. package/lib/dependencies/SystemPlugin.js +6 -6
  82. package/lib/dependencies/WebAssemblyExportImportedDependency.js +29 -0
  83. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  84. package/lib/formatLocation.js +15 -7
  85. package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
  86. package/lib/node/NodeMainTemplatePlugin.js +6 -3
  87. package/lib/node/NodeSourcePlugin.js +9 -5
  88. package/lib/node/NodeWatchFileSystem.js +29 -12
  89. package/lib/node/ReadFileCompileWasmTemplatePlugin.js +11 -2
  90. package/lib/optimize/AggressiveSplittingPlugin.js +12 -6
  91. package/lib/optimize/ConcatenatedModule.js +19 -8
  92. package/lib/optimize/MergeDuplicateChunksPlugin.js +6 -3
  93. package/lib/optimize/ModuleConcatenationPlugin.js +23 -10
  94. package/lib/optimize/OccurrenceOrderPlugin.js +11 -4
  95. package/lib/optimize/RemoveParentModulesPlugin.js +17 -7
  96. package/lib/optimize/SideEffectsFlagPlugin.js +14 -3
  97. package/lib/optimize/SplitChunksPlugin.js +33 -20
  98. package/lib/performance/AssetsOverSizeLimitWarning.js +7 -7
  99. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -7
  100. package/lib/performance/NoAsyncChunksWarning.js +5 -5
  101. package/lib/util/SortableSet.js +5 -2
  102. package/lib/util/StackedSetMap.js +12 -5
  103. package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +1 -2
  104. package/lib/wasm/WasmFinalizeExportsPlugin.js +66 -0
  105. package/lib/wasm/WasmMainTemplatePlugin.js +87 -43
  106. package/lib/wasm/WebAssemblyGenerator.js +117 -74
  107. package/lib/wasm/WebAssemblyJavascriptGenerator.js +92 -49
  108. package/lib/wasm/WebAssemblyModulesPlugin.js +11 -1
  109. package/lib/wasm/WebAssemblyParser.js +96 -24
  110. package/lib/wasm/WebAssemblyUtils.js +17 -6
  111. package/lib/web/FetchCompileWasmTemplatePlugin.js +13 -1
  112. package/lib/web/JsonpChunkTemplatePlugin.js +7 -0
  113. package/lib/web/JsonpMainTemplate.runtime.js +2 -1
  114. package/lib/web/JsonpMainTemplatePlugin.js +68 -63
  115. package/lib/webpack.js +2 -1
  116. package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
  117. package/package.json +12 -11
  118. package/schemas/WebpackOptions.json +8 -0
package/lib/Parser.js CHANGED
@@ -7,8 +7,8 @@
7
7
  // Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
8
8
 
9
9
  const acorn = require("acorn-dynamic-import").default;
10
- const { Tapable, SyncBailHook } = require("tapable");
11
- const HookMap = require("tapable/lib/HookMap");
10
+ const { Tapable, SyncBailHook, HookMap } = require("tapable");
11
+ const util = require("util");
12
12
  const vm = require("vm");
13
13
  const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
14
14
  const StackedSetMap = require("./util/StackedSetMap");
@@ -23,7 +23,7 @@ const joinRanges = (startRange, endRange) => {
23
23
  const defaultParserOptions = {
24
24
  ranges: true,
25
25
  locations: true,
26
- ecmaVersion: 2018,
26
+ ecmaVersion: 2019,
27
27
  sourceType: "module",
28
28
  onComment: null,
29
29
  plugins: {
@@ -31,6 +31,16 @@ const defaultParserOptions = {
31
31
  }
32
32
  };
33
33
 
34
+ // regexp to match at lease one "magic comment"
35
+ const webpackCommentRegExp = new RegExp(/(^|\W)webpack[A-Z]{1,}[A-Za-z]{1,}:/);
36
+
37
+ const EMPTY_ARRAY = [];
38
+
39
+ const EMPTY_COMMENT_OPTIONS = {
40
+ options: null,
41
+ errors: null
42
+ };
43
+
34
44
  class Parser extends Tapable {
35
45
  constructor(options, sourceType = "auto") {
36
46
  super();
@@ -117,17 +127,18 @@ class Parser extends Tapable {
117
127
  const regexp = HOOK_MAP_COMPAT_CONFIG[name];
118
128
  const match = regexp.exec(options.name);
119
129
  if (match) {
120
- if (match[1])
130
+ if (match[1]) {
121
131
  this.hooks[name].tap(
122
132
  match[1],
123
133
  options.fn.name || "unnamed compat plugin",
124
134
  options.fn.bind(this)
125
135
  );
126
- else
136
+ } else {
127
137
  this.hooks[name].tap(
128
138
  options.fn.name || "unnamed compat plugin",
129
139
  options.fn.bind(this)
130
140
  );
141
+ }
131
142
  return true;
132
143
  }
133
144
  }
@@ -156,12 +167,14 @@ class Parser extends Tapable {
156
167
  .setBoolean(expr.value)
157
168
  .setRange(expr.range);
158
169
  }
159
- if (expr.value === null)
170
+ if (expr.value === null) {
160
171
  return new BasicEvaluatedExpression().setNull().setRange(expr.range);
161
- if (expr.value instanceof RegExp)
172
+ }
173
+ if (expr.value instanceof RegExp) {
162
174
  return new BasicEvaluatedExpression()
163
175
  .setRegExp(expr.value)
164
176
  .setRange(expr.range);
177
+ }
165
178
  });
166
179
  this.hooks.evaluate.for("LogicalExpression").tap("Parser", expr => {
167
180
  let left;
@@ -411,22 +424,26 @@ class Parser extends Tapable {
411
424
  .setRange(expr.range);
412
425
  }
413
426
  const arg = this.evaluateExpression(expr.argument);
414
- if (arg.isString() || arg.isWrapped())
427
+ if (arg.isString() || arg.isWrapped()) {
415
428
  return new BasicEvaluatedExpression()
416
429
  .setString("string")
417
430
  .setRange(expr.range);
418
- else if (arg.isNumber())
431
+ }
432
+ if (arg.isNumber()) {
419
433
  return new BasicEvaluatedExpression()
420
434
  .setString("number")
421
435
  .setRange(expr.range);
422
- else if (arg.isBoolean())
436
+ }
437
+ if (arg.isBoolean()) {
423
438
  return new BasicEvaluatedExpression()
424
439
  .setString("boolean")
425
440
  .setRange(expr.range);
426
- else if (arg.isArray() || arg.isConstArray() || arg.isRegExp())
441
+ }
442
+ if (arg.isArray() || arg.isConstArray() || arg.isRegExp()) {
427
443
  return new BasicEvaluatedExpression()
428
444
  .setString("object")
429
445
  .setRange(expr.range);
446
+ }
430
447
  } else if (expr.operator === "!") {
431
448
  const argument = this.evaluateExpression(expr.argument);
432
449
  if (!argument) return;
@@ -434,19 +451,23 @@ class Parser extends Tapable {
434
451
  return new BasicEvaluatedExpression()
435
452
  .setBoolean(!argument.bool)
436
453
  .setRange(expr.range);
437
- } else if (argument.isTruthy()) {
454
+ }
455
+ if (argument.isTruthy()) {
438
456
  return new BasicEvaluatedExpression()
439
457
  .setBoolean(false)
440
458
  .setRange(expr.range);
441
- } else if (argument.isFalsy()) {
459
+ }
460
+ if (argument.isFalsy()) {
442
461
  return new BasicEvaluatedExpression()
443
462
  .setBoolean(true)
444
463
  .setRange(expr.range);
445
- } else if (argument.isString()) {
464
+ }
465
+ if (argument.isString()) {
446
466
  return new BasicEvaluatedExpression()
447
467
  .setBoolean(!argument.string)
448
468
  .setRange(expr.range);
449
- } else if (argument.isNumber()) {
469
+ }
470
+ if (argument.isNumber()) {
450
471
  return new BasicEvaluatedExpression()
451
472
  .setBoolean(!argument.number)
452
473
  .setRange(expr.range);
@@ -696,7 +717,9 @@ class Parser extends Tapable {
696
717
  result = param.string.split(arg.string);
697
718
  } else if (arg.isRegExp()) {
698
719
  result = param.string.split(arg.regExp);
699
- } else return;
720
+ } else {
721
+ return;
722
+ }
700
723
  return new BasicEvaluatedExpression()
701
724
  .setArray(result)
702
725
  .setRange(expr.range);
@@ -710,10 +733,16 @@ class Parser extends Tapable {
710
733
  const alternate = this.evaluateExpression(expr.alternate);
711
734
  if (!consequent || !alternate) return;
712
735
  res = new BasicEvaluatedExpression();
713
- if (consequent.isConditional()) res.setOptions(consequent.options);
714
- else res.setOptions([consequent]);
715
- if (alternate.isConditional()) res.addOptions(alternate.options);
716
- else res.addOptions([alternate]);
736
+ if (consequent.isConditional()) {
737
+ res.setOptions(consequent.options);
738
+ } else {
739
+ res.setOptions([consequent]);
740
+ }
741
+ if (alternate.isConditional()) {
742
+ res.addOptions(alternate.options);
743
+ } else {
744
+ res.addOptions([alternate]);
745
+ }
717
746
  } else {
718
747
  res = this.evaluateExpression(
719
748
  conditionValue ? expr.consequent : expr.alternate
@@ -735,9 +764,9 @@ class Parser extends Tapable {
735
764
 
736
765
  getRenameIdentifier(expr) {
737
766
  const result = this.evaluateExpression(expr);
738
- if (!result) return;
739
- if (result.isIdentifier()) return result.identifier;
740
- return;
767
+ if (result && result.isIdentifier()) {
768
+ return result.identifier;
769
+ }
741
770
  }
742
771
 
743
772
  walkClass(classy) {
@@ -746,17 +775,21 @@ class Parser extends Tapable {
746
775
  const wasTopLevel = this.scope.topLevelScope;
747
776
  this.scope.topLevelScope = false;
748
777
  for (const methodDefinition of classy.body.body) {
749
- if (methodDefinition.type === "MethodDefinition")
778
+ if (methodDefinition.type === "MethodDefinition") {
750
779
  this.walkMethodDefinition(methodDefinition);
780
+ }
751
781
  }
752
782
  this.scope.topLevelScope = wasTopLevel;
753
783
  }
754
784
  }
755
785
 
756
786
  walkMethodDefinition(methodDefinition) {
757
- if (methodDefinition.computed && methodDefinition.key)
787
+ if (methodDefinition.computed && methodDefinition.key) {
758
788
  this.walkExpression(methodDefinition.key);
759
- if (methodDefinition.value) this.walkExpression(methodDefinition.value);
789
+ }
790
+ if (methodDefinition.value) {
791
+ this.walkExpression(methodDefinition.value);
792
+ }
760
793
  }
761
794
 
762
795
  // Prewalking iterates the scope for variable declarations
@@ -912,7 +945,9 @@ class Parser extends Tapable {
912
945
 
913
946
  prewalkIfStatement(statement) {
914
947
  this.prewalkStatement(statement.consequent);
915
- if (statement.alternate) this.prewalkStatement(statement.alternate);
948
+ if (statement.alternate) {
949
+ this.prewalkStatement(statement.alternate);
950
+ }
916
951
  }
917
952
 
918
953
  walkIfStatement(statement) {
@@ -920,10 +955,15 @@ class Parser extends Tapable {
920
955
  if (result === undefined) {
921
956
  this.walkExpression(statement.test);
922
957
  this.walkStatement(statement.consequent);
923
- if (statement.alternate) this.walkStatement(statement.alternate);
958
+ if (statement.alternate) {
959
+ this.walkStatement(statement.alternate);
960
+ }
924
961
  } else {
925
- if (result) this.walkStatement(statement.consequent);
926
- else if (statement.alternate) this.walkStatement(statement.alternate);
962
+ if (result) {
963
+ this.walkStatement(statement.consequent);
964
+ } else if (statement.alternate) {
965
+ this.walkStatement(statement.alternate);
966
+ }
927
967
  }
928
968
  }
929
969
 
@@ -1006,26 +1046,34 @@ class Parser extends Tapable {
1006
1046
 
1007
1047
  prewalkForStatement(statement) {
1008
1048
  if (statement.init) {
1009
- if (statement.init.type === "VariableDeclaration")
1049
+ if (statement.init.type === "VariableDeclaration") {
1010
1050
  this.prewalkStatement(statement.init);
1051
+ }
1011
1052
  }
1012
1053
  this.prewalkStatement(statement.body);
1013
1054
  }
1014
1055
 
1015
1056
  walkForStatement(statement) {
1016
1057
  if (statement.init) {
1017
- if (statement.init.type === "VariableDeclaration")
1058
+ if (statement.init.type === "VariableDeclaration") {
1018
1059
  this.walkStatement(statement.init);
1019
- else this.walkExpression(statement.init);
1060
+ } else {
1061
+ this.walkExpression(statement.init);
1062
+ }
1063
+ }
1064
+ if (statement.test) {
1065
+ this.walkExpression(statement.test);
1066
+ }
1067
+ if (statement.update) {
1068
+ this.walkExpression(statement.update);
1020
1069
  }
1021
- if (statement.test) this.walkExpression(statement.test);
1022
- if (statement.update) this.walkExpression(statement.update);
1023
1070
  this.walkStatement(statement.body);
1024
1071
  }
1025
1072
 
1026
1073
  prewalkForInStatement(statement) {
1027
- if (statement.left.type === "VariableDeclaration")
1074
+ if (statement.left.type === "VariableDeclaration") {
1028
1075
  this.prewalkVariableDeclaration(statement.left);
1076
+ }
1029
1077
  this.prewalkStatement(statement.body);
1030
1078
  }
1031
1079
 
@@ -1142,7 +1190,7 @@ class Parser extends Tapable {
1142
1190
  switch (specifier.type) {
1143
1191
  case "ExportSpecifier": {
1144
1192
  const name = specifier.exported.name;
1145
- if (source)
1193
+ if (source) {
1146
1194
  this.hooks.exportImportSpecifier.call(
1147
1195
  statement,
1148
1196
  source,
@@ -1150,13 +1198,14 @@ class Parser extends Tapable {
1150
1198
  name,
1151
1199
  specifierIndex
1152
1200
  );
1153
- else
1201
+ } else {
1154
1202
  this.hooks.exportSpecifier.call(
1155
1203
  statement,
1156
1204
  specifier.local.name,
1157
1205
  name,
1158
1206
  specifierIndex
1159
1207
  );
1208
+ }
1160
1209
  break;
1161
1210
  }
1162
1211
  }
@@ -1309,7 +1358,11 @@ class Parser extends Tapable {
1309
1358
  }
1310
1359
 
1311
1360
  walkCatchClause(catchClause) {
1312
- this.inScope([catchClause.param], () => {
1361
+ // Error binding is optional in catch clause since ECMAScript 2019
1362
+ const errorBinding =
1363
+ catchClause.param === null ? EMPTY_ARRAY : [catchClause.param];
1364
+
1365
+ this.inScope(errorBinding, () => {
1313
1366
  this.prewalkStatement(catchClause.body);
1314
1367
  this.walkStatement(catchClause.body);
1315
1368
  });
@@ -1445,11 +1498,15 @@ class Parser extends Tapable {
1445
1498
  }
1446
1499
 
1447
1500
  walkArrayExpression(expression) {
1448
- if (expression.elements) this.walkExpressions(expression.elements);
1501
+ if (expression.elements) {
1502
+ this.walkExpressions(expression.elements);
1503
+ }
1449
1504
  }
1450
1505
 
1451
1506
  walkSpreadElement(expression) {
1452
- if (expression.argument) this.walkExpression(expression.argument);
1507
+ if (expression.argument) {
1508
+ this.walkExpression(expression.argument);
1509
+ }
1453
1510
  }
1454
1511
 
1455
1512
  walkObjectExpression(expression) {
@@ -1463,10 +1520,16 @@ class Parser extends Tapable {
1463
1520
  this.walkExpression(prop.argument);
1464
1521
  continue;
1465
1522
  }
1466
- if (prop.computed) this.walkExpression(prop.key);
1467
- if (prop.shorthand) this.scope.inShorthand = true;
1523
+ if (prop.computed) {
1524
+ this.walkExpression(prop.key);
1525
+ }
1526
+ if (prop.shorthand) {
1527
+ this.scope.inShorthand = true;
1528
+ }
1468
1529
  this.walkExpression(prop.value);
1469
- if (prop.shorthand) this.scope.inShorthand = false;
1530
+ if (prop.shorthand) {
1531
+ this.scope.inShorthand = false;
1532
+ }
1470
1533
  }
1471
1534
  }
1472
1535
 
@@ -1576,10 +1639,15 @@ class Parser extends Tapable {
1576
1639
  if (result === undefined) {
1577
1640
  this.walkExpression(expression.test);
1578
1641
  this.walkExpression(expression.consequent);
1579
- if (expression.alternate) this.walkExpression(expression.alternate);
1642
+ if (expression.alternate) {
1643
+ this.walkExpression(expression.alternate);
1644
+ }
1580
1645
  } else {
1581
- if (result) this.walkExpression(expression.consequent);
1582
- else if (expression.alternate) this.walkExpression(expression.alternate);
1646
+ if (result) {
1647
+ this.walkExpression(expression.consequent);
1648
+ } else if (expression.alternate) {
1649
+ this.walkExpression(expression.alternate);
1650
+ }
1583
1651
  }
1584
1652
  }
1585
1653
 
@@ -1596,21 +1664,30 @@ class Parser extends Tapable {
1596
1664
  }
1597
1665
 
1598
1666
  this.walkExpression(expression.callee);
1599
- if (expression.arguments) this.walkExpressions(expression.arguments);
1667
+ if (expression.arguments) {
1668
+ this.walkExpressions(expression.arguments);
1669
+ }
1600
1670
  }
1601
1671
 
1602
1672
  walkYieldExpression(expression) {
1603
- if (expression.argument) this.walkExpression(expression.argument);
1673
+ if (expression.argument) {
1674
+ this.walkExpression(expression.argument);
1675
+ }
1604
1676
  }
1605
1677
 
1606
1678
  walkTemplateLiteral(expression) {
1607
- if (expression.expressions) this.walkExpressions(expression.expressions);
1679
+ if (expression.expressions) {
1680
+ this.walkExpressions(expression.expressions);
1681
+ }
1608
1682
  }
1609
1683
 
1610
1684
  walkTaggedTemplateExpression(expression) {
1611
- if (expression.tag) this.walkExpression(expression.tag);
1612
- if (expression.quasi && expression.quasi.expressions)
1685
+ if (expression.tag) {
1686
+ this.walkExpression(expression.tag);
1687
+ }
1688
+ if (expression.quasi && expression.quasi.expressions) {
1613
1689
  this.walkExpressions(expression.quasi.expressions);
1690
+ }
1614
1691
  }
1615
1692
 
1616
1693
  walkClassExpression(expression) {
@@ -1624,8 +1701,9 @@ class Parser extends Tapable {
1624
1701
  const hook = this.hooks.canRename.get(renameIdentifier);
1625
1702
  if (hook !== undefined && hook.call(argOrThis)) {
1626
1703
  const hook = this.hooks.rename.get(renameIdentifier);
1627
- if (hook === undefined || !hook.call(argOrThis))
1704
+ if (hook === undefined || !hook.call(argOrThis)) {
1628
1705
  return renameIdentifier;
1706
+ }
1629
1707
  }
1630
1708
  }
1631
1709
  this.walkExpression(argOrThis);
@@ -1852,11 +1930,12 @@ class Parser extends Tapable {
1852
1930
  parseString(expression) {
1853
1931
  switch (expression.type) {
1854
1932
  case "BinaryExpression":
1855
- if (expression.operator === "+")
1933
+ if (expression.operator === "+") {
1856
1934
  return (
1857
1935
  this.parseString(expression.left) +
1858
1936
  this.parseString(expression.right)
1859
1937
  );
1938
+ }
1860
1939
  break;
1861
1940
  case "Literal":
1862
1941
  return expression.value + "";
@@ -1903,12 +1982,20 @@ class Parser extends Tapable {
1903
1982
  const consequent = this.parseCalculatedString(expression.consequent);
1904
1983
  const alternate = this.parseCalculatedString(expression.alternate);
1905
1984
  const items = [];
1906
- if (consequent.conditional) items.push(...consequent.conditional);
1907
- else if (!consequent.code) items.push(consequent);
1908
- else break;
1909
- if (alternate.conditional) items.push(...alternate.conditional);
1910
- else if (!alternate.code) items.push(alternate);
1911
- else break;
1985
+ if (consequent.conditional) {
1986
+ items.push(...consequent.conditional);
1987
+ } else if (!consequent.code) {
1988
+ items.push(consequent);
1989
+ } else {
1990
+ break;
1991
+ }
1992
+ if (alternate.conditional) {
1993
+ items.push(...alternate.conditional);
1994
+ } else if (!alternate.code) {
1995
+ items.push(alternate);
1996
+ } else {
1997
+ break;
1998
+ }
1912
1999
  return {
1913
2000
  range: undefined,
1914
2001
  value: "",
@@ -1975,8 +2062,9 @@ class Parser extends Tapable {
1975
2062
  sourceType: this.sourceType,
1976
2063
  locations: false
1977
2064
  });
1978
- if (ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement")
2065
+ if (ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement") {
1979
2066
  throw new Error("evaluate: Source is not a expression");
2067
+ }
1980
2068
  return this.evaluateExpression(ast.body[0].expression);
1981
2069
  }
1982
2070
 
@@ -1986,20 +2074,27 @@ class Parser extends Tapable {
1986
2074
  );
1987
2075
  }
1988
2076
 
1989
- getCommentOptions(range) {
2077
+ parseCommentOptions(range) {
1990
2078
  const comments = this.getComments(range);
1991
- if (comments.length === 0) return null;
1992
- const options = comments.map(comment => {
1993
- try {
1994
- let val = vm.runInNewContext(
1995
- `(function(){return {${comment.value}};})()`
1996
- );
1997
- return val;
1998
- } catch (e) {
1999
- return {};
2079
+ if (comments.length === 0) {
2080
+ return EMPTY_COMMENT_OPTIONS;
2081
+ }
2082
+ let options = {};
2083
+ let errors = [];
2084
+ for (const comment of comments) {
2085
+ const { value } = comment;
2086
+ if (value && webpackCommentRegExp.test(value)) {
2087
+ // try compile only if webpack options comment is present
2088
+ try {
2089
+ const val = vm.runInNewContext(`(function(){return {${value}};})()`);
2090
+ Object.assign(options, val);
2091
+ } catch (e) {
2092
+ e.comment = comment;
2093
+ errors.push(e);
2094
+ }
2000
2095
  }
2001
- });
2002
- return options.reduce((o, i) => Object.assign(o, i), {});
2096
+ }
2097
+ return { options, errors };
2003
2098
  }
2004
2099
 
2005
2100
  getNameForExpression(expression) {
@@ -2029,8 +2124,12 @@ class Parser extends Tapable {
2029
2124
  return null;
2030
2125
  }
2031
2126
  let prefix = "";
2032
- for (let i = exprName.length - 1; i >= 2; i--) prefix += exprName[i] + ".";
2033
- if (exprName.length > 1) prefix += exprName[1];
2127
+ for (let i = exprName.length - 1; i >= 2; i--) {
2128
+ prefix += exprName[i] + ".";
2129
+ }
2130
+ if (exprName.length > 1) {
2131
+ prefix += exprName[1];
2132
+ }
2034
2133
  const name = prefix ? prefix + "." + exprName[0] : exprName[0];
2035
2134
  const nameGeneral = prefix;
2036
2135
  return {
@@ -2083,4 +2182,12 @@ class Parser extends Tapable {
2083
2182
  }
2084
2183
  }
2085
2184
 
2185
+ // TODO remove in webpack 5
2186
+ Object.defineProperty(Parser.prototype, "getCommentOptions", {
2187
+ configurable: false,
2188
+ value: util.deprecate(function(range) {
2189
+ return this.parseCommentOptions(range).options;
2190
+ }, "Parser.getCommentOptions: Use Parser.parseCommentOptions(range) instead")
2191
+ });
2192
+
2086
2193
  module.exports = Parser;
@@ -72,8 +72,11 @@ ParserHelpers.evaluateToIdentifier = (identifier, truthy) => {
72
72
  let evex = new BasicEvaluatedExpression()
73
73
  .setIdentifier(identifier)
74
74
  .setRange(expr.range);
75
- if (truthy === true) evex = evex.setTruthy();
76
- else if (truthy === false) evex = evex.setFalsy();
75
+ if (truthy === true) {
76
+ evex = evex.setTruthy();
77
+ } else if (truthy === false) {
78
+ evex = evex.setFalsy();
79
+ }
77
80
  return evex;
78
81
  };
79
82
  };
@@ -85,7 +88,7 @@ ParserHelpers.expressionIsUnsupported = (parser, message) => {
85
88
  parser.state.current.addDependency(dep);
86
89
  if (!parser.state.module) return;
87
90
  parser.state.module.warnings.push(
88
- new UnsupportedFeatureWarning(parser.state.module, message)
91
+ new UnsupportedFeatureWarning(parser.state.module, message, expr.loc)
89
92
  );
90
93
  return true;
91
94
  };
@@ -101,7 +101,7 @@ class ProgressPlugin {
101
101
 
102
102
  const update = module => {
103
103
  handler(
104
- 0.1 + doneModules / Math.max(lastModulesCount, moduleCount) * 0.6,
104
+ 0.1 + (doneModules / Math.max(lastModulesCount, moduleCount)) * 0.6,
105
105
  "building modules",
106
106
  `${doneModules}/${moduleCount} modules`,
107
107
  `${activeModules.length} active`,
@@ -187,7 +187,7 @@ class ProgressPlugin {
187
187
  const numberOfHooks = Object.keys(hooks).length;
188
188
  Object.keys(hooks).forEach((name, idx) => {
189
189
  const title = hooks[name];
190
- const percentage = idx / numberOfHooks * 0.25 + 0.7;
190
+ const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
191
191
  compilation.hooks[name].intercept({
192
192
  name: "ProgressPlugin",
193
193
  context: true,
@@ -222,6 +222,21 @@ class ProgressPlugin {
222
222
  handler(0.95, "emitting", tap.name);
223
223
  }
224
224
  });
225
+ compiler.hooks.afterEmit.intercept({
226
+ name: "ProgressPlugin",
227
+ context: true,
228
+ call: () => {
229
+ handler(0.98, "after emitting");
230
+ },
231
+ tap: (context, tap) => {
232
+ if (context) {
233
+ context.reportProgress = (p, ...args) => {
234
+ handler(0.98, "after emitting", tap.name, ...args);
235
+ };
236
+ }
237
+ handler(0.98, "after emitting", tap.name);
238
+ }
239
+ });
225
240
  compiler.hooks.done.tap("ProgressPlugin", () => {
226
241
  handler(1, "");
227
242
  });
package/lib/RawModule.js CHANGED
@@ -42,9 +42,11 @@ module.exports = class RawModule extends Module {
42
42
  }
43
43
 
44
44
  source() {
45
- if (this.useSourceMap)
45
+ if (this.useSourceMap) {
46
46
  return new OriginalSource(this.sourceStr, this.identifier());
47
- else return new RawSource(this.sourceStr);
47
+ } else {
48
+ return new RawSource(this.sourceStr);
49
+ }
48
50
  }
49
51
 
50
52
  updateHash(hash) {