@lynx-js/react 0.129.0 → 0.129.2
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 +24 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/globalProps.test.ts +27 -6
- package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
- package/runtime/__test__/element-template/fixtures/gesture/direct/index.tsx +33 -0
- package/runtime/__test__/element-template/fixtures/spread/mts/index.tsx +197 -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/callDestroyLifetimeFun.test.ts +89 -3
- package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +88 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +3 -0
- package/runtime/__test__/element-template/native/reload.test.ts +118 -2
- package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +5 -5
- package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +1 -1
- package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +70 -0
- package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +3 -4
- package/runtime/__test__/element-template/runtime/background/reload.test.ts +74 -0
- package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +212 -7
- package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/prop-adapters/gesture-compiled.test.ts +200 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +420 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +527 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +185 -6
- package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +21 -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/template/element-template-handle.test.ts +32 -0
- package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +309 -26
- 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/updateGlobalProps.event.test.jsx +2 -2
- package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +3 -3
- package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
- package/runtime/__test__/snapshot/preact.test.jsx +0 -3
- package/runtime/__test__/snapshot/ref.test.jsx +30 -0
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +12 -0
- package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
- package/runtime/lazy/element-template-internal.js +1 -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/capture-main-thread-object.js +2 -1
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
- 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/globalProps.js +1 -1
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js +1 -1
- 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/runtime-destroy.js +1 -1
- package/runtime/lib/core/runtime-destroy.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/attr-slots.js +5 -2
- package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js +11 -12
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js +16 -11
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +23 -0
- package/runtime/lib/element-template/background/hydrate.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/debug/alog.d.ts +1 -1
- package/runtime/lib/element-template/debug/alog.js +4 -1
- package/runtime/lib/element-template/debug/alog.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 +2 -2
- package/runtime/lib/element-template/internal.js +1 -14
- 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/native/callDestroyLifetimeFun.js +6 -1
- package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
- 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/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 +8 -2
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +57 -50
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.js +1 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js +35 -10
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/gesture.d.ts +23 -0
- package/runtime/lib/element-template/prop-adapters/gesture.js +97 -0
- package/runtime/lib/element-template/prop-adapters/gesture.js.map +1 -0
- package/runtime/lib/element-template/prop-adapters/spread.d.ts +6 -1
- package/runtime/lib/element-template/prop-adapters/spread.js +72 -2
- package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
- package/runtime/lib/element-template/protocol/opcodes.d.ts +1 -0
- package/runtime/lib/element-template/protocol/opcodes.js +1 -0
- package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +7 -1
- 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 +31 -2
- 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/attr-slot-plan.d.ts +4 -2
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.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 +7 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +380 -50
- 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 +3 -2
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js +10 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/typed-attributes.js +3 -3
- package/runtime/lib/element-template/runtime/template/typed-attributes.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/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 +23 -17
- package/runtime/lib/snapshot/lifecycle/destroy.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/ref/delay.d.ts +5 -0
- package/runtime/lib/snapshot/lifecycle/ref/delay.js +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.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 +11 -8
- 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/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/jsFunctionLifecycle.d.ts +2 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +6 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.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/capture-main-thread-object.ts +2 -1
- package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
- package/runtime/src/core/globalProps.ts +1 -1
- package/runtime/src/core/lynx/lazy-bundle.ts +1 -1
- package/runtime/src/core/lynx-data-processors.ts +124 -1
- package/runtime/src/core/runtime-destroy.ts +1 -1
- package/runtime/src/document.ts +0 -6
- package/runtime/src/element-template/background/attr-slots.ts +5 -1
- package/runtime/src/element-template/background/commit-hook.ts +18 -12
- package/runtime/src/element-template/background/destroy.ts +16 -13
- package/runtime/src/element-template/background/hydrate.ts +23 -0
- package/runtime/src/element-template/client/root.ts +1 -3
- package/runtime/src/element-template/debug/alog.ts +5 -2
- package/runtime/src/element-template/index.ts +2 -2
- package/runtime/src/element-template/internal.ts +1 -20
- package/runtime/src/element-template/lynx/env.ts +1 -1
- package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +5 -1
- package/runtime/src/element-template/native/flush.ts +10 -0
- package/runtime/src/element-template/native/main-thread-api.ts +3 -6
- package/runtime/src/element-template/native/mts-destroy.ts +7 -2
- package/runtime/src/element-template/native/patch-listener.ts +62 -57
- package/runtime/src/element-template/native/reload-background.ts +1 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +32 -11
- package/runtime/src/element-template/prop-adapters/gesture.ts +144 -0
- package/runtime/src/element-template/prop-adapters/spread.ts +110 -2
- package/runtime/src/element-template/protocol/opcodes.ts +1 -0
- package/runtime/src/element-template/protocol/types.ts +8 -13
- package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
- package/runtime/src/element-template/runtime/patch.ts +38 -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/attr-slot-plan.ts +31 -4
- 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 +456 -50
- package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +14 -4
- package/runtime/src/element-template/runtime/template/typed-attributes.ts +3 -3
- 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/snapshot/lifecycle/destroy.ts +23 -18
- 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/ref/delay.ts +1 -1
- package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
- package/runtime/src/snapshot/lynx/calledByNative.ts +11 -9
- 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/worklet-runtime/README.md +30 -10
- 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/jsFunctionLifecycle.ts +6 -0
- package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
- package/runtime/types/types.d.ts +2 -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 +49 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +133 -297
- package/transform/__test__/defines.spec.js +30 -0
- package/transform/__test__/fixture.spec.js +11 -11
- package/transform/__test__/main-thread-object-compat.spec.js +111 -0
- package/transform/__test__/object-methods.spec.js +79 -0
- package/transform/crates/swc_plugin_element_template/lib.rs +11 -0
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +113 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +63 -57
- package/transform/crates/swc_plugin_worklet/lib.rs +393 -589
- package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +11 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +12 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +14 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +17 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +5 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +5 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +1 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/transform/package.json +0 -1
- package/transform/src/lib.rs +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +167 -69
- 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 +226 -132
- 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
|
@@ -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() {
|
|
@@ -300,21 +311,28 @@ impl StmtGen {
|
|
|
300
311
|
});
|
|
301
312
|
Expr::Ident(capture_source)
|
|
302
313
|
};
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
.into();
|
|
314
|
+
// Older externalized runtimes do not export this helper. Keep ordinary
|
|
315
|
+
// main-thread function captures working by using the narrowed fallback.
|
|
316
|
+
let captured = quote!(
|
|
317
|
+
"captureMainThreadObject?.($source)" as Expr,
|
|
318
|
+
source: Expr = capture_argument.clone(),
|
|
319
|
+
);
|
|
311
320
|
let captured_or_fallback: Expr = BinExpr {
|
|
312
321
|
span: DUMMY_SP,
|
|
313
322
|
op: BinaryOp::NullishCoalescing,
|
|
314
|
-
left: captured,
|
|
323
|
+
left: captured.into(),
|
|
315
324
|
right: fallback,
|
|
316
325
|
}
|
|
317
326
|
.into();
|
|
327
|
+
let captured_or_fallback: Expr = if is_optional {
|
|
328
|
+
quote!(
|
|
329
|
+
"$src == null ? $src : $expr" as Expr,
|
|
330
|
+
src: Expr = capture_argument.clone(),
|
|
331
|
+
expr: Expr = captured_or_fallback,
|
|
332
|
+
)
|
|
333
|
+
} else {
|
|
334
|
+
captured_or_fallback
|
|
335
|
+
};
|
|
318
336
|
*value = if source_argument.is_ident() {
|
|
319
337
|
captured_or_fallback.into()
|
|
320
338
|
} else {
|
|
@@ -407,7 +425,6 @@ impl StmtGen {
|
|
|
407
425
|
*/
|
|
408
426
|
fn gen_register_worklet_stmt(params: RegisterWorkletParams) -> Stmt {
|
|
409
427
|
let RegisterWorkletParams {
|
|
410
|
-
mode,
|
|
411
428
|
target,
|
|
412
429
|
worklet_type,
|
|
413
430
|
function_name,
|
|
@@ -416,11 +433,14 @@ impl StmtGen {
|
|
|
416
433
|
extracted_js_fns,
|
|
417
434
|
hash,
|
|
418
435
|
is_class_member,
|
|
419
|
-
named_imports,
|
|
420
436
|
requires_main_thread_runtime,
|
|
421
437
|
register_worklet,
|
|
422
438
|
} = params;
|
|
423
439
|
|
|
440
|
+
if target != TransformTarget::LEPUS {
|
|
441
|
+
return EmptyStmt { span: DUMMY_SP }.into();
|
|
442
|
+
}
|
|
443
|
+
|
|
424
444
|
let function_to_register = Box::new(StmtGen::gen_function_to_register(
|
|
425
445
|
function,
|
|
426
446
|
function_name,
|
|
@@ -430,35 +450,21 @@ impl StmtGen {
|
|
|
430
450
|
is_class_member,
|
|
431
451
|
));
|
|
432
452
|
|
|
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()
|
|
453
|
+
*requires_main_thread_runtime = true;
|
|
454
|
+
let registration = quote_expr!("$register($type_, $hash, $fn_)",
|
|
455
|
+
register: Ident = register_worklet.clone(),
|
|
456
|
+
type_: Expr = Expr::Lit(worklet_type.type_str().into()),
|
|
457
|
+
hash: Expr = hash,
|
|
458
|
+
fn_: Expr = Expr::Fn(FnExpr {
|
|
459
|
+
ident: None,
|
|
460
|
+
function: function_to_register,
|
|
461
|
+
}),
|
|
462
|
+
);
|
|
463
|
+
ExprStmt {
|
|
464
|
+
span: DUMMY_SP,
|
|
465
|
+
expr: registration,
|
|
461
466
|
}
|
|
467
|
+
.into()
|
|
462
468
|
}
|
|
463
469
|
|
|
464
470
|
fn gen_function_to_register(
|