@lynx-js/react 0.128.0 → 0.129.1
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.
- package/CHANGELOG.md +34 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/entry-re-eval.test.ts +161 -0
- package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
- package/runtime/__test__/core/reload-scoped-dual-thread-communication.test.ts +129 -0
- package/runtime/__test__/core/thread-function-call.test.ts +1 -0
- package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +2 -0
- package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
- package/runtime/__test__/element-template/native/index.test.ts +8 -0
- package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
- package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +83 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +104 -0
- package/runtime/__test__/element-template/native/reload.test.ts +79 -1
- package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +7 -1
- package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -0
- package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
- package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +31 -5
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +214 -10
- package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +2 -0
- package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
- package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +121 -26
- package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +89 -2
- package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +5 -0
- package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
- package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
- package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
- package/runtime/__test__/shared/component-stack.test.ts +211 -0
- package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
- package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
- package/runtime/__test__/snapshot/lifecycle/re-eval-reload.test.jsx +114 -0
- package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +169 -0
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +63 -0
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-main-thread.test.jsx +103 -0
- package/runtime/__test__/snapshot/lifecycle.test.jsx +61 -1
- package/runtime/__test__/snapshot/lynx/lazy-effect-scheduling.test.jsx +105 -0
- package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
- package/runtime/__test__/snapshot/preact.test.jsx +0 -3
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
- package/runtime/__test__/snapshot/ssr.test.jsx +2 -2
- package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +6 -11
- package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +1 -1
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +24 -1
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +27 -1
- package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
- package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
- package/runtime/lazy/element-template-internal.js +0 -1
- package/runtime/lazy/internal.js +1 -1
- package/runtime/lazy/jsx-dev-runtime.js +1 -1
- package/runtime/lazy/jsx-runtime.js +1 -1
- package/runtime/lazy/legacy-react-runtime.js +1 -1
- package/runtime/lazy/react-lepus.js +1 -1
- package/runtime/lazy/react.js +1 -1
- package/runtime/lib/core/background-function/exec-map.d.ts +2 -0
- package/runtime/lib/core/background-function/exec-map.js +7 -0
- package/runtime/lib/core/background-function/exec-map.js.map +1 -1
- package/runtime/lib/core/background-function/run-on-background.js +15 -16
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/capture-main-thread-object.js +2 -1
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
- package/runtime/lib/core/card-lifetime.d.ts +5 -0
- package/runtime/lib/core/card-lifetime.js +17 -0
- package/runtime/lib/core/card-lifetime.js.map +1 -0
- package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/entry-reload.d.ts +7 -0
- package/runtime/lib/core/entry-reload.js +49 -0
- package/runtime/lib/core/entry-reload.js.map +1 -0
- package/runtime/lib/core/lynx/lazy-bundle.js +5 -2
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
- package/runtime/lib/core/lynx-data-processors.js +3 -0
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/main-thread-ref-id.js +4 -4
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
- package/runtime/lib/core/reload-scoped-event.d.ts +5 -0
- package/runtime/lib/core/reload-scoped-event.js +26 -0
- package/runtime/lib/core/reload-scoped-event.js.map +1 -0
- package/runtime/lib/core/reload-version.js +4 -3
- package/runtime/lib/core/reload-version.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.d.ts +2 -0
- package/runtime/lib/core/runtime-destroy.js +10 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/core/thread-function-call/main-thread.js +5 -4
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/core/thread-function-call/return-value.js +6 -5
- package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
- package/runtime/lib/document.js +0 -5
- package/runtime/lib/document.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js +24 -22
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js +2 -6
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/client/root.d.ts +1 -1
- package/runtime/lib/element-template/client/root.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +2 -2
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +1 -1
- package/runtime/lib/element-template/internal.js +0 -13
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/main-thread-ref-init-value.d.ts +3 -0
- package/runtime/lib/element-template/main-thread-ref-init-value.js +38 -0
- package/runtime/lib/element-template/main-thread-ref-init-value.js.map +1 -0
- package/runtime/lib/element-template/native/flush.d.ts +1 -0
- package/runtime/lib/element-template/native/flush.js +9 -0
- package/runtime/lib/element-template/native/flush.js.map +1 -0
- package/runtime/lib/element-template/native/index.js +2 -0
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/main-thread-api.js +3 -7
- package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js +10 -2
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +58 -54
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.d.ts +1 -1
- package/runtime/lib/element-template/native/reload-background.js +12 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.d.ts +6 -0
- package/runtime/lib/element-template/native/reload-main-thread.js +20 -3
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.d.ts +2 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.js +1 -0
- package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +0 -2
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +4 -0
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +41 -21
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/internal.d.ts +1 -1
- package/runtime/lib/internal.js +1 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +2 -125
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/shared/component-stack.d.ts +0 -4
- package/runtime/lib/shared/component-stack.js +21 -5
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/shared/index-map.d.ts +4 -1
- package/runtime/lib/shared/index-map.js +5 -2
- package/runtime/lib/shared/index-map.js.map +1 -1
- package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js +6 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +6 -2
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +21 -18
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.d.ts +9 -2
- package/runtime/lib/snapshot/lifecycle/reload.js +29 -8
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/list/list.js +3 -2
- package/runtime/lib/snapshot/list/list.js.map +1 -1
- package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +14 -11
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/list.js +2 -1
- package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +4 -2
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +11 -11
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +1 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +6 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ctx.d.ts +1 -1
- package/runtime/lib/snapshot/worklet/ctx.js +6 -1
- package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js +6 -0
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js +3 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +8 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/listeners.js +2 -2
- package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.js +3 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
- package/runtime/lib/worklet-runtime/runOnMainThread.js +4 -3
- package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/background-function/exec-map.ts +9 -0
- package/runtime/src/core/background-function/run-on-background.ts +14 -16
- package/runtime/src/core/capture-main-thread-object.ts +2 -1
- package/runtime/src/core/card-lifetime.ts +18 -0
- package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
- package/runtime/src/core/entry-reload.ts +63 -0
- package/runtime/src/core/lynx/lazy-bundle.ts +5 -2
- package/runtime/src/core/lynx-data-processors.ts +124 -1
- package/runtime/src/core/main-thread-ref-id.ts +5 -4
- package/runtime/src/core/reload-scoped-event.ts +35 -0
- package/runtime/src/core/reload-version.ts +5 -3
- package/runtime/src/core/runtime-destroy.ts +12 -1
- package/runtime/src/core/thread-function-call/main-thread.ts +4 -4
- package/runtime/src/core/thread-function-call/return-value.ts +6 -5
- package/runtime/src/document.ts +0 -6
- package/runtime/src/element-template/background/commit-hook.ts +32 -23
- package/runtime/src/element-template/background/hydration-listener.ts +2 -6
- package/runtime/src/element-template/client/root.ts +1 -3
- package/runtime/src/element-template/index.ts +2 -2
- package/runtime/src/element-template/internal.ts +0 -20
- package/runtime/src/element-template/lynx/env.ts +1 -1
- package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
- package/runtime/src/element-template/native/flush.ts +10 -0
- package/runtime/src/element-template/native/index.ts +2 -0
- package/runtime/src/element-template/native/main-thread-api.ts +3 -6
- package/runtime/src/element-template/native/mts-destroy.ts +10 -2
- package/runtime/src/element-template/native/patch-listener.ts +62 -62
- package/runtime/src/element-template/native/reload-background.ts +13 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +32 -3
- package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
- package/runtime/src/element-template/protocol/types.ts +0 -15
- package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
- package/runtime/src/element-template/runtime/patch.ts +5 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
- package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +51 -21
- package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +2 -2
- package/runtime/src/element-template/types.d.ts +6 -0
- package/runtime/src/internal.ts +1 -1
- package/runtime/src/lynx-api.ts +2 -124
- package/runtime/src/shared/component-stack.ts +22 -5
- package/runtime/src/shared/index-map.ts +3 -2
- package/runtime/src/snapshot/lifecycle/destroy.ts +7 -0
- package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +26 -19
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
- package/runtime/src/snapshot/lifecycle/reload.ts +47 -11
- package/runtime/src/snapshot/list/list.ts +9 -2
- package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
- package/runtime/src/snapshot/lynx/calledByNative.ts +14 -13
- package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
- package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
- package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
- package/runtime/src/snapshot/snapshot/list.ts +5 -1
- package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +19 -12
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +10 -1
- package/runtime/src/snapshot/worklet/ctx.ts +10 -1
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +6 -0
- package/runtime/src/worklet-runtime/README.md +33 -0
- package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
- package/runtime/src/worklet-runtime/delayRunOnBackground.ts +3 -1
- package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +8 -1
- package/runtime/src/worklet-runtime/listeners.ts +4 -7
- package/runtime/src/worklet-runtime/mainThreadObject.ts +2 -1
- package/runtime/src/worklet-runtime/runOnMainThread.ts +4 -3
- package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
- package/runtime/types/types.d.ts +3 -1
- package/runtime/vitest.config.ts +0 -2
- package/testing-library/.turbo/turbo-build.log +7 -7
- package/testing-library/src/__tests__/act.test.jsx +0 -7
- package/testing-library/src/__tests__/alog.test.jsx +12 -54
- package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
- package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
- package/testing-library/src/__tests__/worklet.test.jsx +59 -5
- package/transform/.turbo/turbo-build$colon$wasm.log +63 -136
- package/transform/__test__/defines.spec.js +137 -0
- package/transform/__test__/object-methods.spec.js +79 -0
- package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +56 -48
- package/transform/crates/swc_plugin_worklet/lib.rs +400 -595
- package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +6 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +12 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +1 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +3 -1
- package/transform/package.json +0 -1
- package/transform/src/lib.rs +173 -12
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +105 -32
- package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +193 -194
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
- package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/hmr.js +0 -28
- package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
- package/runtime/src/snapshot/worklet/hmr.ts +0 -34
- /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
- /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
use rustc_hash::FxHashSet;
|
|
2
|
+
use swc_core::ecma::ast::*;
|
|
3
|
+
use swc_core::ecma::visit::{Visit, VisitWith};
|
|
4
|
+
|
|
5
|
+
#[derive(Default)]
|
|
6
|
+
struct References {
|
|
7
|
+
used: FxHashSet<Id>,
|
|
8
|
+
declared: FxHashSet<Id>,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
impl Visit for References {
|
|
12
|
+
fn visit_ident(&mut self, ident: &Ident) {
|
|
13
|
+
self.used.insert(ident.to_id());
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
fn visit_binding_ident(&mut self, ident: &BindingIdent) {
|
|
17
|
+
self.declared.insert(ident.to_id());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
pub fn collect_imports(stmt: &Stmt, imports: &[ImportDecl]) -> Vec<ModuleItem> {
|
|
22
|
+
let mut references = References::default();
|
|
23
|
+
stmt.visit_with(&mut references);
|
|
24
|
+
let mut items = vec![];
|
|
25
|
+
for import in imports {
|
|
26
|
+
if import.type_only {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
let mut import = import.clone();
|
|
30
|
+
import.specifiers.retain(|specifier| {
|
|
31
|
+
if matches!(specifier, ImportSpecifier::Named(named) if named.is_type_only) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
let id = specifier.local().to_id();
|
|
35
|
+
references.used.contains(&id) && !references.declared.contains(&id)
|
|
36
|
+
});
|
|
37
|
+
if !import.specifiers.is_empty() {
|
|
38
|
+
items.push(ModuleItem::ModuleDecl(ModuleDecl::Import(import)));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
items
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#[cfg(test)]
|
|
45
|
+
mod tests {
|
|
46
|
+
use super::*;
|
|
47
|
+
use swc_core::common::DUMMY_SP;
|
|
48
|
+
use swc_core::quote;
|
|
49
|
+
|
|
50
|
+
#[test]
|
|
51
|
+
fn excludes_type_only_unused_and_locally_declared_bindings() {
|
|
52
|
+
let named = |name: &str, is_type_only| {
|
|
53
|
+
ImportSpecifier::Named(ImportNamedSpecifier {
|
|
54
|
+
span: DUMMY_SP,
|
|
55
|
+
local: Ident::new_no_ctxt(name.into(), DUMMY_SP),
|
|
56
|
+
imported: None,
|
|
57
|
+
is_type_only,
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
let import = ImportDecl {
|
|
61
|
+
span: DUMMY_SP,
|
|
62
|
+
phase: ImportPhase::Evaluation,
|
|
63
|
+
specifiers: vec![named("needed", false)],
|
|
64
|
+
src: Box::new("./values.js".into()),
|
|
65
|
+
type_only: false,
|
|
66
|
+
with: None,
|
|
67
|
+
};
|
|
68
|
+
let stmt = quote!("function handler(captured) { return [needed, captured]; }" as Stmt);
|
|
69
|
+
let collected = collect_imports(
|
|
70
|
+
&stmt,
|
|
71
|
+
&[
|
|
72
|
+
ImportDecl {
|
|
73
|
+
type_only: true,
|
|
74
|
+
..import.clone()
|
|
75
|
+
},
|
|
76
|
+
ImportDecl {
|
|
77
|
+
specifiers: vec![named("needed", true)],
|
|
78
|
+
..import.clone()
|
|
79
|
+
},
|
|
80
|
+
ImportDecl {
|
|
81
|
+
specifiers: vec![
|
|
82
|
+
named("needed", false),
|
|
83
|
+
named("captured", false),
|
|
84
|
+
named("unused", false),
|
|
85
|
+
],
|
|
86
|
+
..import
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
);
|
|
90
|
+
assert_eq!(collected.len(), 1);
|
|
91
|
+
let ModuleItem::ModuleDecl(ModuleDecl::Import(import)) = &collected[0] else {
|
|
92
|
+
panic!("expected a dependency import");
|
|
93
|
+
};
|
|
94
|
+
assert_eq!(import.specifiers.len(), 1);
|
|
95
|
+
assert_eq!(import.specifiers[0].local().sym, "needed");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -6,7 +6,7 @@ use std::mem::{swap, take};
|
|
|
6
6
|
use std::ops::Deref;
|
|
7
7
|
use std::{borrow::Cow, cmp::max};
|
|
8
8
|
use swc_core::common::util::take::Take;
|
|
9
|
-
use swc_core::common::EqIgnoreSpan;
|
|
9
|
+
use swc_core::common::{EqIgnoreSpan, DUMMY_SP};
|
|
10
10
|
use swc_core::ecma::ast::*;
|
|
11
11
|
use swc_core::ecma::utils::quote_ident;
|
|
12
12
|
use swc_core::ecma::visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
|
|
@@ -43,6 +43,7 @@ pub struct ExtractingIdentsCollector {
|
|
|
43
43
|
member_expr_depth: u32,
|
|
44
44
|
// when `d` in `a.b.c.d` is visited, `member_expr_path` should be [a, b, c].
|
|
45
45
|
member_expr_path: Vec<Box<Expr>>,
|
|
46
|
+
optional_member_sources: Vec<Box<Expr>>,
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
impl ExtractingIdentsCollector {
|
|
@@ -63,9 +64,14 @@ impl ExtractingIdentsCollector {
|
|
|
63
64
|
}],
|
|
64
65
|
member_expr_depth: 0,
|
|
65
66
|
member_expr_path: vec![],
|
|
67
|
+
optional_member_sources: vec![],
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
pub fn take_optional_member_sources(&mut self) -> Vec<Box<Expr>> {
|
|
72
|
+
take(&mut self.optional_member_sources)
|
|
73
|
+
}
|
|
74
|
+
|
|
69
75
|
pub fn take_values(&mut self) -> Box<Expr> {
|
|
70
76
|
self.values_extracted.take()
|
|
71
77
|
}
|
|
@@ -116,7 +122,7 @@ impl ExtractingIdentsCollector {
|
|
|
116
122
|
.contains(&String::from(s)))
|
|
117
123
|
}
|
|
118
124
|
|
|
119
|
-
fn add_if_needed(&mut self, name: Box<Expr
|
|
125
|
+
fn add_if_needed(&mut self, name: Box<Expr>) {
|
|
120
126
|
assert!(name.is_ident() || name.is_lit() || name.is_this());
|
|
121
127
|
|
|
122
128
|
if self.member_expr_path.is_empty()
|
|
@@ -143,15 +149,16 @@ impl ExtractingIdentsCollector {
|
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
if !name.is_this() {
|
|
152
|
+
let expr_to_extract = Self::expr_from_path(&self.member_expr_path);
|
|
146
153
|
if !self.member_expr_path.is_empty() && self.member_expr_path[0].is_this() {
|
|
147
154
|
Self::add_inner(
|
|
148
|
-
expr_to_extract,
|
|
155
|
+
&expr_to_extract,
|
|
149
156
|
&mut self.this_expr_to_extract,
|
|
150
157
|
&self.member_expr_path[1..],
|
|
151
158
|
);
|
|
152
159
|
} else {
|
|
153
160
|
Self::add_inner(
|
|
154
|
-
expr_to_extract,
|
|
161
|
+
&expr_to_extract,
|
|
155
162
|
&mut self.values_extracted,
|
|
156
163
|
&self.member_expr_path,
|
|
157
164
|
)
|
|
@@ -247,6 +254,85 @@ impl ExtractingIdentsCollector {
|
|
|
247
254
|
})
|
|
248
255
|
}
|
|
249
256
|
|
|
257
|
+
fn is_extractable_member_obj(expr: &Expr) -> bool {
|
|
258
|
+
match expr {
|
|
259
|
+
Expr::Ident(_) | Expr::Member(_) | Expr::This(_) => true,
|
|
260
|
+
Expr::OptChain(opt_chain) => matches!(&*opt_chain.base, OptChainBase::Member(_)),
|
|
261
|
+
_ => false,
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
fn expr_from_path(path: &[Box<Expr>]) -> Box<Expr> {
|
|
266
|
+
let mut expr = path[0].clone();
|
|
267
|
+
for segment in &path[1..] {
|
|
268
|
+
let prop = match &**segment {
|
|
269
|
+
Expr::Ident(id) => MemberProp::Ident(id.clone().into()),
|
|
270
|
+
Expr::Lit(Lit::Str(_)) => MemberProp::Computed(ComputedPropName {
|
|
271
|
+
span: DUMMY_SP,
|
|
272
|
+
expr: segment.clone(),
|
|
273
|
+
}),
|
|
274
|
+
_ => unreachable!("Unexpected property name type - expected Ident or Str"),
|
|
275
|
+
};
|
|
276
|
+
expr = Expr::Member(MemberExpr {
|
|
277
|
+
span: DUMMY_SP,
|
|
278
|
+
obj: expr,
|
|
279
|
+
prop,
|
|
280
|
+
})
|
|
281
|
+
.into();
|
|
282
|
+
}
|
|
283
|
+
expr
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
fn visit_member_expr(&mut self, n: &mut MemberExpr, optional: bool) {
|
|
287
|
+
let prop_is_computed = n.prop.is_computed();
|
|
288
|
+
let prop_is_computed_lit = prop_is_computed && n.prop.as_computed().unwrap().expr.is_lit();
|
|
289
|
+
let prop_is_computed_lit_str = prop_is_computed_lit
|
|
290
|
+
&& matches!(
|
|
291
|
+
n.prop.as_computed().unwrap().expr.as_lit().unwrap(),
|
|
292
|
+
Lit::Str(_)
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
if (prop_is_computed && !prop_is_computed_lit_str)
|
|
296
|
+
|| (n.prop.is_ident() && n.prop.as_ident().unwrap().sym == "current")
|
|
297
|
+
|| !Self::is_extractable_member_obj(&n.obj)
|
|
298
|
+
{
|
|
299
|
+
self.member_expr_depth = 0;
|
|
300
|
+
n.obj.visit_mut_with(self);
|
|
301
|
+
} else {
|
|
302
|
+
self.member_expr_depth += 1;
|
|
303
|
+
n.obj.visit_mut_with(self);
|
|
304
|
+
self.member_expr_depth = max(self.member_expr_depth, 1) - 1;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
let extracted_prop = match &n.prop {
|
|
308
|
+
MemberProp::Computed(comp) if prop_is_computed_lit_str => {
|
|
309
|
+
Some(Expr::Lit(comp.expr.as_lit().unwrap().clone()).into())
|
|
310
|
+
}
|
|
311
|
+
MemberProp::Computed(_) => {
|
|
312
|
+
n.prop.visit_mut_with(self);
|
|
313
|
+
None
|
|
314
|
+
}
|
|
315
|
+
MemberProp::Ident(ident) => Some(Expr::Ident(ident.clone().into()).into()),
|
|
316
|
+
_ => None,
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
if let Some(prop) = extracted_prop {
|
|
320
|
+
if !self.member_expr_path.is_empty() {
|
|
321
|
+
if optional {
|
|
322
|
+
let source = Self::expr_from_path(&self.member_expr_path);
|
|
323
|
+
if !self
|
|
324
|
+
.optional_member_sources
|
|
325
|
+
.iter()
|
|
326
|
+
.any(|existing| existing.eq_ignore_span(&source))
|
|
327
|
+
{
|
|
328
|
+
self.optional_member_sources.push(source);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
self.add_if_needed(prop);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
250
336
|
fn push_fn_scope(&mut self, ids_declared_in_scope: FxHashSet<Id>) {
|
|
251
337
|
let last_scope = self.scope_env.last().unwrap();
|
|
252
338
|
self.scope_env.push(ScopeEnv {
|
|
@@ -275,7 +361,7 @@ impl VisitMut for ExtractingIdentsCollector {
|
|
|
275
361
|
|
|
276
362
|
fn visit_mut_this_expr(&mut self, n: &mut ThisExpr) {
|
|
277
363
|
if self.member_expr_depth > 0 && !self.scope_env.last().unwrap().is_inner_fn_scope {
|
|
278
|
-
self.add_if_needed(Expr::This(*n).into()
|
|
364
|
+
self.add_if_needed(Expr::This(*n).into());
|
|
279
365
|
}
|
|
280
366
|
}
|
|
281
367
|
|
|
@@ -293,57 +379,21 @@ impl VisitMut for ExtractingIdentsCollector {
|
|
|
293
379
|
.iter()
|
|
294
380
|
.any(|env| env.ids_declared_locally.contains(&n.to_id()))
|
|
295
381
|
{
|
|
296
|
-
self.add_if_needed(
|
|
297
|
-
Expr::Ident(n.clone()).into(),
|
|
298
|
-
&Expr::Ident(n.clone()).into(),
|
|
299
|
-
);
|
|
382
|
+
self.add_if_needed(Expr::Ident(n.clone()).into());
|
|
300
383
|
}
|
|
301
384
|
|
|
302
385
|
n.visit_mut_children_with(self);
|
|
303
386
|
}
|
|
304
387
|
|
|
305
|
-
fn
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
&& matches!(
|
|
310
|
-
n.prop.as_computed().unwrap().expr.as_lit().unwrap(),
|
|
311
|
-
Lit::Str(_)
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
if (prop_is_computed && !prop_is_computed_lit_str)
|
|
315
|
-
|| (n.prop.is_ident() && n.prop.as_ident().unwrap().sym == "current")
|
|
316
|
-
|| !(n.obj.is_ident() || n.obj.is_member() || n.obj.is_this())
|
|
317
|
-
{
|
|
318
|
-
self.member_expr_depth = 0;
|
|
319
|
-
n.obj.visit_mut_with(self);
|
|
320
|
-
} else {
|
|
321
|
-
self.member_expr_depth += 1;
|
|
322
|
-
n.obj.visit_mut_with(self);
|
|
323
|
-
self.member_expr_depth = max(self.member_expr_depth, 1) - 1;
|
|
388
|
+
fn visit_mut_opt_chain_expr(&mut self, n: &mut OptChainExpr) {
|
|
389
|
+
match &mut *n.base {
|
|
390
|
+
OptChainBase::Member(member) => self.visit_member_expr(member, n.optional),
|
|
391
|
+
OptChainBase::Call(call) => call.visit_mut_with(self),
|
|
324
392
|
}
|
|
393
|
+
}
|
|
325
394
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
if prop_is_computed_lit_str {
|
|
329
|
-
if !self.member_expr_path.is_empty() {
|
|
330
|
-
self.add_if_needed(
|
|
331
|
-
Expr::Lit(comp.expr.as_lit().unwrap().clone()).into(),
|
|
332
|
-
&Expr::Member(n.clone()).into(),
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
} else {
|
|
336
|
-
n.prop.visit_mut_with(self);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
MemberProp::Ident(ident) if !self.member_expr_path.is_empty() => {
|
|
340
|
-
self.add_if_needed(
|
|
341
|
-
Expr::Ident(ident.clone().into()).into(),
|
|
342
|
-
&Expr::Member(n.clone()).into(),
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
_ => {}
|
|
346
|
-
}
|
|
395
|
+
fn visit_mut_member_expr(&mut self, n: &mut MemberExpr) {
|
|
396
|
+
self.visit_member_expr(n, false);
|
|
347
397
|
}
|
|
348
398
|
|
|
349
399
|
/*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#![allow(clippy::boxed_local)]
|
|
2
2
|
use crate::extract_ident::ExtractingIdentsCollector;
|
|
3
3
|
use crate::worklet_type::WorkletType;
|
|
4
|
-
use crate::TransformMode;
|
|
5
4
|
use std::collections::HashSet;
|
|
6
5
|
use std::vec;
|
|
7
6
|
use swc_core::common::{EqIgnoreSpan, DUMMY_SP};
|
|
@@ -37,7 +36,6 @@ impl VisitMut for CaptureRootReplacer {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
struct RegisterWorkletParams<'a> {
|
|
40
|
-
mode: TransformMode,
|
|
41
39
|
target: TransformTarget,
|
|
42
40
|
worklet_type: WorkletType,
|
|
43
41
|
function_name: Ident,
|
|
@@ -46,7 +44,6 @@ struct RegisterWorkletParams<'a> {
|
|
|
46
44
|
extracted_js_fns: Vec<(IdentName, Box<Expr>)>,
|
|
47
45
|
hash: Expr,
|
|
48
46
|
is_class_member: bool,
|
|
49
|
-
named_imports: &'a mut HashSet<String>,
|
|
50
47
|
requires_main_thread_runtime: &'a mut bool,
|
|
51
48
|
register_worklet: &'a Ident,
|
|
52
49
|
}
|
|
@@ -54,7 +51,6 @@ struct RegisterWorkletParams<'a> {
|
|
|
54
51
|
impl StmtGen {
|
|
55
52
|
#[allow(clippy::too_many_arguments)]
|
|
56
53
|
pub fn transform_worklet(
|
|
57
|
-
mode: TransformMode,
|
|
58
54
|
worklet_type: WorkletType,
|
|
59
55
|
hash: String,
|
|
60
56
|
target: TransformTarget,
|
|
@@ -70,12 +66,16 @@ impl StmtGen {
|
|
|
70
66
|
let hash = Expr::Lit(hash.into());
|
|
71
67
|
let mut extracted_value = ident_collector.take_values();
|
|
72
68
|
let mut extracted_this_expr = ident_collector.take_this_expr();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
let optional_member_sources = ident_collector.take_optional_member_sources();
|
|
70
|
+
if StmtGen::wrap_main_thread_object_candidates(
|
|
71
|
+
&mut extracted_value,
|
|
72
|
+
CaptureRoot::Ident,
|
|
73
|
+
&optional_member_sources,
|
|
74
|
+
) | StmtGen::wrap_main_thread_object_candidates(
|
|
75
|
+
&mut extracted_this_expr,
|
|
76
|
+
CaptureRoot::ThisMember,
|
|
77
|
+
&optional_member_sources,
|
|
78
|
+
) {
|
|
79
79
|
named_imports.insert("captureMainThreadObject".into());
|
|
80
80
|
}
|
|
81
81
|
let extracted_idents = ident_collector.take_idents();
|
|
@@ -87,10 +87,8 @@ impl StmtGen {
|
|
|
87
87
|
// that could turn an anonymous registration into a second worklet.
|
|
88
88
|
let mut collected_function = function.clone();
|
|
89
89
|
collected_function.body.as_mut().unwrap().stmts.remove(0);
|
|
90
|
-
let mut collected_imports = HashSet::new();
|
|
91
90
|
let mut collected_runtime_requirement = false;
|
|
92
91
|
StmtGen::gen_register_worklet_stmt(RegisterWorkletParams {
|
|
93
|
-
mode,
|
|
94
92
|
target: TransformTarget::LEPUS,
|
|
95
93
|
worklet_type: worklet_type.clone(),
|
|
96
94
|
function_name: function_name.clone(),
|
|
@@ -99,7 +97,6 @@ impl StmtGen {
|
|
|
99
97
|
extracted_js_fns: extracted_js_fns.clone(),
|
|
100
98
|
hash: hash.clone(),
|
|
101
99
|
is_class_member,
|
|
102
|
-
named_imports: &mut collected_imports,
|
|
103
100
|
requires_main_thread_runtime: &mut collected_runtime_requirement,
|
|
104
101
|
register_worklet,
|
|
105
102
|
})
|
|
@@ -119,7 +116,6 @@ impl StmtGen {
|
|
|
119
116
|
named_imports,
|
|
120
117
|
),
|
|
121
118
|
StmtGen::gen_register_worklet_stmt(RegisterWorkletParams {
|
|
122
|
-
mode,
|
|
123
119
|
target: if target == TransformTarget::MIXED {
|
|
124
120
|
TransformTarget::LEPUS
|
|
125
121
|
} else {
|
|
@@ -132,7 +128,6 @@ impl StmtGen {
|
|
|
132
128
|
extracted_js_fns,
|
|
133
129
|
hash,
|
|
134
130
|
is_class_member,
|
|
135
|
-
named_imports,
|
|
136
131
|
requires_main_thread_runtime,
|
|
137
132
|
register_worklet,
|
|
138
133
|
}),
|
|
@@ -240,6 +235,7 @@ impl StmtGen {
|
|
|
240
235
|
fn wrap_main_thread_object_candidates(
|
|
241
236
|
extracted_value: &mut Box<Expr>,
|
|
242
237
|
capture_root: CaptureRoot,
|
|
238
|
+
optional_member_sources: &[Box<Expr>],
|
|
243
239
|
) -> bool {
|
|
244
240
|
let mut wrapped = false;
|
|
245
241
|
let Some(object) = extracted_value.as_mut_object() else {
|
|
@@ -263,13 +259,21 @@ impl StmtGen {
|
|
|
263
259
|
let Some(source) = source else {
|
|
264
260
|
continue;
|
|
265
261
|
};
|
|
266
|
-
wrapped |= StmtGen::wrap_main_thread_object_candidate(
|
|
262
|
+
wrapped |= StmtGen::wrap_main_thread_object_candidate(
|
|
263
|
+
&mut key_value.value,
|
|
264
|
+
source,
|
|
265
|
+
optional_member_sources,
|
|
266
|
+
);
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
wrapped
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
fn wrap_main_thread_object_candidate(
|
|
272
|
+
fn wrap_main_thread_object_candidate(
|
|
273
|
+
value: &mut Box<Expr>,
|
|
274
|
+
source: Expr,
|
|
275
|
+
optional_member_sources: &[Box<Expr>],
|
|
276
|
+
) -> bool {
|
|
273
277
|
let Some(object) = value.as_mut_object() else {
|
|
274
278
|
return false;
|
|
275
279
|
};
|
|
@@ -285,9 +289,16 @@ impl StmtGen {
|
|
|
285
289
|
continue;
|
|
286
290
|
}
|
|
287
291
|
let child_source = StmtGen::append_member(source.clone(), &key_value.key);
|
|
288
|
-
StmtGen::wrap_main_thread_object_candidate(
|
|
292
|
+
StmtGen::wrap_main_thread_object_candidate(
|
|
293
|
+
&mut key_value.value,
|
|
294
|
+
child_source,
|
|
295
|
+
optional_member_sources,
|
|
296
|
+
);
|
|
289
297
|
}
|
|
290
298
|
|
|
299
|
+
let is_optional = optional_member_sources
|
|
300
|
+
.iter()
|
|
301
|
+
.any(|optional_source| optional_source.as_ref().eq_ignore_span(&source));
|
|
291
302
|
let mut fallback = value.clone();
|
|
292
303
|
let source_argument = source.clone();
|
|
293
304
|
let capture_argument = if source.is_ident() {
|
|
@@ -315,6 +326,15 @@ impl StmtGen {
|
|
|
315
326
|
right: fallback,
|
|
316
327
|
}
|
|
317
328
|
.into();
|
|
329
|
+
let captured_or_fallback: Expr = if is_optional {
|
|
330
|
+
quote!(
|
|
331
|
+
"$src == null ? $src : $expr" as Expr,
|
|
332
|
+
src: Expr = capture_argument.clone(),
|
|
333
|
+
expr: Expr = captured_or_fallback,
|
|
334
|
+
)
|
|
335
|
+
} else {
|
|
336
|
+
captured_or_fallback
|
|
337
|
+
};
|
|
318
338
|
*value = if source_argument.is_ident() {
|
|
319
339
|
captured_or_fallback.into()
|
|
320
340
|
} else {
|
|
@@ -407,7 +427,6 @@ impl StmtGen {
|
|
|
407
427
|
*/
|
|
408
428
|
fn gen_register_worklet_stmt(params: RegisterWorkletParams) -> Stmt {
|
|
409
429
|
let RegisterWorkletParams {
|
|
410
|
-
mode,
|
|
411
430
|
target,
|
|
412
431
|
worklet_type,
|
|
413
432
|
function_name,
|
|
@@ -416,11 +435,14 @@ impl StmtGen {
|
|
|
416
435
|
extracted_js_fns,
|
|
417
436
|
hash,
|
|
418
437
|
is_class_member,
|
|
419
|
-
named_imports,
|
|
420
438
|
requires_main_thread_runtime,
|
|
421
439
|
register_worklet,
|
|
422
440
|
} = params;
|
|
423
441
|
|
|
442
|
+
if target != TransformTarget::LEPUS {
|
|
443
|
+
return EmptyStmt { span: DUMMY_SP }.into();
|
|
444
|
+
}
|
|
445
|
+
|
|
424
446
|
let function_to_register = Box::new(StmtGen::gen_function_to_register(
|
|
425
447
|
function,
|
|
426
448
|
function_name,
|
|
@@ -430,35 +452,21 @@ impl StmtGen {
|
|
|
430
452
|
is_class_member,
|
|
431
453
|
));
|
|
432
454
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
expr: registration,
|
|
447
|
-
}
|
|
448
|
-
.into()
|
|
449
|
-
} else if mode == TransformMode::Development {
|
|
450
|
-
named_imports.insert("registerWorkletOnBackground".into());
|
|
451
|
-
quote!("registerWorkletOnBackground($type_, $hash, $fn_)" as Stmt,
|
|
452
|
-
type_: Expr = Expr::Lit(worklet_type.type_str().into()),
|
|
453
|
-
hash: Expr = hash,
|
|
454
|
-
fn_: Expr = Expr::Fn(FnExpr {
|
|
455
|
-
ident: None,
|
|
456
|
-
function: function_to_register,
|
|
457
|
-
}),
|
|
458
|
-
)
|
|
459
|
-
} else {
|
|
460
|
-
EmptyStmt { span: DUMMY_SP }.into()
|
|
455
|
+
*requires_main_thread_runtime = true;
|
|
456
|
+
let registration = quote_expr!("$register($type_, $hash, $fn_)",
|
|
457
|
+
register: Ident = register_worklet.clone(),
|
|
458
|
+
type_: Expr = Expr::Lit(worklet_type.type_str().into()),
|
|
459
|
+
hash: Expr = hash,
|
|
460
|
+
fn_: Expr = Expr::Fn(FnExpr {
|
|
461
|
+
ident: None,
|
|
462
|
+
function: function_to_register,
|
|
463
|
+
}),
|
|
464
|
+
);
|
|
465
|
+
ExprStmt {
|
|
466
|
+
span: DUMMY_SP,
|
|
467
|
+
expr: registration,
|
|
461
468
|
}
|
|
469
|
+
.into()
|
|
462
470
|
}
|
|
463
471
|
|
|
464
472
|
fn gen_function_to_register(
|