@depup/webpack 5.110.3-depup.0 → 5.111.1-depup.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 (283) hide show
  1. package/README.md +7 -8
  2. package/changes.json +7 -11
  3. package/lib/APIPlugin.js +26 -11
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/Cache.js +8 -3
  6. package/lib/CacheFacade.js +1 -1
  7. package/lib/CircularModulesPlugin.js +157 -55
  8. package/lib/CleanPlugin.js +2 -2
  9. package/lib/CompatibilityPlugin.js +3 -4
  10. package/lib/Compilation.js +336 -337
  11. package/lib/Compiler.js +213 -51
  12. package/lib/ConstPlugin.js +16 -132
  13. package/lib/CopyPlugin.js +1054 -0
  14. package/lib/DefinePlugin.js +24 -8
  15. package/lib/DependencyTemplate.js +2 -1
  16. package/lib/DotenvPlugin.js +24 -28
  17. package/lib/ErrorHelpers.js +113 -0
  18. package/lib/ExportsInfo.js +20 -16
  19. package/lib/ExternalModule.js +47 -22
  20. package/lib/FileSystemInfo.js +17 -14
  21. package/lib/FlagDependencyExportsPlugin.js +53 -34
  22. package/lib/FlagDependencyUsagePlugin.js +9 -13
  23. package/lib/Generator.js +24 -2
  24. package/lib/HotModuleReplacementPlugin.js +55 -7
  25. package/lib/IgnorePlugin.js +1 -1
  26. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  27. package/lib/LoaderOptionsPlugin.js +1 -1
  28. package/lib/MainTemplate.js +5 -1
  29. package/lib/Module.js +19 -10
  30. package/lib/ModuleGraph.js +6 -9
  31. package/lib/MultiCompiler.js +7 -17
  32. package/lib/MultiWatching.js +1 -1
  33. package/lib/NormalModule.js +135 -50
  34. package/lib/NormalModuleFactory.js +1 -1
  35. package/lib/RuntimeGlobals.js +21 -7
  36. package/lib/RuntimeModule.js +28 -12
  37. package/lib/RuntimePlugin.js +30 -3
  38. package/lib/RuntimeTemplate.js +813 -518
  39. package/lib/SourceMapDevToolPlugin.js +54 -104
  40. package/lib/TemplatedPathPlugin.js +16 -59
  41. package/lib/Watching.js +9 -0
  42. package/lib/WebpackOptionsApply.js +84 -91
  43. package/lib/asset/AssetBytesGenerator.js +7 -1
  44. package/lib/asset/AssetGenerator.js +50 -24
  45. package/lib/asset/AssetModule.js +3 -0
  46. package/lib/asset/AssetSourceGenerator.js +7 -1
  47. package/lib/asset/WebManifestParser.js +7 -5
  48. package/lib/buildChunkGraph.js +11 -15
  49. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  50. package/lib/cache/IdleFileCachePlugin.js +2 -2
  51. package/lib/cache/MemoryCachePlugin.js +4 -4
  52. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  53. package/lib/cache/PackFileCacheStrategy.js +17 -19
  54. package/lib/cache/getLazyHashedEtag.js +3 -5
  55. package/lib/config/browserslistTargetHandler.js +17 -4
  56. package/lib/config/defaults.js +138 -128
  57. package/lib/config/getClaimedAssetTypes.js +10 -11
  58. package/lib/config/normalization.js +82 -12
  59. package/lib/config/target.js +13 -4
  60. package/lib/container/ContainerReferencePlugin.js +6 -0
  61. package/lib/container/RemoteRuntimeModule.js +9 -0
  62. package/lib/container/declaredRemotes.js +39 -0
  63. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  64. package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
  65. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  66. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  67. package/lib/css/CssGenerator.js +27 -11
  68. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  69. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  70. package/lib/css/CssModule.js +1 -1
  71. package/lib/css/CssModulesPlugin.js +7 -6
  72. package/lib/css/CssParser.js +162 -31
  73. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  74. package/lib/css/cssMinify.js +43 -32
  75. package/lib/css/data.js +3514 -869
  76. package/lib/css/syntax.js +6370 -1220
  77. package/lib/debug/ProfilingPlugin.js +7 -4
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  79. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  80. package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
  81. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  82. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
  83. package/lib/dependencies/CommonJsPlugin.js +19 -3
  84. package/lib/dependencies/CommonJsRequireDependency.js +14 -5
  85. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  86. package/lib/dependencies/ContextDependency.js +1 -1
  87. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  88. package/lib/dependencies/ContextElementDependency.js +1 -1
  89. package/lib/dependencies/CssIcssExportDependency.js +13 -9
  90. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  91. package/lib/dependencies/CssUrlDependency.js +3 -5
  92. package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
  93. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  94. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +10 -7
  95. package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
  96. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +74 -17
  97. package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
  98. package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
  99. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  100. package/lib/dependencies/HarmonyImportDependency.js +6 -1
  101. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +111 -17
  102. package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
  103. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
  104. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  105. package/lib/dependencies/HtmlEntryDependency.js +124 -102
  106. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  107. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  108. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  109. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  110. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  111. package/lib/dependencies/ImportMetaPlugin.js +67 -25
  112. package/lib/dependencies/ImportParserPlugin.js +1 -1
  113. package/lib/dependencies/LoaderPlugin.js +26 -1
  114. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  115. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  116. package/lib/dependencies/URLContextDependency.js +1 -1
  117. package/lib/dependencies/URLDependency.js +6 -5
  118. package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
  119. package/lib/dependencies/WorkerDependency.js +7 -7
  120. package/lib/dependencies/WorkletDependency.js +7 -11
  121. package/lib/dll/DelegatedModule.js +18 -1
  122. package/lib/dll/DllReferencePlugin.js +11 -8
  123. package/lib/dll/LibManifestPlugin.js +1 -1
  124. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  125. package/lib/errors/DuplicateModulesWarning.js +12 -7
  126. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  127. package/lib/errors/ExternalStarReexportError.js +44 -0
  128. package/lib/errors/HookWebpackError.js +3 -2
  129. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  130. package/lib/errors/ModuleParseError.js +2 -1
  131. package/lib/errors/UnusedAssetsWarning.js +36 -0
  132. package/lib/errors/UnusedFederationWarning.js +35 -0
  133. package/lib/errors/UnusedModulesWarning.js +38 -0
  134. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  135. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  136. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  137. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  138. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  139. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  140. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  141. package/lib/html/HtmlGenerator.js +72 -87
  142. package/lib/html/HtmlModulesPlugin.js +418 -200
  143. package/lib/html/HtmlParser.js +110 -147
  144. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  145. package/lib/html/data.js +142 -7
  146. package/lib/html/htmlMinify.js +92 -122
  147. package/lib/html/syntax.js +1618 -1391
  148. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  149. package/lib/index.js +49 -3
  150. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  151. package/lib/javascript/JavascriptGenerator.js +8 -1
  152. package/lib/javascript/JavascriptModule.js +1 -0
  153. package/lib/javascript/JavascriptModulesPlugin.js +73 -72
  154. package/lib/javascript/JavascriptParser.js +1970 -900
  155. package/lib/javascript/StartupHelpers.js +27 -3
  156. package/lib/javascript/data.js +172 -0
  157. package/lib/javascript/grammar.js +5546 -0
  158. package/lib/javascript/parser.js +1500 -0
  159. package/lib/javascript/regexp.js +1762 -0
  160. package/lib/javascript/regexpData.js +51 -0
  161. package/lib/javascript/syntax.js +9061 -5262
  162. package/lib/json/JsonGenerator.js +7 -1
  163. package/lib/library/ModuleLibraryPlugin.js +171 -132
  164. package/lib/loaders/LoaderRunner.js +137 -9
  165. package/lib/node/NodeWatchFileSystem.js +3 -9
  166. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  167. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  168. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  169. package/lib/optimize/ConcatenatedModule.js +178 -120
  170. package/lib/optimize/ConstExportsPlugin.js +50 -39
  171. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  172. package/lib/optimize/InlineExports.js +20 -123
  173. package/lib/optimize/InnerGraphPlugin.js +7 -13
  174. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  175. package/lib/optimize/MangleExportsPlugin.js +13 -4
  176. package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
  177. package/lib/optimize/RealContentHashPlugin.js +68 -9
  178. package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
  179. package/lib/optimize/SplitChunksPlugin.js +2 -4
  180. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  181. package/lib/performance/BroadContextsPlugin.js +1 -1
  182. package/lib/performance/CacheEffectivenessPlugin.js +7 -7
  183. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  184. package/lib/performance/EvalUsagePlugin.js +5 -2
  185. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  186. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  187. package/lib/performance/SizeLimitsPlugin.js +2 -4
  188. package/lib/performance/TopLevelThisPlugin.js +5 -4
  189. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  190. package/lib/performance/UnusedFederationPlugin.js +147 -0
  191. package/lib/performance/UnusedModulesPlugin.js +141 -0
  192. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  193. package/lib/performance/isOnlyReexported.js +65 -0
  194. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  195. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
  196. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  197. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  198. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  199. package/lib/prefetch/ResourceHintPlugin.js +18 -23
  200. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  201. package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
  202. package/lib/rules/RuleSetCompiler.js +211 -4
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +98 -66
  204. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  205. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  206. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  207. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  208. package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
  209. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  210. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  211. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  212. package/lib/runtime/GlobalRuntimeModule.js +11 -4
  213. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  214. package/lib/runtime/HelperRuntimeModule.js +10 -0
  215. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +305 -224
  216. package/lib/runtime/NonceRuntimeModule.js +9 -0
  217. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  218. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  219. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  220. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  221. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  222. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  223. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  224. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  225. package/lib/schemes/DataUriPlugin.js +3 -6
  226. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  227. package/lib/serialization/BinaryMiddleware.js +9 -9
  228. package/lib/serialization/FileMiddleware.js +16 -16
  229. package/lib/serialization/ObjectMiddleware.js +168 -139
  230. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  231. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  232. package/lib/sharing/ShareRuntimeModule.js +9 -0
  233. package/lib/sharing/declaredShared.js +47 -0
  234. package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
  235. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  236. package/lib/typescript/TypeScriptPlugin.js +2 -3
  237. package/lib/url/URLParserPlugin.js +6 -8
  238. package/lib/util/LocConverter.js +4 -7
  239. package/lib/util/SourceProcessor.js +91 -91
  240. package/lib/util/async.js +292 -0
  241. package/lib/util/buildDiagnostics.js +69 -0
  242. package/lib/util/chainedImports.js +3 -4
  243. package/lib/util/concatenate.js +4 -4
  244. package/lib/util/createHooksRegistry.js +1 -2
  245. package/lib/util/dataURL.js +2 -3
  246. package/lib/util/deterministicGrouping.js +8 -13
  247. package/lib/util/findGraphRoots.js +6 -13
  248. package/lib/util/fs.js +27 -1
  249. package/lib/util/globUtils.js +1 -1
  250. package/lib/util/handlerKeys.js +40 -0
  251. package/lib/util/hash/wasm-hash.js +3 -4
  252. package/lib/util/identifier.js +20 -0
  253. package/lib/util/internalSerializables.js +5 -1
  254. package/lib/util/registerExternalSerializer.js +6 -45
  255. package/lib/util/semver.js +5 -3
  256. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  257. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  258. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  259. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  260. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
  261. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  262. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  263. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  264. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  265. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  266. package/package.json +55 -46
  267. package/schemas/WebpackOptions.check.js +1 -1
  268. package/schemas/WebpackOptions.json +379 -66
  269. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  270. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  271. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  272. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  273. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  274. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  275. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  276. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  277. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  278. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  279. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  280. package/types.d.ts +1723 -604
  281. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  282. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  283. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -0,0 +1,1500 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ // cspell:ignore binop prec Prec stanceof Uncapturing
