cfsolve 0.1.2 → 0.1.4

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 (395) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +8 -3
  4. data/THIRD_PARTY_LICENSES/README.md +71 -254
  5. data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
  6. data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
  7. data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
  8. data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
  9. data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
  10. data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
  11. data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
  12. data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
  13. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
  14. data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
  15. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
  16. data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
  17. data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
  18. data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
  19. data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
  20. data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
  21. data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
  22. data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
  23. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
  24. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
  25. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
  26. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
  27. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
  28. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
  29. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
  30. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
  31. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
  32. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
  33. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
  34. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
  35. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
  36. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
  37. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
  38. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
  39. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
  40. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
  41. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
  42. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
  43. data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
  44. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
  45. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
  46. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
  47. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
  48. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
  49. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
  50. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
  51. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
  52. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
  53. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
  54. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
  55. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
  56. data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
  57. data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
  58. data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
  59. data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
  60. data/UPSTREAM.md +14 -6
  61. data/ext/cfsolve/Cargo.lock +534 -1727
  62. data/ext/cfsolve/Cargo.toml +4 -0
  63. data/ext/cfsolve/src/main.rs +1 -1
  64. data/lib/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
  65. data/lib/cfsolve/profiles/chrome-157-macos.json +613 -0
  66. data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  67. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  68. data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
  69. data/lib/cfsolve/version.rb +2 -2
  70. data/lib/cfsolve.rb +1 -1
  71. data/vendor/cfsolve/Cargo.lock +561 -1729
  72. data/vendor/cfsolve/Cargo.toml +26 -8
  73. data/vendor/cfsolve/README.md +57 -5
  74. data/vendor/cfsolve/examples/check_answers.rs +2 -2
  75. data/vendor/cfsolve/examples/compare_session.rs +1 -2
  76. data/vendor/cfsolve/examples/solver_profile.rs +84 -0
  77. data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
  78. data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
  79. data/vendor/cfsolve/examples/tls_echo.rs +3 -3
  80. data/vendor/cfsolve/examples/turnstile_smoke.rs +58 -0
  81. data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
  82. data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
  83. data/vendor/cfsolve/profiles/chrome-157-macos.json +613 -0
  84. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  85. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  86. data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
  87. data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
  88. data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
  89. data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
  90. data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
  91. data/vendor/cfsolve/src/capture/proxy.rs +44 -13
  92. data/vendor/cfsolve/src/capture/sessions.rs +4 -3
  93. data/vendor/cfsolve/src/capture/upstream.rs +1 -1
  94. data/vendor/cfsolve/src/challenge/codec.rs +4 -2
  95. data/vendor/cfsolve/src/challenge/expression.rs +161 -117
  96. data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
  97. data/vendor/cfsolve/src/challenge/installed.rs +13 -6
  98. data/vendor/cfsolve/src/challenge/merge.rs +120 -80
  99. data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
  100. data/vendor/cfsolve/src/challenge/payload.rs +69 -31
  101. data/vendor/cfsolve/src/challenge/program.rs +197 -178
  102. data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
  103. data/vendor/cfsolve/src/challenge/source.rs +151 -96
  104. data/vendor/cfsolve/src/challenge/state.rs +180 -148
  105. data/vendor/cfsolve/src/challenge/tally.rs +64 -50
  106. data/vendor/cfsolve/src/challenge.rs +1 -0
  107. data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
  108. data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
  109. data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
  110. data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
  111. data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
  112. data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
  113. data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
  114. data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
  115. data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
  116. data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
  117. data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
  118. data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
  119. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
  120. data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
  121. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
  122. data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
  123. data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
  124. data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
  125. data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
  126. data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
  127. data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
  128. data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
  129. data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
  130. data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
  131. data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
  132. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
  133. data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
  134. data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
  135. data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
  136. data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
  137. data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
  138. data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
  139. data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
  140. data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
  141. data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
  142. data/vendor/cfsolve/src/deobfuscate.rs +15 -11
  143. data/vendor/cfsolve/src/embedding_page/extra_params.rs +132 -24
  144. data/vendor/cfsolve/src/embedding_page/page.rs +41 -1
  145. data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
  146. data/vendor/cfsolve/src/error.rs +40 -5
  147. data/vendor/cfsolve/src/fingerprint.rs +8 -2
  148. data/vendor/cfsolve/src/http/client.rs +7 -10
  149. data/vendor/cfsolve/src/http/requests.rs +2 -2
  150. data/vendor/cfsolve/src/js/ast.rs +479 -263
  151. data/vendor/cfsolve/src/lib.rs +1 -0
  152. data/vendor/cfsolve/src/listing/fold.rs +19 -9
  153. data/vendor/cfsolve/src/listing/query.rs +1 -47
  154. data/vendor/cfsolve/src/performance_clock.rs +20 -1
  155. data/vendor/cfsolve/src/profiling.rs +49 -0
  156. data/vendor/cfsolve/src/script.rs +35 -24
  157. data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
  158. data/vendor/cfsolve/src/session/channel.rs +2 -2
  159. data/vendor/cfsolve/src/session/initial.rs +12 -11
  160. data/vendor/cfsolve/src/session/probes.rs +1 -0
  161. data/vendor/cfsolve/src/session/sink.rs +26 -1
  162. data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
  163. data/vendor/cfsolve/src/session.rs +1 -1
  164. data/vendor/cfsolve/src/solver.rs +3 -1
  165. data/vendor/cfsolve/src/stage2/analysis/analyze.rs +33 -4
  166. data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
  167. data/vendor/cfsolve/src/stage2/analysis/discovery.rs +13 -2
  168. data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
  169. data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
  170. data/vendor/cfsolve/src/stage2/benchmark.rs +113 -41
  171. data/vendor/cfsolve/src/stage2/call_stack.rs +1564 -1041
  172. data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
  173. data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +1 -0
  174. data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
  175. data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
  176. data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
  177. data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
  178. data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
  179. data/vendor/cfsolve/src/stage2/probes/dates.rs +44 -0
  180. data/vendor/cfsolve/src/stage2/probes/parent_info_array.rs +326 -0
  181. data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
  182. data/vendor/cfsolve/src/stage2/probes/stack.rs +117 -4
  183. data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +80 -2
  184. data/vendor/cfsolve/src/stage2/probes.rs +1 -0
  185. data/vendor/cfsolve/src/stage2/queries.rs +50 -0
  186. data/vendor/cfsolve/src/stage2/reference.rs +5 -0
  187. data/vendor/cfsolve/src/stage2/registry.rs +8 -2
  188. data/vendor/cfsolve/src/stage2/replay.rs +34 -3
  189. data/vendor/cfsolve/src/stage2/stylesheets.rs +35 -0
  190. data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
  191. data/vendor/cfsolve/src/stage2/trace.rs +134 -108
  192. data/vendor/cfsolve/src/stage2/value_labels.rs +185 -0
  193. data/vendor/cfsolve/src/stage2/vocabulary.rs +112 -17
  194. data/vendor/cfsolve/src/stage2.rs +3 -0
  195. data/vendor/cfsolve/src/vm/disassemble.rs +75 -7
  196. data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
  197. data/vendor/cfsolve/src/vm/encoded_names.rs +635 -0
  198. data/vendor/cfsolve/src/vm/extract.rs +550 -250
  199. data/vendor/cfsolve/src/vm/fixtures/free_functions/README.md +9 -0
  200. data/vendor/cfsolve/src/vm/fixtures/free_functions/machine.js +7438 -0
  201. data/vendor/cfsolve/src/vm/fixtures/free_functions/program.base64 +1 -0
  202. data/vendor/cfsolve/src/vm/interpret/access.rs +71 -50
  203. data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
  204. data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
  205. data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
  206. data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
  207. data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
  208. data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
  209. data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
  210. data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
  211. data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
  212. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +160 -58
  213. data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
  214. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
  215. data/vendor/cfsolve/src/vm/interpret/pattern.rs +1765 -0
  216. data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
  217. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +392 -0
  218. data/vendor/cfsolve/src/vm/interpret/run.rs +120 -45
  219. data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
  220. data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
  221. data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
  222. data/vendor/cfsolve/src/vm/interpret.rs +9 -1
  223. data/vendor/cfsolve/src/vm/machine.rs +116 -51
  224. data/vendor/cfsolve/src/vm/output.rs +19 -6
  225. data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
  226. data/vendor/cfsolve/src/vm/registers.rs +35 -21
  227. data/vendor/cfsolve/src/vm/session.rs +189 -121
  228. data/vendor/cfsolve/src/vm/value.rs +22 -19
  229. data/vendor/cfsolve/src/vm.rs +3 -1
  230. data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
  231. data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
  232. metadata +106 -178
  233. data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
  234. data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
  235. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
  236. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
  237. data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
  238. data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
  239. data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
  240. data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
  241. data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
  242. data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
  243. data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
  244. data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
  245. data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
  246. data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
  247. data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
  248. data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
  249. data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
  250. data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
  251. data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
  252. data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
  253. data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
  254. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
  255. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
  256. data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
  257. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
  258. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
  259. data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
  260. data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
  261. data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
  262. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
  263. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
  264. data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
  265. data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
  266. data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
  267. data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
  268. data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
  269. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
  270. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
  271. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
  272. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
  273. data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
  274. data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
  275. data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
  276. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
  277. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
  278. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
  279. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
  280. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
  281. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
  282. data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
  283. data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
  284. data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
  285. data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
  286. data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
  287. data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
  288. data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
  289. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
  290. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
  291. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
  292. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
  293. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
  294. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
  295. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
  296. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
  297. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
  298. data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
  299. data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
  300. data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
  301. data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
  302. data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
  303. data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
  304. data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
  305. data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
  306. data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
  307. data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
  308. data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
  309. data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
  310. data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
  311. data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
  312. data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
  313. data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
  314. data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
  315. data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
  316. data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
  317. data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
  318. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
  319. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
  320. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
  321. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
  322. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
  323. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
  324. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
  325. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
  326. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
  327. data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
  328. data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
  329. data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
  330. data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
  331. data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
  332. data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
  333. data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
  334. data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
  335. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
  336. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
  337. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
  338. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
  339. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
  340. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
  341. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
  342. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
  343. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
  344. data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
  345. data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
  346. data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
  347. data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
  348. data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
  349. data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
  350. data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
  351. data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
  352. data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
  353. data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
  354. data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
  355. data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
  356. data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
  357. data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
  358. data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
  359. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
  360. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
  361. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
  362. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
  363. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
  364. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
  365. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
  366. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
  367. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
  368. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
  369. data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
  370. data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
  371. data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
  372. /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
  373. /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
  374. /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
  375. /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
  376. /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
  377. /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
  378. /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
  379. /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
  380. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
  381. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
  382. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
  383. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
  384. /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
  385. /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
  386. /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
  387. /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
  388. /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
  389. /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
  390. /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
  391. /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
  392. /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
  393. /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
  394. /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
  395. /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
