webpack 5.86.0 → 5.88.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (207) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +1 -1
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/CaseSensitiveModulesWarning.js +3 -1
  5. package/lib/ChunkGraph.js +4 -4
  6. package/lib/ChunkGroup.js +10 -3
  7. package/lib/CompatibilityPlugin.js +50 -30
  8. package/lib/Compilation.js +2 -1
  9. package/lib/Compiler.js +3 -1
  10. package/lib/ConcatenationScope.js +2 -2
  11. package/lib/ConditionalInitFragment.js +11 -1
  12. package/lib/ConstPlugin.js +57 -29
  13. package/lib/ContextModule.js +4 -1
  14. package/lib/ContextReplacementPlugin.js +13 -0
  15. package/lib/DelegatedModule.js +15 -3
  16. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  17. package/lib/Dependency.js +11 -5
  18. package/lib/DllEntryPlugin.js +11 -1
  19. package/lib/DllReferencePlugin.js +13 -1
  20. package/lib/Entrypoint.js +1 -1
  21. package/lib/ErrorHelpers.js +1 -0
  22. package/lib/EvalSourceMapDevToolPlugin.js +4 -0
  23. package/lib/ExportsInfo.js +17 -3
  24. package/lib/ExportsInfoApiPlugin.js +14 -5
  25. package/lib/ExternalModule.js +5 -0
  26. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  27. package/lib/FlagDependencyUsagePlugin.js +3 -1
  28. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  29. package/lib/HotModuleReplacementPlugin.js +8 -0
  30. package/lib/InitFragment.js +28 -5
  31. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  32. package/lib/LibManifestPlugin.js +20 -4
  33. package/lib/Module.js +7 -2
  34. package/lib/ModuleDependencyError.js +4 -2
  35. package/lib/ModuleDependencyWarning.js +4 -2
  36. package/lib/ModuleGraph.js +31 -24
  37. package/lib/ModuleGraphConnection.js +19 -6
  38. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  39. package/lib/ModuleNotFoundError.js +5 -2
  40. package/lib/ModuleProfile.js +1 -0
  41. package/lib/ModuleRestoreError.js +2 -0
  42. package/lib/ModuleStoreError.js +2 -1
  43. package/lib/ModuleTypeConstants.js +7 -0
  44. package/lib/MultiWatching.js +4 -0
  45. package/lib/NodeStuffPlugin.js +32 -6
  46. package/lib/ProvidePlugin.js +13 -4
  47. package/lib/RawModule.js +3 -1
  48. package/lib/RequireJsStuffPlugin.js +7 -0
  49. package/lib/RuntimeGlobals.js +5 -0
  50. package/lib/RuntimeModule.js +3 -3
  51. package/lib/RuntimePlugin.js +6 -3
  52. package/lib/RuntimeTemplate.js +22 -4
  53. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  54. package/lib/SourceMapDevToolPlugin.js +7 -2
  55. package/lib/UseStrictPlugin.js +10 -3
  56. package/lib/WebpackError.js +6 -5
  57. package/lib/WebpackIsIncludedPlugin.js +6 -4
  58. package/lib/WebpackOptionsApply.js +1 -1
  59. package/lib/WebpackOptionsDefaulter.js +10 -3
  60. package/lib/asset/AssetGenerator.js +2 -1
  61. package/lib/asset/AssetParser.js +11 -6
  62. package/lib/asset/AssetSourceParser.js +8 -3
  63. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  64. package/lib/cache/IdleFileCachePlugin.js +2 -1
  65. package/lib/cache/PackFileCacheStrategy.js +35 -14
  66. package/lib/config/browserslistTargetHandler.js +7 -7
  67. package/lib/config/defaults.js +43 -26
  68. package/lib/container/RemoteRuntimeModule.js +1 -1
  69. package/lib/css/CssLoadingRuntimeModule.js +30 -13
  70. package/lib/css/CssModulesPlugin.js +5 -2
  71. package/lib/css/CssParser.js +22 -0
  72. package/lib/dependencies/AMDDefineDependency.js +34 -4
  73. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  74. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  75. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  76. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  77. package/lib/dependencies/CommonJsPlugin.js +13 -8
  78. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  79. package/lib/dependencies/ConstDependency.js +2 -2
  80. package/lib/dependencies/ContextDependency.js +7 -2
  81. package/lib/dependencies/CssImportDependency.js +1 -1
  82. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  83. package/lib/dependencies/CssUrlDependency.js +3 -3
  84. package/lib/dependencies/DllEntryDependency.js +5 -0
  85. package/lib/dependencies/DynamicExports.js +10 -6
  86. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  87. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  88. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  89. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  90. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  91. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  92. package/lib/dependencies/HarmonyExports.js +9 -5
  93. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
  94. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  95. package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
  96. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  97. package/lib/dependencies/ImportDependency.js +5 -3
  98. package/lib/dependencies/ImportEagerDependency.js +5 -3
  99. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  100. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  101. package/lib/dependencies/ImportParserPlugin.js +62 -25
  102. package/lib/dependencies/ImportWeakDependency.js +5 -3
  103. package/lib/dependencies/ModuleDependency.js +1 -1
  104. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  105. package/lib/dependencies/ProvidedDependency.js +4 -1
  106. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  107. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  108. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  109. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  110. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  111. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  112. package/lib/dependencies/SystemPlugin.js +17 -5
  113. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  114. package/lib/dependencies/URLDependency.js +2 -2
  115. package/lib/dependencies/URLPlugin.js +9 -4
  116. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  117. package/lib/dependencies/WorkerPlugin.js +59 -22
  118. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  119. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  120. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  121. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  122. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  123. package/lib/javascript/BasicEvaluatedExpression.js +23 -15
  124. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  125. package/lib/javascript/JavascriptParser.js +135 -63
  126. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  127. package/lib/logging/runtime.js +1 -1
  128. package/lib/logging/truncateArgs.js +4 -0
  129. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  130. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  131. package/lib/optimize/InnerGraph.js +1 -1
  132. package/lib/optimize/InnerGraphPlugin.js +2 -1
  133. package/lib/performance/SizeLimitsPlugin.js +7 -4
  134. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  135. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  136. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  137. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  138. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  139. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  140. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  141. package/lib/rules/RuleSetCompiler.js +3 -3
  142. package/lib/rules/UseEffectRulePlugin.js +6 -4
  143. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  144. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  145. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  146. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  147. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  148. package/lib/runtime/CompatRuntimeModule.js +7 -2
  149. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  150. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  151. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  152. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  153. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  154. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  155. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  156. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  157. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  158. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  159. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  160. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  161. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  162. package/lib/runtime/NonceRuntimeModule.js +1 -1
  163. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  164. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  165. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  166. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  167. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  168. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  169. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  170. package/lib/serialization/ObjectMiddleware.js +6 -3
  171. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  172. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  173. package/lib/sharing/ProvideSharedDependency.js +11 -0
  174. package/lib/sharing/ProvideSharedModule.js +4 -0
  175. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  176. package/lib/sharing/ShareRuntimeModule.js +12 -5
  177. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  178. package/lib/sharing/utils.js +32 -5
  179. package/lib/util/AsyncQueue.js +4 -2
  180. package/lib/util/ParallelismFactorCalculator.js +10 -0
  181. package/lib/util/Semaphore.js +1 -1
  182. package/lib/util/createHash.js +30 -9
  183. package/lib/util/deprecation.js +10 -3
  184. package/lib/util/deterministicGrouping.js +50 -11
  185. package/lib/util/findGraphRoots.js +4 -2
  186. package/lib/util/memoize.js +3 -3
  187. package/lib/util/processAsyncTree.js +7 -1
  188. package/lib/util/registerExternalSerializer.js +1 -1
  189. package/lib/util/runtime.js +14 -1
  190. package/lib/util/smartGrouping.js +1 -1
  191. package/lib/validateSchema.js +6 -2
  192. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  193. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  194. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  195. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  196. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  197. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  198. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  199. package/lib/webpack.js +11 -2
  200. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  201. package/module.d.ts +1 -0
  202. package/package.json +5 -4
  203. package/schemas/WebpackOptions.check.js +1 -1
  204. package/schemas/WebpackOptions.json +39 -5
  205. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  206. package/schemas/plugins/css/CssParserOptions.json +1 -1
  207. package/types.d.ts +519 -222