9
+
10
+ const {
11
+ ASTRAL_IDENTIFIER_PART_RANGES,
12
+ ASTRAL_IDENTIFIER_START_RANGES,
13
+ IDENTIFIER_PART_RANGES,
14
+ IDENTIFIER_START_RANGES
15
+ } = require("./data");
16
+
17
+ /** @typedef {{ label: string, keyword?: string, beforeExpr: boolean, startsExpr: boolean, isLoop: boolean, isAssign: boolean, prefix: boolean, postfix: boolean, binop: number | null, updateContext: ((prevType: TokenType) => void) | null }} TokenTypeShape */
18
+
19
+ /** @typedef {{ line: number, column: number }} PositionLike a position as any caller may state one */
20
+ /** @typedef {{ kind?: string | null, name?: string, statementStart?: number }} LabelLike a label in scope, as any caller may hold one */
21
+ /** @typedef {{ type: string, start: number, end: number, loc?: EXPECTED_ANY, sourceFile?: string, range?: [number, number] }} NodeLike a node as this parser builds one, whichever fields the options asked for */
22
+ /** @typedef {NodeLike & { token: string }} TokenLike */
23
+ /** @typedef {{ token: string, isExpr: boolean, preserveSpace?: boolean, override?: EXPECTED_ANY, generator?: boolean }} TokContextLike a tokenizer context, as the owned tokenizer reads one */
24
+ /** @typedef {import("estree").Identifier & NodeLike} Identifier */
25
+ /** @typedef {import("estree").MetaProperty & NodeLike} MetaProperty */
26
+ /** @typedef {NodeLike & { key: Identifier | (import("estree").Literal & NodeLike), value: import("estree").Literal & NodeLike }} ImportAttribute an import attribute, whose key and value carry offsets like every other node */
27
+ /** @typedef {import("estree").Program & NodeLike} Program */
28
+ /** @typedef {import("estree").ImportExpression & NodeLike} ImportExpression */
29
+ /** @typedef {import("estree").ImportSpecifier & NodeLike} ImportSpecifier */
30
+ /** @typedef {import("estree").ImportDefaultSpecifier & NodeLike} ImportDefaultSpecifier */
31
+ /** @typedef {import("estree").ImportNamespaceSpecifier & NodeLike} ImportNamespaceSpecifier */
32
+ /** @typedef {(import("estree").Expression & NodeLike) | (NodeLike & { type: "ParenthesizedExpression", expression: Expression })} Expression an expression node, including the parenthesized one `preserveParens` asks for */
33
+ /** @typedef {3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025 | 2026 | "latest"} EcmaVersion the ECMAScript versions the parser accepts */
34
+ /** @typedef {(isBlock: boolean, text: string, start: number, end: number, startLoc?: Position | null, endLoc?: Position | null) => void} OnComment what the tokenizer calls for each comment */
35
+ /**
36
+ * @typedef {object} Options what a caller may ask the parser for
37
+ * @property {EcmaVersion} ecmaVersion which edition to parse
38
+ * @property {("script" | "module" | "commonjs")=} sourceType the goal symbol
39
+ * @property {boolean=} strict whether the code is strict whatever it says
40
+ * @property {((lastTokEnd: number, lastTokEndLoc?: Position | null) => void)=} onInsertedSemicolon called where a semicolon was inserted
41
+ * @property {((lastTokEnd: number, lastTokEndLoc?: Position | null) => void)=} onTrailingComma called at a trailing comma
42
+ * @property {(boolean | "never")=} allowReserved whether reserved words may name things
43
+ * @property {boolean=} allowReturnOutsideFunction whether `return` may sit at the top level
44
+ * @property {boolean=} allowImportExportEverywhere whether module syntax may sit anywhere
45
+ * @property {boolean=} allowAwaitOutsideFunction whether `await` may sit outside a function
46
+ * @property {boolean=} allowSuperOutsideMethod whether `super` may sit outside a method
47
+ * @property {boolean=} allowHashBang whether a leading `#!` line is skipped
48
+ * @property {boolean=} checkPrivateFields whether private names must be declared
49
+ * @property {boolean=} locations whether nodes carry `loc`
50
+ * @property {{ line: number, column: number }=} startLocation where the first offset falls
51
+ * @property {(((token: EXPECTED_ANY) => void) | EXPECTED_ANY[])=} onToken where tokens are reported
52
+ * @property {(OnComment | EXPECTED_ANY[])=} onComment where comments are reported
53
+ * @property {boolean=} ranges whether nodes carry `range`
54
+ * @property {NodeLike=} program a program node to append to
55
+ * @property {string=} sourceFile the name errors and locations carry
56
+ * @property {string=} directSourceFile the name every node carries
57
+ * @property {boolean=} preserveParens whether parentheses become nodes
58
+ */
59
+ /**
60
+ * @typedef {object} ResolvedOptions the options once every default is filled in and every alternative spelling is normalized
61
+ * @property {number} ecmaVersion the edition, as the number the parser compares against
62
+ * @property {"script" | "module" | "commonjs"} sourceType the goal symbol
63
+ * @property {boolean} strict whether the code is strict whatever it says
64
+ * @property {((lastTokEnd: number, lastTokEndLoc?: Position | null) => void) | null} onInsertedSemicolon called where a semicolon was inserted
65
+ * @property {((lastTokEnd: number, lastTokEndLoc?: Position | null) => void) | null} onTrailingComma called at a trailing comma
66
+ * @property {boolean | "never"} allowReserved whether reserved words may name things
67
+ * @property {boolean} allowReturnOutsideFunction whether `return` may sit at the top level
68
+ * @property {boolean} allowImportExportEverywhere whether module syntax may sit anywhere
69
+ * @property {boolean} allowAwaitOutsideFunction whether `await` may sit outside a function
70
+ * @property {boolean} allowSuperOutsideMethod whether `super` may sit outside a method
71
+ * @property {boolean} allowHashBang whether a leading `#!` line is skipped
72
+ * @property {boolean} checkPrivateFields whether private names must be declared
73
+ * @property {boolean} locations whether nodes carry `loc`
74
+ * @property {{ line: number, column: number } | null} startLocation where the first offset falls
75
+ * @property {((token: EXPECTED_ANY) => void) | null} onToken where tokens are reported
76
+ * @property {OnComment | null} onComment where comments are reported
77
+ * @property {boolean} ranges whether nodes carry `range`
78
+ * @property {NodeLike | null} program a program node to append to
79
+ * @property {string | null} sourceFile the name errors and locations carry
80
+ * @property {string | null} directSourceFile the name every node carries
81
+ * @property {boolean} preserveParens whether parentheses become nodes
82
+ */
83
+
84
+ // The first code point above the Basic Multilingual Plane, where the surrogate
85
+ // pairs the astral tables describe begin.
86
+ const FIRST_ASTRAL = 0x10000;
87
+
88
+ /**
89
+ * Decode one run-length table into flat `[start, end)` bounds. Kept until the
90
+ * first non-ASCII classification asks for it, which most builds never do.
91
+ * @param {number[]} ranges gap-and-length pairs
92
+ * @param {number} base the code point the first gap counts from
93
+ * @returns {Uint32Array} the bounds, ascending and non-overlapping
94
+ */
95
+ const decodeRanges = (ranges, base) => {
96
+ const bounds = new Uint32Array(ranges.length);
97
+ let position = base;
98
+ for (let i = 0; i < ranges.length; i += 2) {
99
+ position += ranges[i];
100
+ bounds[i] = position;
101
+ position += ranges[i + 1];
102
+ bounds[i + 1] = position;
103
+ }
104
+ return bounds;
105
+ };
106
+
107
+ /** @type {Uint32Array | null} */
108
+ let identifierStartBounds = null;
109
+ /** @type {Uint32Array | null} */
110
+ let identifierPartBounds = null;
111
+ /** @type {Uint32Array | null} */
112
+ let astralStartBounds = null;
113
+ /** @type {Uint32Array | null} */
114
+ let astralPartBounds = null;
115
+
116
+ /**
117
+ * Binary search over flat `[start, end)` bounds. Both tests are written to
118
+ * answer `false` for a `NaN` code, which is what `charCodeAt` past the end is.
119
+ * @param {Uint32Array} bounds the decoded table
120
+ * @param {number} code the code point to classify
121
+ * @returns {boolean} whether a range covers it
122
+ */
123
+ const inRanges = (bounds, code) => {
124
+ let low = 0;
125
+ let high = (bounds.length >> 1) - 1;
126
+ while (low <= high) {
127
+ const middle = (low + high) >> 1;
128
+ const index = middle << 1;
129
+ if (code >= bounds[index + 1]) low = middle + 1;
130
+ else if (code >= bounds[index]) return true;
131
+ else high = middle - 1;
132
+ }
133
+ return false;
134
+ };
135
+
136
+ /**
137
+ * Whether a code point can start an identifier, matching acorn's tables.
138
+ * @param {number} code the code point
139
+ * @param {boolean=} astral whether code points above the BMP may match
140
+ * @returns {boolean} whether it can start an identifier
141
+ */
142
+ const isIdentifierStart = (code, astral) => {
143
+ if (code < 65) return code === 36;
144
+ if (code < 91) return true;
145
+ if (code < 97) return code === 95;
146
+ if (code < 123) return true;
147
+ if (code <= 0xffff) {
148
+ if (code < 0xaa) return false;
149
+ if (identifierStartBounds === null) {
150
+ identifierStartBounds = decodeRanges(IDENTIFIER_START_RANGES, 0x80);
151
+ }
152
+ return inRanges(identifierStartBounds, code);
153
+ }
154
+ if (astral === false) return false;
155
+ if (astralStartBounds === null) {
156
+ astralStartBounds = decodeRanges(
157
+ ASTRAL_IDENTIFIER_START_RANGES,
158
+ FIRST_ASTRAL
159
+ );
160
+ }
161
+ return inRanges(astralStartBounds, code);
162
+ };
163
+
164
+ /**
165
+ * Whether a code point can continue an identifier, matching acorn's tables.
166
+ * @param {number} code the code point
167
+ * @param {boolean=} astral whether code points above the BMP may match
168
+ * @returns {boolean} whether it can continue an identifier
169
+ */
170
+ const isIdentifierChar = (code, astral) => {
171
+ if (code < 48) return code === 36;
172
+ if (code < 58) return true;
173
+ if (code < 65) return false;
174
+ if (code < 91) return true;
175
+ if (code < 97) return code === 95;
176
+ if (code < 123) return true;
177
+ if (code <= 0xffff) {
178
+ if (code < 0xaa) return false;
179
+ if (identifierPartBounds === null) {
180
+ identifierPartBounds = decodeRanges(IDENTIFIER_PART_RANGES, 0x80);
181
+ }
182
+ return inRanges(identifierPartBounds, code);
183
+ }
184
+ if (astral === false) return false;
185
+ if (astralPartBounds === null) {
186
+ astralPartBounds = decodeRanges(
187
+ ASTRAL_IDENTIFIER_PART_RANGES,
188
+ FIRST_ASTRAL
189
+ );
190
+ }
191
+ return inRanges(astralPartBounds, code);
192
+ };
193
+
194
+ // A whole line break, where CRLF counts as one.
195
+ const lineBreak = /\r\n?|\n|\u2028|\u2029/;
196
+ const lineBreakG = new RegExp(lineBreak.source, "g");
197
+ const nonASCIIwhitespace = /[\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]/;
198
+ const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
199
+
200
+ /**
201
+ * @param {number} code the code point
202
+ * @returns {boolean} whether it terminates a line
203
+ */
204
+ const isNewLine = (code) =>
205
+ code === 10 || code === 13 || code === 0x2028 || code === 0x2029;
206
+
207
+ /**
208
+ * The offset just past the next line break at or after `from`.
209
+ * @param {string} code the source text
210
+ * @param {number} from where to start looking
211
+ * @param {number=} end where to stop looking
212
+ * @returns {number} the offset, or `-1` when there is no break
213
+ */
214
+ const nextLineBreak = (code, from, end) => {
215
+ const limit = end === undefined ? code.length : end;
216
+ for (let i = from; i < limit; i++) {
217
+ const next = code.charCodeAt(i);
218
+ if (isNewLine(next)) {
219
+ return i < limit - 1 && next === 13 && code.charCodeAt(i + 1) === 10
220
+ ? i + 2
221
+ : i + 1;
222
+ }
223
+ }
224
+ return -1;
225
+ };
226
+
227
+ /** @type {Record<string, RegExp>} */
228
+ const regexpCache = Object.create(null);
229
+
230
+ /**
231
+ * A cached `^(?:a|b|…)$` matcher for a space-separated word list.
232
+ * @param {string} words the list
233
+ * @returns {RegExp} the matcher
234
+ */
235
+ const wordsRegexp = (words) => {
236
+ const cached = regexpCache[words];
237
+ if (cached !== undefined) return cached;
238
+ const built = new RegExp(`^(?:${words.replace(/ /g, "|")})$`);
239
+ regexpCache[words] = built;
240
+ return built;
241
+ };
242
+
243
+ /**
244
+ * @param {number} code a code point
245
+ * @returns {string} the string for it, encoded as UTF-16
246
+ */
247
+ const codePointToString = (code) => {
248
+ if (code <= 0xffff) return String.fromCharCode(code);
249
+ const rest = code - 0x10000;
250
+ return String.fromCharCode((rest >> 10) + 0xd800, (rest & 1023) + 0xdc00);
251
+ };
252
+
253
+ // Reserved word lists for the dialects the parser accepts.
254
+ const reservedWords = {
255
+ 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
256
+ 5: "class enum extends super const export import",
257
+ 6: "enum",
258
+ strict:
259
+ "implements interface let package private protected public static yield",
260
+ strictBind: "eval arguments"
261
+ };
262
+
263
+ const ecma5AndLessKeywords =
264
+ "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
265
+
266
+ const keywordLists = {
267
+ 5: ecma5AndLessKeywords,
268
+ "5module": `${ecma5AndLessKeywords} export import`,
269
+ 6: `${ecma5AndLessKeywords} const class extends export import super`
270
+ };
271
+
272
+ /**
273
+ * A token's kind, carrying what the parser needs to know about it without
274
+ * re-inspecting the source: whether an expression may follow, its binary
275
+ * precedence, and how it updates the tokenizer's context.
276
+ */
277
+ class TokenType {
278
+ /**
279
+ * @param {string} label how the token prints in errors
280
+ * @param {{ keyword?: string, beforeExpr?: boolean, startsExpr?: boolean, isLoop?: boolean, isAssign?: boolean, prefix?: boolean, postfix?: boolean, binop?: number }=} conf what the token allows
281
+ */
282
+ constructor(label, conf) {
283
+ const options = conf || {};
284
+ this.label = label;
285
+ this.keyword = options.keyword;
286
+ this.beforeExpr = Boolean(options.beforeExpr);
287
+ this.startsExpr = Boolean(options.startsExpr);
288
+ this.isLoop = Boolean(options.isLoop);
289
+ this.isAssign = Boolean(options.isAssign);
290
+ this.prefix = Boolean(options.prefix);
291
+ this.postfix = Boolean(options.postfix);
292
+ this.binop = options.binop || null;
293
+ /** @type {((prevType: TokenType) => void) | null} */
294
+ this.updateContext = null;
295
+ }
296
+ }
297
+
298
+ /**
299
+ * @param {string} name how the operator prints
300
+ * @param {number} prec its binary precedence
301
+ * @returns {TokenType} the token type
302
+ */
303
+ const binop = (name, prec) =>
304
+ new TokenType(name, { beforeExpr: true, binop: prec });
305
+
306
+ const beforeExpr = { beforeExpr: true };
307
+ const startsExpr = { startsExpr: true };
308
+
309
+ /** @type {Record<string, TokenType>} */
310
+ const keywordTypes = {};
311
+
312
+ /**
313
+ * Define a keyword's token type and record it under its name.
314
+ * @param {string} name the keyword
315
+ * @param {{ beforeExpr?: boolean, startsExpr?: boolean, isLoop?: boolean, prefix?: boolean, binop?: number }=} options what the keyword allows
316
+ * @returns {TokenType} the token type
317
+ */
318
+ const kw = (name, options) => {
319
+ const conf = { ...options, keyword: name };
320
+ const type = new TokenType(name, conf);
321
+ keywordTypes[name] = type;
322
+ return type;
323
+ };
324
+
325
+ const tokTypes = {
326
+ num: new TokenType("num", startsExpr),
327
+ regexp: new TokenType("regexp", startsExpr),
328
+ string: new TokenType("string", startsExpr),
329
+ name: new TokenType("name", startsExpr),
330
+ privateId: new TokenType("privateId", startsExpr),
331
+ eof: new TokenType("eof"),
332
+
333
+ bracketL: new TokenType("[", { beforeExpr: true, startsExpr: true }),
334
+ bracketR: new TokenType("]"),
335
+ braceL: new TokenType("{", { beforeExpr: true, startsExpr: true }),
336
+ braceR: new TokenType("}"),
337
+ parenL: new TokenType("(", { beforeExpr: true, startsExpr: true }),
338
+ parenR: new TokenType(")"),
339
+ comma: new TokenType(",", beforeExpr),
340
+ semi: new TokenType(";", beforeExpr),
341
+ colon: new TokenType(":", beforeExpr),
342
+ dot: new TokenType("."),
343
+ question: new TokenType("?", beforeExpr),
344
+ questionDot: new TokenType("?."),
345
+ arrow: new TokenType("=>", beforeExpr),
346
+ template: new TokenType("template"),
347
+ invalidTemplate: new TokenType("invalidTemplate"),
348
+ ellipsis: new TokenType("...", beforeExpr),
349
+ backQuote: new TokenType("`", startsExpr),
350
+ dollarBraceL: new TokenType("${", { beforeExpr: true, startsExpr: true }),
351
+
352
+ eq: new TokenType("=", { beforeExpr: true, isAssign: true }),
353
+ assign: new TokenType("_=", { beforeExpr: true, isAssign: true }),
354
+ incDec: new TokenType("++/--", {
355
+ prefix: true,
356
+ postfix: true,
357
+ startsExpr: true
358
+ }),
359
+ prefix: new TokenType("!/~", {
360
+ beforeExpr: true,
361
+ prefix: true,
362
+ startsExpr: true
363
+ }),
364
+ logicalOR: binop("||", 1),
365
+ logicalAND: binop("&&", 2),
366
+ bitwiseOR: binop("|", 3),
367
+ bitwiseXOR: binop("^", 4),
368
+ bitwiseAND: binop("&", 5),
369
+ equality: binop("==/!=/===/!==", 6),
370
+ relational: binop("</>/<=/>=", 7),
371
+ bitShift: binop("<</>>/>>>", 8),
372
+ plusMin: new TokenType("+/-", {
373
+ beforeExpr: true,
374
+ binop: 9,
375
+ prefix: true,
376
+ startsExpr: true
377
+ }),
378
+ modulo: binop("%", 10),
379
+ star: binop("*", 10),
380
+ slash: binop("/", 10),
381
+ starstar: new TokenType("**", { beforeExpr: true }),
382
+ coalesce: binop("??", 1),
383
+
384
+ _break: kw("break"),
385
+ _case: kw("case", beforeExpr),
386
+ _catch: kw("catch"),
387
+ _continue: kw("continue"),
388
+ _debugger: kw("debugger"),
389
+ _default: kw("default", beforeExpr),
390
+ _do: kw("do", { isLoop: true, beforeExpr: true }),
391
+ _else: kw("else", beforeExpr),
392
+ _finally: kw("finally"),
393
+ _for: kw("for", { isLoop: true }),
394
+ _function: kw("function", startsExpr),
395
+ _if: kw("if"),
396
+ _return: kw("return", beforeExpr),
397
+ _switch: kw("switch"),
398
+ _throw: kw("throw", beforeExpr),
399
+ _try: kw("try"),
400
+ _var: kw("var"),
401
+ _const: kw("const"),
402
+ _while: kw("while", { isLoop: true }),
403
+ _with: kw("with"),
404
+ _new: kw("new", { beforeExpr: true, startsExpr: true }),
405
+ _this: kw("this", startsExpr),
406
+ _super: kw("super", startsExpr),
407
+ _class: kw("class", startsExpr),
408
+ _extends: kw("extends", beforeExpr),
409
+ _export: kw("export"),
410
+ _import: kw("import", startsExpr),
411
+ _null: kw("null", startsExpr),
412
+ _true: kw("true", startsExpr),
413
+ _false: kw("false", startsExpr),
414
+ _in: kw("in", { beforeExpr: true, binop: 7 }),
415
+ _instanceof: kw("instanceof", { beforeExpr: true, binop: 7 }),
416
+ _typeof: kw("typeof", { beforeExpr: true, prefix: true, startsExpr: true }),
417
+ _void: kw("void", { beforeExpr: true, prefix: true, startsExpr: true }),
418
+ _delete: kw("delete", { beforeExpr: true, prefix: true, startsExpr: true })
419
+ };
420
+
421
+ /**
422
+ * A tokenizer context: what kind of brace, paren or template the tokenizer is
423
+ * inside, which decides how the next `/` or `}` reads.
424
+ */
425
+ class TokContext {
426
+ /**
427
+ * @param {string} token the opening token
428
+ * @param {boolean} isExpr whether the context holds an expression
429
+ * @param {boolean=} preserveSpace whether whitespace is significant inside
430
+ * @param {((parser: EXPECTED_ANY) => void)=} override how to read the next token
431
+ * @param {boolean=} generator whether the enclosing function is a generator
432
+ */
433
+ constructor(token, isExpr, preserveSpace, override, generator) {
434
+ this.token = token;
435
+ this.isExpr = Boolean(isExpr);
436
+ this.preserveSpace = Boolean(preserveSpace);
437
+ this.override = override;
438
+ this.generator = Boolean(generator);
439
+ }
440
+ }
441
+
442
+ const tokContexts = {
443
+ b_stat: new TokContext("{", false),
444
+ b_expr: new TokContext("{", true),
445
+ b_tmpl: new TokContext("${", false),
446
+ p_stat: new TokContext("(", false),
447
+ p_expr: new TokContext("(", true),
448
+ q_tmpl: new TokContext("`", true, true, (parser) =>
449
+ parser.tryReadTemplateToken()
450
+ ),
451
+ f_stat: new TokContext("function", false),
452
+ f_expr: new TokContext("function", true),
453
+ f_expr_gen: new TokContext("function", true, false, undefined, true),
454
+ f_gen: new TokContext("function", false, false, undefined, true)
455
+ };
456
+
457
+ /** A `{ line, column }` pair, as `options.locations` reports one. */
458
+ class Position {
459
+ /**
460
+ * @param {number} line one-based line number
461
+ * @param {number} col zero-based column
462
+ */
463
+ constructor(line, col) {
464
+ this.line = line;
465
+ this.column = col;
466
+ }
467
+
468
+ /**
469
+ * @param {number} n how far to move along the line
470
+ * @returns {Position} the shifted position
471
+ */
472
+ offset(n) {
473
+ return new Position(this.line, this.column + n);
474
+ }
475
+ }
476
+
477
+ /** The `loc` a node carries when `options.locations` is on. */
478
+ class SourceLocation {
479
+ /**
480
+ * @param {EXPECTED_ANY} p the parser, for its `sourceFile`
481
+ * @param {PositionLike | null | undefined} start where the node starts
482
+ * @param {PositionLike | null | undefined} end where it ends
483
+ */
484
+ constructor(p, start, end) {
485
+ this.start = start;
486
+ this.end = end;
487
+ if (p.sourceFile !== null) this.source = p.sourceFile;
488
+ }
489
+ }
490
+
491
+ /**
492
+ * The line and column an offset falls on, for callers that parsed without
493
+ * `options.locations`.
494
+ * @param {string} input the source text
495
+ * @param {number} offset the offset to locate
496
+ * @returns {Position} where it falls
497
+ */
498
+ const getLineInfo = (input, offset) => {
499
+ let line = 1;
500
+ let cur = 0;
501
+ for (;;) {
502
+ const nextBreak = nextLineBreak(input, cur, offset);
503
+ if (nextBreak < 0) return new Position(line, offset - cur);
504
+ ++line;
505
+ cur = nextBreak;
506
+ }
507
+ };
508
+
509
+ const defaultOptions = {
510
+ ecmaVersion: null,
511
+ sourceType: "script",
512
+ strict: false,
513
+ onInsertedSemicolon: null,
514
+ onTrailingComma: null,
515
+ allowReserved: null,
516
+ allowReturnOutsideFunction: false,
517
+ allowImportExportEverywhere: false,
518
+ allowAwaitOutsideFunction: null,
519
+ allowSuperOutsideMethod: null,
520
+ allowHashBang: false,
521
+ checkPrivateFields: true,
522
+ locations: false,
523
+ startLocation: null,
524
+ onToken: null,
525
+ onComment: null,
526
+ ranges: false,
527
+ program: null,
528
+ sourceFile: null,
529
+ directSourceFile: null,
530
+ preserveParens: false
531
+ };
532
+
533
+ /**
534
+ * Turn an `onComment` array into the callback the tokenizer calls.
535
+ * @param {EXPECTED_ANY} options the normalized options
536
+ * @param {EXPECTED_ANY[]} array where to push each comment
537
+ * @returns {EXPECTED_ANY} the callback
538
+ */
539
+ const pushComment = (options, array) =>
540
+ /**
541
+ * @this {EXPECTED_ANY}
542
+ * @param {boolean} block whether it is a block comment
543
+ * @param {string} text its text
544
+ * @param {number} start where it starts
545
+ * @param {number} end where it ends
546
+ * @param {Position=} startLoc its start position
547
+ * @param {Position=} endLoc its end position
548
+ * @returns {void}
549
+ */
550
+ function pushOneComment(block, text, start, end, startLoc, endLoc) {
551
+ /** @type {EXPECTED_ANY} */
552
+ const comment = {
553
+ type: block ? "Block" : "Line",
554
+ value: text,
555
+ start,
556
+ end
557
+ };
558
+ if (options.locations) {
559
+ comment.loc = new SourceLocation(this, startLoc, endLoc);
560
+ }
561
+ if (options.ranges) comment.range = [start, end];
562
+ array.push(comment);
563
+ };
564
+
565
+ let warnedAboutEcmaVersion = false;
566
+
567
+ /** @type {typeof import("./grammar") | undefined} */
568
+ let grammarModule;
569
+
570
+ /**
571
+ * The methods `Parser` defines only as stubs that load the grammar on first
572
+ * use; the grammar's own take their slots once it is installed.
573
+ * @type {(string | symbol)[]}
574
+ */
575
+ const GRAMMAR_STUBS = ["parse", "parseExpression", "getToken", Symbol.iterator];
576
+
577
+ /**
578
+ * Copy the grammar onto `Parser.prototype`, once. `lib/javascript/syntax.js`
579
+ * serves every production a webpack build reaches, so the grammar stays
580
+ * unloaded unless something asks this parser to parse.
581
+ * @returns {typeof import("./grammar")} the grammar module
582
+ */
583
+ const installGrammar = () => {
584
+ if (grammarModule !== undefined) return grammarModule;
585
+
586
+ // held here so a stub never pays the module loader's lookup per token
587
+ const loaded = require("./grammar");
588
+
589
+ loaded.install(Parser);
590
+ // a stub left in place would still delegate on every token
591
+ for (const name of GRAMMAR_STUBS) {
592
+ /** @type {EXPECTED_ANY} */ (Parser.prototype)[name] =
593
+ /** @type {EXPECTED_ANY} */ (loaded.Grammar.prototype)[name];
594
+ }
595
+ grammarModule = loaded;
596
+ return loaded;
597
+ };
598
+
599
+ /**
600
+ * Fill in every option the parser reads, and normalize the two that are stated
601
+ * in more than one way: `ecmaVersion` as a year, and array comment sinks.
602
+ * @param {Partial<Options> | null | undefined} opts what the caller passed
603
+ * @returns {ResolvedOptions} the normalized options
604
+ */
605
+ const getOptions = (opts) => {
606
+ /** @type {EXPECTED_ANY} */
607
+ const options = {};
608
+ for (const opt of Object.keys(defaultOptions)) {
609
+ options[opt] =
610
+ opts && Object.prototype.hasOwnProperty.call(opts, opt)
611
+ ? /** @type {EXPECTED_ANY} */ (opts)[opt]
612
+ : /** @type {EXPECTED_ANY} */ (defaultOptions)[opt];
613
+ }
614
+
615
+ if (options.ecmaVersion === "latest") {
616
+ options.ecmaVersion = 1e8;
617
+ } else if (
618
+ options.ecmaVersion === null ||
619
+ options.ecmaVersion === undefined
620
+ ) {
621
+ if (
622
+ !warnedAboutEcmaVersion &&
623
+ typeof console === "object" &&
624
+ // eslint-disable-next-line no-console
625
+ console.warn
626
+ ) {
627
+ warnedAboutEcmaVersion = true;
628
+ // eslint-disable-next-line no-console
629
+ console.warn(
630
+ "Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future."
631
+ );
632
+ }
633
+ options.ecmaVersion = 11;
634
+ } else if (options.ecmaVersion >= 2015) {
635
+ options.ecmaVersion -= 2009;
636
+ }
637
+
638
+ if (options.allowReserved === null || options.allowReserved === undefined) {
639
+ options.allowReserved = options.ecmaVersion < 5;
640
+ }
641
+
642
+ if (
643
+ !opts ||
644
+ opts.allowHashBang === null ||
645
+ opts.allowHashBang === undefined
646
+ ) {
647
+ options.allowHashBang = options.ecmaVersion >= 14;
648
+ }
649
+
650
+ if (Array.isArray(options.onToken)) {
651
+ const tokens = options.onToken;
652
+ options.onToken = (/** @type {EXPECTED_ANY} */ token) => tokens.push(token);
653
+ }
654
+ if (Array.isArray(options.onComment)) {
655
+ options.onComment = pushComment(options, options.onComment);
656
+ }
657
+
658
+ if (options.sourceType === "commonjs" && options.allowAwaitOutsideFunction) {
659
+ throw new Error(
660
+ "Cannot use allowAwaitOutsideFunction with sourceType: commonjs"
661
+ );
662
+ }
663
+
664
+ return /** @type {ResolvedOptions} */ (options);
665
+ };
666
+
667
+ // Each scope gets a bitset that may contain these flags.
668
+ const SCOPE_TOP = 1;
669
+ const SCOPE_FUNCTION = 2;
670
+ const SCOPE_ASYNC = 4;
671
+ const SCOPE_GENERATOR = 8;
672
+ const SCOPE_ARROW = 16;
673
+ const SCOPE_SIMPLE_CATCH = 32;
674
+ const SCOPE_SUPER = 64;
675
+ const SCOPE_DIRECT_SUPER = 128;
676
+ const SCOPE_CLASS_STATIC_BLOCK = 256;
677
+ const SCOPE_CLASS_FIELD_INIT = 512;
678
+ const SCOPE_SWITCH = 1024;
679
+ const SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK;
680
+
681
+ /**
682
+ * @param {boolean} async whether the function is async
683
+ * @param {boolean} generator whether it is a generator
684
+ * @returns {number} the scope flags for its body
685
+ */
686
+ const functionFlags = (async, generator) =>
687
+ SCOPE_FUNCTION |
688
+ (async ? SCOPE_ASYNC : 0) |
689
+ (generator ? SCOPE_GENERATOR : 0);
690
+
691
+ // What kind of binding a name introduces, for `checkLVal*` and `declareName`.
692
+ const BIND_NONE = 0;
693
+ const BIND_VAR = 1;
694
+ const BIND_LEXICAL = 2;
695
+ const BIND_FUNCTION = 3;
696
+ const BIND_SIMPLE_CATCH = 4;
697
+ const BIND_OUTSIDE = 5;
698
+
699
+ /**
700
+ * One lexical scope, holding the names declared directly in it. Each set is
701
+ * built only once a name goes into it, which most scopes never do.
702
+ */
703
+ class Scope {
704
+ /**
705
+ * @param {number} flags what kind of scope it is
706
+ */
707
+ constructor(flags) {
708
+ this.flags = flags;
709
+ /** @type {Set<string> | undefined} */
710
+ this.var = undefined;
711
+ /** @type {Set<string> | undefined} */
712
+ this.lexical = undefined;
713
+ /** @type {Set<string> | undefined} */
714
+ this.functions = undefined;
715
+ // The scope's first lexical name: a simple catch scope's parameter, and
716
+ // the only element of `lexical` that anything reads by position.
717
+ /** @type {string | undefined} */
718
+ this.firstLexical = undefined;
719
+ // WHY: the declarations that hoist to this scope, in source order, kept
720
+ // for the consumer that would otherwise re-walk every statement to find
721
+ // them again. Only a var scope fills it; `exitScope` hands it to the
722
+ // node that owns the scope and clears the slot before pooling.
723
+ /** @type {(NodeLike | number)[] | undefined} */
724
+ this.hoisted = undefined;
725
+ }
726
+ }
727
+
728
+ /** An ESTree node, as this parser builds one. */
729
+ class Node {
730
+ /**
731
+ * @param {Parser} parser the parser building it
732
+ * @param {number} pos where the node starts
733
+ * @param {Position=} loc the start position, when locations are tracked
734
+ */
735
+ constructor(parser, pos, loc) {
736
+ this.type = "";
737
+ this.start = pos;
738
+ this.end = 0;
739
+ if (parser.options.locations) {
740
+ this.loc = new SourceLocation(
741
+ parser,
742
+ /** @type {Position} */ (loc),
743
+ /** @type {EXPECTED_ANY} */ (undefined)
744
+ );
745
+ }
746
+ if (parser.options.directSourceFile) {
747
+ this.sourceFile = parser.options.directSourceFile;
748
+ }
749
+ if (parser.options.ranges) this.range = [pos, 0];
750
+ }
751
+ }
752
+
753
+ /** A token as `options.onToken` receives one. */
754
+ class Token {
755
+ /**
756
+ * @param {EXPECTED_ANY} p the parser, read at its current token
757
+ */
758
+ constructor(p) {
759
+ this.type = p.type;
760
+ this.value = p.value;
761
+ this.start = p.start;
762
+ this.end = p.end;
763
+ if (p.options.locations) {
764
+ this.loc = new SourceLocation(p, p.startLoc, p.endLoc);
765
+ }
766
+ if (p.options.ranges) this.range = [p.start, p.end];
767
+ }
768
+ }
769
+
770
+ /**
771
+ * Where a shorthand assignment, trailing comma or parenthesized pattern was
772
+ * seen, so the expression parser can raise once it knows whether it is
773
+ * parsing an expression or a binding pattern.
774
+ */
775
+ class DestructuringErrors {
776
+ constructor() {
777
+ this.shorthandAssign = -1;
778
+ this.trailingComma = -1;
779
+ this.parenthesizedAssign = -1;
780
+ this.parenthesizedBind = -1;
781
+ this.doubleProto = -1;
782
+ }
783
+ }
784
+
785
+ /** A label in scope, and what may jump to it. */
786
+ class Label {
787
+ /**
788
+ * @param {string | null} kind what the label names
789
+ * @param {string=} name the label's own name
790
+ * @param {number=} statementStart where the labelled statement starts
791
+ */
792
+ constructor(kind, name, statementStart) {
793
+ /** @type {string | null | undefined} */
794
+ this.kind = kind;
795
+ /** @type {string | undefined} */
796
+ this.name = name;
797
+ /** @type {number | undefined} */
798
+ this.statementStart = statementStart;
799
+ }
800
+ }
801
+
802
+ // How a function declaration was reached, which decides whether it may be
803
+ // unnamed and whether its name binds in the enclosing scope.
804
+
805
+ // A directive prologue entry, used to spot `"use strict"` before parsing.
806
+ const literalDirective = /^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/;
807
+
808
+ /**
809
+ * The ECMAScript parser webpack owns, ported from acorn 8.18.0 so the bundler
810
+ * ships no parser dependency. `lib/javascript/syntax.js` subclasses it and
811
+ * overrides the hot paths.
812
+ * acorn source: https://github.com/acornjs/acorn/blob/8.18.0/acorn/src/state.js
813
+ */
814
+ class Parser {
815
+ /**
816
+ * @param {Partial<Options> | null | undefined} options parser options
817
+ * @param {string} input the source text
818
+ * @param {number=} startPos offset to start at
819
+ */
820
+ constructor(options, input, startPos) {
821
+ const resolved = getOptions(options);
822
+ this.options = resolved;
823
+ this.sourceFile = resolved.sourceFile;
824
+ this.keywords = wordsRegexp(
825
+ /** @type {EXPECTED_ANY} */ (keywordLists)[
826
+ resolved.ecmaVersion >= 6
827
+ ? 6
828
+ : resolved.sourceType === "module"
829
+ ? "5module"
830
+ : 5
831
+ ]
832
+ );
833
+ let reserved = "";
834
+ if (resolved.allowReserved !== true) {
835
+ reserved = /** @type {EXPECTED_ANY} */ (reservedWords)[
836
+ resolved.ecmaVersion >= 6 ? 6 : resolved.ecmaVersion === 5 ? 5 : 3
837
+ ];
838
+ if (resolved.sourceType === "module") reserved += " await";
839
+ }
840
+ this.reservedWords = wordsRegexp(reserved);
841
+ const reservedStrict = `${reserved ? `${reserved} ` : ""}${reservedWords.strict}`;
842
+ this.reservedWordsStrict = wordsRegexp(reservedStrict);
843
+ this.reservedWordsStrictBind = wordsRegexp(
844
+ `${reservedStrict} ${reservedWords.strictBind}`
845
+ );
846
+ this.input = String(input);
847
+
848
+ // Whether the last `readWord1` saw an escape, which stops a word from
849
+ // reading as a keyword.
850
+ this.containsEsc = false;
851
+
852
+ this.pos = startPos || 0;
853
+ this.curLine = 1;
854
+ if (resolved.startLocation) {
855
+ this.lineStart = this.pos - resolved.startLocation.column;
856
+ this.curLine = resolved.startLocation.line;
857
+ } else if (startPos) {
858
+ this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
859
+ if (resolved.locations) {
860
+ this.curLine = this.input
861
+ .slice(0, this.lineStart)
862
+ .split(lineBreak).length;
863
+ }
864
+ } else {
865
+ this.lineStart = 0;
866
+ }
867
+
868
+ this.type = tokTypes.eof;
869
+ /** @type {EXPECTED_ANY} */
870
+ this.value = null;
871
+ // acorn writes each pair through one chained assignment, so the second
872
+ // name of each is the slot created first
873
+ this.end = this.pos;
874
+ this.start = this.pos;
875
+ /** @type {Position | undefined} */
876
+ this.endLoc = this.curPosition();
877
+ /** @type {Position | undefined} */
878
+ this.startLoc = this.endLoc;
879
+
880
+ /** @type {Position | null | undefined} */
881
+ this.lastTokStartLoc = null;
882
+ /** @type {Position | null | undefined} */
883
+ this.lastTokEndLoc = null;
884
+ this.lastTokEnd = this.pos;
885
+ this.lastTokStart = this.pos;
886
+
887
+ // Enough syntactic context to tell a regexp apart from a division.
888
+ /** @type {TokContextLike[]} */
889
+ this.context = this.initialContext();
890
+ this.exprAllowed = true;
891
+
892
+ this.inModule = resolved.sourceType === "module";
893
+ this.strict =
894
+ this.inModule ||
895
+ resolved.strict === true ||
896
+ this.strictDirective(this.pos);
897
+
898
+ this.potentialArrowAt = -1;
899
+ this.potentialArrowInForAwait = false;
900
+
901
+ // Where a `yield`/`await` was seen, to check once it is known whether the
902
+ // surrounding parameters were defaults.
903
+ this.awaitIdentPos = 0;
904
+ this.awaitPos = 0;
905
+ this.yieldPos = 0;
906
+ /** @type {LabelLike[]} */
907
+ this.labels = [];
908
+ /** @type {Record<string, NodeLike>} */
909
+ this.undefinedExports = Object.create(null);
910
+
911
+ if (
912
+ this.pos === 0 &&
913
+ resolved.allowHashBang &&
914
+ this.input.slice(0, 2) === "#!"
915
+ ) {
916
+ this.skipLineComment(2);
917
+ }
918
+
919
+ /** @type {Scope[]} */
920
+ this.scopeStack = [];
921
+ this.enterScope(
922
+ resolved.sourceType === "commonjs" ? SCOPE_FUNCTION : SCOPE_TOP
923
+ );
924
+
925
+ /** @type {import("./regexp").RegExpValidationState | null} */
926
+ this.regexpState = null;
927
+
928
+ /** @type {EXPECTED_ANY[]} */
929
+ this.privateNameStack = [];
930
+ }
931
+
932
+ /** @returns {boolean} whether the innermost var scope is a function */
933
+ get inFunction() {
934
+ return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0;
935
+ }
936
+
937
+ /** @returns {boolean} whether the innermost var scope is a generator */
938
+ get inGenerator() {
939
+ return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0;
940
+ }
941
+
942
+ /** @returns {boolean} whether the innermost var scope is async */
943
+ get inAsync() {
944
+ return (this.currentVarScope().flags & SCOPE_ASYNC) > 0;
945
+ }
946
+
947
+ /** @returns {boolean} whether `await` is an operator here */
948
+ get canAwait() {
949
+ for (let i = this.scopeStack.length - 1; i >= 0; i--) {
950
+ const { flags } = this.scopeStack[i];
951
+ if (flags & (SCOPE_CLASS_STATIC_BLOCK | SCOPE_CLASS_FIELD_INIT)) {
952
+ return false;
953
+ }
954
+ if (flags & SCOPE_FUNCTION) return (flags & SCOPE_ASYNC) > 0;
955
+ }
956
+ return Boolean(
957
+ (this.inModule && this.options.ecmaVersion >= 13) ||
958
+ this.options.allowAwaitOutsideFunction
959
+ );
960
+ }
961
+
962
+ /** @returns {boolean} whether `return` is allowed here */
963
+ get allowReturn() {
964
+ if (this.inFunction) return true;
965
+ if (
966
+ this.options.allowReturnOutsideFunction &&
967
+ this.currentVarScope().flags & SCOPE_TOP
968
+ ) {
969
+ return true;
970
+ }
971
+ return false;
972
+ }
973
+
974
+ /** @returns {boolean} whether `super` may be referenced here */
975
+ get allowSuper() {
976
+ const { flags } = this.currentThisScope();
977
+ return Boolean(
978
+ (flags & SCOPE_SUPER) > 0 || this.options.allowSuperOutsideMethod
979
+ );
980
+ }
981
+
982
+ /** @returns {boolean} whether `super()` may be called here */
983
+ get allowDirectSuper() {
984
+ return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0;
985
+ }
986
+
987
+ /** @returns {boolean | number} whether function declarations bind like `var` here */
988
+ get treatFunctionsAsVar() {
989
+ return this.treatFunctionsAsVarInScope(this.currentScope());
990
+ }
991
+
992
+ /** @returns {boolean} whether `new.target` may be referenced here */
993
+ get allowNewDotTarget() {
994
+ for (let i = this.scopeStack.length - 1; i >= 0; i--) {
995
+ const { flags } = this.scopeStack[i];
996
+ if (
997
+ flags & (SCOPE_CLASS_STATIC_BLOCK | SCOPE_CLASS_FIELD_INIT) ||
998
+ (flags & SCOPE_FUNCTION && !(flags & SCOPE_ARROW))
999
+ ) {
1000
+ return true;
1001
+ }
1002
+ }
1003
+ return false;
1004
+ }
1005
+
1006
+ /** @returns {boolean} whether a `using` declaration may appear here */
1007
+ get allowUsing() {
1008
+ const { flags } = this.currentScope();
1009
+ if (flags & SCOPE_SWITCH) return false;
1010
+ if (!this.inModule && flags & SCOPE_TOP) return false;
1011
+ return true;
1012
+ }
1013
+
1014
+ /** @returns {boolean} whether the innermost var scope is a class static block */
1015
+ get inClassStaticBlock() {
1016
+ return (this.currentVarScope().flags & SCOPE_CLASS_STATIC_BLOCK) > 0;
1017
+ }
1018
+
1019
+ /**
1020
+ * @param {...((parser: EXPECTED_ANY) => EXPECTED_ANY)} plugins the plugins to apply
1021
+ * @returns {EXPECTED_ANY} the extended parser class
1022
+ */
1023
+ static extend(...plugins) {
1024
+ /** @type {EXPECTED_ANY} */
1025
+ let cls = this;
1026
+ for (let i = 0; i < plugins.length; i++) cls = plugins[i](cls);
1027
+ return cls;
1028
+ }
1029
+
1030
+ /**
1031
+ * @param {string} input the source text
1032
+ * @param {Partial<Options>=} options parser options
1033
+ * @returns {Program} the parsed program
1034
+ */
1035
+ static parse(input, options) {
1036
+ return new this(options, input).parse();
1037
+ }
1038
+
1039
+ /**
1040
+ * @param {string} input the source text
1041
+ * @param {number} pos where the expression starts
1042
+ * @param {Partial<Options>=} options parser options
1043
+ * @returns {Expression} the parsed expression
1044
+ */
1045
+ static parseExpressionAt(input, pos, options) {
1046
+ installGrammar();
1047
+ const parser = /** @type {import("./grammar").Grammar} */ (
1048
+ /** @type {unknown} */ (new this(options, input, pos))
1049
+ );
1050
+ parser.nextToken();
1051
+ return parser.parseExpression();
1052
+ }
1053
+
1054
+ /**
1055
+ * @param {string} input the source text
1056
+ * @param {Partial<Options>=} options parser options
1057
+ * @returns {Parser} a parser positioned before the first token
1058
+ */
1059
+ static tokenizer(input, options) {
1060
+ return new this(options, input);
1061
+ }
1062
+
1063
+ /**
1064
+ * Whether a directive prologue starting at `start` opens with `"use strict"`.
1065
+ * acorn source: https://github.com/acornjs/acorn/blob/8.18.0/acorn/src/parseutil.js
1066
+ * @param {number} start where the prologue may begin
1067
+ * @returns {boolean} whether the code is strict
1068
+ */
1069
+ strictDirective(start) {
1070
+ if (this.options.ecmaVersion < 5) return false;
1071
+ let at = start;
1072
+ for (;;) {
1073
+ skipWhiteSpace.lastIndex = at;
1074
+ at += /** @type {RegExpExecArray} */ (skipWhiteSpace.exec(this.input))[0]
1075
+ .length;
1076
+ const match = literalDirective.exec(this.input.slice(at));
1077
+ if (!match) return false;
1078
+ if ((match[1] || match[2]) === "use strict") {
1079
+ skipWhiteSpace.lastIndex = at + match[0].length;
1080
+ const spaceAfter = /** @type {RegExpExecArray} */ (
1081
+ skipWhiteSpace.exec(this.input)
1082
+ );
1083
+ const end = spaceAfter.index + spaceAfter[0].length;
1084
+ const next = this.input.charAt(end);
1085
+ return (
1086
+ next === ";" ||
1087
+ next === "}" ||
1088
+ (lineBreak.test(spaceAfter[0]) &&
1089
+ !(
1090
+ /[(`.[+\-/*%<>=,?^&]/.test(next) ||
1091
+ (next === "!" && this.input.charAt(end + 1) === "=")
1092
+ ))
1093
+ );
1094
+ }
1095
+ at += match[0].length;
1096
+
1097
+ skipWhiteSpace.lastIndex = at;
1098
+ at += /** @type {RegExpExecArray} */ (skipWhiteSpace.exec(this.input))[0]
1099
+ .length;
1100
+ if (this.input[at] === ";") at++;
1101
+ }
1102
+ }
1103
+
1104
+ /**
1105
+ * @param {number=} pos where the offending token starts
1106
+ * @returns {never} never returns
1107
+ */
1108
+ unexpected(pos) {
1109
+ this.raise(
1110
+ pos === null || pos === undefined ? this.start : pos,
1111
+ "Unexpected token"
1112
+ );
1113
+ }
1114
+
1115
+ /**
1116
+ * @returns {EXPECTED_ANY} the parsed program
1117
+ */
1118
+ parse() {
1119
+ return installGrammar().Grammar.prototype.parse.call(this);
1120
+ }
1121
+
1122
+ /**
1123
+ * Read a full expression, including the comma operator.
1124
+ * acorn source: https://github.com/acornjs/acorn/blob/8.18.0/acorn/src/expression.js
1125
+ * @param {boolean | string=} forInit whether `in` is held back as an operator
1126
+ * @param {EXPECTED_ANY=} refDestructuringErrors where to record deferred errors
1127
+ * @returns {EXPECTED_ANY} the expression
1128
+ */
1129
+ parseExpression(forInit, refDestructuringErrors) {
1130
+ return installGrammar().Grammar.prototype.parseExpression.call(
1131
+ this,
1132
+ forInit,
1133
+ refDestructuringErrors
1134
+ );
1135
+ }
1136
+
1137
+ /** @returns {Token} the token after the current one */
1138
+ getToken() {
1139
+ return installGrammar().Grammar.prototype.getToken.call(this);
1140
+ }
1141
+
1142
+ /** @returns {Iterator<Token>} the remaining tokens */
1143
+ [Symbol.iterator]() {
1144
+ return installGrammar().Grammar.prototype[Symbol.iterator].call(this);
1145
+ }
1146
+
1147
+ /** @returns {TokContextLike[]} the context stack a fresh parser starts with */
1148
+ initialContext() {
1149
+ return [tokContexts.b_stat];
1150
+ }
1151
+
1152
+ /**
1153
+ * @param {number} flags what kind of scope it is
1154
+ * @returns {void}
1155
+ */
1156
+ enterScope(flags) {
1157
+ this.scopeStack.push(new Scope(flags));
1158
+ }
1159
+
1160
+ /**
1161
+ * @param {{ flags: number }} scope the scope to ask about
1162
+ * @returns {boolean | number} whether function names bind like `var` in it
1163
+ */
1164
+ treatFunctionsAsVarInScope(scope) {
1165
+ return Boolean(
1166
+ scope.flags & SCOPE_FUNCTION ||
1167
+ (!this.inModule && scope.flags & SCOPE_TOP)
1168
+ );
1169
+ }
1170
+
1171
+ /** @returns {Scope} the innermost scope */
1172
+ currentScope() {
1173
+ return this.scopeStack[this.scopeStack.length - 1];
1174
+ }
1175
+
1176
+ /** @returns {Scope} the innermost scope `var` reaches */
1177
+ currentVarScope() {
1178
+ for (let i = this.scopeStack.length - 1; ; i--) {
1179
+ const scope = this.scopeStack[i];
1180
+ if (
1181
+ scope.flags &
1182
+ (SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK)
1183
+ ) {
1184
+ return scope;
1185
+ }
1186
+ }
1187
+ }
1188
+
1189
+ /** @returns {Scope} the innermost scope that binds `this` */
1190
+ currentThisScope() {
1191
+ for (let i = this.scopeStack.length - 1; ; i--) {
1192
+ const scope = this.scopeStack[i];
1193
+ if (
1194
+ scope.flags &
1195
+ (SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK) &&
1196
+ !(scope.flags & SCOPE_ARROW)
1197
+ ) {
1198
+ return scope;
1199
+ }
1200
+ }
1201
+ }
1202
+
1203
+ /**
1204
+ * Report a parse error, naming where in the source it was found.
1205
+ * acorn source: https://github.com/acornjs/acorn/blob/8.18.0/acorn/src/location.js
1206
+ * @param {number} pos where the error is
1207
+ * @param {string} message what is wrong
1208
+ * @returns {never} never returns
1209
+ */
1210
+ raise(pos, message) {
1211
+ const loc = getLineInfo(this.input, pos);
1212
+ let text = `${message} (${loc.line}:${loc.column})`;
1213
+ if (this.sourceFile) text += ` in ${this.sourceFile}`;
1214
+ const err = /** @type {EXPECTED_ANY} */ (new SyntaxError(text));
1215
+ err.pos = pos;
1216
+ err.loc = loc;
1217
+ err.raisedAt = this.pos;
1218
+ throw err;
1219
+ }
1220
+
1221
+ /**
1222
+ * @param {number} pos where the error is
1223
+ * @param {string} message what is wrong
1224
+ * @returns {never} never returns
1225
+ */
1226
+ raiseRecoverable(pos, message) {
1227
+ return this.raise(pos, message);
1228
+ }
1229
+
1230
+ /** @returns {Position | undefined} where the tokenizer stands, when tracked */
1231
+ curPosition() {
1232
+ if (this.options.locations) {
1233
+ return new Position(this.curLine, this.pos - this.lineStart);
1234
+ }
1235
+ }
1236
+
1237
+ /**
1238
+ * @param {number} startSkip how many characters open the comment
1239
+ * @returns {void}
1240
+ */
1241
+ skipLineComment(startSkip) {
1242
+ const start = this.pos;
1243
+ const startLoc = this.options.onComment && this.curPosition();
1244
+ this.pos += startSkip;
1245
+ let ch = this.input.charCodeAt(this.pos);
1246
+ while (this.pos < this.input.length && !isNewLine(ch)) {
1247
+ ch = this.input.charCodeAt(++this.pos);
1248
+ }
1249
+ if (this.options.onComment) {
1250
+ this.options.onComment(
1251
+ false,
1252
+ this.input.slice(start + startSkip, this.pos),
1253
+ start,
1254
+ this.pos,
1255
+ startLoc,
1256
+ this.curPosition()
1257
+ );
1258
+ }
1259
+ }
1260
+ }
1261
+
1262
+ /**
1263
+ * @param {EXPECTED_ANY} node the operand of `delete`
1264
+ * @returns {boolean} whether it names a variable rather than a property
1265
+ */
1266
+ const isLocalVariableAccess = (node) =>
1267
+ node.type === "Identifier" ||
1268
+ (node.type === "ParenthesizedExpression" &&
1269
+ isLocalVariableAccess(node.expression));
1270
+
1271
+ /**
1272
+ * @param {EXPECTED_ANY} node the operand of `delete`
1273
+ * @returns {boolean} whether it reads a private field
1274
+ */
1275
+ const isPrivateFieldAccess = (node) =>
1276
+ (node.type === "MemberExpression" &&
1277
+ node.property.type === "PrivateIdentifier") ||
1278
+ (node.type === "ChainExpression" && isPrivateFieldAccess(node.expression)) ||
1279
+ (node.type === "ParenthesizedExpression" &&
1280
+ isPrivateFieldAccess(node.expression));
1281
+
1282
+ /**
1283
+ * @param {string} str the literal's text
1284
+ * @param {boolean} isLegacyOctalNumericLiteral whether a leading zero makes it octal
1285
+ * @returns {number} its value
1286
+ */
1287
+ const stringToNumber = (str, isLegacyOctalNumericLiteral) => {
1288
+ if (isLegacyOctalNumericLiteral) return Number.parseInt(str, 8);
1289
+
1290
+ // `parseFloat` stops at the first separator, so they come out first.
1291
+ return Number.parseFloat(str.replace(/_/g, ""));
1292
+ };
1293
+
1294
+ // Thrown to unwind out of a template element whose escape is bad, so the raw
1295
+ // text can be re-read without cooking it.
1296
+
1297
+ // Token-specific context updates. A closing brace or paren pops what its
1298
+ // opener pushed, and a `{` is only a block where `braceIsBlock` says so.
1299
+ /**
1300
+ * @this {EXPECTED_ANY}
1301
+ * @returns {void}
1302
+ */
1303
+ function closeBraceOrParenContext() {
1304
+ if (this.context.length === 1) {
1305
+ this.exprAllowed = true;
1306
+ return;
1307
+ }
1308
+ let out = this.context.pop();
1309
+ if (out === tokContexts.b_stat && this.curContext().token === "function") {
1310
+ out = this.context.pop();
1311
+ }
1312
+ this.exprAllowed = !out.isExpr;
1313
+ }
1314
+
1315
+ /**
1316
+ * @this {EXPECTED_ANY}
1317
+ * @param {TokenType} prevType the token before this one
1318
+ * @returns {void}
1319
+ */
1320
+ function braceLContext(prevType) {
1321
+ this.context.push(
1322
+ this.braceIsBlock(prevType) ? tokContexts.b_stat : tokContexts.b_expr
1323
+ );
1324
+ this.exprAllowed = true;
1325
+ }
1326
+
1327
+ /**
1328
+ * @this {EXPECTED_ANY}
1329
+ * @returns {void}
1330
+ */
1331
+ function dollarBraceLContext() {
1332
+ this.context.push(tokContexts.b_tmpl);
1333
+ this.exprAllowed = true;
1334
+ }
1335
+
1336
+ /**
1337
+ * @this {EXPECTED_ANY}
1338
+ * @param {TokenType} prevType the token before this one
1339
+ * @returns {void}
1340
+ */
1341
+ function parenLContext(prevType) {
1342
+ const statementParens =
1343
+ prevType === tokTypes._if ||
1344
+ prevType === tokTypes._for ||
1345
+ prevType === tokTypes._with ||
1346
+ prevType === tokTypes._while;
1347
+ this.context.push(statementParens ? tokContexts.p_stat : tokContexts.p_expr);
1348
+ this.exprAllowed = true;
1349
+ }
1350
+
1351
+ /**
1352
+ * `++`/`--` leaves `exprAllowed` as it stands, since it reads as either a
1353
+ * prefix or a postfix operator.
1354
+ * @returns {void}
1355
+ */
1356
+ function incDecContext() {}
1357
+
1358
+ /**
1359
+ * @this {EXPECTED_ANY}
1360
+ * @param {TokenType} prevType the token before this one
1361
+ * @returns {void}
1362
+ */
1363
+ function functionOrClassContext(prevType) {
1364
+ if (
1365
+ prevType.beforeExpr &&
1366
+ prevType !== tokTypes._else &&
1367
+ !(prevType === tokTypes.semi && this.curContext() !== tokContexts.p_stat) &&
1368
+ !(
1369
+ prevType === tokTypes._return &&
1370
+ lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
1371
+ ) &&
1372
+ !(
1373
+ (prevType === tokTypes.colon || prevType === tokTypes.braceL) &&
1374
+ this.curContext() === tokContexts.b_stat
1375
+ )
1376
+ ) {
1377
+ this.context.push(tokContexts.f_expr);
1378
+ } else {
1379
+ this.context.push(tokContexts.f_stat);
1380
+ }
1381
+ this.exprAllowed = false;
1382
+ }
1383
+
1384
+ /**
1385
+ * @this {EXPECTED_ANY}
1386
+ * @returns {void}
1387
+ */
1388
+ function colonContext() {
1389
+ if (this.curContext().token === "function") this.context.pop();
1390
+ this.exprAllowed = true;
1391
+ }
1392
+
1393
+ /**
1394
+ * @this {EXPECTED_ANY}
1395
+ * @returns {void}
1396
+ */
1397
+ function backQuoteContext() {
1398
+ if (this.curContext() === tokContexts.q_tmpl) this.context.pop();
1399
+ else this.context.push(tokContexts.q_tmpl);
1400
+ this.exprAllowed = false;
1401
+ }
1402
+
1403
+ /**
1404
+ * @this {EXPECTED_ANY}
1405
+ * @param {TokenType} prevType the token before this one
1406
+ * @returns {void}
1407
+ */
1408
+ function starContext(prevType) {
1409
+ if (prevType === tokTypes._function) {
1410
+ const index = this.context.length - 1;
1411
+ this.context[index] =
1412
+ this.context[index] === tokContexts.f_expr
1413
+ ? tokContexts.f_expr_gen
1414
+ : tokContexts.f_gen;
1415
+ }
1416
+ this.exprAllowed = true;
1417
+ }
1418
+
1419
+ /**
1420
+ * A name allows an expression after it only where it was `of` or a `yield`
1421
+ * that the enclosing generator makes an operator.
1422
+ * @this {EXPECTED_ANY}
1423
+ * @param {TokenType} prevType the token before this one
1424
+ * @returns {void}
1425
+ */
1426
+ function nameContext(prevType) {
1427
+ let allowed = false;
1428
+ if (
1429
+ this.options.ecmaVersion >= 6 &&
1430
+ prevType !== tokTypes.dot &&
1431
+ ((this.value === "of" && !this.exprAllowed) ||
1432
+ (this.value === "yield" && this.inGeneratorContext()))
1433
+ ) {
1434
+ allowed = true;
1435
+ }
1436
+ this.exprAllowed = allowed;
1437
+ }
1438
+
1439
+ tokTypes.parenR.updateContext = closeBraceOrParenContext;
1440
+ tokTypes.braceR.updateContext = closeBraceOrParenContext;
1441
+ tokTypes.braceL.updateContext = braceLContext;
1442
+ tokTypes.dollarBraceL.updateContext = dollarBraceLContext;
1443
+ tokTypes.parenL.updateContext = parenLContext;
1444
+ tokTypes.incDec.updateContext = incDecContext;
1445
+ tokTypes._function.updateContext = functionOrClassContext;
1446
+ tokTypes._class.updateContext = functionOrClassContext;
1447
+ tokTypes.colon.updateContext = colonContext;
1448
+ tokTypes.backQuote.updateContext = backQuoteContext;
1449
+ tokTypes.star.updateContext = starContext;
1450
+ tokTypes.name.updateContext = nameContext;
1451
+
1452
+ module.exports.BIND_FUNCTION = BIND_FUNCTION;
1453
+ module.exports.BIND_LEXICAL = BIND_LEXICAL;
1454
+ module.exports.BIND_NONE = BIND_NONE;
1455
+ module.exports.BIND_OUTSIDE = BIND_OUTSIDE;
1456
+ module.exports.BIND_SIMPLE_CATCH = BIND_SIMPLE_CATCH;
1457
+ module.exports.BIND_VAR = BIND_VAR;
1458
+ module.exports.DestructuringErrors = DestructuringErrors;
1459
+ module.exports.Label = Label;
1460
+ module.exports.Node = Node;
1461
+ module.exports.Parser = Parser;
1462
+ module.exports.Position = Position;
1463
+ module.exports.SCOPE_ARROW = SCOPE_ARROW;
1464
+ module.exports.SCOPE_ASYNC = SCOPE_ASYNC;
1465
+ module.exports.SCOPE_CLASS_FIELD_INIT = SCOPE_CLASS_FIELD_INIT;
1466
+ module.exports.SCOPE_CLASS_STATIC_BLOCK = SCOPE_CLASS_STATIC_BLOCK;
1467
+ module.exports.SCOPE_DIRECT_SUPER = SCOPE_DIRECT_SUPER;
1468
+ module.exports.SCOPE_FUNCTION = SCOPE_FUNCTION;
1469
+ module.exports.SCOPE_GENERATOR = SCOPE_GENERATOR;
1470
+ module.exports.SCOPE_SIMPLE_CATCH = SCOPE_SIMPLE_CATCH;
1471
+ module.exports.SCOPE_SUPER = SCOPE_SUPER;
1472
+ module.exports.SCOPE_SWITCH = SCOPE_SWITCH;
1473
+ module.exports.SCOPE_TOP = SCOPE_TOP;
1474
+ module.exports.SCOPE_VAR = SCOPE_VAR;
1475
+ module.exports.Scope = Scope;
1476
+ module.exports.SourceLocation = SourceLocation;
1477
+ module.exports.TokContext = TokContext;
1478
+ module.exports.Token = Token;
1479
+ module.exports.TokenType = TokenType;
1480
+ module.exports.codePointToString = codePointToString;
1481
+ module.exports.defaultOptions = defaultOptions;
1482
+ module.exports.functionFlags = functionFlags;
1483
+ module.exports.getLineInfo = getLineInfo;
1484
+ module.exports.getOptions = getOptions;
1485
+ module.exports.installGrammar = installGrammar;
1486
+ module.exports.isIdentifierChar = isIdentifierChar;
1487
+ module.exports.isIdentifierStart = isIdentifierStart;
1488
+ module.exports.isLocalVariableAccess = isLocalVariableAccess;
1489
+ module.exports.isNewLine = isNewLine;
1490
+ module.exports.isPrivateFieldAccess = isPrivateFieldAccess;
1491
+ module.exports.keywordTypes = keywordTypes;
1492
+ module.exports.lineBreak = lineBreak;
1493
+ module.exports.lineBreakG = lineBreakG;
1494
+ module.exports.nextLineBreak = nextLineBreak;
1495
+ module.exports.nonASCIIwhitespace = nonASCIIwhitespace;
1496
+ module.exports.skipWhiteSpace = skipWhiteSpace;
1497
+ module.exports.stringToNumber = stringToNumber;
1498
+ module.exports.tokContexts = tokContexts;
1499
+ module.exports.tokTypes = tokTypes;
1500
+ module.exports.wordsRegexp = wordsRegexp;