cfsolve 0.1.1 → 0.1.3

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