@@ -1,6 +1,6 @@
1
- //! Compiles JavaScript into plans run by [`super::evaluate`]. Slot plans store function locals
1
+ //! Compiles JavaScript into plans, which [`super::compile`] turns into closures. Slot plans store function locals
2
2
  //! in numbered slots, except locals that nested functions mention, which stay in the call's
3
- //! scope for those functions to capture. Scoped plans resolve all names through scopes.
3
+ //! scope for those functions to capture. Scoped plans resolve every binding through scopes.
4
4
  //! Unsupported syntax becomes a node that stops evaluation if reached.
5
5
 
6
6
  #[cfg(test)]
@@ -9,59 +9,94 @@ use std::cell::RefCell;
9
9
  use std::ptr;
10
10
  use std::rc::Rc;
11
11
 
12
- use rustc_hash::FxHashSet as HashSet;
13
- use swc_core::atoms::{Atom, atom};
14
- use swc_core::ecma::ast::{
15
- ArrowExpr, AssignTarget, BinaryOp, BlockStmt, BlockStmtOrExpr, Callee, CatchClause, Class,
16
- Decl, DoWhileStmt, Expr, ExprOrSpread, FnDecl, Function, Ident, Lit, MemberExpr, MemberProp,
17
- Pat, Prop, PropName, PropOrSpread, SimpleAssignTarget, Stmt, UnaryOp, UpdateOp, VarDecl,
18
- VarDeclKind, VarDeclOrExpr, VarDeclarator, WhileStmt,
12
+ use oxc::ast::ast::{
13
+ Argument, ArrayExpressionElement, ArrowFunctionBody, ArrowFunctionExpression,
14
+ BindingIdentifier, BindingPattern, CatchClause, Class, Expression as Expr, ForStatementInit,
15
+ FormalParameters, Function, IdentifierReference, MemberExpression, ObjectPropertyKind,
16
+ PropertyKey, PropertyKind, SimpleAssignmentTarget, Statement as Stmt, VariableDeclaration,
17
+ VariableDeclarationKind, VariableDeclarator,
19
18
  };
20
- use swc_core::ecma::visit::{Visit, VisitWith};
19
+ use oxc::ast_visit::{Visit, walk};
20
+ use oxc::semantic::{ScopeFlags, SymbolId};
21
+ use oxc::syntax::operator::{BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator};
21
22
 
22
23
  use super::compile::{self, Code};
23
24
  use super::semantics;
24
- use crate::vm::HashMap;
25
+ use crate::js::ast::{Binding, Script};
25
26
  use crate::vm::value::Value;
27
+ use crate::vm::{HashMap, HashSet, extract};
28
+
29
+ /// What a call runs: parameters, then a body. A script function's body is its statements; the
30
+ /// dispatch decoder's is assembled from the dispatch loop (see [`crate::vm::dispatch`]).
31
+ #[derive(Clone, Copy)]
32
+ pub(crate) struct Routine<'ast> {
33
+ pub(crate) parameters: &'ast FormalParameters<'ast>,
34
+ /// Declarations run first without their initializers, so they only declare their names.
35
+ pub(crate) declarations: &'ast [&'ast VariableDeclaration<'ast>],
36
+ pub(crate) statements: &'ast [Stmt<'ast>],
37
+ /// What the routine returns after its statements, if they do not return.
38
+ pub(crate) returns: Option<&'ast Expr<'ast>>,
39
+ /// Identifies the routine's plans: the address of the function body or decoder.
40
+ pub(crate) address: usize,
41
+ }
42
+
43
+ impl<'ast> Routine<'ast> {
44
+ /// The routine of a function with a body.
45
+ pub(crate) fn function(function: &'ast Function<'ast>) -> Option<Self> {
46
+ let body = function.body.as_deref()?;
47
+ Some(Self {
48
+ parameters: &function.params,
49
+ declarations: &[],
50
+ statements: &body.statements,
51
+ returns: None,
52
+ address: ptr::from_ref(body).addr(),
53
+ })
54
+ }
55
+ }
26
56
 
27
57
  /// Caches plans by source-node address. The session's definition keeps those nodes alive longer
28
58
  /// than the cache.
29
59
  #[derive(Default)]
30
60
  pub(crate) struct Plans<'ast> {
31
- /// `None` marks functions that need a scoped plan.
61
+ /// `None` marks routines that need a scoped plan.
32
62
  pub(super) slot_plans: RefCell<HashMap<usize, Option<Rc<FunctionPlan<'ast>>>>>,