@@ -47,6 +47,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
47
47
  /** @typedef {import("estree").MetaProperty} MetaProperty */
48
48
  /** @typedef {import("estree").Property} Property */
49
49
  /** @typedef {import("estree").AssignmentPattern} AssignmentPattern */
50
+ /** @typedef {import("estree").ChainElement} ChainElement */
50
51
  /** @typedef {import("estree").Pattern} Pattern */
51
52
  /** @typedef {import("estree").UpdateExpression} UpdateExpression */
52
53
  /** @typedef {import("estree").ObjectExpression} ObjectExpression */
@@ -105,7 +106,7 @@ const parser = AcornParser.extend(importAssertions);
105
106
  class VariableInfo {
106
107
  /**
107
108
  * @param {ScopeInfo} declaredScope scope in which the variable is declared
108
- * @param {string | true} freeName which free name the variable aliases, or true when none
109
+ * @param {string | true | undefined} freeName which free name the variable aliases, or true when none
109
110
  * @param {TagInfo | undefined} tagInfo info about tags
110
111
  */
111
112
  constructor(declaredScope, freeName, tagInfo) {
@@ -131,9 +132,10 @@ class VariableInfo {
131
132
  * @property {StackedMap<string, VariableInfo | ScopeInfo>} definitions
132
133
  * @property {boolean | "arrow"} topLevelScope
133
134
  * @property {boolean | string} inShorthand
135
+ * @property {boolean} inTaggedTemplateTag
136
+ * @property {boolean} inTry
134
137
  * @property {boolean} isStrict
135
138
  * @property {boolean} isAsmJs
136
- * @property {boolean} inTry
137
139
  */
138
140
 
139
141
  /** @typedef {[number, number]} Range */
@@ -347,7 +349,7 @@ class JavascriptParser extends Parser {
347
349
  importCall: new SyncBailHook(["expression"]),
348
350
  /** @type {SyncBailHook<[Expression], boolean | void>} */
349
351
  topLevelAwait: new SyncBailHook(["expression"]),
350
- /** @type {HookMap<SyncBailHook<[BaseCallExpression], boolean | void>>} */
352
+ /** @type {HookMap<SyncBailHook<[CallExpression], boolean | void>>} */
351
353
  call: new HookMap(() => new SyncBailHook(["expression"])),
352
354
  /** Something like "a.b()" */
353
355
  /** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[], Range[]], boolean | void>>} */
@@ -372,7 +374,7 @@ class JavascriptParser extends Parser {
372
374
  ])
373
375
  ),
374
376
  /** Something like "a.b().c.d()"" */
375
- /** @type {HookMap<SyncBailHook<[Expression, string[], CallExpression, string[]], boolean | void>>} */
377
+ /** @type {HookMap<SyncBailHook<[CallExpression, string[], CallExpression, string[]], boolean | void>>} */
376
378
  callMemberChainOfCallMemberChain: new HookMap(
377
379
  () =>
378
380
  new SyncBailHook([
@@ -390,7 +392,7 @@ class JavascriptParser extends Parser {
390
392
  binaryExpression: new SyncBailHook(["binaryExpression"]),
391
393
  /** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
392
394
  expression: new HookMap(() => new SyncBailHook(["expression"])),
393
- /** @type {HookMap<SyncBailHook<[Expression, string[], boolean[], Range[]], boolean | void>>} */
395
+ /** @type {HookMap<SyncBailHook<[MemberExpression, string[], boolean[], Range[]], boolean | void>>} */
394
396
  expressionMemberChain: new HookMap(
395
397
  () =>
396
398
  new SyncBailHook([
@@ -400,13 +402,13 @@ class JavascriptParser extends Parser {
400
402
  "memberRanges"
401
403
  ])
402
404
  ),
403
- /** @type {HookMap<SyncBailHook<[Expression, string[]], boolean | void>>} */
405
+ /** @type {HookMap<SyncBailHook<[MemberExpression, string[]], boolean | void>>} */
404
406
  unhandledExpressionMemberChain: new HookMap(
405
407
  () => new SyncBailHook(["expression", "members"])
406
408
  ),
407
- /** @type {SyncBailHook<[Expression], boolean | void>} */
409
+ /** @type {SyncBailHook<[ConditionalExpression], boolean | void>} */
408
410
  expressionConditionalOperator: new SyncBailHook(["expression"]),
409
- /** @type {SyncBailHook<[Expression], boolean | void>} */
411
+ /** @type {SyncBailHook<[LogicalExpression], boolean | void>} */
410
412
  expressionLogicalOperator: new SyncBailHook(["expression"]),
411
413
  /** @type {SyncBailHook<[Program, Comment[]], boolean | void>} */
412
414
  program: new SyncBailHook(["ast", "comments"]),
@@ -422,7 +424,7 @@ class JavascriptParser extends Parser {
422
424
  this.semicolons = undefined;
423
425
  /** @type {(Statement | ModuleDeclaration | Expression)[]} */
424
426
  this.statementPath = undefined;
425
- /** @type {Statement | ModuleDeclaration | Expression} */
427
+ /** @type {Statement | ModuleDeclaration | Expression | undefined} */
426
428
  this.prevStatement = undefined;
427
429
  /** @type {WeakMap<Expression, Set<string>>} */
428
430
  this.destructuringAssignmentProperties = undefined;
@@ -438,27 +440,29 @@ class JavascriptParser extends Parser {
438
440
  case "number":
439
441
  return new BasicEvaluatedExpression()
440
442
  .setNumber(expr.value)
441
- .setRange(expr.range);
443
+ .setRange(/** @type {Range} */ (expr.range));
442
444
  case "bigint":
443
445
  return new BasicEvaluatedExpression()
444
446
  .setBigInt(expr.value)
445
- .setRange(expr.range);
447
+ .setRange(/** @type {Range} */ (expr.range));
446
448
  case "string":
447
449
  return new BasicEvaluatedExpression()
448
450
  .setString(expr.value)
449
- .setRange(expr.range);
451
+ .setRange(/** @type {Range} */ (expr.range));
450
452
  case "boolean":
451
453
  return new BasicEvaluatedExpression()
452
454
  .setBoolean(expr.value)
453
- .setRange(expr.range);
455
+ .setRange(/** @type {Range} */ (expr.range));
454
456
  }
455
457
  if (expr.value === null) {
456
- return new BasicEvaluatedExpression().setNull().setRange(expr.range);
458
+ return new BasicEvaluatedExpression()
459
+ .setNull()
460
+ .setRange(/** @type {Range} */ (expr.range));
457
461
  }
458
462
  if (expr.value instanceof RegExp) {
459
463
  return new BasicEvaluatedExpression()
460
464
  .setRegExp(expr.value)
461
- .setRange(expr.range);
465
+ .setRange(/** @type {Range} */ (expr.range));
462
466
  }
463
467
  });
464
468
  this.hooks.evaluate.for("NewExpression").tap("JavascriptParser", _expr => {
@@ -493,7 +497,7 @@ class JavascriptParser extends Parser {
493
497
  } else {
494
498
  return new BasicEvaluatedExpression()
495
499
  .setRegExp(new RegExp(""))
496
- .setRange(expr.range);
500
+ .setRange(/** @type {Range} */ (expr.range));
497
501
  }
498
502
 
499
503
  const arg2 = expr.arguments[1];
@@ -518,7 +522,7 @@ class JavascriptParser extends Parser {
518
522
 
519
523
  return new BasicEvaluatedExpression()
520
524
  .setRegExp(flags ? new RegExp(regExp, flags) : new RegExp(regExp))
521
- .setRange(expr.range);
525
+ .setRange(/** @type {Range} */ (expr.range));
522
526
  });
523
527
  this.hooks.evaluate
524
528
  .for("LogicalExpression")
@@ -584,7 +588,7 @@ class JavascriptParser extends Parser {
584
588
  * @param {boolean | number | BigInt | string} value the value to convert to an expression
585
589
  * @param {BinaryExpression | UnaryExpression} expr the expression being evaluated
586
590
  * @param {boolean} sideEffects whether the expression has side effects
587
- * @returns {BasicEvaluatedExpression} the evaluated expression
591
+ * @returns {BasicEvaluatedExpression | undefined} the evaluated expression
588
592
  * @example
589
593
  *
590
594
  * ```js
@@ -611,22 +615,22 @@ class JavascriptParser extends Parser {
611
615
  return new BasicEvaluatedExpression()
612
616
  .setBoolean(value)
613
617
  .setSideEffects(sideEffects)
614
- .setRange(expr.range);
618
+ .setRange(/** @type {Range} */ (expr.range));
615
619
  case "number":
616
620
  return new BasicEvaluatedExpression()
617
621
  .setNumber(value)
618
622
  .setSideEffects(sideEffects)
619
- .setRange(expr.range);
623
+ .setRange(/** @type {Range} */ (expr.range));
620
624
  case "bigint":
621
625
  return new BasicEvaluatedExpression()
622
626
  .setBigInt(value)
623
627
  .setSideEffects(sideEffects)
624
- .setRange(expr.range);
628
+ .setRange(/** @type {Range} */ (expr.range));
625
629
  case "string":
626
630
  return new BasicEvaluatedExpression()
627
631
  .setString(value)
628
632
  .setSideEffects(sideEffects)
629
- .setRange(expr.range);
633
+ .setRange(/** @type {Range} */ (expr.range));
630
634
  }
631
635
  };
632
636
 
@@ -720,7 +724,7 @@ class JavascriptParser extends Parser {
720
724
  const left = this.evaluateExpression(expr.left);
721
725
  const right = this.evaluateExpression(expr.right);
722
726
  const res = new BasicEvaluatedExpression();
723
- res.setRange(expr.range);
727
+ res.setRange(/** @type {Range} */ (expr.range));
724
728
 
725
729
  const leftConst = left.isCompileTimeValue();
726
730
  const rightConst = right.isCompileTimeValue();
@@ -758,8 +762,14 @@ class JavascriptParser extends Parser {
758
762
  (rightPrimitive === false &&
759
763
  (rightConst || leftPrimitive === true)) ||
760
764
  // Different nullish or boolish status also means not equal
761
- isAlwaysDifferent(left.asBool(), right.asBool()) ||
762
- isAlwaysDifferent(left.asNullish(), right.asNullish())
765
+ isAlwaysDifferent(
766
+ /** @type {boolean} */ (left.asBool()),
767
+ /** @type {boolean} */ (right.asBool())
768
+ ) ||
769
+ isAlwaysDifferent(
770
+ /** @type {boolean} */ (left.asNullish()),
771
+ /** @type {boolean} */ (right.asNullish())
772
+ )
763
773
  ) {
764
774
  return res
765
775
  .setBoolean(!eql)
@@ -1363,7 +1373,7 @@ class JavascriptParser extends Parser {
1363
1373
 
1364
1374
  const part = new BasicEvaluatedExpression()
1365
1375
  .setString(quasi)
1366
- .setRange(quasiExpr.range)
1376
+ .setRange(/** @type {Range} */ (quasiExpr.range))
1367
1377
  .setExpression(quasiExpr);
1368
1378
  quasis.push(part);
1369
1379
  parts.push(part);
@@ -1381,11 +1391,11 @@ class JavascriptParser extends Parser {
1381
1391
 
1382
1392
  const { quasis, parts } = getSimplifiedTemplateResult("cooked", node);
1383
1393
  if (parts.length === 1) {
1384
- return parts[0].setRange(node.range);
1394
+ return parts[0].setRange(/** @type {Range} */ (node.range));
1385
1395
  }
1386
1396
  return new BasicEvaluatedExpression()
1387
1397
  .setTemplateString(quasis, parts, "cooked")
1388
- .setRange(node.range);
1398
+ .setRange(/** @type {Range} */ (node.range));
1389
1399
  });
1390
1400
  this.hooks.evaluate
1391
1401
  .for("TaggedTemplateExpression")
@@ -1400,7 +1410,7 @@ class JavascriptParser extends Parser {
1400
1410
  );
1401
1411
  return new BasicEvaluatedExpression()
1402
1412
  .setTemplateString(quasis, parts, "raw")
1403
- .setRange(node.range);
1413
+ .setRange(/** @type {Range} */ (node.range));
1404
1414
  }
1405
1415
  });
1406
1416
 
@@ -1490,7 +1500,7 @@ class JavascriptParser extends Parser {
1490
1500
  return new BasicEvaluatedExpression()
1491
1501
  .setArray(result)
1492
1502
  .setSideEffects(param.couldHaveSideEffects())
1493
- .setRange(expr.range);
1503
+ .setRange(/** @type {Range} */ (expr.range));
1494
1504
  });
1495
1505
  this.hooks.evaluate
1496
1506
  .for("ConditionalExpression")
@@ -1505,12 +1515,16 @@ class JavascriptParser extends Parser {
1505
1515
  const alternate = this.evaluateExpression(expr.alternate);
1506
1516
  res = new BasicEvaluatedExpression();
1507
1517
  if (consequent.isConditional()) {
1508
- res.setOptions(consequent.options);
1518
+ res.setOptions(
1519
+ /** @type {BasicEvaluatedExpression[]} */ (consequent.options)
1520
+ );
1509
1521
  } else {
1510
1522
  res.setOptions([consequent]);
1511
1523
  }
1512
1524
  if (alternate.isConditional()) {
1513
- res.addOptions(alternate.options);
1525
+ res.addOptions(
1526
+ /** @type {BasicEvaluatedExpression[]} */ (alternate.options)
1527
+ );
1514
1528
  } else {
1515
1529
  res.addOptions([alternate]);
1516
1530
  }
@@ -1520,7 +1534,7 @@ class JavascriptParser extends Parser {
1520
1534
  );
1521
1535
  if (condition.couldHaveSideEffects()) res.setSideEffects();
1522
1536
  }
1523
- res.setRange(expr.range);
1537
+ res.setRange(/** @type {Range} */ (expr.range));
1524
1538
  return res;
1525
1539
  });
1526
1540
  this.hooks.evaluate
@@ -1538,7 +1552,7 @@ class JavascriptParser extends Parser {
1538
1552
  if (!items.every(Boolean)) return;
1539
1553
  return new BasicEvaluatedExpression()
1540
1554
  .setItems(items)
1541
- .setRange(expr.range);
1555
+ .setRange(/** @type {Range} */ (expr.range));
1542
1556
  });
1543
1557
  this.hooks.evaluate
1544
1558
  .for("ChainExpression")
@@ -1573,11 +1587,13 @@ class JavascriptParser extends Parser {
1573
1587
  }
1574
1588
 
1575
1589
  while (optionalExpressionsStack.length > 0) {
1576
- const expression = optionalExpressionsStack.pop();
1590
+ const expression =
1591
+ /** @type {Expression} */
1592
+ (optionalExpressionsStack.pop());
1577
1593
  const evaluated = this.evaluateExpression(expression);
1578
1594
 
1579
1595
  if (evaluated.asNullish()) {
1580
- return evaluated.setRange(_expr.range);
1596
+ return evaluated.setRange(/** @type {Range} */ (_expr.range));
1581
1597
  }
1582
1598
  }
1583
1599
  return this.evaluateExpression(expr.expression);
@@ -2458,6 +2474,10 @@ class JavascriptParser extends Parser {
2458
2474
  }
2459
2475
  }
2460
2476
 
2477
+ /**
2478
+ * @param {ObjectPattern} objectPattern object pattern
2479
+ * @returns {Set<string> | undefined} set of names or undefined if not all keys are identifiers
2480
+ */
2461
2481
  _preWalkObjectPattern(objectPattern) {
2462
2482
  const ids = new Set();
2463
2483
  const properties = objectPattern.properties;
@@ -2696,6 +2716,9 @@ class JavascriptParser extends Parser {
2696
2716
  }
2697
2717
  }
2698
2718
 
2719
+ /**
2720
+ * @param {TODO} expression expression
2721
+ */
2699
2722
  walkExpression(expression) {
2700
2723
  switch (expression.type) {
2701
2724
  case "ArrayExpression":
@@ -3108,7 +3131,9 @@ class JavascriptParser extends Parser {
3108
3131
  */
3109
3132
  walkTaggedTemplateExpression(expression) {
3110
3133
  if (expression.tag) {
3134
+ this.scope.inTaggedTemplateTag = true;
3111
3135
  this.walkExpression(expression.tag);
3136
+ this.scope.inTaggedTemplateTag = false;
3112
3137
  }
3113
3138
  if (expression.quasi && expression.quasi.expressions) {
3114
3139
  this.walkExpressions(expression.quasi.expressions);
@@ -3423,10 +3448,10 @@ class JavascriptParser extends Parser {
3423
3448
  * @template R
3424
3449
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
3425
3450
  * @param {MemberExpression} expr expression info
3426
- * @param {function(string, string | ScopeInfo | VariableInfo, function(): string[]): any} fallback callback when variable in not handled by hooks
3427
- * @param {function(string): any} defined callback when variable is defined
3451
+ * @param {(function(string, string | ScopeInfo | VariableInfo, function(): string[]): any) | undefined} fallback callback when variable in not handled by hooks
3452
+ * @param {(function(string): any) | undefined} defined callback when variable is defined
3428
3453
  * @param {AsArray<T>} args args for the hook
3429
- * @returns {R} result of hook
3454
+ * @returns {R | undefined} result of hook
3430
3455
  */
3431
3456
  callHooksForExpressionWithFallback(
3432
3457
  hookMap,
@@ -3458,7 +3483,7 @@ class JavascriptParser extends Parser {
3458
3483
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
3459
3484
  * @param {string} name key in map
3460
3485
  * @param {AsArray<T>} args args for the hook
3461
- * @returns {R} result of hook
3486
+ * @returns {R | undefined} result of hook
3462
3487
  */
3463
3488
  callHooksForName(hookMap, name, ...args) {
3464
3489
  return this.callHooksForNameWithFallback(
@@ -3476,7 +3501,7 @@ class JavascriptParser extends Parser {
3476
3501
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks that should be called
3477
3502
  * @param {ExportedVariableInfo} info variable info
3478
3503
  * @param {AsArray<T>} args args for the hook
3479
- * @returns {R} result of hook
3504
+ * @returns {R | undefined} result of hook
3480
3505
  */
3481
3506
  callHooksForInfo(hookMap, info, ...args) {
3482
3507
  return this.callHooksForInfoWithFallback(
@@ -3493,10 +3518,10 @@ class JavascriptParser extends Parser {
3493
3518
  * @template R
3494
3519
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
3495
3520
  * @param {ExportedVariableInfo} info variable info
3496
- * @param {function(string): any} fallback callback when variable in not handled by hooks
3497
- * @param {function(): any} defined callback when variable is defined
3521
+ * @param {(function(string): any) | undefined} fallback callback when variable in not handled by hooks
3522
+ * @param {(function(): any) | undefined} defined callback when variable is defined
3498
3523
  * @param {AsArray<T>} args args for the hook
3499
- * @returns {R} result of hook
3524
+ * @returns {R | undefined} result of hook
3500
3525
  */
3501
3526
  callHooksForInfoWithFallback(hookMap, info, fallback, defined, ...args) {
3502
3527
  let name;
@@ -3543,10 +3568,10 @@ class JavascriptParser extends Parser {
3543
3568
  * @template R
3544
3569
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
3545
3570
  * @param {string} name key in map
3546
- * @param {function(string): any} fallback callback when variable in not handled by hooks
3547
- * @param {function(): any} defined callback when variable is defined
3571
+ * @param {(function(string): any) | undefined} fallback callback when variable in not handled by hooks
3572
+ * @param {(function(): any) | undefined} defined callback when variable is defined
3548
3573
  * @param {AsArray<T>} args args for the hook
3549
- * @returns {R} result of hook
3574
+ * @returns {R | undefined} result of hook
3550
3575
  */
3551
3576
  callHooksForNameWithFallback(hookMap, name, fallback, defined, ...args) {
3552
3577
  return this.callHooksForInfoWithFallback(
@@ -3570,6 +3595,7 @@ class JavascriptParser extends Parser {
3570
3595
  topLevelScope: oldScope.topLevelScope,
3571
3596
  inTry: false,
3572
3597
  inShorthand: false,
3598
+ inTaggedTemplateTag: false,
3573
3599
  isStrict: oldScope.isStrict,
3574
3600
  isAsmJs: oldScope.isAsmJs,
3575
3601
  definitions: oldScope.definitions.createChild()
@@ -3586,12 +3612,19 @@ class JavascriptParser extends Parser {
3586
3612
  this.scope = oldScope;
3587
3613
  }
3588
3614
 
3615
+ /**
3616
+ * @param {boolean} hasThis true, when this is defined
3617
+ * @param {any} params scope params
3618
+ * @param {function(): void} fn inner function
3619
+ * @returns {void}
3620
+ */
3589
3621
  inClassScope(hasThis, params, fn) {
3590
3622
  const oldScope = this.scope;
3591
3623
  this.scope = {
3592
3624
  topLevelScope: oldScope.topLevelScope,
3593
3625
  inTry: false,
3594
3626
  inShorthand: false,
3627
+ inTaggedTemplateTag: false,
3595
3628
  isStrict: oldScope.isStrict,
3596
3629
  isAsmJs: oldScope.isAsmJs,
3597
3630
  definitions: oldScope.definitions.createChild()
@@ -3610,12 +3643,19 @@ class JavascriptParser extends Parser {
3610
3643
  this.scope = oldScope;
3611
3644
  }
3612
3645
 
3646
+ /**
3647
+ * @param {boolean} hasThis true, when this is defined
3648
+ * @param {any} params scope params
3649
+ * @param {function(): void} fn inner function
3650
+ * @returns {void}
3651
+ */
3613
3652
  inFunctionScope(hasThis, params, fn) {
3614
3653
  const oldScope = this.scope;
3615
3654
  this.scope = {
3616
3655
  topLevelScope: oldScope.topLevelScope,
3617
3656
  inTry: false,
3618
3657
  inShorthand: false,
3658
+ inTaggedTemplateTag: false,
3619
3659
  isStrict: oldScope.isStrict,
3620
3660
  isAsmJs: oldScope.isAsmJs,
3621
3661
  definitions: oldScope.definitions.createChild()
@@ -3634,12 +3674,17 @@ class JavascriptParser extends Parser {
3634
3674
  this.scope = oldScope;
3635
3675
  }
3636
3676
 
3677
+ /**
3678
+ * @param {function(): void} fn inner function
3679
+ * @returns {void}
3680
+ */
3637
3681
  inBlockScope(fn) {
3638
3682
  const oldScope = this.scope;
3639
3683
  this.scope = {
3640
3684
  topLevelScope: oldScope.topLevelScope,
3641
3685
  inTry: oldScope.inTry,
3642
3686
  inShorthand: false,
3687
+ inTaggedTemplateTag: false,
3643
3688
  isStrict: oldScope.isStrict,
3644
3689
  isAsmJs: oldScope.isAsmJs,
3645
3690
  definitions: oldScope.definitions.createChild()
@@ -3650,15 +3695,28 @@ class JavascriptParser extends Parser {
3650
3695
  this.scope = oldScope;
3651
3696
  }
3652
3697
 
3698
+ /**
3699
+ * @param {Array<Directive | Statement | ModuleDeclaration>} statements statements
3700
+ */
3653
3701
  detectMode(statements) {
3654
3702
  const isLiteral =
3655
3703
  statements.length >= 1 &&
3656
3704
  statements[0].type === "ExpressionStatement" &&
3657
3705
  statements[0].expression.type === "Literal";
3658
- if (isLiteral && statements[0].expression.value === "use strict") {
3706
+ if (
3707
+ isLiteral &&
3708
+ /** @type {Literal} */
3709
+ (/** @type {ExpressionStatement} */ (statements[0]).expression).value ===
3710
+ "use strict"
3711
+ ) {
3659
3712
  this.scope.isStrict = true;
3660
3713
  }
3661
- if (isLiteral && statements[0].expression.value === "use asm") {
3714
+ if (
3715
+ isLiteral &&
3716
+ /** @type {Literal} */
3717
+ (/** @type {ExpressionStatement} */ (statements[0]).expression).value ===
3718
+ "use asm"
3719
+ ) {
3662
3720
  this.scope.isAsmJs = true;
3663
3721
  }
3664
3722
  }
@@ -3761,7 +3819,7 @@ class JavascriptParser extends Parser {
3761
3819
  }
3762
3820
 
3763
3821
  /**
3764
- * @param {Expression} expression expression node
3822
+ * @param {TODO} expression expression node
3765
3823
  * @returns {BasicEvaluatedExpression} evaluation result
3766
3824
  */
3767
3825
  evaluateExpression(expression) {
@@ -3779,7 +3837,7 @@ class JavascriptParser extends Parser {
3779
3837
  // ignore error
3780
3838
  }
3781
3839
  return new BasicEvaluatedExpression()
3782
- .setRange(expression.range)
3840
+ .setRange(/** @type {Range} */ (expression.range))
3783
3841
  .setExpression(expression);
3784
3842
  }
3785
3843
 
@@ -3916,6 +3974,7 @@ class JavascriptParser extends Parser {
3916
3974
  topLevelScope: true,
3917
3975
  inTry: false,
3918
3976
  inShorthand: false,
3977
+ inTaggedTemplateTag: false,
3919
3978
  isStrict: false,
3920
3979
  isAsmJs: false,
3921
3980
  definitions: new StackedMap()
@@ -4024,43 +4083,52 @@ class JavascriptParser extends Parser {
4024
4083
 
4025
4084
  case "VariableDeclaration":
4026
4085
  return expr.declarations.every(decl =>
4027
- this.isPure(decl.init, decl.range[0])
4086
+ this.isPure(decl.init, /** @type {Range} */ (decl.range)[0])
4028
4087
  );
4029
4088
 
4030
4089
  case "ConditionalExpression":
4031
4090
  return (
4032
4091
  this.isPure(expr.test, commentsStartPos) &&
4033
- this.isPure(expr.consequent, expr.test.range[1]) &&
4034
- this.isPure(expr.alternate, expr.consequent.range[1])
4092
+ this.isPure(
4093
+ expr.consequent,
4094
+ /** @type {Range} */ (expr.test.range)[1]
4095
+ ) &&
4096
+ this.isPure(
4097
+ expr.alternate,
4098
+ /** @type {Range} */ (expr.consequent.range)[1]
4099
+ )
4035
4100
  );
4036
4101
 
4037
4102
  case "LogicalExpression":
4038
4103
  return (
4039
4104
  this.isPure(expr.left, commentsStartPos) &&
4040
- this.isPure(expr.right, expr.left.range[1])
4105
+ this.isPure(expr.right, /** @type {Range} */ (expr.left.range)[1])
4041
4106
  );
4042
4107
 
4043
4108
  case "SequenceExpression":
4044
4109
  return expr.expressions.every(expr => {
4045
4110
  const pureFlag = this.isPure(expr, commentsStartPos);
4046
- commentsStartPos = expr.range[1];
4111
+ commentsStartPos = /** @type {Range} */ (expr.range)[1];
4047
4112
  return pureFlag;
4048
4113
  });
4049
4114
 
4050
4115
  case "CallExpression": {
4051
4116
  const pureFlag =
4052
- expr.range[0] - commentsStartPos > 12 &&
4053
- this.getComments([commentsStartPos, expr.range[0]]).some(
4117
+ /** @type {Range} */ (expr.range)[0] - commentsStartPos > 12 &&
4118
+ this.getComments([
4119
+ commentsStartPos,
4120
+ /** @type {Range} */ (expr.range)[0]
4121
+ ]).some(
4054
4122
  comment =>
4055
4123
  comment.type === "Block" &&
4056
4124
  /^\s*(#|@)__PURE__\s*$/.test(comment.value)
4057
4125
  );
4058
4126
  if (!pureFlag) return false;
4059
- commentsStartPos = expr.callee.range[1];
4127
+ commentsStartPos = /** @type {Range} */ (expr.callee.range)[1];
4060
4128
  return expr.arguments.every(arg => {
4061
4129
  if (arg.type === "SpreadElement") return false;
4062
4130
  const pureFlag = this.isPure(arg, commentsStartPos);
4063
- commentsStartPos = arg.range[1];
4131
+ commentsStartPos = /** @type {Range} */ (arg.range)[1];
4064
4132
  return pureFlag;
4065
4133
  });
4066
4134
  }
@@ -4114,6 +4182,10 @@ class JavascriptParser extends Parser {
4114
4182
  this.semicolons.delete(pos);
4115
4183
  }
4116
4184
 
4185
+ /**
4186
+ * @param {Expression} expr expression
4187
+ * @returns {boolean} true, when the expression is a statement level expression
4188
+ */
4117
4189
  isStatementLevelExpression(expr) {
4118
4190
  const currentStatement = this.statementPath[this.statementPath.length - 1];
4119
4191
  return (
@@ -4303,7 +4375,7 @@ class JavascriptParser extends Parser {
4303
4375
 
4304
4376
  /**
4305
4377
  * @param {string} varName variable name
4306
- * @returns {{name: string, info: VariableInfo | string}} name of the free variable and variable info for that
4378
+ * @returns {{name: string, info: VariableInfo | string} | undefined} name of the free variable and variable info for that
4307
4379
  */
4308
4380
  getFreeInfoFromVariable(varName) {
4309
4381
  const info = this.getVariableInfo(varName);
@@ -4383,7 +4455,7 @@ class JavascriptParser extends Parser {
4383
4455
 
4384
4456
  /**
4385
4457
  * @param {MemberExpression} expression an expression
4386
- * @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => string[]}} name info
4458
+ * @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => string[]} | undefined} name info
4387
4459
  */
4388
4460
  getNameForExpression(expression) {
4389
4461
  return this.getMemberExpressionInfo(
@@ -4407,7 +4479,7 @@ class JavascriptParser extends Parser {
4407
4479
  sourceType: type === "auto" ? "module" : type
4408
4480
  };
4409
4481
 
4410
- /** @type {AnyNode} */
4482
+ /** @type {AnyNode | undefined} */
4411
4483
  let ast;
4412
4484
  let error;
4413
4485
  let threw = false;