cfsolve 0.1.2 → 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 +7 -0
- 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 +7 -5
- 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 +266 -265
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
- 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 -0
- data/vendor/cfsolve/examples/check_answers.rs +2 -2
- data/vendor/cfsolve/examples/compare_session.rs +1 -2
- 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 +2 -2
- 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 +266 -265
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
- 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/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- 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 +11 -10
- data/vendor/cfsolve/src/challenge/installed.rs +13 -6
- 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 +69 -31
- 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 +180 -148
- 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 +198 -203
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
- 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 +353 -327
- 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 -18
- 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 +7 -10
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -263
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -9
- data/vendor/cfsolve/src/listing/query.rs +1 -47
- 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 +5 -5
- 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.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
- data/vendor/cfsolve/src/stage2/benchmark.rs +62 -31
- data/vendor/cfsolve/src/stage2/call_stack.rs +1415 -1025
- 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/plan.rs +5 -4
- data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +134 -108
- data/vendor/cfsolve/src/stage2/vocabulary.rs +1 -11
- data/vendor/cfsolve/src/stage2.rs +2 -0
- data/vendor/cfsolve/src/vm/disassemble.rs +7 -3
- 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 +63 -48
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
- data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
- data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
- data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
- data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +123 -59
- 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 +586 -338
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +116 -45
- 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 +9 -1
- data/vendor/cfsolve/src/vm/machine.rs +56 -49
- data/vendor/cfsolve/src/vm/output.rs +13 -5
- data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
- data/vendor/cfsolve/src/vm/session.rs +185 -120
- data/vendor/cfsolve/src/vm/value.rs +22 -19
- data/vendor/cfsolve/src/vm.rs +2 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- metadata +94 -178
- 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/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,141 +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
|
-
|
|
13
|
-
|
|
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,
|
|
14
18
|
};
|
|
15
|
-
use
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
use
|
|
21
|
-
use
|
|
22
|
-
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;
|
|
23
28
|
|
|
24
29
|
use crate::engine::{self, Lines};
|
|
25
30
|
|
|
26
|
-
///
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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>,
|
|
30
42
|
}
|
|
31
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
|
+
|
|
32
65
|
impl ParsedScript {
|
|
33
|
-
///
|
|
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`.
|
|
34
149
|
///
|
|
35
150
|
/// # Panics
|
|
36
151
|
///
|
|
37
152
|
/// Panics if `node` was not parsed from this script.
|
|
38
153
|
#[must_use]
|
|
39
|
-
pub(crate) fn text(&self, node: &
|
|
40
|
-
|
|
41
|
-
let offset = |position: BytePos| (position.0 - self.file.start_pos.0) as usize;
|
|
42
|
-
&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)
|
|
43
156
|
}
|
|
44
157
|
|
|
45
|
-
/// 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.
|
|
46
160
|
///
|
|
47
161
|
/// # Panics
|
|
48
162
|
///
|
|
49
163
|
/// Panics if `at` is outside this script.
|
|
50
164
|
#[must_use]
|
|
51
|
-
pub(crate) fn position(&self, at:
|
|
52
|
-
let
|
|
53
|
-
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);
|
|
54
167
|
(line as usize + 1, column as usize + 1)
|
|
55
168
|
}
|
|
56
|
-
}
|
|
57
169
|
|
|
58
|
-
///
|
|
59
|
-
|
|
60
|
-
pub(crate) fn
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
Ok(parsed)
|
|
67
|
-
}
|
|
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
|
+
}
|
|
68
177
|
|
|
69
|
-
///
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
ensure!(parser.take_errors().is_empty(), "{what} has parse errors");
|
|
78
|
-
Ok(ParsedScript { script, file })
|
|
79
|
-
}
|
|
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
|
+
}
|
|
80
186
|
|
|
81
|
-
///
|
|
82
|
-
#[
|
|
83
|
-
pub(crate) fn
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
+
}
|
|
90
294
|
}
|
|
91
295
|
|
|
92
|
-
/// Returns a string literal or template without substitutions as
|
|
93
|
-
/// 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.
|
|
94
298
|
#[must_use]
|
|
95
|
-
pub(crate) fn
|
|
299
|
+
pub(crate) fn static_string<'a>(expression: &Expression<'a>) -> Option<JSStr<'a>> {
|
|
96
300
|
match expression {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
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
|
|
100
304
|
}
|
|
101
305
|
_ => None,
|
|
102
306
|
}
|
|
103
307
|
}
|
|
104
308
|
|
|
105
|
-
/// Converts [`
|
|
309
|
+
/// Converts [`static_string`] to a Rust string. Returns `None` for lone surrogates instead of
|
|
106
310
|
/// replacing them with U+FFFD and changing the recovered value.
|
|
107
311
|
#[must_use]
|
|
108
|
-
pub(crate) fn static_str(expression: &
|
|
109
|
-
|
|
312
|
+
pub(crate) fn static_str<'a>(expression: &Expression<'a>) -> Option<&'a str> {
|
|
313
|
+
static_string(expression)?.as_str()
|
|
110
314
|
}
|
|
111
315
|
|
|
112
316
|
/// The static name of a member property: `object.name`, `object["name"]`, or
|
|
113
317
|
/// ``object[`name`]`` when the template has no substitutions.
|
|
114
318
|
#[must_use]
|
|
115
|
-
pub(crate) fn member_str(
|
|
116
|
-
match
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
_ => 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,
|
|
120
324
|
}
|
|
121
325
|
}
|
|
122
326
|
|
|
123
327
|
/// Matches a property read directly from an identifier, such as a namespace or local, using
|
|
124
328
|
/// [`member_str`].
|
|
125
329
|
#[must_use]
|
|
126
|
-
pub(crate) fn ident_property(member: &
|
|
127
|
-
match
|
|
128
|
-
|
|
330
|
+
pub(crate) fn ident_property<'a>(member: &MemberExpression<'a>) -> Option<&'a str> {
|
|
331
|
+
match member.object() {
|
|
332
|
+
Expression::Identifier(_) => member_str(member),
|
|
129
333
|
_ => None,
|
|
130
334
|
}
|
|
131
335
|
}
|
|
132
336
|
|
|
133
|
-
/// Reads an identifier or quoted
|
|
337
|
+
/// Reads an identifier or quoted property key. Excludes numeric and computed keys.
|
|
134
338
|
#[must_use]
|
|
135
|
-
pub(crate) fn key_str(key: &
|
|
339
|
+
pub(crate) fn key_str<'a>(key: &PropertyKey<'a>, computed: bool) -> Option<&'a str> {
|
|
136
340
|
match key {
|
|
137
|
-
|
|
138
|
-
|
|
341
|
+
_ if computed => None,
|
|
342
|
+
PropertyKey::StaticIdentifier(name) => Some(name.name.as_str()),
|
|
343
|
+
PropertyKey::StringLiteral(name) => name.value.as_str(),
|
|
139
344
|
_ => None,
|
|
140
345
|
}
|
|
141
346
|
}
|
|
@@ -143,165 +348,162 @@ pub(crate) fn key_str(key: &PropName) -> Option<&str> {
|
|
|
143
348
|
/// Reads keys accepted by [`key_str`], plus computed static strings such as `["name"]` or
|
|
144
349
|
/// ``[`name`]``.
|
|
145
350
|
#[must_use]
|
|
146
|
-
pub(crate) fn static_key_str(key: &
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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(),
|
|
150
365
|
}
|
|
151
366
|
}
|
|
152
367
|
|
|
153
368
|
/// Matches `key: value` properties, excluding spreads, methods, accessors, and shorthand
|
|
154
369
|
/// entries.
|
|
155
370
|
#[must_use]
|
|
156
|
-
pub(crate) fn key_value
|
|
157
|
-
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
|
+
}
|
|
158
382
|
}
|
|
159
383
|
|
|
160
384
|
/// Returns only [`key_value`] properties from an object literal.
|
|
161
|
-
pub(crate) fn key_values
|
|
162
|
-
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)
|
|
163
389
|
}
|
|
164
390
|
|
|
165
|
-
/// 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)`.
|
|
166
393
|
#[must_use]
|
|
167
|
-
pub(crate) fn string_literals(
|
|
168
|
-
let mut literals = StringLiterals
|
|
169
|
-
|
|
170
|
-
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
|
|
171
398
|
}
|
|
172
399
|
|
|
173
|
-
|
|
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
|
+
}
|
|
174
408
|
|
|
175
|
-
impl
|
|
176
|
-
fn
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
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);
|
|
181
413
|
}
|
|
182
414
|
}
|
|
183
415
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
read: fn(&FnDecl) -> Option<T>,
|
|
189
|
-
results: Vec<T>,
|
|
190
|
-
}
|
|
191
|
-
impl<T> Visit for Found<T> {
|
|
192
|
-
fn visit_fn_decl(&mut self, declaration: &FnDecl) {
|
|
193
|
-
self.results.extend((self.read)(declaration));
|
|
194
|
-
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());
|
|
195
420
|
}
|
|
421
|
+
walk::walk_expression(self, expression);
|
|
196
422
|
}
|
|
197
|
-
let mut found = Found {
|
|
198
|
-
read,
|
|
199
|
-
results: Vec::new(),
|
|
200
|
-
};
|
|
201
|
-
script.visit_with(&mut found);
|
|
202
|
-
found.results
|
|
203
|
-
}
|
|
204
423
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
declaration.ident.sym.to_string(),
|
|
211
|
-
(*declaration.function).clone(),
|
|
212
|
-
))
|
|
213
|
-
})
|
|
214
|
-
}
|
|
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
|
+
}
|
|
215
429
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
functions.0
|
|
222
|
-
}
|
|
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
|
+
}
|
|
223
435
|
|
|
224
|
-
|
|
436
|
+
fn visit_object_property(&mut self, property: &ObjectProperty<'a>) {
|
|
437
|
+
self.key(property.computed, &property.key);
|
|
438
|
+
self.visit_expression(&property.value);
|
|
439
|
+
}
|
|
225
440
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
self.0.push((declaration.ident.to_id(), function));
|
|
230
|
-
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);
|
|
231
444
|
}
|
|
232
445
|
|
|
233
|
-
fn
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
{
|
|
238
|
-
self.0.push((name.to_id(), (*function.function).clone()));
|
|
239
|
-
}
|
|
240
|
-
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);
|
|
241
450
|
}
|
|
242
451
|
|
|
243
|
-
fn
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
{
|
|
247
|
-
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);
|
|
248
457
|
}
|
|
249
|
-
declaration.visit_children_with(self);
|
|
250
458
|
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/// Whether an expression is a `Date.now()` call.
|
|
254
|
-
#[must_use]
|
|
255
|
-
pub(crate) fn is_date_now(expression: &Expr) -> bool {
|
|
256
|
-
expression
|
|
257
|
-
.as_call()
|
|
258
|
-
.and_then(|call| call.callee.as_expr()?.as_member())
|
|
259
|
-
.is_some_and(|member| is_method_of(member, "Date", "now"))
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/// Matches a method call on the plain identifier `object`, such as `<object>.<property>(...)`.
|
|
263
|
-
#[must_use]
|
|
264
|
-
pub(crate) fn is_method_of(member: &MemberExpr, object: &str, property: &str) -> bool {
|
|
265
|
-
matches!(&*member.obj, Expr::Ident(ident) if ident.sym == object)
|
|
266
|
-
&& member_str(&member.prop) == Some(property)
|
|
267
|
-
}
|
|
268
459
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
+
}
|
|
275
466
|
}
|
|
276
|
-
Some((assignment.left.as_ident()?.to_id(), &assignment.right))
|
|
277
467
|
}
|
|
278
468
|
|
|
279
469
|
/// Matches `callee(args)` when the callee is a plain identifier.
|
|
280
470
|
#[must_use]
|
|
281
|
-
pub(crate) fn direct_call
|
|
282
|
-
|
|
283
|
-
|
|
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
|
+
}
|
|
284
480
|
}
|
|
285
481
|
|
|
286
482
|
/// Returns the object and arguments from `object.name(args)` or `object["name"](args)`.
|
|
287
483
|
#[must_use]
|
|
288
|
-
pub(crate) fn method_call<'a>(
|
|
289
|
-
expression: &'a
|
|
484
|
+
pub(crate) fn method_call<'b, 'a>(
|
|
485
|
+
expression: &'b Expression<'a>,
|
|
290
486
|
name: &str,
|
|
291
|
-
) -> Option<(&'a
|
|
292
|
-
let call = expression
|
|
293
|
-
|
|
294
|
-
|
|
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[..]))
|
|
295
493
|
}
|
|
296
494
|
|
|
297
495
|
/// A numeric literal, possibly signed or parenthesized.
|
|
298
496
|
#[must_use]
|
|
299
|
-
pub(crate) fn number(expression: &
|
|
497
|
+
pub(crate) fn number(expression: &Expression<'_>) -> Option<f64> {
|
|
300
498
|
match expression {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
+
}
|
|
305
507
|
_ => None,
|
|
306
508
|
}
|
|
307
509
|
}
|
|
@@ -309,34 +511,37 @@ pub(crate) fn number(expression: &Expr) -> Option<f64> {
|
|
|
309
511
|
/// Evaluates numeric arithmetic: literals, parentheses, and the unary and binary numeric
|
|
310
512
|
/// operators. `leaf` supplies the value of anything else, such as a known parameter.
|
|
311
513
|
#[must_use]
|
|
312
|
-
pub(crate) fn fold_number
|
|
313
|
-
|
|
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);
|
|
314
519
|
match expression {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
let operand = fold(&value.
|
|
319
|
-
match value.
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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)),
|
|
323
528
|
_ => None,
|
|
324
529
|
}
|
|
325
530
|
}
|
|
326
|
-
|
|
531
|
+
Expression::BinaryExpression(binary) => {
|
|
327
532
|
let (left, right) = (fold(&binary.left)?, fold(&binary.right)?);
|
|
328
|
-
match binary.
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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)),
|
|
340
545
|
_ => None,
|
|
341
546
|
}
|
|
342
547
|
}
|
|
@@ -354,68 +559,79 @@ pub(crate) fn array_index(value: f64) -> Option<usize> {
|
|
|
354
559
|
/// Matches a numeric-literal [`array_index`]. Unlike [`number`], does not unwrap signs or
|
|
355
560
|
/// parentheses.
|
|
356
561
|
#[must_use]
|
|
357
|
-
pub(crate) fn index_literal(expression: &
|
|
562
|
+
pub(crate) fn index_literal(expression: &Expression<'_>) -> Option<usize> {
|
|
358
563
|
match expression {
|
|
359
|
-
|
|
360
|
-
_ => None,
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/// Returns the expression from a function whose entire body is `return value;`.
|
|
365
|
-
#[must_use]
|
|
366
|
-
pub(crate) fn returned(function: &Function) -> Option<&Expr> {
|
|
367
|
-
match function.body.as_ref()?.stmts.as_slice() {
|
|
368
|
-
[Stmt::Return(returned)] => returned.arg.as_deref(),
|
|
564
|
+
Expression::NumericLiteral(value) => array_index(value.value),
|
|
369
565
|
_ => None,
|
|
370
566
|
}
|
|
371
567
|
}
|
|
372
568
|
|
|
373
|
-
///
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
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;
|
|
382
577
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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())
|
|
390
585
|
}
|
|
391
586
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
expr: expression,
|
|
399
|
-
})
|
|
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
|
+
}
|
|
400
593
|
}
|
|
401
594
|
|
|
402
595
|
#[cfg(test)]
|
|
403
596
|
mod tests {
|
|
597
|
+
use oxc::ast::ast::CallExpression;
|
|
598
|
+
|
|
404
599
|
use super::*;
|
|
405
600
|
|
|
406
601
|
/// Only a static key reads through a computed string literal.
|
|
407
602
|
#[test]
|
|
408
603
|
fn static_keys_also_accept_computed_strings() {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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]);
|
|
420
636
|
}
|
|
421
637
|
}
|