33
- scoped_plans: RefCell<HashMap<usize, Rc<[Statement<'ast>]>>>,
63
+ scoped_plans: RefCell<HashMap<usize, Rc<[Code<'ast>]>>>,
34
64
  /// Forces scoped plans for comparison tests.
35
65
  #[cfg(test)]
36
66
  pub(super) disabled: Cell<bool>,
37
67
  }
38
68
 
39
69
  impl<'ast> Plans<'ast> {
40
- pub(super) fn slots(&self, function: &'ast Function) -> Option<Rc<FunctionPlan<'ast>>> {
70
+ pub(super) fn slots(
71
+ &self,
72
+ script: Script<'ast>,
73
+ routine: Routine<'ast>,
74
+ ) -> Option<Rc<FunctionPlan<'ast>>> {
41
75
  #[cfg(test)]
42
76
  if self.disabled.get() {
43
77
  return None;
44
78
  }
45
- let address = ptr::from_ref(function).addr();
46
- if let Some(plan) = self.slot_plans.borrow().get(&address) {
79
+ if let Some(plan) = self.slot_plans.borrow().get(&routine.address) {
47
80
  return plan.clone();
48
81
  }
49
- let plan = FunctionPlan::compile(function).map(Rc::new);
50
- self.slot_plans.borrow_mut().insert(address, plan.clone());
82
+ let plan = FunctionPlan::compile(script, routine).map(Rc::new);
83
+ self.slot_plans
84
+ .borrow_mut()
85
+ .insert(routine.address, plan.clone());
51
86
  plan
52
87
  }
53
88
 
54
- /// Returns the scoped plan of a function body or arrow, compiling it on first use.
55
- pub(super) fn scoped<T>(
89
+ /// Returns the scoped plan of the routine or arrow at `address`, compiling `plan` on first
90
+ /// use.
91
+ pub(super) fn scoped(
56
92
  &self,
57
- code: &'ast T,
58
- compile: impl FnOnce(&'ast T) -> Vec<Statement<'ast>>,
59
- ) -> Rc<[Statement<'ast>]> {
60
- let address = ptr::from_ref(code).addr();
93
+ address: usize,
94
+ plan: impl FnOnce() -> Vec<Statement<'ast>>,
95
+ ) -> Rc<[Code<'ast>]> {
61
96
  if let Some(plan) = self.scoped_plans.borrow().get(&address) {
62
97
  return plan.clone();
63
98
  }
64
- let plan: Rc<[Statement<'ast>]> = compile(code).into();
99
+ let plan: Rc<[Code<'ast>]> = compile::statements(&plan()).into();
65
100
  self.scoped_plans.borrow_mut().insert(address, plan.clone());
66
101
  plan
67
102
  }
@@ -82,131 +117,222 @@ impl<'ast> FunctionPlan<'ast> {
82
117
  /// Attempts to compile a slot plan. Returns `None` to request a scoped plan for unsupported
83
118
  /// syntax, parenthesized callees, computed object keys, logical assignments, parameter
84
119
  /// patterns, variables named `arguments`, or arrows reading `arguments`.
85
- pub(super) fn compile(function: &'ast Function) -> Option<Self> {
86
- let body = function.body.as_ref()?;
120
+ pub(super) fn compile(script: Script<'ast>, routine: Routine<'ast>) -> Option<Self> {
87
121
  let mut compiler = PlanCompiler {
88
- captured: captured(body),
89
- ..PlanCompiler::default()
122
+ captured: captured(script, routine),
123
+ ..PlanCompiler::new(script)
90
124
  };
91
- let mut parameters = Vec::with_capacity(function.params.len());
92
- for parameter in &function.params {
93
- let name = &parameter.pat.as_ident()?.sym;
94
- if name == "arguments" {
125
+ let parameters = extract::parameters(routine.parameters)?;
126
+ let mut names = Vec::with_capacity(parameters.len());
127
+ for parameter in parameters {
128
+ if parameter.name == "arguments" {
95
129
  return None;
96
130
  }
97
- compiler.local(name);
98
- parameters.push(compiler.name(name));
131
+ let binding = Binding::Symbol(parameter.symbol_id());
132
+ compiler.local(binding);
133
+ names.push(compiler.name(binding));
134
+ }
135
+ for declaration in routine.declarations {
136
+ for declarator in &declaration.declarations {
137
+ compiler.declared(declarator);
138
+ }
139
+ }
140
+ for statement in routine.statements {
141
+ compiler.visit_statement(statement);
99
142
  }
100
- body.visit_with(&mut compiler);
101
- let body = compiler.body(&body.stmts);
143
+ let body = compiler.routine(routine);
102
144
  if compiler.rejected {
103
145
  return None;
104
146
  }
105
147
  Some(Self {
106
- parameters,
107
- arguments: compiler.locals.get(&atom!("arguments")).copied(),
148
+ parameters: names,
149
+ arguments: compiler.locals.get(&Binding::Global("arguments")).copied(),
108
150
  locals: compiler.locals.len(),
109
151
  code: compile::statements(&body),
110
152
  })
111
153
  }
112
154
  }
113
155
 
114
- pub(super) fn scoped(statements: &[Stmt]) -> Vec<Statement<'_>> {
115
- PlanCompiler::default().statements(statements)
156
+ pub(super) fn scoped_statement<'ast>(
157
+ script: Script<'ast>,
158
+ statement: &'ast Stmt<'ast>,
159
+ ) -> Statement<'ast> {
160
+ PlanCompiler::new(script).statement(statement, None)
116
161
  }
117
162
 
118
- /// Scoped execution plan for a function body. Function declarations bind their names at the start
119
- /// of the call.
120
- pub(super) fn scoped_body(statements: &[Stmt]) -> Vec<Statement<'_>> {
121
- PlanCompiler::default().body(statements)
163
+ /// Scoped execution plan for a routine's body. Function declarations bind their names at the
164
+ /// start of the call.
165
+ pub(super) fn scoped_routine<'ast>(
166
+ script: Script<'ast>,
167
+ routine: Routine<'ast>,
168
+ ) -> Vec<Statement<'ast>> {
169
+ PlanCompiler::new(script).routine(routine)
122
170
  }
123
171
 
124
- pub(super) fn scoped_expression(expression: &Expr) -> Expression<'_> {
125
- PlanCompiler::default().expression(expression)
172
+ pub(super) fn scoped_expression<'ast>(
173
+ script: Script<'ast>,
174
+ expression: &'ast Expr<'ast>,
175
+ ) -> Expression<'ast> {
176
+ PlanCompiler::new(script).expression(expression)
126
177
  }
127
178
 
128
- pub(super) fn scoped_arrow(arrow: &ArrowExpr) -> Vec<Statement<'_>> {
129
- match &*arrow.body {
130
- BlockStmtOrExpr::BlockStmt(body) => scoped_body(&body.stmts),
131
- BlockStmtOrExpr::Expr(body) => vec![Statement::Return(Some(scoped_expression(body)))],
179
+ pub(super) fn scoped_arrow<'ast>(
180
+ script: Script<'ast>,
181
+ arrow: &'ast ArrowFunctionExpression<'ast>,
182
+ ) -> Vec<Statement<'ast>> {
183
+ let mut compiler = PlanCompiler::new(script);
184
+ match &arrow.body {
185
+ ArrowFunctionBody::FunctionBody(body) => compiler.body(&body.statements),
186
+ body => {
187
+ let body = body
188
+ .as_expression()
189
+ .expect("an arrow body is a block or an expression");
190
+ vec![Statement::Return(Some(compiler.expression(body)))]
191
+ }
132
192
  }
133
193
  }
134
194
 
135
- #[derive(Default)]
136
- struct PlanCompiler {
195
+ struct PlanCompiler<'a> {
196
+ script: Script<'a>,
137
197
  /// Slots of a slot plan's locals; empty for scoped plans.
138
- locals: HashMap<Atom, usize>,
139
- /// Names nested functions mention. Locals with these names stay in the call's scope.
140
- captured: HashSet<Atom>,
198
+ locals: HashMap<Binding<'a>, usize>,
199
+ /// Bindings nested functions mention. These locals stay in the call's scope.
200
+ captured: HashSet<SymbolId>,
141
201
  /// Whether compilation needs a scoped plan. Ignored when compiling scoped plans.
142
202
  rejected: bool,
143
203
  }
144
204
 
145
- impl Visit for PlanCompiler {
146
- fn visit_var_declarator(&mut self, declaration: &VarDeclarator) {
147
- if let Pat::Ident(name) = &declaration.name {
148
- self.local(&name.sym);
149
- }
150
- declaration.visit_children_with(self);
205
+ impl<'a> Visit<'a> for PlanCompiler<'a> {
206
+ fn visit_variable_declarator(&mut self, declarator: &VariableDeclarator<'a>) {
207
+ self.declared(declarator);
208
+ walk::walk_variable_declarator(self, declarator);
151
209
  }
152
210
 
153
- fn visit_ident(&mut self, name: &Ident) {
154
- if name.sym == "arguments" {
155
- self.local(&name.sym);
211
+ fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
212
+ if reference.name == "arguments" {
213
+ self.local(self.script.binding(reference));
156
214
  }
157
215
  }
158
216
 
159
- /// Treat a nested function declaration as a local binding in the enclosing function.
160
- fn visit_fn_decl(&mut self, declaration: &FnDecl) {
161
- self.local(&declaration.ident.sym);
217
+ /// Treat a nested function declaration as a local binding in the enclosing function. A
218
+ /// nested function's own locals remain separate.
219
+ fn visit_function(&mut self, function: &Function<'a>, _: ScopeFlags) {
220
+ if function.is_declaration()
221
+ && let Some(name) = &function.id
222
+ {
223
+ self.local(Binding::Symbol(name.symbol_id()));
224
+ }
162
225
  }
163
226
 
164
227
  /// Treat a `catch` parameter as a function local in the execution plan.
165
- fn visit_catch_clause(&mut self, clause: &CatchClause) {
166
- if let Some(Pat::Ident(name)) = &clause.param {
167
- self.local(&name.sym);
228
+ fn visit_catch_clause(&mut self, clause: &CatchClause<'a>) {
229
+ if let Some(parameter) = &clause.param
230
+ && let BindingPattern::BindingIdentifier(name) = &parameter.pattern
231
+ {
232
+ self.local(Binding::Symbol(name.symbol_id()));
168
233
  }
169
- clause.visit_children_with(self);
234
+ walk::walk_catch_clause(self, clause);
170
235
  }
171
236
 
172
- // A nested function's own locals remain separate.
173
- fn visit_function(&mut self, _: &Function) {}
174
- fn visit_arrow_expr(&mut self, _: &ArrowExpr) {}
175
- fn visit_class(&mut self, _: &Class) {}
237
+ fn visit_arrow_function_expression(&mut self, _: &ArrowFunctionExpression<'a>) {}
238
+ fn visit_class(&mut self, _: &Class<'a>) {}
176
239
  }
177
240
 
178
- /// Every name a nested function mentions, at any depth.
179
- #[derive(Default)]
180
- struct Names(HashSet<Atom>);
241
+ /// The symbols of a routine's own bindings that functions, arrows, and classes nested in it
242
+ /// reference. A function's `arguments` has no symbol; arrows reading it are rejected.
243
+ fn captured<'a>(script: Script<'a>, routine: Routine<'a>) -> HashSet<SymbolId> {
244
+ #[derive(Default)]
245
+ struct Bindings(HashSet<SymbolId>);
246
+
247
+ impl<'a> Visit<'a> for Bindings {
248
+ fn visit_binding_identifier(&mut self, name: &BindingIdentifier<'a>) {
249
+ self.0.insert(name.symbol_id());
250
+ }
251
+
252
+ fn visit_function(&mut self, function: &Function<'a>, _: ScopeFlags) {
253
+ if function.is_declaration()
254
+ && let Some(name) = &function.id
255
+ {
256
+ self.0.insert(name.symbol_id());
257
+ }
258
+ }
181
259
 
182
- impl Visit for Names {
183
- fn visit_ident(&mut self, name: &Ident) {
184
- self.0.insert(name.sym.clone());
260
+ fn visit_class(&mut self, class: &Class<'a>) {
261
+ if class.is_declaration()
262
+ && let Some(name) = &class.id
263
+ {
264
+ self.0.insert(name.symbol_id());
265
+ }
266
+ }
267
+
268
+ fn visit_arrow_function_expression(&mut self, _: &ArrowFunctionExpression<'a>) {}
185
269
  }
186
- }
187
270
 
188
- /// The names that functions, arrows, and classes nested in `body` mention, except `arguments`,
189
- /// which functions shadow and arrows reading it are rejected for.
190
- fn captured(body: &BlockStmt) -> HashSet<Atom> {
191
- struct Nested(Names);
271
+ struct References<'s, 'a> {
272
+ script: Script<'a>,
273
+ bindings: &'s HashSet<SymbolId>,
274
+ captured: HashSet<SymbolId>,
275
+ }
276
+
277
+ impl<'a> Visit<'a> for References<'_, 'a> {
278
+ fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
279
+ if let Some(symbol) = self.script.symbol(reference)
280
+ && self.bindings.contains(&symbol)
281
+ {
282
+ self.captured.insert(symbol);
283
+ }
284
+ }
285
+ }
286
+
287
+ struct Nested<'s, 'a>(References<'s, 'a>);
288
+
289
+ impl<'a> Visit<'a> for Nested<'_, 'a> {
290
+ fn visit_function(&mut self, function: &Function<'a>, flags: ScopeFlags) {
291
+ self.0.visit_function(function, flags);
292
+ }
192
293
 
193
- impl Visit for Nested {
194
- fn visit_function(&mut self, function: &Function) {
195
- function.visit_with(&mut self.0);
294
+ fn visit_arrow_function_expression(&mut self, arrow: &ArrowFunctionExpression<'a>) {
295
+ self.0.visit_arrow_function_expression(arrow);
196
296
  }
197
- fn visit_arrow_expr(&mut self, arrow: &ArrowExpr) {
198
- arrow.visit_with(&mut self.0);
297
+
298
+ fn visit_class(&mut self, class: &Class<'a>) {
299
+ self.0.visit_class(class);
199
300
  }
200
- fn visit_class(&mut self, class: &Class) {
201
- class.visit_with(&mut self.0);
301
+ }
302
+
303
+ let mut bindings = Bindings::default();
304
+ bindings.visit_formal_parameters(routine.parameters);
305
+ for declaration in routine.declarations {
306
+ for declarator in &declaration.declarations {
307
+ bindings.visit_binding_pattern(&declarator.id);
202
308
  }
203
309
  }
310
+ for statement in routine.statements {
311
+ bindings.visit_statement(statement);
312
+ }
313
+ let mut nested = Nested(References {
314
+ script,
315
+ bindings: &bindings.0,
316
+ captured: HashSet::default(),
317
+ });
318
+ for statement in routine.statements {
319
+ nested.visit_statement(statement);
320
+ }
321
+ nested.0.captured
322
+ }
323
+
324
+ /// Whether a visited node mentions `arguments`, to reject arrows that read the enclosing one.
325
+ #[derive(Default)]
326
+ struct MentionsArguments(bool);
327
+
328
+ impl<'a> Visit<'a> for MentionsArguments {
329
+ fn visit_identifier_reference(&mut self, name: &IdentifierReference<'a>) {
330
+ self.0 |= name.name == "arguments";
331
+ }
204
332
 
205
- let mut nested = Nested(Names::default());
206
- body.visit_with(&mut nested);
207
- let Nested(Names(mut names)) = nested;
208
- names.remove(&atom!("arguments"));
209
- names
333
+ fn visit_binding_identifier(&mut self, name: &BindingIdentifier<'a>) {
334
+ self.0 |= name.name == "arguments";
335
+ }
210
336
  }
211
337
 
212
338
  pub(super) struct Case<'ast> {
@@ -241,11 +367,11 @@ pub(super) enum Statement<'ast> {
241
367
  body: Box<Statement<'ast>>,
242
368
  /// Whether the body runs once before the test, as in `do ... while`.
243
369
  body_first: bool,
244
- label: Option<&'ast Atom>,
370
+ label: Option<&'ast str>,
245
371
  },
246
- Break(Option<&'ast Atom>),
247
- Continue(Option<&'ast Atom>),
248
- Label(&'ast Atom, Box<Statement<'ast>>),
372
+ Break(Option<&'ast str>),
373
+ Continue(Option<&'ast str>),
374
+ Label(&'ast str, Box<Statement<'ast>>),
249
375
  /// A `try` statement with its catch parameter, catch body, and finally body.
250
376
  Try {
251
377
  block: Vec<Statement<'ast>>,
@@ -258,7 +384,7 @@ pub(super) enum Statement<'ast> {
258
384
 
259
385
  pub(super) enum Expression<'ast> {
260
386
  Logical {
261
- operator: BinaryOp,
387
+ operator: LogicalOperator,
262
388
  left: Box<Expression<'ast>>,
263
389
  right: Box<Expression<'ast>>,
264
390
  /// Whether the right side is [`pure`].
@@ -271,20 +397,22 @@ pub(super) enum Expression<'ast> {
271
397
  Member(Box<Expression<'ast>>, Property<'ast>),
272
398
  Call(Box<Expression<'ast>>, Vec<Expression<'ast>>),
273
399
  New(Box<Expression<'ast>>, Vec<Expression<'ast>>),
274
- Binary(BinaryOp, Box<Expression<'ast>>, Box<Expression<'ast>>),
400
+ Binary(BinaryOperator, Box<Expression<'ast>>, Box<Expression<'ast>>),
275
401
  /// An arithmetic or bitwise operator, with its operation on numbers (see
276
402
  /// [`semantics::numeric`]).
277
403
  Arithmetic {
278
- operator: BinaryOp,
404
+ operator: BinaryOperator,
279
405
  operation: fn(f64, f64) -> f64,
280
406
  left: Box<Expression<'ast>>,
281
407
  right: Box<Expression<'ast>>,
282
408
  },
283
- Unary(UnaryOp, Box<Expression<'ast>>),
284
- Assign(Target<'ast>, Option<BinaryOp>, Box<Expression<'ast>>),
409
+ Unary(UnaryOperator, Box<Expression<'ast>>),
410
+ Assign(Target<'ast>, Option<BinaryOperator>, Box<Expression<'ast>>),
411
+ /// `&&=`, `||=` or `??=`, which stops evaluation once its target is located.
412
+ LogicalAssign(Target<'ast>),
285
413
  Update {
286
414
  target: Target<'ast>,
287
- operator: UpdateOp,
415
+ operator: UpdateOperator,
288
416
  prefix: bool,
289
417
  },
290
418
  Conditional(
@@ -294,8 +422,8 @@ pub(super) enum Expression<'ast> {
294
422
  ),
295
423
  Array(Vec<Option<Expression<'ast>>>),
296
424
  Object(Vec<(Property<'ast>, Expression<'ast>)>),
297
- Function(Option<&'ast Atom>, &'ast Function),
298
- Arrow(&'ast ArrowExpr),
425
+ Function(Option<&'ast str>, &'ast Function<'ast>),
426
+ Arrow(&'ast ArrowFunctionExpression<'ast>),
299
427
  /// Syntax the interpreter does not follow, described for diagnostics.
300
428
  Unsupported(&'static str),
301
429
  }
@@ -310,97 +438,157 @@ pub(super) enum Target<'ast> {
310
438
  Member(Box<Expression<'ast>>, Property<'ast>),
311
439
  }
312
440
 
313
- /// A name a plan reads or writes: a local, by its slot, or a name resolved through scopes.
441
+ /// A binding a plan reads or writes: a local, by its slot, or a binding resolved through
442
+ /// scopes.
314
443
  #[derive(Clone, Copy)]
315
444
  pub(super) enum Name<'ast> {
316
- Local(usize, &'ast Atom),
317
- Global(&'ast Atom),
445
+ Local(usize, Binding<'ast>),
446
+ Scoped(Binding<'ast>),
318
447
  }
319
448
 
320
449
  impl<'ast> Name<'ast> {
321
- pub(super) fn atom(self) -> &'ast Atom {
450
+ pub(super) fn binding(self) -> Binding<'ast> {
322
451
  match self {
323
- Self::Local(_, name) | Self::Global(name) => name,
452
+ Self::Local(_, binding) | Self::Scoped(binding) => binding,
324
453
  }
325
454
  }
326
455
  }
327
456
 
328
- impl PlanCompiler {
329
- /// Gives local `name` a slot unless a nested function mentions it.
330
- fn local(&mut self, name: &Atom) {
331
- if !self.captured.contains(name) {
332
- let next = self.locals.len();
333
- self.locals.entry(name.clone()).or_insert(next);
457
+ impl<'a> PlanCompiler<'a> {
458
+ fn new(script: Script<'a>) -> Self {
459
+ Self {
460
+ script,
461
+ locals: HashMap::default(),
462
+ captured: HashSet::default(),
463
+ rejected: false,
334
464
  }
335
465
  }
336
466
 
467
+ /// Gives local `binding` a slot unless a nested function mentions it.
468
+ fn local(&mut self, binding: Binding<'a>) {
469
+ if let Binding::Symbol(symbol) = binding
470
+ && self.captured.contains(&symbol)
471
+ {
472
+ return;
473
+ }
474
+ let next = self.locals.len();
475
+ self.locals.entry(binding).or_insert(next);
476
+ }
477
+
478
+ /// Gives the variable `declarator` declares a slot.
479
+ fn declared(&mut self, declarator: &VariableDeclarator<'a>) {
480
+ if let BindingPattern::BindingIdentifier(name) = &declarator.id {
481
+ self.local(Binding::Symbol(name.symbol_id()));
482
+ }
483
+ }
484
+
485
+ /// Plans a routine: its function declarations, then its declarations without initializers,
486
+ /// its statements, and what it returns.
487
+ fn routine(&mut self, routine: Routine<'a>) -> Vec<Statement<'a>> {
488
+ let mut plan = self.hoisted(routine.statements);
489
+ for declaration in routine.declarations {
490
+ plan.push(self.variables(declaration, false));
491
+ }
492
+ plan.extend(self.statements(routine.statements));
493
+ if let Some(returned) = routine.returns {
494
+ plan.push(Statement::Return(Some(self.expression(returned))));
495
+ }
496
+ plan
497
+ }
498
+
337
499
  /// Plans a function body or block, binding its function declarations before executing
338
500
  /// statements, as JavaScript hoists them to the start of the body or block. Declarations
339
- /// beside the VM class are planned as statements and resolved as globals.
340
- fn body<'a>(&mut self, statements: &'a [Stmt]) -> Vec<Statement<'a>> {
501
+ /// beside the VM class are planned as statements and resolve through the session.
502
+ fn body(&mut self, statements: &'a [Stmt<'a>]) -> Vec<Statement<'a>> {
503
+ let mut plan = self.hoisted(statements);
504
+ plan.extend(self.statements(statements));
505
+ plan
506
+ }
507
+
508
+ /// Declarations binding the functions `statements` declare.
509
+ fn hoisted(&mut self, statements: &'a [Stmt<'a>]) -> Vec<Statement<'a>> {
341
510
  let mut plan = Vec::with_capacity(statements.len());
342
511
  for statement in statements {
343
- if let Stmt::Decl(Decl::Fn(declaration)) = statement {
344
- let name = &declaration.ident.sym;
512
+ if let Stmt::FunctionDeclaration(function) = statement
513
+ && let Some(name) = &function.id
514
+ {
345
515
  plan.push(Statement::Declare(vec![Declaration {
346
- name: self.name(name),
347
- init: Some(Expression::Function(Some(name), &declaration.function)),
516
+ name: self.name(Binding::Symbol(name.symbol_id())),
517
+ init: Some(Expression::Function(Some(name.name.as_str()), function)),
348
518
  keeps: false,
349
519
  }]));
350
520
  }
351
521
  }
352
- plan.extend(self.statements(statements));
353
522
  plan
354
523
  }
355
524
 
356
- fn statements<'a>(&mut self, statements: &'a [Stmt]) -> Vec<Statement<'a>> {
525
+ fn statements(&mut self, statements: &'a [Stmt<'a>]) -> Vec<Statement<'a>> {
357
526
  statements
358
527
  .iter()
359
528
  .map(|statement| self.statement(statement, None))
360
529
  .collect()
361
530
  }
362
531
 
363
- fn statement<'a>(&mut self, statement: &'a Stmt, label: Option<&'a Atom>) -> Statement<'a> {
532
+ fn statement(&mut self, statement: &'a Stmt<'a>, label: Option<&'a str>) -> Statement<'a> {
364
533
  match statement {
365
- Stmt::Expr(expression) => Statement::Expression(self.expression(&expression.expr)),
366
- Stmt::Decl(Decl::Var(declaration)) => self.variables(declaration),
367
- // Declarations do not bind their names; the names resolve as globals.
368
- Stmt::Decl(Decl::Fn(_) | Decl::Class(_)) | Stmt::Empty(_) => Statement::Empty,
369
- Stmt::Decl(_) => Statement::Expression(self.unsupported("a declaration")),
370
- Stmt::Block(block) => Statement::Block(self.body(&block.stmts)),
371
- Stmt::If(branch) => Statement::If(
534
+ Stmt::ExpressionStatement(expression) => {
535
+ Statement::Expression(self.expression(&expression.expression))
536
+ }
537
+ Stmt::VariableDeclaration(declaration) if !declaration.kind.is_using() => {
538
+ self.variables(declaration, true)
539
+ }
540
+ // Declarations do not bind their names; the names resolve through scopes.
541
+ Stmt::FunctionDeclaration(_) | Stmt::ClassDeclaration(_) | Stmt::EmptyStatement(_) => {
542
+ Statement::Empty
543
+ }
544
+ Stmt::BlockStatement(block) => Statement::Block(self.body(&block.body)),
545
+ Stmt::IfStatement(branch) => Statement::If(
372
546
  self.expression(&branch.test),
373
- Box::new(self.statement(&branch.cons, None)),
547
+ Box::new(self.statement(&branch.consequent, None)),
374
548
  branch
375
- .alt
549
+ .alternate
376
550
  .as_ref()
377
- .map(|alt| Box::new(self.statement(alt, None))),
551
+ .map(|alternate| Box::new(self.statement(alternate, None))),
378
552
  ),
379
- Stmt::Return(returned) => {
380
- Statement::Return(returned.arg.as_ref().map(|arg| self.expression(arg)))
381
- }
382
- Stmt::Throw(thrown) => Statement::Throw(self.expression(&thrown.arg)),
383
- Stmt::Switch(switch) => {
553
+ Stmt::ReturnStatement(returned) => Statement::Return(
554
+ returned
555
+ .argument
556
+ .as_ref()
557
+ .map(|argument| self.expression(argument)),
558
+ ),
559
+ Stmt::ThrowStatement(thrown) => Statement::Throw(self.expression(&thrown.argument)),
560
+ Stmt::SwitchStatement(switch) => {
384
561
  let discriminant = self.expression(&switch.discriminant);
385
562
  let cases = switch.cases.iter().map(|case| Case {
386
563
  test: case.test.as_ref().map(|test| self.expression(test)),
387
- body: self.statements(&case.cons),
564
+ body: self.statements(&case.consequent),
388
565
  });
389
566
  Statement::Switch(discriminant, cases.collect())
390
567
  }
391
- Stmt::Break(branch) => Statement::Break(branch.label.as_ref().map(|label| &label.sym)),
392
- Stmt::Continue(branch) => {
393
- Statement::Continue(branch.label.as_ref().map(|label| &label.sym))
568
+ Stmt::BreakStatement(branch) => {
569
+ Statement::Break(branch.label.as_ref().map(|label| label.name.as_str()))
394
570
  }
395
- Stmt::Labeled(labeled) => Statement::Label(
396
- &labeled.label.sym,
397
- Box::new(self.statement(&labeled.body, Some(&labeled.label.sym))),
398
- ),
399
- Stmt::For(looping) => Statement::Loop {
571
+ Stmt::ContinueStatement(branch) => {
572
+ Statement::Continue(branch.label.as_ref().map(|label| label.name.as_str()))
573
+ }
574
+ Stmt::LabeledStatement(labeled) => {
575
+ let name = labeled.label.name.as_str();
576
+ Statement::Label(name, Box::new(self.statement(&labeled.body, Some(name))))
577
+ }
578
+ Stmt::ForStatement(looping) => Statement::Loop {
400
579
  init: looping.init.as_ref().map(|init| {
401
580
  Box::new(match init {
402
- VarDeclOrExpr::VarDecl(declaration) => self.variables(declaration),
403
- VarDeclOrExpr::Expr(init) => Statement::Expression(self.expression(init)),
581
+ ForStatementInit::VariableDeclaration(declaration)
582
+ if !declaration.kind.is_using() =>
583
+ {
584
+ self.variables(declaration, true)
585
+ }
586
+ ForStatementInit::VariableDeclaration(_) => {
587
+ Statement::Expression(self.unsupported("a declaration"))
588
+ }
589
+ init => Statement::Expression(
590
+ self.expression(init.as_expression().expect("an expression")),
591
+ ),
404
592
  })
405
593
  }),
406
594
  test: looping.test.as_ref().map(|test| self.expression(test)),
@@ -412,46 +600,64 @@ impl PlanCompiler {
412
600
  body_first: false,
413
601
  label,
414
602
  },
415
- Stmt::While(WhileStmt { test, body, .. })
416
- | Stmt::DoWhile(DoWhileStmt { test, body, .. }) => Statement::Loop {
603
+ Stmt::WhileStatement(looping) => Statement::Loop {
417
604
  init: None,
418
- test: Some(self.expression(test)),
605
+ test: Some(self.expression(&looping.test)),
419
606
  update: None,
420
- body: Box::new(self.statement(body, None)),
421
- body_first: matches!(statement, Stmt::DoWhile(_)),
607
+ body: Box::new(self.statement(&looping.body, None)),
608
+ body_first: false,
422
609
  label,
423
610
  },
424
- Stmt::Try(attempt) => {
425
- let handler = attempt.handler.as_ref();
611
+ Stmt::DoWhileStatement(looping) => Statement::Loop {
612
+ init: None,
613
+ test: Some(self.expression(&looping.test)),
614
+ update: None,
615
+ body: Box::new(self.statement(&looping.body, None)),
616
+ body_first: true,
617
+ label,
618
+ },
619
+ Stmt::TryStatement(attempt) => {
620
+ let handler = attempt.handler.as_deref();
426
621
  let parameter = match handler.and_then(|handler| handler.param.as_ref()) {
427
622
  None => None,
428
- Some(Pat::Ident(name)) => Some(self.name(&name.sym)),
429
- Some(_) => {
430
- return Statement::Expression(self.unsupported("a destructuring catch"));
431
- }
623
+ Some(parameter) => match &parameter.pattern {
624
+ BindingPattern::BindingIdentifier(name) => {
625
+ Some(self.name(Binding::Symbol(name.symbol_id())))
626
+ }
627
+ _ => {
628
+ return Statement::Expression(
629
+ self.unsupported("a destructuring catch"),
630
+ );
631
+ }
632
+ },
432
633
  };
433
634
  Statement::Try {
434
- block: self.body(&attempt.block.stmts),
635
+ block: self.body(&attempt.block.body),
435
636
  parameter,
436
- handler: handler.map(|handler| self.body(&handler.body.stmts)),
437
- finalizer: attempt
438
- .finalizer
439
- .as_ref()
440
- .map(|body| self.body(&body.stmts)),
637
+ handler: handler.map(|handler| self.body(&handler.body.body)),
638
+ finalizer: attempt.finalizer.as_ref().map(|body| self.body(&body.body)),
441
639
  }
442
640
  }
443
- Stmt::ForIn(_) | Stmt::ForOf(_) => {
641
+ Stmt::ForInStatement(_) | Stmt::ForOfStatement(_) => {
444
642
  Statement::Expression(self.unsupported("a for-in or for-of loop"))
445
643
  }
446
- Stmt::With(_) => Statement::Expression(self.unsupported("a with statement")),
447
- Stmt::Debugger(_) => Statement::Expression(self.unsupported("a debugger statement")),
644
+ Stmt::WithStatement(_) => Statement::Expression(self.unsupported("a with statement")),
645
+ Stmt::DebuggerStatement(_) => {
646
+ Statement::Expression(self.unsupported("a debugger statement"))
647
+ }
648
+ _ => Statement::Expression(self.unsupported("a declaration")),
448
649
  }
449
650
  }
450
651
 
451
- fn variables<'a>(&mut self, declaration: &'a VarDecl) -> Statement<'a> {
452
- let mut declarations = Vec::with_capacity(declaration.decls.len());
453
- for declarator in &declaration.decls {
454
- let Pat::Ident(name) = &declarator.name else {
652
+ /// Plans a variable declaration, with its initializers if `initialized`.
653
+ fn variables(
654
+ &mut self,
655
+ declaration: &'a VariableDeclaration<'a>,
656
+ initialized: bool,
657
+ ) -> Statement<'a> {
658
+ let mut declarations = Vec::with_capacity(declaration.declarations.len());
659
+ for declarator in &declaration.declarations {
660
+ let BindingPattern::BindingIdentifier(name) = &declarator.id else {
455
661
  // The declarators before it run first.
456
662
  let stop = self.unsupported("a destructuring declaration");
457
663
  return Statement::Block(vec![
@@ -459,256 +665,290 @@ impl PlanCompiler {
459
665
  Statement::Expression(stop),
460
666
  ]);
461
667
  };
462
- self.rejected |= name.sym == "arguments";
668
+ self.rejected |= name.name == "arguments";
669
+ let init = declarator.init.as_ref().filter(|_| initialized);
463
670
  declarations.push(Declaration {
464
- name: self.name(&name.sym),
465
- init: declarator.init.as_ref().map(|init| self.expression(init)),
466
- keeps: declaration.kind == VarDeclKind::Var && declarator.init.is_none(),
671
+ name: self.name(Binding::Symbol(name.symbol_id())),
672
+ init: init.map(|init| self.expression(init)),
673
+ keeps: declaration.kind == VariableDeclarationKind::Var && init.is_none(),
467
674
  });
468
675
  }
469
676
  Statement::Declare(declarations)
470
677
  }
471
678
 
472
- fn property<'a>(&mut self, property: &'a MemberProp) -> Property<'a> {
473
- match property {
474
- MemberProp::Ident(name) => Property::Name(&name.sym),
475
- MemberProp::Computed(key) => Property::Computed(Box::new(self.expression(&key.expr))),
476
- MemberProp::PrivateName(_) => self.unsupported_key("a private name"),
679
+ fn name(&self, binding: Binding<'a>) -> Name<'a> {
680
+ match self.locals.get(&binding) {
681
+ Some(&slot) => Name::Local(slot, binding),
682
+ None => Name::Scoped(binding),
477
683
  }
478
684
  }
479
685
 
480
- fn name<'a>(&self, name: &'a Atom) -> Name<'a> {
481
- match self.locals.get(name) {
482
- Some(&slot) => Name::Local(slot, name),
483
- None => Name::Global(name),
484
- }
686
+ fn reference(&self, reference: &IdentifierReference<'a>) -> Name<'a> {
687
+ self.name(self.script.binding(reference))
485
688
  }
486
689
 
487
- fn member_target<'a>(&mut self, member: &'a MemberExpr) -> Target<'a> {
488
- Target::Member(
489
- Box::new(self.expression(&member.obj)),
490
- self.property(&member.prop),
491
- )
690
+ /// Plans the object and property of `member`, or returns `None` for a `super` property.
691
+ fn member(
692
+ &mut self,
693
+ member: &'a MemberExpression<'a>,
694
+ ) -> Option<(Expression<'a>, Property<'a>)> {
695
+ if matches!(member.object(), Expr::Super(_)) {
696
+ return None;
697
+ }
698
+ let object = self.expression(member.object());
699
+ let property = match member {
700
+ MemberExpression::StaticMemberExpression(member) => {
701
+ Property::Name(member.property.name.as_str())
702
+ }
703
+ MemberExpression::ComputedMemberExpression(member) => {
704
+ Property::Computed(Box::new(self.expression(&member.expression)))
705
+ }
706
+ MemberExpression::PrivateFieldExpression(_) => self.unsupported_key("a private name"),
707
+ };
708
+ Some((object, property))
492
709
  }
493
710
 
494
- fn arguments<'a>(&mut self, arguments: &'a [ExprOrSpread]) -> Vec<Expression<'a>> {
711
+ fn arguments(&mut self, arguments: &'a [Argument<'a>]) -> Vec<Expression<'a>> {
495
712
  arguments
496
713
  .iter()
497
- .map(|argument| match argument.spread {
498
- None => self.expression(&argument.expr),
499
- Some(_) => self.unsupported("a spread argument"),
714
+ .map(|argument| match argument.as_expression() {
715
+ Some(argument) => self.expression(argument),
716
+ None => self.unsupported("a spread argument"),
500
717
  })
501
718
  .collect()
502
719
  }
503
720
 
504
721
  /// Compiles a `key: value` property. Unsupported property forms stop evaluation before the
505
722
  /// value.
506
- fn object_property<'a>(
723
+ fn object_property(
507
724
  &mut self,
508
- property: &'a PropOrSpread,
725
+ property: &'a ObjectPropertyKind<'a>,
509
726
  ) -> (Property<'a>, Expression<'a>) {
510
727
  let property = match property {
511
- PropOrSpread::Prop(property) => match &**property {
512
- Prop::KeyValue(property) => property,
513
- _ => return self.unsupported_property("an object method or shorthand"),
514
- },
515
- PropOrSpread::Spread(_) => return self.unsupported_property("a spread property"),
728
+ ObjectPropertyKind::ObjectProperty(property)
729
+ if property.kind == PropertyKind::Init
730
+ && !property.method
731
+ && !property.shorthand =>
732
+ {
733
+ property
734
+ }
735
+ ObjectPropertyKind::ObjectProperty(_) => {
736
+ return self.unsupported_property("an object method or shorthand");
737
+ }
738
+ ObjectPropertyKind::SpreadProperty(_) => {
739
+ return self.unsupported_property("a spread property");
740
+ }
516
741
  };
517
742
  let key = match &property.key {
518
- PropName::Ident(name) => Property::Name(&name.sym),
743
+ key if property.computed => {
744
+ self.rejected = true;
745
+ let key = key
746
+ .as_expression()
747
+ .expect("a computed key is an expression");
748
+ Property::Computed(Box::new(self.expression(key)))
749
+ }
750
+ PropertyKey::StaticIdentifier(name) => Property::Name(name.name.as_str()),
519
751
  // Property keys require text; lone-surrogate strings have no text representation.
520
- PropName::Str(name) => match name.value.as_str() {
752
+ PropertyKey::StringLiteral(name) => match name.value.as_str() {
521
753
  Some(name) => Property::Name(name),
522
754
  None => self.unsupported_key("an object key with a lone surrogate"),
523
755
  },
524
- PropName::Num(number) => {
756
+ PropertyKey::NumericLiteral(number) => {
525
757
  Property::Computed(Box::new(Expression::Constant(Value::Number(number.value))))
526
758
  }
527
- PropName::Computed(key) => {
528
- self.rejected = true;
529
- Property::Computed(Box::new(self.expression(&key.expr)))
530
- }
531
- PropName::BigInt(_) => self.unsupported_key("a bigint key"),
759
+ PropertyKey::BigIntLiteral(_) => self.unsupported_key("a bigint key"),
760
+ _ => self.unsupported_key("a private name"),
532
761
  };
533
762
  (key, self.expression(&property.value))
534
763
  }
535
764
 
536
765
  /// Compiles unsupported syntax as a node that stops evaluation. Slot-plan compilation
537
766
  /// rejects it.
538
- fn unsupported<'a>(&mut self, reason: &'static str) -> Expression<'a> {
767
+ fn unsupported(&mut self, reason: &'static str) -> Expression<'a> {
539
768
  self.rejected = true;
540
769
  Expression::Unsupported(reason)
541
770
  }
542
771
 
543
- fn unsupported_key<'a>(&mut self, reason: &'static str) -> Property<'a> {
772
+ fn unsupported_key(&mut self, reason: &'static str) -> Property<'a> {
544
773
  Property::Computed(Box::new(self.unsupported(reason)))
545
774
  }
546
775
 
547
776
  /// A property that stops at its key; its value is never reached.
548
- fn unsupported_property<'a>(&mut self, reason: &'static str) -> (Property<'a>, Expression<'a>) {
777
+ fn unsupported_property(&mut self, reason: &'static str) -> (Property<'a>, Expression<'a>) {
549
778
  (
550
779
  self.unsupported_key(reason),
551
780
  Expression::Unsupported(reason),
552
781
  )
553
782
  }
554
783
 
555
- fn expression<'a>(&mut self, expression: &'a Expr) -> Expression<'a> {
784
+ /// Plans a name or member target, or returns `None` for other targets.
785
+ fn target(&mut self, target: &'a SimpleAssignmentTarget<'a>) -> Option<Target<'a>> {
786
+ match target {
787
+ SimpleAssignmentTarget::AssignmentTargetIdentifier(name) => {
788
+ Some(Target::Name(self.reference(name)))
789
+ }
790
+ target => {
791
+ let (object, property) = self.member(target.as_member_expression()?)?;
792
+ Some(Target::Member(Box::new(object), property))
793
+ }
794
+ }
795
+ }
796
+
797
+ fn expression(&mut self, expression: &'a Expr<'a>) -> Expression<'a> {
556
798
  match expression {
557
- Expr::Lit(literal) => Expression::Constant(match literal {
558
- Lit::Num(number) => Value::Number(number.value),
559
- // Literals may hold lone surrogates, which only code units keep.
560
- Lit::Str(text) => Value::String(text.value.to_ill_formed_utf16().collect()),
561
- Lit::Bool(value) => Value::Bool(value.value),
562
- Lit::Null(_) => Value::Null,
563
- _ => return self.unsupported("a regular expression or bigint literal"),
564
- }),
565
- Expr::Tpl(template) if template.exprs.is_empty() => {
566
- match template
567
- .quasis
568
- .first()
569
- .and_then(|quasi| quasi.cooked.as_ref())
570
- {
799
+ Expr::NumericLiteral(number) => Expression::Constant(Value::Number(number.value)),
800
+ // Literals may hold lone surrogates, which only code units keep.
801
+ Expr::StringLiteral(text) => {
802
+ Expression::Constant(Value::String(text.value.encode_utf16().collect()))
803
+ }
804
+ Expr::BooleanLiteral(value) => Expression::Constant(Value::Bool(value.value)),
805
+ Expr::NullLiteral(_) => Expression::Constant(Value::Null),
806
+ Expr::RegExpLiteral(_) | Expr::BigIntLiteral(_) => {
807
+ self.unsupported("a regular expression or bigint literal")
808
+ }
809
+ Expr::TemplateLiteral(template) if template.expressions.is_empty() => {
810
+ match template.quasis.first().and_then(|quasi| quasi.value.cooked) {
571
811
  Some(cooked) => {
572
- Expression::Constant(Value::String(cooked.to_ill_formed_utf16().collect()))
812
+ Expression::Constant(Value::String(cooked.encode_utf16().collect()))
573
813
  }
574
814
  None => self.unsupported("a raw template"),
575
815
  }
576
816
  }
577
- Expr::Ident(name) => Expression::Name(self.name(&name.sym)),
578
- Expr::This(_) => Expression::This,
579
- Expr::Paren(paren) => self.expression(&paren.expr),
580
- Expr::Seq(sequence) => Expression::Sequence(
817
+ Expr::Identifier(name) => Expression::Name(self.reference(name)),
818
+ Expr::ThisExpression(_) => Expression::This,
819
+ Expr::ParenthesizedExpression(paren) => self.expression(&paren.expression),
820
+ Expr::SequenceExpression(sequence) => Expression::Sequence(
581
821
  sequence
582
- .exprs
822
+ .expressions
583
823
  .iter()
584
824
  .map(|expression| self.expression(expression))
585
825
  .collect(),
586
826
  ),
587
- Expr::Member(member) => Expression::Member(
588
- Box::new(self.expression(&member.obj)),
589
- self.property(&member.prop),
590
- ),
591
- Expr::Call(call) => {
592
- let Callee::Expr(callee) = &call.callee else {
827
+ Expr::StaticMemberExpression(_)
828
+ | Expr::ComputedMemberExpression(_)
829
+ | Expr::PrivateFieldExpression(_) => {
830
+ let member = expression
831
+ .as_member_expression()
832
+ .expect("a member expression");
833
+ match self.member(member) {
834
+ Some((object, property)) => Expression::Member(Box::new(object), property),
835
+ None => self.unsupported("a super property expression"),
836
+ }
837
+ }
838
+ Expr::CallExpression(call) => {
839
+ let callee = &call.callee;
840
+ if matches!(callee, Expr::Super(_)) {
593
841
  return self.unsupported("a super or import call");
594
- };
595
- self.rejected |= matches!(&**callee, Expr::Paren(_));
842
+ }
843
+ self.rejected |= matches!(callee, Expr::ParenthesizedExpression(_));
596
844
  // The interpreter calls parenthesized members without a receiver, like
597
845
  // `(0, o.f)()`. JavaScript normally preserves the receiver in `(o.f)()`.
598
- let callee = match (&**callee, self.expression(callee)) {
599
- (Expr::Paren(_), member @ Expression::Member(..)) => {
846
+ let callee = match (callee, self.expression(callee)) {
847
+ (Expr::ParenthesizedExpression(_), member @ Expression::Member(..)) => {
600
848
  Expression::Sequence(vec![member])
601
849
  }
602
850
  (_, callee) => callee,
603
851
  };
604
- Expression::Call(Box::new(callee), self.arguments(&call.args))
852
+ Expression::Call(Box::new(callee), self.arguments(&call.arguments))
605
853
  }
606
- Expr::New(construction) => Expression::New(
854
+ Expr::ImportExpression(_) => self.unsupported("a super or import call"),
855
+ Expr::NewExpression(construction) => Expression::New(
607
856
  Box::new(self.expression(&construction.callee)),
608
- match &construction.args {
609
- Some(arguments) => self.arguments(arguments),
610
- None => Vec::new(),
611
- },
857
+ self.arguments(&construction.arguments),
612
858
  ),
613
- Expr::Bin(binary) => {
859
+ Expr::LogicalExpression(logical) => Expression::Logical {
860
+ operator: logical.operator,
861
+ left: Box::new(self.expression(&logical.left)),
862
+ right: Box::new(self.expression(&logical.right)),
863
+ pure: pure(&logical.right),
864
+ },
865
+ Expr::BinaryExpression(binary) => {
614
866
  let left = Box::new(self.expression(&binary.left));
615
867
  let right = Box::new(self.expression(&binary.right));
616
- match binary.op {
617
- operator @ (BinaryOp::LogicalAnd
618
- | BinaryOp::LogicalOr
619
- | BinaryOp::NullishCoalescing) => Expression::Logical {
868
+ let operator = binary.operator;
869
+ match semantics::numeric(operator) {
870
+ Some(operation) => Expression::Arithmetic {
620
871
  operator,
872
+ operation,
621
873
  left,
622
874
  right,
623
- pure: pure(&binary.right),
624
- },
625
- operator => match semantics::numeric(operator) {
626
- Some(operation) => Expression::Arithmetic {
627
- operator,
628
- operation,
629
- left,
630
- right,
631
- },
632
- None => Expression::Binary(operator, left, right),
633
875
  },
876
+ None => Expression::Binary(operator, left, right),
634
877
  }
635
878
  }
636
- Expr::Unary(unary) if unary.op == UnaryOp::Delete => self.unsupported("delete"),
637
- Expr::Unary(unary) => {
638
- Expression::Unary(unary.op, Box::new(self.expression(&unary.arg)))
879
+ Expr::UnaryExpression(unary) if unary.operator == UnaryOperator::Delete => {
880
+ self.unsupported("delete")
639
881
  }
640
- Expr::Assign(assign) => {
641
- let target = match &assign.left {
642
- AssignTarget::Simple(SimpleAssignTarget::Ident(name)) => {
643
- Target::Name(self.name(&name.id.sym))
644
- }
645
- AssignTarget::Simple(SimpleAssignTarget::Member(member)) => {
646
- self.member_target(member)
647
- }
648
- _ => return self.unsupported("a destructuring assignment"),
882
+ Expr::UnaryExpression(unary) => {
883
+ Expression::Unary(unary.operator, Box::new(self.expression(&unary.argument)))
884
+ }
885
+ Expr::AssignmentExpression(assignment) => {
886
+ let target = assignment.left.as_simple_assignment_target();
887
+ let Some(target) = target.and_then(|target| self.target(target)) else {
888
+ return self.unsupported("a destructuring assignment");
649
889
  };
650
- let operator = assign.op.to_update();
651
- self.rejected |= matches!(
652
- operator,
653
- Some(BinaryOp::LogicalAnd | BinaryOp::LogicalOr | BinaryOp::NullishCoalescing)
654
- );
655
- let right = Box::new(self.expression(&assign.right));
890
+ if assignment.operator.is_logical() {
891
+ self.rejected = true;
892
+ return Expression::LogicalAssign(target);
893
+ }
894
+ let operator = assignment.operator.to_binary_operator();
895
+ let right = Box::new(self.expression(&assignment.right));
656
896
  Expression::Assign(target, operator, right)
657
897
  }
658
- Expr::Update(update) => Expression::Update {
659
- target: match &*update.arg {
660
- Expr::Ident(name) => Target::Name(self.name(&name.sym)),
661
- Expr::Member(member) => self.member_target(member),
662
- _ => return self.unsupported("an increment of an expression"),
898
+ Expr::UpdateExpression(update) => match self.target(&update.argument) {
899
+ Some(target) => Expression::Update {
900
+ target,
901
+ operator: update.operator,
902
+ prefix: update.prefix,
663
903
  },
664
- operator: update.op,
665
- prefix: update.prefix,
904
+ None => self.unsupported("an increment of an expression"),
666
905
  },
667
- Expr::Cond(conditional) => Expression::Conditional(
906
+ Expr::ConditionalExpression(conditional) => Expression::Conditional(
668
907
  Box::new(self.expression(&conditional.test)),
669
- Box::new(self.expression(&conditional.cons)),
670
- Box::new(self.expression(&conditional.alt)),
908
+ Box::new(self.expression(&conditional.consequent)),
909
+ Box::new(self.expression(&conditional.alternate)),
671
910
  ),
672
- Expr::Array(array) => Expression::Array(
911
+ Expr::ArrayExpression(array) => Expression::Array(
673
912
  array
674
- .elems
913
+ .elements
675
914
  .iter()
676
915
  .map(|element| match element {
677
- Some(element) if element.spread.is_none() => {
678
- Some(self.expression(&element.expr))
916
+ ArrayExpressionElement::Elision(_) => None,
917
+ ArrayExpressionElement::SpreadElement(_) => {
918
+ Some(self.unsupported("a spread element"))
919
+ }
920
+ element => {
921
+ Some(self.expression(element.as_expression().expect("an element")))
679
922
  }
680
- Some(_) => Some(self.unsupported("a spread element")),
681
- None => None,
682
923
  })
683
924
  .collect(),
684
925
  ),
685
- Expr::Object(object) => Expression::Object(
926
+ Expr::ObjectExpression(object) => Expression::Object(
686
927
  object
687
- .props
928
+ .properties
688
929
  .iter()
689
930
  .map(|property| self.object_property(property))
690
931
  .collect(),
691
932
  ),
692
- Expr::Fn(function) => {
693
- let name = function.ident.as_ref().map(|ident| &ident.sym);
694
- Expression::Function(name, &function.function)
933
+ Expr::FunctionExpression(function) => {
934
+ let name = function.id.as_ref().map(|name| name.name.as_str());
935
+ Expression::Function(name, function)
695
936
  }
696
937
  // Arrows inherit `arguments`, which slot plans keep out of scopes.
697
- Expr::Arrow(arrow) => {
698
- let mut names = Names::default();
699
- arrow.visit_with(&mut names);
700
- self.rejected |= names.0.contains(&atom!("arguments"));
938
+ Expr::ArrowFunctionExpression(arrow) => {
939
+ let mut mentions = MentionsArguments::default();
940
+ mentions.visit_arrow_function_expression(arrow);
941
+ self.rejected |= mentions.0;
701
942
  Expression::Arrow(arrow)
702
943
  }
703
944
  expression => self.unsupported(match expression {
704
- Expr::Tpl(_) => "a template expression",
705
- Expr::TaggedTpl(_) => "a tagged template expression",
706
- Expr::OptChain(_) => "an optional chain expression",
707
- Expr::Await(_) => "an await expression",
708
- Expr::Yield(_) => "a yield expression",
709
- Expr::Class(_) => "a class expression",
710
- Expr::MetaProp(_) => "a meta property expression",
711
- Expr::SuperProp(_) => "a super property expression",
945
+ Expr::TemplateLiteral(_) => "a template expression",
946
+ Expr::TaggedTemplateExpression(_) => "a tagged template expression",
947
+ Expr::ChainExpression(_) => "an optional chain expression",
948
+ Expr::AwaitExpression(_) => "an await expression",
949
+ Expr::YieldExpression(_) => "a yield expression",
950
+ Expr::ClassExpression(_) => "a class expression",
951
+ Expr::ImportMeta(_) | Expr::NewTarget(_) => "a meta property expression",
712
952
  _ => "an unsupported expression",
713
953
  }),
714
954
  }
@@ -717,21 +957,29 @@ impl PlanCompiler {
717
957
 
718
958
  /// Checks whether `expr` only produces a value or throws. Rejects calls, writes, and
719
959
  /// register-dependent branches.
720
- fn pure(expr: &Expr) -> bool {
960
+ fn pure(expr: &Expr<'_>) -> bool {
721
961
  match expr {
722
- Expr::Lit(_) | Expr::Ident(_) | Expr::This(_) | Expr::Fn(_) | Expr::Arrow(_) => true,
723
- Expr::Tpl(template) => template.exprs.is_empty(),
724
- Expr::Paren(paren) => pure(&paren.expr),
725
- Expr::Seq(sequence) => sequence.exprs.iter().all(|expr| pure(expr)),
726
- Expr::Member(member) => {
727
- pure(&member.obj)
728
- && match &member.prop {
729
- MemberProp::Computed(computed) => pure(&computed.expr),
730
- _ => true,
731
- }
962
+ Expr::NumericLiteral(_)
963
+ | Expr::StringLiteral(_)
964
+ | Expr::BooleanLiteral(_)
965
+ | Expr::NullLiteral(_)
966
+ | Expr::BigIntLiteral(_)
967
+ | Expr::RegExpLiteral(_)
968
+ | Expr::Identifier(_)
969
+ | Expr::ThisExpression(_)
970
+ | Expr::FunctionExpression(_)
971
+ | Expr::ArrowFunctionExpression(_) => true,
972
+ Expr::TemplateLiteral(template) => template.expressions.is_empty(),
973
+ Expr::ParenthesizedExpression(paren) => pure(&paren.expression),
974
+ Expr::SequenceExpression(sequence) => sequence.expressions.iter().all(pure),
975
+ Expr::StaticMemberExpression(member) => pure(&member.object),
976
+ Expr::PrivateFieldExpression(member) => pure(&member.object),
977
+ Expr::ComputedMemberExpression(member) => pure(&member.object) && pure(&member.expression),
978
+ Expr::UnaryExpression(unary) => {
979
+ unary.operator != UnaryOperator::Delete && pure(&unary.argument)
732
980
  }
733
- Expr::Unary(unary) => unary.op != UnaryOp::Delete && pure(&unary.arg),
734
- Expr::Bin(binary) => pure(&binary.left) && pure(&binary.right),
981
+ Expr::BinaryExpression(binary) => pure(&binary.left) && pure(&binary.right),
982
+ Expr::LogicalExpression(logical) => pure(&logical.left) && pure(&logical.right),
735
983
  _ => false,
736
984
  }
737
985
  }