@lynx-js/react 0.126.2 → 0.128.0
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 +36 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/docs/directives.md +90 -0
- package/docs/global-events.md +50 -0
- package/docs/import-attributes.md +43 -0
- package/docs/macros.md +285 -0
- package/package.json +7 -14
- package/refresh/.turbo/turbo-build.log +2 -2
- package/refresh/dist/index.js +26 -6
- package/refresh/package.json +1 -1
- package/runtime/__test__/core/main-thread-object.test.js +149 -0
- package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
- package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +39 -48
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +11 -9
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -3
- package/runtime/__test__/element-template/test-utils/mock/globals.js +6 -0
- package/runtime/__test__/element-template/vitest.config.ts +4 -0
- package/runtime/__test__/snapshot/ctxNotFound.test.ts +271 -0
- package/runtime/__test__/snapshot/event.test.jsx +7 -7
- package/runtime/__test__/snapshot/lazy.test.js +73 -1
- package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
- package/runtime/__test__/snapshot/spread.test.jsx +10 -10
- package/runtime/__test__/snapshot/worklet/main-thread-object.test.jsx +306 -0
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +1 -0
- package/runtime/__test__/worklet-runtime/initEntry.test.js +109 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
- package/runtime/__test__/worklet-runtime/object-methods.test.js +59 -0
- package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +246 -1
- package/runtime/lazy/compat.js +2 -0
- package/runtime/lazy/element-template-internal.js +1 -1
- package/runtime/lazy/element-template.js +2 -0
- package/runtime/lazy/internal.js +2 -1
- package/runtime/lazy/react.js +2 -0
- package/runtime/lib/core/background-function/exec-map.js.map +1 -1
- package/runtime/lib/core/background-function/handle.js.map +1 -1
- package/runtime/lib/core/background-function/run-on-background.d.ts +16 -0
- package/runtime/lib/core/background-function/run-on-background.js +16 -0
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/capture-main-thread-object.d.ts +1 -0
- package/runtime/lib/core/capture-main-thread-object.js +16 -0
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -0
- package/runtime/lib/core/commit-context.js.map +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/compat/lynxComponent.js.map +1 -1
- package/runtime/lib/core/component.js.map +1 -1
- package/runtime/lib/core/forceRootRender.js.map +1 -1
- package/runtime/lib/core/globalProps.d.ts +2 -0
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/hooks/mainThread.js.map +1 -1
- package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
- package/runtime/lib/core/hooks/react.d.ts +4 -0
- package/runtime/lib/core/hooks/react.js +4 -0
- package/runtime/lib/core/hooks/react.js.map +1 -1
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
- package/runtime/lib/core/initData.d.ts +2 -0
- package/runtime/lib/core/initData.js +2 -0
- package/runtime/lib/core/initData.js.map +1 -1
- package/runtime/lib/core/lynx/dynamic-import.js.map +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-backend.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-version.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/lynx-page-data.js.map +1 -1
- package/runtime/lib/core/lynx-update-data.js.map +1 -1
- package/runtime/lib/core/main-thread-function.js.map +1 -1
- package/runtime/lib/core/main-thread-object-handle-registry.d.ts +3 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js +17 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -0
- package/runtime/lib/core/main-thread-object.d.ts +77 -0
- package/runtime/lib/core/main-thread-object.js +258 -0
- package/runtime/lib/core/main-thread-object.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-id.d.ts +1 -0
- package/runtime/lib/core/main-thread-ref-id.js +14 -0
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-init-value.d.ts +1 -1
- package/runtime/lib/core/main-thread-ref-init-value.js +4 -2
- package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
- package/runtime/lib/core/main-thread-ref.d.ts +4 -0
- package/runtime/lib/core/main-thread-ref.js +5 -8
- package/runtime/lib/core/main-thread-ref.js.map +1 -1
- package/runtime/lib/core/mts-capability.js.map +1 -1
- package/runtime/lib/core/performance.js.map +1 -1
- package/runtime/lib/core/ref.js.map +1 -1
- package/runtime/lib/core/reload-version.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
- package/runtime/lib/document.js.map +1 -1
- package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
- package/runtime/lib/element-template/background/commit-context.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/document.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/background/instance.js.map +1 -1
- package/runtime/lib/element-template/background/manager.js.map +1 -1
- package/runtime/lib/element-template/background/page-root-hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/render-scope.js.map +1 -1
- package/runtime/lib/element-template/client/root.js.map +1 -1
- package/runtime/lib/element-template/debug/alog.js.map +1 -1
- package/runtime/lib/element-template/debug/elementPAPICall.js.map +1 -1
- package/runtime/lib/element-template/debug/profile.js.map +1 -1
- package/runtime/lib/element-template/hydration-map.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +2 -0
- package/runtime/lib/element-template/index.js +1 -0
- 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 +1 -1
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/jsx-dev-runtime/index.js.map +1 -1
- package/runtime/lib/element-template/jsx-runtime/index.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/lynx/performance.js.map +1 -1
- package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/event-value.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/event.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
- package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
- package/runtime/lib/element-template/protocol/page.js.map +1 -1
- package/runtime/lib/element-template/protocol/template-type.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +1 -1
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/protocol/update-event.js.map +1 -1
- package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/authored-page.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/host.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -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.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
- package/runtime/lib/element-template/runtime-marker.js.map +1 -1
- package/runtime/lib/index.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 +34 -0
- package/runtime/lib/lynx-api.js +21 -0
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +4 -1
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/root.js.map +1 -1
- package/runtime/lib/runtime-marker.js.map +1 -1
- package/runtime/lib/shared/attribute-name.js.map +1 -1
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/shared/index-map.js.map +1 -1
- package/runtime/lib/shared/profile.js.map +1 -1
- package/runtime/lib/shared/render-constants.js.map +1 -1
- package/runtime/lib/snapshot/alog/elementPAPICall.js.map +1 -1
- package/runtime/lib/snapshot/alog/index.js.map +1 -1
- package/runtime/lib/snapshot/alog/render.js.map +1 -1
- package/runtime/lib/snapshot/compat/componentIs.js.map +1 -1
- package/runtime/lib/snapshot/debug/debug.js.map +1 -1
- package/runtime/lib/snapshot/debug/describeInvalidValue.js.map +1 -1
- package/runtime/lib/snapshot/debug/formatPatch.js.map +1 -1
- package/runtime/lib/snapshot/debug/printSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/debug/vnodeSource.js.map +1 -1
- package/runtime/lib/snapshot/gesture/processGesture.js.map +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +1 -1
- package/runtime/lib/snapshot/gesture/types.js.map +1 -1
- package/runtime/lib/snapshot/index.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/constant.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/delayEvents.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/delayLifecycleEvents.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.d.ts +11 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.js +24 -16
- package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/globalState.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/isMainThreadHydrating.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/nodesRefApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.d.ts +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +29 -7
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +2 -2
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/render.js.map +1 -1
- package/runtime/lib/snapshot/list/list.js.map +1 -1
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/list/pendingListUpdates.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/lynx/children.d.ts +2 -0
- package/runtime/lib/snapshot/lynx/children.js.map +1 -1
- package/runtime/lib/snapshot/lynx/element.d.ts +8 -0
- package/runtime/lib/snapshot/lynx/element.js +4 -0
- package/runtime/lib/snapshot/lynx/element.js.map +1 -1
- package/runtime/lib/snapshot/lynx/env.js.map +1 -1
- package/runtime/lib/snapshot/lynx/injectLepusMethods.js.map +1 -1
- package/runtime/lib/snapshot/lynx/lazyBundleConstants.js.map +1 -1
- package/runtime/lib/snapshot/lynx/nodesRef.js.map +1 -1
- package/runtime/lib/snapshot/lynx/performance.js.map +1 -1
- package/runtime/lib/snapshot/lynx/portals.js.map +1 -1
- package/runtime/lib/snapshot/lynx/portalsPending.js.map +1 -1
- package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.js.map +1 -1
- package/runtime/lib/snapshot/lynx/runWithForce.js.map +1 -1
- package/runtime/lib/snapshot/lynx/suspense.js.map +1 -1
- package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/constants.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/definition.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/dynamicPartType.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/event.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/gesture.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/index.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/reconstructInstanceTree.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceHydrationMap.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/types.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/utils.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/workletEvent.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/workletRef.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
- package/runtime/lib/snapshot/worklet/destroy.js.map +1 -1
- package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
- package/runtime/lib/snapshot/worklet/hmr.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/utils.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/animation/animation.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/animation/effect.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/lepusQuerySelector.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -3
- package/runtime/lib/worklet-runtime/bindings/bindings.js +9 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/events.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +0 -1
- package/runtime/lib/worklet-runtime/bindings/index.js +0 -1
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/types.d.ts +3 -6
- package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
- package/runtime/lib/worklet-runtime/eomImpl.js.map +1 -1
- package/runtime/lib/worklet-runtime/eventPropagation.js.map +1 -1
- package/runtime/lib/worklet-runtime/global.js.map +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js +26 -7
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/index.js +6 -0
- package/runtime/lib/worklet-runtime/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.d.ts +8 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js +67 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -0
- package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/mainThreadFlushLoopGuard.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/version.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRef.d.ts +11 -7
- package/runtime/lib/worklet-runtime/workletRef.js +72 -9
- package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +68 -9
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/background-function/run-on-background.ts +16 -0
- package/runtime/src/core/capture-main-thread-object.ts +17 -0
- package/runtime/src/core/globalProps.ts +2 -0
- package/runtime/src/core/hooks/react.ts +4 -0
- package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
- package/runtime/src/core/initData.ts +2 -0
- package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
- package/runtime/src/core/main-thread-object.ts +380 -0
- package/runtime/src/core/main-thread-ref-id.ts +16 -0
- package/runtime/src/core/main-thread-ref-init-value.ts +12 -4
- package/runtime/src/core/main-thread-ref.ts +7 -8
- package/runtime/src/element-template/background/commit-hook.ts +1 -1
- package/runtime/src/element-template/index.ts +6 -0
- package/runtime/src/element-template/internal.ts +2 -1
- package/runtime/src/element-template/protocol/types.ts +1 -1
- package/runtime/src/internal.ts +1 -1
- package/runtime/src/lynx-api.ts +38 -0
- package/runtime/src/lynx.ts +5 -1
- package/runtime/src/snapshot/lifecycle/patch/error.ts +36 -19
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +29 -7
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +2 -2
- package/runtime/src/snapshot/lynx/children.ts +2 -0
- package/runtime/src/snapshot/lynx/element.ts +8 -0
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +2 -0
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +1 -1
- package/runtime/src/worklet-runtime/bindings/bindings.ts +17 -2
- package/runtime/src/worklet-runtime/bindings/index.ts +0 -1
- package/runtime/src/worklet-runtime/bindings/types.ts +7 -11
- package/runtime/src/worklet-runtime/hydrate.ts +43 -10
- package/runtime/src/worklet-runtime/index.ts +7 -0
- package/runtime/src/worklet-runtime/mainThreadObject.ts +117 -0
- package/runtime/src/worklet-runtime/workletRef.ts +120 -19
- package/runtime/src/worklet-runtime/workletRuntime.ts +83 -11
- package/runtime/tsconfig.json +2 -0
- package/runtime/vitest.config.ts +4 -0
- package/testing-library/.turbo/turbo-build.log +11 -11
- package/testing-library/dist/env/index.js +3 -15
- package/testing-library/dist/index.d.ts +165 -2
- package/testing-library/dist/plugins/index.js +10 -0
- package/testing-library/dist/rstest-config.js +15 -0
- package/testing-library/dist/setupFiles/common/worklet-runtime-init.js +11 -0
- package/testing-library/package.json +2 -1
- package/testing-library/rstest.config.ts +3 -0
- package/testing-library/src/__tests__/lynx.test.jsx +1 -1
- package/testing-library/src/__tests__/rstest-config.test.js +34 -1
- package/testing-library/src/__tests__/worklet.test.jsx +87 -33
- package/testing-library/src/plugins/vitest.ts +5 -1
- package/testing-library/src/rstest-config.ts +17 -1
- package/testing-library/src/setupFiles/common/worklet-runtime-init.js +22 -0
- package/testing-library/tsconfig.docs.json +9 -0
- package/testing-library/typedoc.json +22 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +135 -73
- package/transform/__test__/defines.spec.js +80 -12
- package/transform/__test__/fixture.spec.js +231 -71
- package/transform/__test__/object-methods.spec.js +82 -0
- package/transform/crates/swc_plugin_worklet/decl_collect.rs +10 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +14 -0
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +228 -13
- package/transform/crates/swc_plugin_worklet/lib.rs +599 -150
- package/transform/crates/swc_plugin_worklet/napi.rs +10 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +8 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +12 -7
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_js.js +27 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +43 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +16 -14
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +18 -18
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_lepus.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +7 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +9 -9
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +22 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_globals.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +14 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_type_annotations.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_destructure_from_closure.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_catch_clause_params.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_idents_inside_of_ctx.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_recursively.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +42 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +58 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_arrow_function.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_function_expr.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +3 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +5 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_alias.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general_mixed.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets_in_func.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +14 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_lepus.js +2 -4
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +25 -1
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/lib.rs +193 -23
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +63 -467
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +340 -28
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/transform/vitest.config.ts +5 -1
- package/types/react.docs.d.ts +130 -11
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +0 -8
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +0 -23
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +0 -1
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +0 -25
- package/runtime/worklet-runtime/dev.js +0 -638
- package/runtime/worklet-runtime/main.js +0 -1
- package/testing-library/node_modules/.bin/rsbuild +0 -68
- package/testing-library/node_modules/.bin/rspeedy +0 -68
- package/testing-library/node_modules/.bin/rstest +0 -68
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_inner_ident.js +0 -13
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_outer_ident.js +0 -13
- package/transform/node_modules/.bin/esbuild +0 -59
- package/transform/node_modules/.bin/napi +0 -68
|
@@ -4,13 +4,38 @@ use crate::worklet_type::WorkletType;
|
|
|
4
4
|
use crate::TransformMode;
|
|
5
5
|
use std::collections::HashSet;
|
|
6
6
|
use std::vec;
|
|
7
|
-
use swc_core::common::DUMMY_SP;
|
|
7
|
+
use swc_core::common::{EqIgnoreSpan, DUMMY_SP};
|
|
8
8
|
use swc_core::ecma::ast::*;
|
|
9
|
+
use swc_core::ecma::utils::private_ident;
|
|
10
|
+
use swc_core::ecma::visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
|
|
9
11
|
use swc_core::{quote, quote_expr};
|
|
10
12
|
use swc_plugins_shared::target::TransformTarget;
|
|
11
13
|
|
|
12
14
|
pub struct StmtGen {}
|
|
13
15
|
|
|
16
|
+
#[derive(Clone, Copy)]
|
|
17
|
+
enum CaptureRoot {
|
|
18
|
+
Ident,
|
|
19
|
+
ThisMember,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
struct CaptureRootReplacer {
|
|
23
|
+
source: Expr,
|
|
24
|
+
replacement: Ident,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
impl VisitMut for CaptureRootReplacer {
|
|
28
|
+
noop_visit_mut_type!();
|
|
29
|
+
|
|
30
|
+
fn visit_mut_expr(&mut self, expr: &mut Expr) {
|
|
31
|
+
if expr.eq_ignore_span(&self.source) {
|
|
32
|
+
*expr = Expr::Ident(self.replacement.clone());
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
expr.visit_mut_children_with(self);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
14
39
|
struct RegisterWorkletParams<'a> {
|
|
15
40
|
mode: TransformMode,
|
|
16
41
|
target: TransformTarget,
|
|
@@ -22,7 +47,8 @@ struct RegisterWorkletParams<'a> {
|
|
|
22
47
|
hash: Expr,
|
|
23
48
|
is_class_member: bool,
|
|
24
49
|
named_imports: &'a mut HashSet<String>,
|
|
25
|
-
|
|
50
|
+
requires_main_thread_runtime: &'a mut bool,
|
|
51
|
+
register_worklet: &'a Ident,
|
|
26
52
|
}
|
|
27
53
|
|
|
28
54
|
impl StmtGen {
|
|
@@ -37,28 +63,45 @@ impl StmtGen {
|
|
|
37
63
|
ident_collector: &mut ExtractingIdentsCollector,
|
|
38
64
|
is_class_member: bool,
|
|
39
65
|
named_imports: &mut HashSet<String>,
|
|
40
|
-
|
|
66
|
+
requires_main_thread_runtime: &mut bool,
|
|
67
|
+
register_worklet: &Ident,
|
|
41
68
|
collect_main_thread: bool,
|
|
42
69
|
) -> (Box<Expr>, Stmt, Option<Stmt>) {
|
|
43
70
|
let hash = Expr::Lit(hash.into());
|
|
44
|
-
let extracted_value = ident_collector.take_values();
|
|
71
|
+
let mut extracted_value = ident_collector.take_values();
|
|
72
|
+
let mut extracted_this_expr = ident_collector.take_this_expr();
|
|
73
|
+
if StmtGen::wrap_main_thread_object_candidates(&mut extracted_value, CaptureRoot::Ident)
|
|
74
|
+
| StmtGen::wrap_main_thread_object_candidates(
|
|
75
|
+
&mut extracted_this_expr,
|
|
76
|
+
CaptureRoot::ThisMember,
|
|
77
|
+
)
|
|
78
|
+
{
|
|
79
|
+
named_imports.insert("captureMainThreadObject".into());
|
|
80
|
+
}
|
|
45
81
|
let extracted_idents = ident_collector.take_idents();
|
|
46
82
|
let extracted_js_fns = ident_collector.take_js_fns();
|
|
47
83
|
|
|
48
84
|
let main_thread_stmt = collect_main_thread.then(|| {
|
|
85
|
+
// The injected definition passes through the main-thread transform again.
|
|
86
|
+
// Its function is already lowered; do not leave an authored directive
|
|
87
|
+
// that could turn an anonymous registration into a second worklet.
|
|
88
|
+
let mut collected_function = function.clone();
|
|
89
|
+
collected_function.body.as_mut().unwrap().stmts.remove(0);
|
|
49
90
|
let mut collected_imports = HashSet::new();
|
|
91
|
+
let mut collected_runtime_requirement = false;
|
|
50
92
|
StmtGen::gen_register_worklet_stmt(RegisterWorkletParams {
|
|
51
93
|
mode,
|
|
52
94
|
target: TransformTarget::LEPUS,
|
|
53
95
|
worklet_type: worklet_type.clone(),
|
|
54
96
|
function_name: function_name.clone(),
|
|
55
|
-
function:
|
|
97
|
+
function: collected_function,
|
|
56
98
|
extracted_idents: extracted_idents.clone(),
|
|
57
99
|
extracted_js_fns: extracted_js_fns.clone(),
|
|
58
100
|
hash: hash.clone(),
|
|
59
101
|
is_class_member,
|
|
60
102
|
named_imports: &mut collected_imports,
|
|
61
|
-
|
|
103
|
+
requires_main_thread_runtime: &mut collected_runtime_requirement,
|
|
104
|
+
register_worklet,
|
|
62
105
|
})
|
|
63
106
|
});
|
|
64
107
|
|
|
@@ -70,7 +113,7 @@ impl StmtGen {
|
|
|
70
113
|
target
|
|
71
114
|
},
|
|
72
115
|
extracted_value,
|
|
73
|
-
|
|
116
|
+
extracted_this_expr,
|
|
74
117
|
extracted_js_fns.clone(),
|
|
75
118
|
hash.clone(),
|
|
76
119
|
named_imports,
|
|
@@ -90,7 +133,8 @@ impl StmtGen {
|
|
|
90
133
|
hash,
|
|
91
134
|
is_class_member,
|
|
92
135
|
named_imports,
|
|
93
|
-
|
|
136
|
+
requires_main_thread_runtime,
|
|
137
|
+
register_worklet,
|
|
94
138
|
}),
|
|
95
139
|
main_thread_stmt,
|
|
96
140
|
)
|
|
@@ -193,6 +237,171 @@ impl StmtGen {
|
|
|
193
237
|
.into()
|
|
194
238
|
}
|
|
195
239
|
|
|
240
|
+
fn wrap_main_thread_object_candidates(
|
|
241
|
+
extracted_value: &mut Box<Expr>,
|
|
242
|
+
capture_root: CaptureRoot,
|
|
243
|
+
) -> bool {
|
|
244
|
+
let mut wrapped = false;
|
|
245
|
+
let Some(object) = extracted_value.as_mut_object() else {
|
|
246
|
+
return false;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
for prop in &mut object.props {
|
|
250
|
+
let Some(prop) = prop.as_mut_prop() else {
|
|
251
|
+
continue;
|
|
252
|
+
};
|
|
253
|
+
let Prop::KeyValue(key_value) = prop.as_mut() else {
|
|
254
|
+
continue;
|
|
255
|
+
};
|
|
256
|
+
if !key_value.value.is_object() {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
let source = match capture_root {
|
|
260
|
+
CaptureRoot::Ident => StmtGen::find_root_ident(&key_value.value).map(Expr::Ident),
|
|
261
|
+
CaptureRoot::ThisMember => StmtGen::find_root_this_member(&key_value.value),
|
|
262
|
+
};
|
|
263
|
+
let Some(source) = source else {
|
|
264
|
+
continue;
|
|
265
|
+
};
|
|
266
|
+
wrapped |= StmtGen::wrap_main_thread_object_candidate(&mut key_value.value, source);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
wrapped
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
fn wrap_main_thread_object_candidate(value: &mut Box<Expr>, source: Expr) -> bool {
|
|
273
|
+
let Some(object) = value.as_mut_object() else {
|
|
274
|
+
return false;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
for prop in &mut object.props {
|
|
278
|
+
let Some(prop) = prop.as_mut_prop() else {
|
|
279
|
+
continue;
|
|
280
|
+
};
|
|
281
|
+
let Prop::KeyValue(key_value) = prop.as_mut() else {
|
|
282
|
+
continue;
|
|
283
|
+
};
|
|
284
|
+
if !key_value.value.is_object() {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
let child_source = StmtGen::append_member(source.clone(), &key_value.key);
|
|
288
|
+
StmtGen::wrap_main_thread_object_candidate(&mut key_value.value, child_source);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
let mut fallback = value.clone();
|
|
292
|
+
let source_argument = source.clone();
|
|
293
|
+
let capture_argument = if source.is_ident() {
|
|
294
|
+
source
|
|
295
|
+
} else {
|
|
296
|
+
let capture_source = private_ident!("__mainThreadObjectSource");
|
|
297
|
+
fallback.visit_mut_with(&mut CaptureRootReplacer {
|
|
298
|
+
source,
|
|
299
|
+
replacement: capture_source.clone(),
|
|
300
|
+
});
|
|
301
|
+
Expr::Ident(capture_source)
|
|
302
|
+
};
|
|
303
|
+
let captured = CallExpr {
|
|
304
|
+
ctxt: Default::default(),
|
|
305
|
+
span: DUMMY_SP,
|
|
306
|
+
args: vec![capture_argument.clone().into()],
|
|
307
|
+
callee: Callee::Expr(quote_expr!("captureMainThreadObject")),
|
|
308
|
+
type_args: None,
|
|
309
|
+
}
|
|
310
|
+
.into();
|
|
311
|
+
let captured_or_fallback: Expr = BinExpr {
|
|
312
|
+
span: DUMMY_SP,
|
|
313
|
+
op: BinaryOp::NullishCoalescing,
|
|
314
|
+
left: captured,
|
|
315
|
+
right: fallback,
|
|
316
|
+
}
|
|
317
|
+
.into();
|
|
318
|
+
*value = if source_argument.is_ident() {
|
|
319
|
+
captured_or_fallback.into()
|
|
320
|
+
} else {
|
|
321
|
+
CallExpr {
|
|
322
|
+
ctxt: Default::default(),
|
|
323
|
+
span: DUMMY_SP,
|
|
324
|
+
callee: Callee::Expr(
|
|
325
|
+
ArrowExpr {
|
|
326
|
+
ctxt: Default::default(),
|
|
327
|
+
span: DUMMY_SP,
|
|
328
|
+
params: vec![Pat::Ident(capture_argument.expect_ident().into())],
|
|
329
|
+
body: Box::new(ArrowFunctionBody::Expr(captured_or_fallback.into())),
|
|
330
|
+
is_async: false,
|
|
331
|
+
is_generator: false,
|
|
332
|
+
type_params: None,
|
|
333
|
+
return_type: None,
|
|
334
|
+
}
|
|
335
|
+
.into(),
|
|
336
|
+
),
|
|
337
|
+
args: vec![source_argument.into()],
|
|
338
|
+
type_args: None,
|
|
339
|
+
}
|
|
340
|
+
.into()
|
|
341
|
+
};
|
|
342
|
+
true
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
fn append_member(source: Expr, property: &PropName) -> Expr {
|
|
346
|
+
let property = match property {
|
|
347
|
+
PropName::Ident(ident) => MemberProp::Ident(ident.clone()),
|
|
348
|
+
PropName::Str(value) => MemberProp::Computed(ComputedPropName {
|
|
349
|
+
span: DUMMY_SP,
|
|
350
|
+
expr: Expr::Lit(Lit::Str(value.clone())).into(),
|
|
351
|
+
}),
|
|
352
|
+
PropName::Num(value) => MemberProp::Computed(ComputedPropName {
|
|
353
|
+
span: DUMMY_SP,
|
|
354
|
+
expr: Expr::Lit(Lit::Num(value.clone())).into(),
|
|
355
|
+
}),
|
|
356
|
+
PropName::BigInt(value) => MemberProp::Computed(ComputedPropName {
|
|
357
|
+
span: DUMMY_SP,
|
|
358
|
+
expr: Expr::Lit(Lit::BigInt(value.clone())).into(),
|
|
359
|
+
}),
|
|
360
|
+
PropName::Computed(value) => MemberProp::Computed(value.clone()),
|
|
361
|
+
};
|
|
362
|
+
StmtGen::append_member_prop(source, property)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
fn append_member_prop(source: Expr, property: MemberProp) -> Expr {
|
|
366
|
+
MemberExpr {
|
|
367
|
+
span: DUMMY_SP,
|
|
368
|
+
obj: source.into(),
|
|
369
|
+
prop: property,
|
|
370
|
+
}
|
|
371
|
+
.into()
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
fn find_root_ident(expr: &Expr) -> Option<Ident> {
|
|
375
|
+
match expr {
|
|
376
|
+
Expr::Ident(ident) => Some(ident.clone()),
|
|
377
|
+
Expr::Member(member) => StmtGen::find_root_ident(&member.obj),
|
|
378
|
+
Expr::Object(object) => object.props.iter().find_map(|prop| {
|
|
379
|
+
let prop = prop.as_prop()?;
|
|
380
|
+
match prop.as_ref() {
|
|
381
|
+
Prop::Shorthand(ident) => Some(ident.clone()),
|
|
382
|
+
Prop::KeyValue(key_value) => StmtGen::find_root_ident(&key_value.value),
|
|
383
|
+
_ => None,
|
|
384
|
+
}
|
|
385
|
+
}),
|
|
386
|
+
_ => None,
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
fn find_root_this_member(expr: &Expr) -> Option<Expr> {
|
|
391
|
+
match expr {
|
|
392
|
+
Expr::Member(member) if member.obj.is_this() => Some(Expr::Member(member.clone())),
|
|
393
|
+
Expr::Member(member) => StmtGen::find_root_this_member(&member.obj),
|
|
394
|
+
Expr::Object(object) => object.props.iter().find_map(|prop| {
|
|
395
|
+
let prop = prop.as_prop()?;
|
|
396
|
+
match prop.as_ref() {
|
|
397
|
+
Prop::KeyValue(key_value) => StmtGen::find_root_this_member(&key_value.value),
|
|
398
|
+
_ => None,
|
|
399
|
+
}
|
|
400
|
+
}),
|
|
401
|
+
_ => None,
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
196
405
|
/*
|
|
197
406
|
* registerWorklet($type, $hash, $function);
|
|
198
407
|
*/
|
|
@@ -208,7 +417,8 @@ impl StmtGen {
|
|
|
208
417
|
hash,
|
|
209
418
|
is_class_member,
|
|
210
419
|
named_imports,
|
|
211
|
-
|
|
420
|
+
requires_main_thread_runtime,
|
|
421
|
+
register_worklet,
|
|
212
422
|
} = params;
|
|
213
423
|
|
|
214
424
|
let function_to_register = Box::new(StmtGen::gen_function_to_register(
|
|
@@ -221,16 +431,21 @@ impl StmtGen {
|
|
|
221
431
|
));
|
|
222
432
|
|
|
223
433
|
if target == TransformTarget::LEPUS {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
434
|
+
*requires_main_thread_runtime = true;
|
|
435
|
+
let registration = quote_expr!("$register($type_, $hash, $fn_)",
|
|
436
|
+
register: Ident = register_worklet.clone(),
|
|
227
437
|
type_: Expr = Expr::Lit(worklet_type.type_str().into()),
|
|
228
438
|
hash: Expr = hash,
|
|
229
439
|
fn_: Expr = Expr::Fn(FnExpr {
|
|
230
440
|
ident: None,
|
|
231
441
|
function: function_to_register,
|
|
232
442
|
}),
|
|
233
|
-
)
|
|
443
|
+
);
|
|
444
|
+
ExprStmt {
|
|
445
|
+
span: DUMMY_SP,
|
|
446
|
+
expr: registration,
|
|
447
|
+
}
|
|
448
|
+
.into()
|
|
234
449
|
} else if mode == TransformMode::Development {
|
|
235
450
|
named_imports.insert("registerWorkletOnBackground".into());
|
|
236
451
|
quote!("registerWorkletOnBackground($type_, $hash, $fn_)" as Stmt,
|