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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +10 -9
- data/THIRD_PARTY_LICENSES/README.md +71 -254
- data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
- data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
- data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
- data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
- data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
- data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
- data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
- data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
- data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
- data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
- data/UPSTREAM.md +10 -8
- data/ext/cfsolve/Cargo.lock +534 -1727
- data/ext/cfsolve/Cargo.toml +4 -0
- data/ext/cfsolve/src/main.rs +1 -1
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +2570 -1894
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
- data/lib/cfsolve/profiles/safari-26-ios.json +102 -156
- data/lib/cfsolve/version.rb +2 -2
- data/vendor/cfsolve/Cargo.lock +561 -1729
- data/vendor/cfsolve/Cargo.toml +26 -8
- data/vendor/cfsolve/README.md +4 -35
- data/vendor/cfsolve/examples/build_profile.rs +17 -15
- data/vendor/cfsolve/examples/capture_session.rs +37 -0
- data/vendor/cfsolve/examples/check_answers.rs +66 -0
- data/vendor/cfsolve/examples/compare_session.rs +189 -0
- data/vendor/cfsolve/examples/solver_profile.rs +84 -0
- data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
- data/vendor/cfsolve/examples/stage2_snapshot.rs +6 -3
- data/vendor/cfsolve/examples/tls_echo.rs +3 -3
- data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +2570 -1894
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
- data/vendor/cfsolve/profiles/safari-26-ios.json +102 -156
- data/vendor/cfsolve/scripts/capture_cssom.mjs +42 -0
- data/vendor/cfsolve/scripts/serve_cssom.py +111 -0
- data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
- data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
- data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
- data/vendor/cfsolve/src/capture/profile.rs +7 -18
- data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- data/vendor/cfsolve/src/capture/recorded.rs +42 -7
- data/vendor/cfsolve/src/capture/sessions.rs +4 -3
- data/vendor/cfsolve/src/capture/upstream.rs +1 -1
- data/vendor/cfsolve/src/challenge/codec.rs +4 -2
- data/vendor/cfsolve/src/challenge/expression.rs +161 -117
- data/vendor/cfsolve/src/challenge/installed/audit.rs +132 -0
- data/vendor/cfsolve/src/challenge/installed.rs +127 -269
- data/vendor/cfsolve/src/challenge/merge.rs +120 -80
- data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
- data/vendor/cfsolve/src/challenge/payload.rs +175 -35
- data/vendor/cfsolve/src/challenge/program.rs +197 -178
- data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
- data/vendor/cfsolve/src/challenge/source.rs +151 -96
- data/vendor/cfsolve/src/challenge/state.rs +236 -122
- data/vendor/cfsolve/src/challenge/tally.rs +64 -50
- data/vendor/cfsolve/src/challenge.rs +1 -0
- data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
- data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
- data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
- data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
- data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
- data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
- data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
- data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
- data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
- data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
- data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
- data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
- data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
- data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
- data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
- data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
- data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
- data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +201 -205
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +346 -536
- data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
- data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
- data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
- data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
- data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
- data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
- data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
- data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +361 -322
- data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
- data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
- data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
- data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
- data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
- data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
- data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
- data/vendor/cfsolve/src/deobfuscate.rs +15 -11
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -32
- data/vendor/cfsolve/src/embedding_page/page.rs +28 -2
- data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
- data/vendor/cfsolve/src/error.rs +40 -5
- data/vendor/cfsolve/src/fingerprint.rs +8 -2
- data/vendor/cfsolve/src/http/client.rs +9 -1
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -254
- data/vendor/cfsolve/src/js/objects.rs +9 -2
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -92
- data/vendor/cfsolve/src/listing/query.rs +26 -291
- data/vendor/cfsolve/src/listing.rs +0 -1
- data/vendor/cfsolve/src/performance_clock.rs +20 -1
- data/vendor/cfsolve/src/profiling.rs +49 -0
- data/vendor/cfsolve/src/script.rs +35 -24
- data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
- data/vendor/cfsolve/src/session/channel.rs +2 -2
- data/vendor/cfsolve/src/session/initial.rs +19 -10
- data/vendor/cfsolve/src/session/probes.rs +160 -125
- data/vendor/cfsolve/src/session/sink.rs +26 -1
- data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
- data/vendor/cfsolve/src/session/timing.rs +58 -53
- data/vendor/cfsolve/src/session/widget.rs +5 -6
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +50 -33
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +61 -66
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +33 -22
- data/vendor/cfsolve/src/stage2/analysis/recognize.rs +3 -5
- data/vendor/cfsolve/src/stage2/analysis.rs +0 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +378 -0
- data/vendor/cfsolve/src/stage2/benchmark.rs +66 -38
- data/vendor/cfsolve/src/stage2/call_stack.rs +1463 -1017
- data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
- data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
- data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
- data/vendor/cfsolve/src/stage2/interaction/native.rs +2 -1
- data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -7
- data/vendor/cfsolve/src/stage2/payload/recover.rs +56 -25
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/ice.rs +11 -10
- data/vendor/cfsolve/src/stage2/probes/media.rs +47 -33
- data/vendor/cfsolve/src/stage2/probes/performance.rs +13 -8
- data/vendor/cfsolve/src/stage2/probes/rects.rs +12 -17
- data/vendor/cfsolve/src/stage2/probes/stack.rs +50 -103
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +17 -86
- data/vendor/cfsolve/src/stage2/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/records.rs +4 -13
- data/vendor/cfsolve/src/stage2/reference.json +1 -1
- data/vendor/cfsolve/src/stage2/reference.rs +98 -100
- data/vendor/cfsolve/src/stage2/registry.rs +41 -34
- data/vendor/cfsolve/src/stage2/replay.rs +182 -254
- data/vendor/cfsolve/src/stage2/stylesheets.rs +176 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +152 -108
- data/vendor/cfsolve/src/stage2/vocabulary.rs +103 -403
- data/vendor/cfsolve/src/stage2.rs +4 -1
- data/vendor/cfsolve/src/vm/disassemble.rs +46 -13
- data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
- data/vendor/cfsolve/src/vm/extract.rs +347 -250
- data/vendor/cfsolve/src/vm/interpret/access.rs +67 -68
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +16 -63
- data/vendor/cfsolve/src/vm/interpret/call.rs +192 -51
- data/vendor/cfsolve/src/vm/interpret/compile.rs +643 -0
- data/vendor/cfsolve/src/vm/interpret/copies.rs +232 -120
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +149 -40
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +189 -572
- data/vendor/cfsolve/src/vm/interpret/explore.rs +159 -46
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +169 -0
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +414 -0
- data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
- data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
- data/vendor/cfsolve/src/vm/interpret/plan.rs +605 -330
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +314 -54
- data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
- data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
- data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
- data/vendor/cfsolve/src/vm/interpret.rs +16 -3
- data/vendor/cfsolve/src/vm/machine.rs +58 -47
- data/vendor/cfsolve/src/vm/output.rs +13 -5
- data/vendor/cfsolve/src/vm/packed_names.rs +311 -0
- data/vendor/cfsolve/src/vm/session.rs +197 -110
- data/vendor/cfsolve/src/vm/value.rs +35 -19
- data/vendor/cfsolve/src/vm.rs +3 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- data/vendor/cfsolve/vendor/btls-sys/src/lib.rs +3 -0
- metadata +106 -183
- data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
- data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
- data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
- data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
- data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
- data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
- data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
- data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
- data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
- data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
- data/vendor/cfsolve/src/listing/normalize.rs +0 -264
- data/vendor/cfsolve/src/stage2/analysis/outputs.rs +0 -327
- data/vendor/cfsolve/src/stage2/probes/stylesheets.rs +0 -249
- data/vendor/cfsolve/src/stage2/reference-expanded.json +0 -42
- data/vendor/cfsolve/src/stage2/session_names.rs +0 -470
- /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
|
@@ -1,132 +1,346 @@
|
|
|
1
|
-
//!
|
|
2
|
-
//! deobfuscation.
|
|
1
|
+
//! Oxc parsing, semantic analysis, and syntax matchers used by extraction and the VM.
|
|
3
2
|
//!
|
|
4
|
-
//!
|
|
3
|
+
//! Every parsed script carries its [`Scoping`], so code identifies bindings by [`SymbolId`].
|
|
4
|
+
//! Names identify only unresolved references, which are globals. Matchers accept different
|
|
5
|
+
//! syntax depending on the extractor's requirements.
|
|
5
6
|
|
|
6
7
|
use std::collections::BTreeSet;
|
|
8
|
+
use std::{fmt, mem};
|
|
7
9
|
|
|
8
10
|
use anyhow::{Result, ensure};
|
|
9
|
-
use
|
|
10
|
-
use
|
|
11
|
-
use
|
|
12
|
-
|
|
11
|
+
use oxc::allocator::Allocator;
|
|
12
|
+
use oxc::ast::AstKind;
|
|
13
|
+
use oxc::ast::ast::{
|
|
14
|
+
AccessorProperty, Argument, AssignmentTarget, BindingPattern, BindingProperty, Directive,
|
|
15
|
+
Expression, Function, IdentifierReference, MemberExpression, MethodDefinition,
|
|
16
|
+
ObjectExpression, ObjectProperty, ObjectPropertyKind, Program, PropertyDefinition, PropertyKey,
|
|
17
|
+
PropertyKind,
|
|
13
18
|
};
|
|
14
|
-
use
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
use
|
|
20
|
-
use
|
|
19
|
+
use oxc::ast_visit::{Visit, walk};
|
|
20
|
+
use oxc::parser::{ParseOptions, Parser};
|
|
21
|
+
use oxc::semantic::{AstNodes, Scoping, SemanticBuilder, SymbolId};
|
|
22
|
+
use oxc::span::{GetSpan, SourceType};
|
|
23
|
+
use oxc::str::JSStr;
|
|
24
|
+
use oxc::syntax::node::GetNodeId;
|
|
25
|
+
use oxc::syntax::operator::{AssignmentOperator, BinaryOperator, UnaryOperator};
|
|
26
|
+
use oxc::syntax::scope::ScopeFlags;
|
|
27
|
+
use self_cell::self_cell;
|
|
21
28
|
|
|
22
29
|
use crate::engine::{self, Lines};
|
|
23
30
|
|
|
24
|
-
///
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
/// The arena and source text a [`Parsed`] tree borrows.
|
|
32
|
+
struct Owner {
|
|
33
|
+
allocator: Allocator,
|
|
34
|
+
source: String,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// A tree, allocated in its arena, and its semantic analysis.
|
|
38
|
+
struct Parsed<'a> {
|
|
39
|
+
program: &'a Program<'a>,
|
|
40
|
+
scoping: Scoping,
|
|
41
|
+
nodes: AstNodes<'a>,
|
|
28
42
|
}
|
|
29
43
|
|
|
44
|
+
self_cell!(
|
|
45
|
+
struct Cell {
|
|
46
|
+
owner: Owner,
|
|
47
|
+
#[covariant]
|
|
48
|
+
dependent: Parsed,
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
/// A parsed script that owns its arena, source text, and semantic analysis. See [`Script`] for
|
|
53
|
+
/// the borrowed view extractors use.
|
|
54
|
+
pub(crate) struct ParsedScript(Cell);
|
|
55
|
+
|
|
56
|
+
// SAFETY: Oxc trees are `!Send` and `!Sync` because their arena vectors can allocate through a
|
|
57
|
+
// shared `&Allocator`, and their nodes hold semantic IDs in `Cell`s. A `ParsedScript` owns the
|
|
58
|
+
// arena together with every node allocated in it, so moving it moves them all, and it never
|
|
59
|
+
// exposes the `Allocator`. Semantic IDs are written only by `SemanticBuilder` while the script is
|
|
60
|
+
// built; afterwards the tree is only read, so shared references cannot race.
|
|
61
|
+
unsafe impl Send for ParsedScript {}
|
|
62
|
+
// SAFETY: See `Send` above: after construction nothing allocates in the arena or writes a node.
|
|
63
|
+
unsafe impl Sync for ParsedScript {}
|
|
64
|
+
|
|
30
65
|
impl ParsedScript {
|
|
31
|
-
///
|
|
66
|
+
/// Parses `source` as a classic script, using `what` to identify it in errors. Rejects
|
|
67
|
+
/// recoverable parse errors and early errors. Parentheses remain in the tree.
|
|
68
|
+
pub(crate) fn parse(what: &str, source: &str) -> Result<Self> {
|
|
69
|
+
Self::build(what, source.to_owned(), |allocator, source| {
|
|
70
|
+
let parsed = Parser::new(allocator, source, SourceType::script())
|
|
71
|
+
.with_options(ParseOptions::default())
|
|
72
|
+
.parse();
|
|
73
|
+
ensure!(
|
|
74
|
+
parsed.diagnostics.is_empty(),
|
|
75
|
+
"cannot parse {what}: {:?}",
|
|
76
|
+
parsed.diagnostics
|
|
77
|
+
);
|
|
78
|
+
Ok(parsed.program)
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// Builds a script from the tree `build` returns for `source` and analyzes its scopes.
|
|
83
|
+
/// `build` may rewrite the tree, such as by decoding strings; spans keep pointing into
|
|
84
|
+
/// `source`.
|
|
85
|
+
pub(crate) fn build(
|
|
86
|
+
what: &str,
|
|
87
|
+
source: String,
|
|
88
|
+
build: impl for<'a> FnOnce(&'a Allocator, &'a str) -> Result<Program<'a>>,
|
|
89
|
+
) -> Result<Self> {
|
|
90
|
+
let owner = Owner {
|
|
91
|
+
allocator: Allocator::default(),
|
|
92
|
+
source,
|
|
93
|
+
};
|
|
94
|
+
Cell::try_new(owner, |owner| {
|
|
95
|
+
let program = owner
|
|
96
|
+
.allocator
|
|
97
|
+
.alloc(build(&owner.allocator, &owner.source)?);
|
|
98
|
+
let semantic = SemanticBuilder::new()
|
|
99
|
+
.with_check_syntax_error(true)
|
|
100
|
+
.with_build_nodes(true)
|
|
101
|
+
.build(program);
|
|
102
|
+
ensure!(
|
|
103
|
+
semantic.diagnostics.is_empty(),
|
|
104
|
+
"{what} has early errors: {:?}",
|
|
105
|
+
semantic.diagnostics
|
|
106
|
+
);
|
|
107
|
+
let (scoping, nodes) = semantic.semantic.into_scoping_and_nodes();
|
|
108
|
+
Ok(Parsed {
|
|
109
|
+
program,
|
|
110
|
+
scoping,
|
|
111
|
+
nodes,
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
.map(Self)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#[must_use]
|
|
118
|
+
pub(crate) fn script(&self) -> Script<'_> {
|
|
119
|
+
let parsed = self.0.borrow_dependent();
|
|
120
|
+
Script {
|
|
121
|
+
program: parsed.program,
|
|
122
|
+
scoping: &parsed.scoping,
|
|
123
|
+
nodes: &parsed.nodes,
|
|
124
|
+
source: &self.0.borrow_owner().source,
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// A program with its scopes, semantic nodes, and source text. Spans are byte offsets into the
|
|
130
|
+
/// source. [`AstNodes`] list every node in source order with its parent, and lend nodes for the
|
|
131
|
+
/// program's lifetime, unlike [`Visit`], whose borrows end with each visit.
|
|
132
|
+
#[derive(Clone, Copy)]
|
|
133
|
+
pub(crate) struct Script<'a> {
|
|
134
|
+
pub program: &'a Program<'a>,
|
|
135
|
+
pub scoping: &'a Scoping,
|
|
136
|
+
pub nodes: &'a AstNodes<'a>,
|
|
137
|
+
pub source: &'a str,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// What an identifier reference resolves to: a binding in the script, or a global by name.
|
|
141
|
+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
|
142
|
+
pub(crate) enum Binding<'a> {
|
|
143
|
+
Symbol(SymbolId),
|
|
144
|
+
Global(&'a str),
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
impl<'a> Script<'a> {
|
|
148
|
+
/// Returns the original source text of `node`.
|
|
32
149
|
///
|
|
33
150
|
/// # Panics
|
|
34
151
|
///
|
|
35
152
|
/// Panics if `node` was not parsed from this script.
|
|
36
153
|
#[must_use]
|
|
37
|
-
pub(crate) fn text(&self, node: &
|
|
38
|
-
|
|
39
|
-
let offset = |position: BytePos| (position.0 - self.file.start_pos.0) as usize;
|
|
40
|
-
&self.file.src[offset(span.lo)..offset(span.hi)]
|
|
154
|
+
pub(crate) fn text(&self, node: &impl GetSpan) -> &'a str {
|
|
155
|
+
node.span().source_text(self.source)
|
|
41
156
|
}
|
|
42
157
|
|
|
43
|
-
/// Returns the one-based line and UTF-16 column
|
|
158
|
+
/// Returns the one-based line and UTF-16 column of byte offset `at`, matching V8 stack
|
|
159
|
+
/// traces.
|
|
44
160
|
///
|
|
45
161
|
/// # Panics
|
|
46
162
|
///
|
|
47
163
|
/// Panics if `at` is outside this script.
|
|
48
164
|
#[must_use]
|
|
49
|
-
pub(crate) fn position(&self, at:
|
|
50
|
-
let
|
|
51
|
-
let (line, column) = engine::line_and_column(before, Lines::Script);
|
|
165
|
+
pub(crate) fn position(&self, at: u32) -> (usize, usize) {
|
|
166
|
+
let (line, column) = engine::line_and_column(&self.source[..at as usize], Lines::Script);
|
|
52
167
|
(line as usize + 1, column as usize + 1)
|
|
53
168
|
}
|
|
54
|
-
}
|
|
55
169
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
170
|
+
/// The binding `reference` resolves to, or `None` for a global.
|
|
171
|
+
#[must_use]
|
|
172
|
+
pub(crate) fn symbol(&self, reference: &IdentifierReference<'_>) -> Option<SymbolId> {
|
|
173
|
+
self.scoping
|
|
174
|
+
.get_reference(reference.reference_id())
|
|
175
|
+
.symbol_id()
|
|
176
|
+
}
|
|
59
177
|
|
|
60
|
-
///
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
ensure!(parser.take_errors().is_empty(), "{what} has parse errors");
|
|
69
|
-
Ok(ParsedScript { script, file })
|
|
70
|
-
}
|
|
178
|
+
/// What `reference` resolves to.
|
|
179
|
+
#[must_use]
|
|
180
|
+
pub(crate) fn binding(&self, reference: &IdentifierReference<'a>) -> Binding<'a> {
|
|
181
|
+
match self.symbol(reference) {
|
|
182
|
+
Some(symbol) => Binding::Symbol(symbol),
|
|
183
|
+
None => Binding::Global(reference.name.as_str()),
|
|
184
|
+
}
|
|
185
|
+
}
|
|
71
186
|
|
|
72
|
-
///
|
|
73
|
-
#[
|
|
74
|
-
pub(crate) fn
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
187
|
+
/// Whether `expression` is a reference to the global `name`, which no binding shadows.
|
|
188
|
+
#[must_use]
|
|
189
|
+
pub(crate) fn is_global(&self, expression: &Expression<'_>, name: &str) -> bool {
|
|
190
|
+
matches!(expression, Expression::Identifier(reference)
|
|
191
|
+
if reference.name == name && self.symbol(reference).is_none())
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/// Whether `expression` is a reference to `symbol`.
|
|
195
|
+
#[must_use]
|
|
196
|
+
pub(crate) fn refers_to(&self, expression: &Expression<'_>, symbol: SymbolId) -> bool {
|
|
197
|
+
matches!(expression, Expression::Identifier(reference)
|
|
198
|
+
if self.symbol(reference) == Some(symbol))
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/// Whether an expression is a `Date.now()` call on the global `Date`.
|
|
202
|
+
#[must_use]
|
|
203
|
+
pub(crate) fn is_date_now(&self, expression: &Expression<'_>) -> bool {
|
|
204
|
+
matches!(expression, Expression::CallExpression(call) if call
|
|
205
|
+
.callee
|
|
206
|
+
.as_member_expression()
|
|
207
|
+
.is_some_and(|member| self.is_method_of(member, "Date", "now")))
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/// Matches `<object>.<property>` where `object` is an unshadowed global, such as
|
|
211
|
+
/// `Math.floor`.
|
|
212
|
+
#[must_use]
|
|
213
|
+
pub(crate) fn is_method_of(
|
|
214
|
+
&self,
|
|
215
|
+
member: &MemberExpression<'_>,
|
|
216
|
+
object: &str,
|
|
217
|
+
property: &str,
|
|
218
|
+
) -> bool {
|
|
219
|
+
self.is_global(member.object(), object) && member_str(member) == Some(property)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// Every function in the program, declared, expressed, or a method, in source order.
|
|
223
|
+
pub(crate) fn functions(&self) -> impl Iterator<Item = &'a Function<'a>> + use<'a> {
|
|
224
|
+
self.nodes
|
|
225
|
+
.iter()
|
|
226
|
+
.filter_map(|node| node.kind().as_function())
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/// Applies `read` to each function declaration in the program, in source order, keeping
|
|
230
|
+
/// what it returns.
|
|
231
|
+
pub(crate) fn in_declared_functions<T>(
|
|
232
|
+
&self,
|
|
233
|
+
read: impl FnMut(&'a Function<'a>) -> Option<T>,
|
|
234
|
+
) -> Vec<T> {
|
|
235
|
+
self.functions()
|
|
236
|
+
.filter(|function| function.is_declaration())
|
|
237
|
+
.filter_map(read)
|
|
238
|
+
.collect()
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/// Returns declared, assigned, and variable-initialized functions by binding, in source
|
|
242
|
+
/// order, including functions assigned to globals.
|
|
243
|
+
#[must_use]
|
|
244
|
+
pub(crate) fn named_functions(&self) -> Vec<(Binding<'a>, &'a Function<'a>)> {
|
|
245
|
+
self.nodes
|
|
246
|
+
.iter()
|
|
247
|
+
.filter_map(|node| match node.kind() {
|
|
248
|
+
AstKind::Function(function) if function.is_declaration() => {
|
|
249
|
+
Some((Binding::Symbol(function.id.as_ref()?.symbol_id()), function))
|
|
250
|
+
}
|
|
251
|
+
AstKind::AssignmentExpression(assignment)
|
|
252
|
+
if assignment.operator == AssignmentOperator::Assign
|
|
253
|
+
&& let AssignmentTarget::AssignmentTargetIdentifier(name) =
|
|
254
|
+
&assignment.left
|
|
255
|
+
&& let Expression::FunctionExpression(function) = &assignment.right =>
|
|
256
|
+
{
|
|
257
|
+
Some((self.binding(name), &**function))
|
|
258
|
+
}
|
|
259
|
+
AstKind::VariableDeclarator(declaration)
|
|
260
|
+
if let BindingPattern::BindingIdentifier(name) = &declaration.id
|
|
261
|
+
&& let Some(Expression::FunctionExpression(function)) =
|
|
262
|
+
&declaration.init =>
|
|
263
|
+
{
|
|
264
|
+
Some((Binding::Symbol(name.symbol_id()), &**function))
|
|
265
|
+
}
|
|
266
|
+
_ => None,
|
|
267
|
+
})
|
|
268
|
+
.collect()
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/// The source name of `binding`: its declared name, or the global's.
|
|
272
|
+
#[must_use]
|
|
273
|
+
pub(crate) fn name(&self, binding: Binding<'a>) -> &'a str {
|
|
274
|
+
match binding {
|
|
275
|
+
Binding::Symbol(symbol) => self.scoping.symbol_name(symbol),
|
|
276
|
+
Binding::Global(name) => name,
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/// Lends `node`, which a visitor borrowed briefly, for the program's lifetime, using `kind`
|
|
281
|
+
/// such as `AstKind::as_call_expression`.
|
|
282
|
+
///
|
|
283
|
+
/// # Panics
|
|
284
|
+
///
|
|
285
|
+
/// Panics if `node` is not from this program.
|
|
286
|
+
#[must_use]
|
|
287
|
+
pub(crate) fn lend<T: GetNodeId>(
|
|
288
|
+
&self,
|
|
289
|
+
node: &T,
|
|
290
|
+
kind: fn(AstKind<'a>) -> Option<&'a T>,
|
|
291
|
+
) -> &'a T {
|
|
292
|
+
kind(self.nodes.kind(node.node_id())).expect("semantic nodes match the tree")
|
|
293
|
+
}
|
|
81
294
|
}
|
|
82
295
|
|
|
83
|
-
/// Returns a string literal or template without substitutions as
|
|
84
|
-
/// surrogates. Does not unwrap parentheses.
|
|
296
|
+
/// Returns a string literal or template without substitutions as JavaScript code units,
|
|
297
|
+
/// preserving lone surrogates. Does not unwrap parentheses.
|
|
85
298
|
#[must_use]
|
|
86
|
-
pub(crate) fn
|
|
299
|
+
pub(crate) fn static_string<'a>(expression: &Expression<'a>) -> Option<JSStr<'a>> {
|
|
87
300
|
match expression {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
template.quasis.first()?.cooked
|
|
301
|
+
Expression::StringLiteral(value) => Some(value.value),
|
|
302
|
+
Expression::TemplateLiteral(template) if template.expressions.is_empty() => {
|
|
303
|
+
template.quasis.first()?.value.cooked
|
|
91
304
|
}
|
|
92
305
|
_ => None,
|
|
93
306
|
}
|
|
94
307
|
}
|
|
95
308
|
|
|
96
|
-
/// Converts [`
|
|
309
|
+
/// Converts [`static_string`] to a Rust string. Returns `None` for lone surrogates instead of
|
|
97
310
|
/// replacing them with U+FFFD and changing the recovered value.
|
|
98
311
|
#[must_use]
|
|
99
|
-
pub(crate) fn static_str(expression: &
|
|
100
|
-
|
|
312
|
+
pub(crate) fn static_str<'a>(expression: &Expression<'a>) -> Option<&'a str> {
|
|
313
|
+
static_string(expression)?.as_str()
|
|
101
314
|
}
|
|
102
315
|
|
|
103
316
|
/// The static name of a member property: `object.name`, `object["name"]`, or
|
|
104
317
|
/// ``object[`name`]`` when the template has no substitutions.
|
|
105
318
|
#[must_use]
|
|
106
|
-
pub(crate) fn member_str(
|
|
107
|
-
match
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
_ => None,
|
|
319
|
+
pub(crate) fn member_str<'a>(member: &MemberExpression<'a>) -> Option<&'a str> {
|
|
320
|
+
match member {
|
|
321
|
+
MemberExpression::StaticMemberExpression(member) => Some(member.property.name.as_str()),
|
|
322
|
+
MemberExpression::ComputedMemberExpression(member) => static_str(&member.expression),
|
|
323
|
+
MemberExpression::PrivateFieldExpression(_) => None,
|
|
111
324
|
}
|
|
112
325
|
}
|
|
113
326
|
|
|
114
327
|
/// Matches a property read directly from an identifier, such as a namespace or local, using
|
|
115
328
|
/// [`member_str`].
|
|
116
329
|
#[must_use]
|
|
117
|
-
pub(crate) fn ident_property(member: &
|
|
118
|
-
match
|
|
119
|
-
|
|
330
|
+
pub(crate) fn ident_property<'a>(member: &MemberExpression<'a>) -> Option<&'a str> {
|
|
331
|
+
match member.object() {
|
|
332
|
+
Expression::Identifier(_) => member_str(member),
|
|
120
333
|
_ => None,
|
|
121
334
|
}
|
|
122
335
|
}
|
|
123
336
|
|
|
124
|
-
/// Reads an identifier or quoted
|
|
337
|
+
/// Reads an identifier or quoted property key. Excludes numeric and computed keys.
|
|
125
338
|
#[must_use]
|
|
126
|
-
pub(crate) fn key_str(key: &
|
|
339
|
+
pub(crate) fn key_str<'a>(key: &PropertyKey<'a>, computed: bool) -> Option<&'a str> {
|
|
127
340
|
match key {
|
|
128
|
-
|
|
129
|
-
|
|
341
|
+
_ if computed => None,
|
|
342
|
+
PropertyKey::StaticIdentifier(name) => Some(name.name.as_str()),
|
|
343
|
+
PropertyKey::StringLiteral(name) => name.value.as_str(),
|
|
130
344
|
_ => None,
|
|
131
345
|
}
|
|
132
346
|
}
|
|
@@ -134,165 +348,162 @@ pub(crate) fn key_str(key: &PropName) -> Option<&str> {
|
|
|
134
348
|
/// Reads keys accepted by [`key_str`], plus computed static strings such as `["name"]` or
|
|
135
349
|
/// ``[`name`]``.
|
|
136
350
|
#[must_use]
|
|
137
|
-
pub(crate) fn static_key_str(key: &
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
351
|
+
pub(crate) fn static_key_str<'a>(key: &PropertyKey<'a>, computed: bool) -> Option<&'a str> {
|
|
352
|
+
if computed {
|
|
353
|
+
static_str(key.as_expression()?)
|
|
354
|
+
} else {
|
|
355
|
+
key_str(key, false)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/// The expression an argument passes, through a spread, as `x` in `f(...x)`.
|
|
360
|
+
#[must_use]
|
|
361
|
+
pub(crate) fn argument_expression<'b, 'a>(argument: &'b Argument<'a>) -> &'b Expression<'a> {
|
|
362
|
+
match argument {
|
|
363
|
+
Argument::SpreadElement(spread) => &spread.argument,
|
|
364
|
+
argument => argument.to_expression(),
|
|
141
365
|
}
|
|
142
366
|
}
|
|
143
367
|
|
|
144
368
|
/// Matches `key: value` properties, excluding spreads, methods, accessors, and shorthand
|
|
145
369
|
/// entries.
|
|
146
370
|
#[must_use]
|
|
147
|
-
pub(crate) fn key_value
|
|
148
|
-
property
|
|
371
|
+
pub(crate) fn key_value<'b, 'a>(
|
|
372
|
+
property: &'b ObjectPropertyKind<'a>,
|
|
373
|
+
) -> Option<&'b ObjectProperty<'a>> {
|
|
374
|
+
match property {
|
|
375
|
+
ObjectPropertyKind::ObjectProperty(property)
|
|
376
|
+
if property.kind == PropertyKind::Init && !property.method && !property.shorthand =>
|
|
377
|
+
{
|
|
378
|
+
Some(property)
|
|
379
|
+
}
|
|
380
|
+
_ => None,
|
|
381
|
+
}
|
|
149
382
|
}
|
|
150
383
|
|
|
151
384
|
/// Returns only [`key_value`] properties from an object literal.
|
|
152
|
-
pub(crate) fn key_values
|
|
153
|
-
object
|
|
385
|
+
pub(crate) fn key_values<'b, 'a>(
|
|
386
|
+
object: &'b ObjectExpression<'a>,
|
|
387
|
+
) -> impl Iterator<Item = &'b ObjectProperty<'a>> {
|
|
388
|
+
object.properties.iter().filter_map(key_value)
|
|
154
389
|
}
|
|
155
390
|
|
|
156
|
-
/// Collects distinct static strings
|
|
391
|
+
/// Collects distinct static strings, see [`static_str`], from the nodes `visit` walks, such as
|
|
392
|
+
/// `|literals| literals.visit_program(program)`.
|
|
157
393
|
#[must_use]
|
|
158
|
-
pub(crate) fn string_literals(
|
|
159
|
-
let mut literals = StringLiterals
|
|
160
|
-
|
|
161
|
-
literals.
|
|
394
|
+
pub(crate) fn string_literals(visit: impl FnOnce(&mut StringLiterals)) -> BTreeSet<String> {
|
|
395
|
+
let mut literals = StringLiterals::default();
|
|
396
|
+
visit(&mut literals);
|
|
397
|
+
literals.literals
|
|
162
398
|
}
|
|
163
399
|
|
|
164
|
-
|
|
400
|
+
/// Collects static strings in expression position. Directives such as `"use strict"` count;
|
|
401
|
+
/// non-computed keys such as `{"key": value}` are names, not expressions, and don't.
|
|
402
|
+
#[derive(Default)]
|
|
403
|
+
pub(crate) struct StringLiterals {
|
|
404
|
+
literals: BTreeSet<String>,
|
|
405
|
+
/// Whether the property key about to be visited is computed.
|
|
406
|
+
computed_key: bool,
|
|
407
|
+
}
|
|
165
408
|
|
|
166
|
-
impl
|
|
167
|
-
fn
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
expression.visit_children_with(self);
|
|
409
|
+
impl StringLiterals {
|
|
410
|
+
fn key(&mut self, computed: bool, key: &PropertyKey<'_>) {
|
|
411
|
+
self.computed_key = computed;
|
|
412
|
+
self.visit_property_key(key);
|
|
172
413
|
}
|
|
173
414
|
}
|
|
174
415
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
read: fn(&FnDecl) -> Option<T>,
|
|
180
|
-
results: Vec<T>,
|
|
181
|
-
}
|
|
182
|
-
impl<T> Visit for Found<T> {
|
|
183
|
-
fn visit_fn_decl(&mut self, declaration: &FnDecl) {
|
|
184
|
-
self.results.extend((self.read)(declaration));
|
|
185
|
-
declaration.visit_children_with(self);
|
|
416
|
+
impl<'a> Visit<'a> for StringLiterals {
|
|
417
|
+
fn visit_expression(&mut self, expression: &Expression<'a>) {
|
|
418
|
+
if let Some(literal) = static_str(expression) {
|
|
419
|
+
self.literals.insert(literal.to_owned());
|
|
186
420
|
}
|
|
421
|
+
walk::walk_expression(self, expression);
|
|
187
422
|
}
|
|
188
|
-
let mut found = Found {
|
|
189
|
-
read,
|
|
190
|
-
results: Vec::new(),
|
|
191
|
-
};
|
|
192
|
-
script.visit_with(&mut found);
|
|
193
|
-
found.results
|
|
194
|
-
}
|
|
195
423
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
declaration.ident.sym.to_string(),
|
|
202
|
-
(*declaration.function).clone(),
|
|
203
|
-
))
|
|
204
|
-
})
|
|
205
|
-
}
|
|
424
|
+
fn visit_directive(&mut self, directive: &Directive<'a>) {
|
|
425
|
+
if let Some(literal) = directive.expression.value.as_str() {
|
|
426
|
+
self.literals.insert(literal.to_owned());
|
|
427
|
+
}
|
|
428
|
+
}
|
|
206
429
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
functions.0
|
|
213
|
-
}
|
|
430
|
+
fn visit_property_key(&mut self, key: &PropertyKey<'a>) {
|
|
431
|
+
if mem::take(&mut self.computed_key) {
|
|
432
|
+
walk::walk_property_key(self, key);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
214
435
|
|
|
215
|
-
|
|
436
|
+
fn visit_object_property(&mut self, property: &ObjectProperty<'a>) {
|
|
437
|
+
self.key(property.computed, &property.key);
|
|
438
|
+
self.visit_expression(&property.value);
|
|
439
|
+
}
|
|
216
440
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
self.0.push((declaration.ident.to_id(), function));
|
|
221
|
-
declaration.visit_children_with(self);
|
|
441
|
+
fn visit_binding_property(&mut self, property: &BindingProperty<'a>) {
|
|
442
|
+
self.key(property.computed, &property.key);
|
|
443
|
+
self.visit_binding_pattern(&property.value);
|
|
222
444
|
}
|
|
223
445
|
|
|
224
|
-
fn
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
{
|
|
229
|
-
self.0.push((name.to_id(), (*function.function).clone()));
|
|
230
|
-
}
|
|
231
|
-
assignment.visit_children_with(self);
|
|
446
|
+
fn visit_method_definition(&mut self, method: &MethodDefinition<'a>) {
|
|
447
|
+
self.visit_decorators(&method.decorators);
|
|
448
|
+
self.key(method.computed, &method.key);
|
|
449
|
+
self.visit_function(&method.value, ScopeFlags::Function);
|
|
232
450
|
}
|
|
233
451
|
|
|
234
|
-
fn
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
{
|
|
238
|
-
self.
|
|
452
|
+
fn visit_property_definition(&mut self, property: &PropertyDefinition<'a>) {
|
|
453
|
+
self.visit_decorators(&property.decorators);
|
|
454
|
+
self.key(property.computed, &property.key);
|
|
455
|
+
if let Some(value) = &property.value {
|
|
456
|
+
self.visit_expression(value);
|
|
239
457
|
}
|
|
240
|
-
declaration.visit_children_with(self);
|
|
241
458
|
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/// Whether an expression is a `Date.now()` call.
|
|
245
|
-
#[must_use]
|
|
246
|
-
pub(crate) fn is_date_now(expression: &Expr) -> bool {
|
|
247
|
-
expression
|
|
248
|
-
.as_call()
|
|
249
|
-
.and_then(|call| call.callee.as_expr()?.as_member())
|
|
250
|
-
.is_some_and(|member| is_method_of(member, "Date", "now"))
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/// Matches a method call on the plain identifier `object`, such as `<object>.<property>(...)`.
|
|
254
|
-
#[must_use]
|
|
255
|
-
pub(crate) fn is_method_of(member: &MemberExpr, object: &str, property: &str) -> bool {
|
|
256
|
-
matches!(&*member.obj, Expr::Ident(ident) if ident.sym == object)
|
|
257
|
-
&& member_str(&member.prop) == Some(property)
|
|
258
|
-
}
|
|
259
459
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
460
|
+
fn visit_accessor_property(&mut self, property: &AccessorProperty<'a>) {
|
|
461
|
+
self.visit_decorators(&property.decorators);
|
|
462
|
+
self.key(property.computed, &property.key);
|
|
463
|
+
if let Some(value) = &property.value {
|
|
464
|
+
self.visit_expression(value);
|
|
465
|
+
}
|
|
266
466
|
}
|
|
267
|
-
Some((assignment.left.as_ident()?.to_id(), &assignment.right))
|
|
268
467
|
}
|
|
269
468
|
|
|
270
469
|
/// Matches `callee(args)` when the callee is a plain identifier.
|
|
271
470
|
#[must_use]
|
|
272
|
-
pub(crate) fn direct_call
|
|
273
|
-
|
|
274
|
-
|
|
471
|
+
pub(crate) fn direct_call<'b, 'a>(
|
|
472
|
+
expression: &'b Expression<'a>,
|
|
473
|
+
) -> Option<(&'b IdentifierReference<'a>, &'b [Argument<'a>])> {
|
|
474
|
+
match expression {
|
|
475
|
+
Expression::CallExpression(call) if let Expression::Identifier(callee) = &call.callee => {
|
|
476
|
+
Some((callee, &call.arguments))
|
|
477
|
+
}
|
|
478
|
+
_ => None,
|
|
479
|
+
}
|
|
275
480
|
}
|
|
276
481
|
|
|
277
482
|
/// Returns the object and arguments from `object.name(args)` or `object["name"](args)`.
|
|
278
483
|
#[must_use]
|
|
279
|
-
pub(crate) fn method_call<'a>(
|
|
280
|
-
expression: &'a
|
|
484
|
+
pub(crate) fn method_call<'b, 'a>(
|
|
485
|
+
expression: &'b Expression<'a>,
|
|
281
486
|
name: &str,
|
|
282
|
-
) -> Option<(&'a
|
|
283
|
-
let call = expression
|
|
284
|
-
|
|
285
|
-
|
|
487
|
+
) -> Option<(&'b Expression<'a>, &'b [Argument<'a>])> {
|
|
488
|
+
let Expression::CallExpression(call) = expression else {
|
|
489
|
+
return None;
|
|
490
|
+
};
|
|
491
|
+
let member = call.callee.as_member_expression()?;
|
|
492
|
+
(member_str(member) == Some(name)).then_some((member.object(), &call.arguments[..]))
|
|
286
493
|
}
|
|
287
494
|
|
|
288
495
|
/// A numeric literal, possibly signed or parenthesized.
|
|
289
496
|
#[must_use]
|
|
290
|
-
pub(crate) fn number(expression: &
|
|
497
|
+
pub(crate) fn number(expression: &Expression<'_>) -> Option<f64> {
|
|
291
498
|
match expression {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
499
|
+
Expression::NumericLiteral(value) => Some(value.value),
|
|
500
|
+
Expression::ParenthesizedExpression(value) => number(&value.expression),
|
|
501
|
+
Expression::UnaryExpression(value) if value.operator == UnaryOperator::UnaryNegation => {
|
|
502
|
+
Some(-number(&value.argument)?)
|
|
503
|
+
}
|
|
504
|
+
Expression::UnaryExpression(value) if value.operator == UnaryOperator::UnaryPlus => {
|
|
505
|
+
number(&value.argument)
|
|
506
|
+
}
|
|
296
507
|
_ => None,
|
|
297
508
|
}
|
|
298
509
|
}
|
|
@@ -300,34 +511,37 @@ pub(crate) fn number(expression: &Expr) -> Option<f64> {
|
|
|
300
511
|
/// Evaluates numeric arithmetic: literals, parentheses, and the unary and binary numeric
|
|
301
512
|
/// operators. `leaf` supplies the value of anything else, such as a known parameter.
|
|
302
513
|
#[must_use]
|
|
303
|
-
pub(crate) fn fold_number
|
|
304
|
-
|
|
514
|
+
pub(crate) fn fold_number<'a>(
|
|
515
|
+
expression: &Expression<'a>,
|
|
516
|
+
leaf: &impl Fn(&Expression<'a>) -> Option<f64>,
|
|
517
|
+
) -> Option<f64> {
|
|
518
|
+
let fold = |expression: &Expression<'a>| fold_number(expression, leaf);
|
|
305
519
|
match expression {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
let operand = fold(&value.
|
|
310
|
-
match value.
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
520
|
+
Expression::NumericLiteral(value) => Some(value.value),
|
|
521
|
+
Expression::ParenthesizedExpression(value) => fold(&value.expression),
|
|
522
|
+
Expression::UnaryExpression(value) => {
|
|
523
|
+
let operand = fold(&value.argument)?;
|
|
524
|
+
match value.operator {
|
|
525
|
+
UnaryOperator::UnaryNegation => Some(-operand),
|
|
526
|
+
UnaryOperator::UnaryPlus => Some(operand),
|
|
527
|
+
UnaryOperator::BitwiseNot => Some(super::bit_not(operand)),
|
|
314
528
|
_ => None,
|
|
315
529
|
}
|
|
316
530
|
}
|
|
317
|
-
|
|
531
|
+
Expression::BinaryExpression(binary) => {
|
|
318
532
|
let (left, right) = (fold(&binary.left)?, fold(&binary.right)?);
|
|
319
|
-
match binary.
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
533
|
+
match binary.operator {
|
|
534
|
+
BinaryOperator::Addition => Some(left + right),
|
|
535
|
+
BinaryOperator::Subtraction => Some(left - right),
|
|
536
|
+
BinaryOperator::Multiplication => Some(left * right),
|
|
537
|
+
BinaryOperator::Division => Some(left / right),
|
|
538
|
+
BinaryOperator::Remainder => Some(left % right),
|
|
539
|
+
BinaryOperator::BitwiseAnd => Some(super::bit_and(left, right)),
|
|
540
|
+
BinaryOperator::BitwiseOR => Some(super::bit_or(left, right)),
|
|
541
|
+
BinaryOperator::BitwiseXOR => Some(super::bit_xor(left, right)),
|
|
542
|
+
BinaryOperator::ShiftLeft => Some(super::shl(left, right)),
|
|
543
|
+
BinaryOperator::ShiftRight => Some(super::shr(left, right)),
|
|
544
|
+
BinaryOperator::ShiftRightZeroFill => Some(super::ushr(left, right)),
|
|
331
545
|
_ => None,
|
|
332
546
|
}
|
|
333
547
|
}
|
|
@@ -345,68 +559,79 @@ pub(crate) fn array_index(value: f64) -> Option<usize> {
|
|
|
345
559
|
/// Matches a numeric-literal [`array_index`]. Unlike [`number`], does not unwrap signs or
|
|
346
560
|
/// parentheses.
|
|
347
561
|
#[must_use]
|
|
348
|
-
pub(crate) fn index_literal(expression: &
|
|
562
|
+
pub(crate) fn index_literal(expression: &Expression<'_>) -> Option<usize> {
|
|
349
563
|
match expression {
|
|
350
|
-
|
|
351
|
-
_ => None,
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/// Returns the expression from a function whose entire body is `return value;`.
|
|
356
|
-
#[must_use]
|
|
357
|
-
pub(crate) fn returned(function: &Function) -> Option<&Expr> {
|
|
358
|
-
match function.body.as_ref()?.stmts.as_slice() {
|
|
359
|
-
[Stmt::Return(returned)] => returned.arg.as_deref(),
|
|
564
|
+
Expression::NumericLiteral(value) => array_index(value.value),
|
|
360
565
|
_ => None,
|
|
361
566
|
}
|
|
362
567
|
}
|
|
363
568
|
|
|
364
|
-
///
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
569
|
+
/// Parses `source` and passes its first statement's expression, without the parentheses
|
|
570
|
+
/// wrapped around it, to `read`.
|
|
571
|
+
#[cfg(test)]
|
|
572
|
+
pub(crate) fn with_expression<T>(
|
|
573
|
+
source: &str,
|
|
574
|
+
read: impl for<'a> FnOnce(Script<'a>, &'a Expression<'a>) -> T,
|
|
575
|
+
) -> T {
|
|
576
|
+
use oxc::ast::ast::Statement;
|
|
373
577
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
578
|
+
// Parentheses make leading braces parse as an object literal.
|
|
579
|
+
let parsed = ParsedScript::parse("expression", &format!("({source})")).unwrap();
|
|
580
|
+
let script = parsed.script();
|
|
581
|
+
let [Statement::ExpressionStatement(statement)] = script.program.body.as_slice() else {
|
|
582
|
+
panic!("{source} is not one expression");
|
|
583
|
+
};
|
|
584
|
+
read(script, statement.expression.without_parentheses())
|
|
381
585
|
}
|
|
382
586
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
expr: expression,
|
|
390
|
-
})
|
|
587
|
+
impl fmt::Debug for ParsedScript {
|
|
588
|
+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
589
|
+
formatter
|
|
590
|
+
.debug_struct("ParsedScript")
|
|
591
|
+
.finish_non_exhaustive()
|
|
592
|
+
}
|
|
391
593
|
}
|
|
392
594
|
|
|
393
595
|
#[cfg(test)]
|
|
394
596
|
mod tests {
|
|
597
|
+
use oxc::ast::ast::CallExpression;
|
|
598
|
+
|
|
395
599
|
use super::*;
|
|
396
600
|
|
|
397
601
|
/// Only a static key reads through a computed string literal.
|
|
398
602
|
#[test]
|
|
399
603
|
fn static_keys_also_accept_computed_strings() {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
604
|
+
with_expression(r#"{a: 1, "b": 2, ["c"]: 3, [d]: 4, 5: 5}"#, |_, object| {
|
|
605
|
+
let Expression::ObjectExpression(object) = object else {
|
|
606
|
+
panic!("not an object")
|
|
607
|
+
};
|
|
608
|
+
let keys: Vec<_> = key_values(object)
|
|
609
|
+
.map(|p| key_str(&p.key, p.computed))
|
|
610
|
+
.collect();
|
|
611
|
+
assert_eq!(keys, [Some("a"), Some("b"), None, None, None]);
|
|
612
|
+
let keys: Vec<_> = key_values(object)
|
|
613
|
+
.map(|p| static_key_str(&p.key, p.computed))
|
|
614
|
+
.collect();
|
|
615
|
+
assert_eq!(keys, [Some("a"), Some("b"), Some("c"), None, None]);
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
#[test]
|
|
620
|
+
fn globals_are_unshadowed_references() {
|
|
621
|
+
let parsed =
|
|
622
|
+
ParsedScript::parse("t", "Date.now(); function f(Date) { Date.now(); }").unwrap();
|
|
623
|
+
let script = parsed.script();
|
|
624
|
+
let mut found = Vec::new();
|
|
625
|
+
struct Calls<'s, 'a>(Script<'a>, &'s mut Vec<bool>);
|
|
626
|
+
impl<'a> Visit<'a> for Calls<'_, 'a> {
|
|
627
|
+
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
628
|
+
let Calls(script, found) = self;
|
|
629
|
+
let member = call.callee.as_member_expression().unwrap();
|
|
630
|
+
found.push(script.is_method_of(member, "Date", "now"));
|
|
631
|
+
walk::walk_call_expression(self, call);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
Calls(script, &mut found).visit_program(script.program);
|
|
635
|
+
assert_eq!(found, [true, false]);
|
|
411
636
|
}
|
|
412
637
|
}
|