@lynx-js/react 0.126.1 → 0.127.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 +40 -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 +4 -3
- package/refresh/.turbo/turbo-build.log +4 -4
- package/refresh/dist/index.js +27 -8
- package/refresh/package.json +2 -2
- package/runtime/__test__/core/main-thread-object.test.js +149 -0
- package/runtime/__test__/element-template/debug/profile-installation.test.tsx +97 -1
- package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -1
- package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
- package/runtime/__test__/element-template/fixtures/render/child-siblings/index.js.txt +15 -11
- package/runtime/__test__/element-template/fixtures/render/component/index.js.txt +8 -7
- package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.js.txt +14 -10
- package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.js.txt +4 -3
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/_shared.ts +2 -9
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/case.ts +2 -4
- package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/case.ts +20 -0
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/case.ts +3 -16
- package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/case.ts +18 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/case.ts +20 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/case.ts +18 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/case.ts +15 -0
- package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.js.txt +12 -11
- package/runtime/__test__/element-template/fixtures/render/mixed-children/index.js.txt +8 -7
- package/runtime/__test__/element-template/fixtures/render/multiple-text/index.js.txt +15 -13
- package/runtime/__test__/element-template/fixtures/render/nested-templates/index.js.txt +9 -7
- package/runtime/__test__/element-template/fixtures/render/react-example/index.js.txt +17 -20
- package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.js.txt +13 -10
- package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.js.txt +14 -11
- package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
- package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +52 -7
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +3 -0
- package/runtime/__test__/element-template/native/reload.test.ts +10 -26
- package/runtime/__test__/element-template/runtime/background/component-stack.test.tsx +76 -0
- package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +87 -43
- package/runtime/__test__/element-template/runtime/background/instance.test.ts +14 -0
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +4 -0
- package/runtime/__test__/element-template/runtime/render/compact-host-debug.test.ts +57 -0
- package/runtime/__test__/element-template/runtime/render/compact-host.test.ts +199 -0
- package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +292 -0
- package/runtime/__test__/element-template/runtime/render/{render-opcodes-into-element-template.et.test.tsx → render-direct-native.test.tsx} +50 -314
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +378 -0
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +491 -0
- package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -28
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +21 -35
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -5
- package/runtime/__test__/element-template/test-utils/debug/renderFixtureRunner.ts +4 -4
- package/runtime/__test__/element-template/vitest.config.ts +2 -1
- package/runtime/__test__/snapshot/ctxNotFound.test.ts +271 -0
- package/runtime/__test__/snapshot/debug/main-thread-children-with-same-key.test.ts +28 -0
- package/runtime/__test__/snapshot/debug/profile.test.jsx +108 -3
- package/runtime/__test__/snapshot/event.test.jsx +7 -7
- package/runtime/__test__/snapshot/lazy.test.js +114 -7
- package/runtime/__test__/snapshot/lifecycle/reloadGc.test.jsx +66 -0
- package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
- package/runtime/__test__/snapshot/lynx/runtime-version.test.ts +140 -0
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
- package/runtime/__test__/snapshot/spread.test.jsx +32 -25
- package/runtime/__test__/snapshot/ssr.legacy-slot.test.jsx +168 -0
- package/runtime/__test__/snapshot/ssr.list.test.jsx +211 -0
- 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/hydrate.test.js +92 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
- package/runtime/__test__/worklet-runtime/object-methods.test.js +60 -0
- package/runtime/__test__/worklet-runtime/runOnBackground.test.js +8 -6
- package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +249 -3
- package/runtime/lazy/compat.js +2 -0
- package/runtime/lazy/element-template-import.js +0 -4
- package/runtime/lazy/element-template-internal.js +19 -8
- package/runtime/lazy/element-template-jsx-dev-runtime.js +1 -8
- package/runtime/lazy/element-template-jsx-runtime.js +1 -3
- package/runtime/lazy/element-template.js +3 -3
- package/runtime/lazy/import.js +0 -4
- package/runtime/lazy/internal.js +17 -1
- package/runtime/lazy/react.js +2 -0
- package/runtime/lazy/target.js +0 -21
- 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.js +16 -0
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -0
- package/runtime/lib/core/globalProps.d.ts +2 -0
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/hooks/react.d.ts +6 -0
- package/runtime/lib/core/hooks/react.js +6 -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/runtime-version.d.ts +16 -0
- package/runtime/lib/core/lynx/runtime-version.js +51 -0
- package/runtime/lib/core/lynx/runtime-version.js.map +1 -0
- 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 +261 -0
- package/runtime/lib/core/main-thread-object.js.map +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/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/document.d.ts +1 -1
- package/runtime/lib/element-template/background/document.js +1 -1
- package/runtime/lib/element-template/background/document.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +51 -19
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/instance.js +5 -6
- package/runtime/lib/element-template/background/instance.js.map +1 -1
- package/runtime/lib/element-template/debug/profile.js +38 -22
- package/runtime/lib/element-template/debug/profile.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +3 -1
- package/runtime/lib/element-template/index.js +2 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +5 -1
- package/runtime/lib/element-template/internal.js +7 -1
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/native/index.js +4 -0
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +1 -1
- package/runtime/lib/element-template/runtime/list/list.d.ts +1 -0
- package/runtime/lib/element-template/runtime/list/list.js +3 -0
- package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +7 -0
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js +65 -0
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/host.d.ts +18 -0
- package/runtime/lib/element-template/runtime/render/host.js +25 -0
- package/runtime/lib/element-template/runtime/render/host.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/render-components.d.ts +6 -0
- package/runtime/lib/element-template/runtime/render/render-components.js +190 -0
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/{render-opcodes.d.ts → render-direct.d.ts} +3 -1
- package/runtime/lib/element-template/runtime/render/render-direct.js +194 -0
- package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +10 -9
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.d.ts +2 -1
- package/runtime/lib/element-template/runtime/template/handle.js +12 -4
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
- package/runtime/lib/element-template/runtime-marker.d.ts +1 -0
- package/runtime/lib/element-template/runtime-marker.js +13 -0
- package/runtime/lib/element-template/runtime-marker.js.map +1 -0
- package/runtime/lib/index.d.ts +1 -1
- package/runtime/lib/index.js +1 -1
- package/runtime/lib/index.js.map +1 -1
- package/runtime/lib/internal.d.ts +4 -1
- package/runtime/lib/internal.js +6 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +49 -6
- package/runtime/lib/lynx-api.js +34 -4
- 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/runtime-marker.d.ts +1 -0
- package/runtime/lib/runtime-marker.js +13 -0
- package/runtime/lib/runtime-marker.js.map +1 -0
- package/runtime/lib/shared/component-stack.js +5 -1
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js +38 -22
- package/runtime/lib/snapshot/debug/profileHooks.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/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/reload.js +3 -0
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +3 -0
- 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 +10 -0
- package/runtime/lib/snapshot/lynx/element.js +6 -0
- package/runtime/lib/snapshot/lynx/element.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +2 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.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/ref/updateInitValue.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +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/types.d.ts +3 -6
- package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js +27 -8
- package/runtime/lib/worklet-runtime/hydrate.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/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 +69 -19
- 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 +6 -0
- package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
- package/runtime/src/core/initData.ts +2 -0
- package/runtime/src/core/lynx/runtime-version.ts +62 -0
- package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
- package/runtime/src/core/main-thread-object.ts +387 -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/background/document.ts +3 -3
- package/runtime/src/element-template/background/hydrate.ts +61 -29
- package/runtime/src/element-template/background/instance.ts +5 -6
- package/runtime/src/element-template/debug/profile.ts +48 -36
- package/runtime/src/element-template/index.ts +7 -1
- package/runtime/src/element-template/internal.ts +14 -1
- package/runtime/src/element-template/native/index.ts +4 -0
- package/runtime/src/element-template/protocol/types.ts +1 -1
- package/runtime/src/element-template/runtime/list/list.ts +4 -0
- package/runtime/src/element-template/runtime/render/create-rendered-host.ts +126 -0
- package/runtime/src/element-template/runtime/render/host.ts +51 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +255 -0
- package/runtime/src/element-template/runtime/render/render-direct.ts +275 -0
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +10 -9
- package/runtime/src/element-template/runtime/template/handle.ts +17 -7
- package/runtime/src/element-template/runtime-marker.ts +17 -0
- package/runtime/src/index.ts +1 -1
- package/runtime/src/internal.ts +11 -1
- package/runtime/src/lynx-api.ts +53 -6
- package/runtime/src/lynx.ts +5 -1
- package/runtime/src/runtime-marker.ts +17 -0
- package/runtime/src/shared/component-stack.ts +5 -1
- package/runtime/src/snapshot/debug/profileHooks.ts +52 -40
- 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/lifecycle/reload.ts +4 -0
- package/runtime/src/snapshot/lynx/calledByNative.ts +4 -0
- package/runtime/src/snapshot/lynx/children.ts +2 -0
- package/runtime/src/snapshot/lynx/element.ts +10 -0
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +2 -1
- 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/types.ts +7 -11
- package/runtime/src/worklet-runtime/hydrate.ts +44 -11
- 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 +84 -21
- package/runtime/types/types.d.ts +2 -0
- package/runtime/worklet-runtime/dev.js +155 -30
- package/runtime/worklet-runtime/main.js +1 -1
- package/testing-library/.turbo/turbo-build.log +12 -12
- package/testing-library/dist/env/index.js +2 -2
- package/testing-library/dist/index.d.ts +167 -4
- package/testing-library/dist/plugins/index.js +1 -1
- package/testing-library/dist/pure.js +45 -44
- package/testing-library/etc/react-lynx-testing-library.api.md +1 -1
- package/testing-library/package.json +4 -3
- package/testing-library/src/__tests__/lynx.test.jsx +1 -1
- package/testing-library/src/__tests__/reload/reloadGc.test.jsx +64 -0
- package/testing-library/src/__tests__/reload/reloadTemplate.js +39 -0
- package/testing-library/src/__tests__/worklet.test.jsx +46 -1
- package/testing-library/tsconfig.docs.json +9 -0
- package/testing-library/typedoc.json +22 -0
- package/testing-library/types/entry.d.ts +2 -2
- package/transform/.turbo/turbo-build$colon$wasm.log +151 -67
- package/transform/__test__/fixture.spec.js +89 -50
- package/transform/__test__/object-methods.spec.js +84 -0
- package/transform/__test__/text.spec.js +75 -0
- package/transform/crates/swc_plugin_compat/lib.rs +4 -3
- package/transform/crates/swc_plugin_compat/napi.rs +4 -3
- package/transform/crates/swc_plugin_define_dce/napi.rs +1 -1
- package/transform/crates/swc_plugin_dynamic_import/lib.rs +105 -3
- package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_suffix_webpack_chunk_name.js +5 -0
- package/transform/crates/swc_plugin_element_template/host_lowering.rs +111 -0
- package/transform/crates/swc_plugin_element_template/lib.rs +41 -5
- package/transform/crates/swc_plugin_element_template/lowering.rs +39 -7
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_generate_attribute_slots_for_dynamic_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_background_conditional_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_boolean_and_number_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_complex_text_structure.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dataset_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_deeply_nested_user_components.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dynamic_class_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_id_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_inline_styles.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_mixed_content.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_nested_structure_and_dynamic_content.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_sibling_user_components.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_spread_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_user_component.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_isolate_arrays_with_child_slot_placeholder.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_keep_code_and_template_attribute_slots_in_sync_for_spread.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_element_template_simple_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_template_with_static_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_template_structure_complex.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_text_attribute_and_child_text_slots.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/element_template.rs +70 -66
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +94 -8
- package/transform/crates/swc_plugin_shake/lib.rs +1 -1
- package/transform/crates/swc_plugin_shake/napi.rs +1 -1
- package/transform/crates/swc_plugin_text/lib.rs +57 -16
- package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_keep_children_for_dynamic_or_multiple_text.js +13 -0
- package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_transform_string_expressions_to_text_attr.js +13 -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 +202 -3
- package/transform/crates/swc_plugin_worklet/lib.rs +468 -3
- 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 +10 -5
- 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 +45 -0
- 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 +16 -16
- 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 +7 -7
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +24 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +16 -0
- 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_transform_js.js +3 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +3 -3
- 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 +16 -0
- package/transform/crates/swc_plugins_shared/jsx_helpers.rs +8 -4
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +7 -6
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/swc_plugin_extract_str/mod.rs +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +63 -270
- package/transform/swc-plugin-reactlynx/index.d.ts +2 -2
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +306 -170
- package/transform/swc-plugin-reactlynx-compat/index.d.ts +3 -3
- 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/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/case.ts +0 -39
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/case.ts +0 -29
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/case.ts +0 -42
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/case.ts +0 -31
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/case.ts +0 -20
- package/runtime/__test__/element-template/runtime/render/render-to-opcodes.et.test.jsx +0 -522
- package/runtime/lib/element-template/runtime/render/render-opcodes.js +0 -216
- package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +0 -1
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.d.ts +0 -16
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +0 -324
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +0 -1
- package/runtime/lib/element-template/runtime-backend-marker.js +0 -6
- package/runtime/lib/element-template/runtime-backend-marker.js.map +0 -1
- package/runtime/lib/runtime-backend-marker.js +0 -6
- package/runtime/lib/runtime-backend-marker.js.map +0 -1
- package/runtime/src/element-template/runtime/render/render-opcodes.ts +0 -313
- package/runtime/src/element-template/runtime/render/render-to-opcodes.ts +0 -411
- package/runtime/src/element-template/runtime-backend-marker.ts +0 -7
- package/runtime/src/runtime-backend-marker.ts +0 -7
- package/testing-library/node_modules/.bin/rsbuild +0 -55
- package/testing-library/node_modules/.bin/rspeedy +0 -55
- package/testing-library/node_modules/.bin/rstest +0 -55
- package/transform/node_modules/.bin/esbuild +0 -46
- package/transform/node_modules/.bin/napi +0 -55
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/passes-bundle-url-to-native-create/native-log.txt +0 -0
- /package/runtime/lib/{element-template/runtime-backend-marker.d.ts → core/capture-main-thread-object.d.ts} +0 -0
- /package/runtime/lib/{runtime-backend-marker.d.ts → core/main-thread-ref-id.d.ts} +0 -0
|
@@ -109,77 +109,65 @@ fn max_attr_slot_index(value: &serde_json::Value) -> Option<usize> {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
fn first_attribute_slots_len(code: &str) -> Option<usize> {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
let mut has_content = false;
|
|
120
|
-
let mut len = 1usize;
|
|
121
|
-
|
|
122
|
-
for ch in code[start..].chars() {
|
|
123
|
-
if let Some(quote_ch) = quote {
|
|
124
|
-
if escape {
|
|
125
|
-
escape = false;
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if ch == '\\' {
|
|
129
|
-
escape = true;
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
if ch == quote_ch {
|
|
133
|
-
quote = None;
|
|
134
|
-
}
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
112
|
+
use std::sync::Arc;
|
|
113
|
+
use swc_core::common::{FileName, SourceMap};
|
|
114
|
+
use swc_core::ecma::{
|
|
115
|
+
ast::*,
|
|
116
|
+
parser::{lexer::Lexer, Parser, StringInput},
|
|
117
|
+
visit::{Visit, VisitWith},
|
|
118
|
+
};
|
|
137
119
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
square_depth -= 1;
|
|
155
|
-
}
|
|
156
|
-
'{' => {
|
|
157
|
-
has_content = true;
|
|
158
|
-
brace_depth += 1;
|
|
159
|
-
}
|
|
160
|
-
'}' => {
|
|
161
|
-
if brace_depth == 0 {
|
|
162
|
-
return None;
|
|
120
|
+
#[derive(Default)]
|
|
121
|
+
struct SlotInput(Option<usize>);
|
|
122
|
+
impl Visit for SlotInput {
|
|
123
|
+
fn visit_jsx_attr(&mut self, attr: &JSXAttr) {
|
|
124
|
+
if let JSXAttrName::Ident(name) = &attr.name {
|
|
125
|
+
if name.sym == "attributeSlots" && self.0.is_none() {
|
|
126
|
+
if let Some(JSXAttrValue::JSXExprContainer(JSXExprContainer {
|
|
127
|
+
expr: JSXExpr::Expr(expr),
|
|
128
|
+
..
|
|
129
|
+
})) = &attr.value
|
|
130
|
+
{
|
|
131
|
+
if let Expr::Array(array) = &**expr {
|
|
132
|
+
self.0 = Some(array.elems.len());
|
|
133
|
+
}
|
|
134
|
+
}
|
|
163
135
|
}
|
|
164
|
-
brace_depth -= 1;
|
|
165
136
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
137
|
+
attr.visit_children_with(self);
|
|
138
|
+
}
|
|
139
|
+
fn visit_call_expr(&mut self, call: &CallExpr) {
|
|
140
|
+
if let Callee::Expr(callee) = &call.callee {
|
|
141
|
+
if let Expr::Member(member) = &**callee {
|
|
142
|
+
if matches!(&member.prop, MemberProp::Ident(name) if name.sym == "__etHost")
|
|
143
|
+
&& self.0.is_none()
|
|
144
|
+
{
|
|
145
|
+
if let Expr::Array(array) = &*call.args[4].expr {
|
|
146
|
+
self.0 = Some(array.elems.len());
|
|
147
|
+
}
|
|
148
|
+
}
|
|
173
149
|
}
|
|
174
|
-
paren_depth -= 1;
|
|
175
150
|
}
|
|
176
|
-
|
|
177
|
-
ch if !ch.is_whitespace() => has_content = true,
|
|
178
|
-
_ => {}
|
|
151
|
+
call.visit_children_with(self);
|
|
179
152
|
}
|
|
180
153
|
}
|
|
181
|
-
|
|
182
|
-
|
|
154
|
+
let cm = Arc::<SourceMap>::default();
|
|
155
|
+
let file = cm.new_source_file(FileName::Anon.into(), code.to_string());
|
|
156
|
+
let lexer = Lexer::new(
|
|
157
|
+
Syntax::Es(EsSyntax {
|
|
158
|
+
jsx: true,
|
|
159
|
+
..Default::default()
|
|
160
|
+
}),
|
|
161
|
+
Default::default(),
|
|
162
|
+
StringInput::from(&*file),
|
|
163
|
+
None,
|
|
164
|
+
);
|
|
165
|
+
let module = Parser::new_from(lexer)
|
|
166
|
+
.parse_module()
|
|
167
|
+
.expect("valid generated code");
|
|
168
|
+
let mut slots = SlotInput::default();
|
|
169
|
+
module.visit_with(&mut slots);
|
|
170
|
+
slots.0
|
|
183
171
|
}
|
|
184
172
|
|
|
185
173
|
fn assert_attribute_slots_match_template(code: &str, templates: &[ElementTemplateAsset]) {
|
|
@@ -779,9 +767,9 @@ fn should_reuse_same_content_template_id_and_asset_in_one_module() {
|
|
|
779
767
|
"same content should emit one template id const:\n{code}"
|
|
780
768
|
);
|
|
781
769
|
assert_eq!(
|
|
782
|
-
code.matches(&format!("
|
|
770
|
+
code.matches(&format!("__etHost({template_id},")).count(),
|
|
783
771
|
2,
|
|
784
|
-
"both
|
|
772
|
+
"both host calls should reference the reused template id exactly once each:\n{code}"
|
|
785
773
|
);
|
|
786
774
|
}
|
|
787
775
|
|
|
@@ -1205,3 +1193,19 @@ fn should_warn_and_override_nested_dynamic_user_css_id_attr_without_reserving_sl
|
|
|
1205
1193
|
"nested dynamic user css-id should be replaced by the framework css-id",
|
|
1206
1194
|
);
|
|
1207
1195
|
}
|
|
1196
|
+
|
|
1197
|
+
#[test]
|
|
1198
|
+
fn should_lower_lepus_hosts_in_component_children_and_jsx_valued_props() {
|
|
1199
|
+
let (code, templates) = transform_to_code_and_templates(
|
|
1200
|
+
r#"const result = <Wrapper first=<view id={first()} /> second={<view id={second()} />}><view key={key()} id={third()} /></Wrapper>;"#,
|
|
1201
|
+
element_template_config(),
|
|
1202
|
+
);
|
|
1203
|
+
assert_eq!(user_templates(&templates).len(), 1, "{code}");
|
|
1204
|
+
assert_eq!(code.matches(".__etHost(").count(), 3, "{code}");
|
|
1205
|
+
assert!(!code.contains("<_et_"), "{code}");
|
|
1206
|
+
assert!(!code.contains("attributeSlots="), "{code}");
|
|
1207
|
+
assert!(
|
|
1208
|
+
code.contains("key(), ["),
|
|
1209
|
+
"key evaluation must precede attributes: {code}"
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
@@ -232,7 +232,7 @@ fn should_emit_direct_event_attr_plan_for_lepus_target() {
|
|
|
232
232
|
"direct event slots should register a sparse ET attr plan",
|
|
233
233
|
);
|
|
234
234
|
assert!(
|
|
235
|
-
code.contains("
|
|
235
|
+
code.contains(",void0,[1,1],void0,void0)"),
|
|
236
236
|
"LEPUS target should keep event markers in attributeSlots before runtime preparation, got: {code}"
|
|
237
237
|
);
|
|
238
238
|
}
|
|
@@ -304,7 +304,7 @@ fn should_emit_direct_main_thread_ref_attr_plan_for_lepus_target() {
|
|
|
304
304
|
"direct main-thread ref slots should register an ET MTRef attr plan",
|
|
305
305
|
);
|
|
306
306
|
assert!(
|
|
307
|
-
code.contains("
|
|
307
|
+
code.contains(",void0,[mainThreadRef],void0,void0)"),
|
|
308
308
|
"LEPUS target should keep raw main-thread refs in attributeSlots before runtime preparation, got: {code}"
|
|
309
309
|
);
|
|
310
310
|
}
|
|
@@ -608,7 +608,7 @@ fn should_keep_static_attribute_values_out_of_et_attribute_slots() {
|
|
|
608
608
|
assert_eq!(attr_by_key("class")["attrSlotIndex"].as_f64(), Some(1.0));
|
|
609
609
|
let code = without_whitespace(&code);
|
|
610
610
|
assert!(
|
|
611
|
-
code.contains("
|
|
611
|
+
code.contains(",void0,[1e400,cls],void0,void0,true)"),
|
|
612
612
|
"overflowed numeric literals should stay observable via ET attribute slots, got: {code}"
|
|
613
613
|
);
|
|
614
614
|
}
|
|
@@ -642,11 +642,11 @@ fn should_not_consume_hidden_et_slots_for_list_item_platform_attrs() {
|
|
|
642
642
|
assert_eq!(recyclable["value"].as_bool(), Some(true));
|
|
643
643
|
let code = without_whitespace(&code);
|
|
644
644
|
assert!(
|
|
645
|
-
code.contains("
|
|
645
|
+
code.contains(",void0,[itemKey],void0,"),
|
|
646
646
|
"legacy list platform info must not consume ET attribute slots, got: {code}"
|
|
647
647
|
);
|
|
648
648
|
assert!(
|
|
649
|
-
code.contains("
|
|
649
|
+
code.contains(",{\"item-key\":itemKey,\"recyclable\":true})"),
|
|
650
650
|
"list item platform info should be available as an ET runtime-only carrier, got: {code}"
|
|
651
651
|
);
|
|
652
652
|
}
|
|
@@ -688,8 +688,8 @@ fn should_lower_exact_list_as_typed_runtime_host() {
|
|
|
688
688
|
"ET list output should expose exact list, attributes, and $0 logical children, got: {code}"
|
|
689
689
|
);
|
|
690
690
|
assert!(
|
|
691
|
-
code.contains("
|
|
692
|
-
&& code.contains("
|
|
691
|
+
code.contains(",{\"item-key\":firstKey,\"full-span\":true})")
|
|
692
|
+
&& code.contains(",{\"item-key\":secondKey,\"recyclable\":true})"),
|
|
693
693
|
"list item roots should carry platform info beside compiled ET roots, got: {code}"
|
|
694
694
|
);
|
|
695
695
|
}
|
|
@@ -756,7 +756,7 @@ fn should_keep_main_thread_attr_descriptor_keys_for_namespaced_attrs() {
|
|
|
756
756
|
"main-thread:ref must use the ET MTRef adapter, got: {code}"
|
|
757
757
|
);
|
|
758
758
|
assert!(
|
|
759
|
-
code.contains("
|
|
759
|
+
code.contains(",void0,[handleTap,viewRef],void0,"),
|
|
760
760
|
"default LEPUS target should keep raw main-thread refs in attributeSlots before runtime preparation, got: {code}"
|
|
761
761
|
);
|
|
762
762
|
|
|
@@ -928,3 +928,89 @@ fn should_preserve_user_wrapper_elements_as_template_nodes() {
|
|
|
928
928
|
assert_eq!(children[1]["kind"], "childSlot");
|
|
929
929
|
assert_eq!(children[1]["elementSlotIndex"].as_f64(), Some(0.0));
|
|
930
930
|
}
|
|
931
|
+
|
|
932
|
+
#[test]
|
|
933
|
+
fn ordered_child_slots_are_lepus_only_and_preserve_template_identity() {
|
|
934
|
+
use swc_plugins_shared::target::TransformTarget;
|
|
935
|
+
|
|
936
|
+
let input = r#"<view key={key()} id={attr()}><view>{first()}</view><text>static</text><view>{second()}</view></view>"#;
|
|
937
|
+
let mut expected_templates = None;
|
|
938
|
+
for target in [
|
|
939
|
+
TransformTarget::LEPUS,
|
|
940
|
+
TransformTarget::JS,
|
|
941
|
+
TransformTarget::MIXED,
|
|
942
|
+
] {
|
|
943
|
+
let (templates, code) = transform_fixture(
|
|
944
|
+
input,
|
|
945
|
+
JSXTransformerConfig {
|
|
946
|
+
target,
|
|
947
|
+
..element_template_config()
|
|
948
|
+
},
|
|
949
|
+
);
|
|
950
|
+
let templates = templates
|
|
951
|
+
.into_iter()
|
|
952
|
+
.map(|template| {
|
|
953
|
+
(
|
|
954
|
+
template.template_id,
|
|
955
|
+
serde_json::to_value(template.compiled_template).unwrap(),
|
|
956
|
+
)
|
|
957
|
+
})
|
|
958
|
+
.collect::<Vec<_>>();
|
|
959
|
+
if let Some(expected) = &expected_templates {
|
|
960
|
+
assert_eq!(&templates, expected);
|
|
961
|
+
} else {
|
|
962
|
+
expected_templates = Some(templates);
|
|
963
|
+
}
|
|
964
|
+
let code = without_whitespace(&code);
|
|
965
|
+
if target == TransformTarget::LEPUS {
|
|
966
|
+
assert!(code.contains(",[first(),second()],void0,true)"), "{code}");
|
|
967
|
+
assert!(!code.contains("$0="), "{code}");
|
|
968
|
+
} else {
|
|
969
|
+
assert!(code.contains("$0={first()}$1={second()}"), "{code}");
|
|
970
|
+
assert!(!code.contains("slotChildren="), "{code}");
|
|
971
|
+
assert!(!code.contains(".__etHost("), "{code}");
|
|
972
|
+
}
|
|
973
|
+
let positions = ["key()", "attr()", "first()", "second()"].map(|expr| {
|
|
974
|
+
assert_eq!(code.matches(expr).count(), 1, "{code}");
|
|
975
|
+
code.find(expr).unwrap()
|
|
976
|
+
});
|
|
977
|
+
assert!(positions.windows(2).all(|pair| pair[0] < pair[1]), "{code}");
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
#[test]
|
|
982
|
+
fn should_specialize_only_adapter_free_lepus_hosts_without_list_item_metadata() {
|
|
983
|
+
use swc_plugins_shared::target::TransformTarget;
|
|
984
|
+
for (input, plain) in [
|
|
985
|
+
("<view id={id} />", true),
|
|
986
|
+
("<view><Child /></view>", true),
|
|
987
|
+
("<view bindtap={onTap} />", false),
|
|
988
|
+
("<view ref={ref} />", false),
|
|
989
|
+
("<view main-thread:ref={ref} />", false),
|
|
990
|
+
("<view main-thread:bindtap={onTap} />", false),
|
|
991
|
+
("<view {...props} />", false),
|
|
992
|
+
("<list-item item-key={key} />", false),
|
|
993
|
+
] {
|
|
994
|
+
for target in [
|
|
995
|
+
TransformTarget::LEPUS,
|
|
996
|
+
TransformTarget::JS,
|
|
997
|
+
TransformTarget::MIXED,
|
|
998
|
+
] {
|
|
999
|
+
let (_, code) = transform_fixture(
|
|
1000
|
+
input,
|
|
1001
|
+
JSXTransformerConfig {
|
|
1002
|
+
target,
|
|
1003
|
+
..element_template_config()
|
|
1004
|
+
},
|
|
1005
|
+
);
|
|
1006
|
+
assert_eq!(
|
|
1007
|
+
without_whitespace(&code).contains(",void0,true)"),
|
|
1008
|
+
plain && target == TransformTarget::LEPUS,
|
|
1009
|
+
"{input}: {code}"
|
|
1010
|
+
);
|
|
1011
|
+
if target == TransformTarget::LEPUS && !plain {
|
|
1012
|
+
assert!(code.contains(".__etHost("), "{input}: {code}");
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
@@ -10,7 +10,7 @@ mod is_component_class;
|
|
|
10
10
|
#[cfg(feature = "napi")]
|
|
11
11
|
pub mod napi;
|
|
12
12
|
|
|
13
|
-
/// {@
|
|
13
|
+
/// {@inheritDoc PluginReactLynxOptions.shake}
|
|
14
14
|
/// @public
|
|
15
15
|
#[derive(Deserialize, PartialEq, Clone, Debug)]
|
|
16
16
|
#[serde(rename_all = "camelCase")]
|
|
@@ -3,7 +3,7 @@ use swc_core::{ecma::ast::*, ecma::visit::VisitMut};
|
|
|
3
3
|
|
|
4
4
|
use crate::{ShakeVisitor as CoreVisitor, ShakeVisitorConfig as CoreConfig};
|
|
5
5
|
|
|
6
|
-
/// {@
|
|
6
|
+
/// {@inheritDoc PluginReactLynxOptions.shake}
|
|
7
7
|
/// @public
|
|
8
8
|
#[napi(object)]
|
|
9
9
|
#[derive(Clone, Debug)]
|
|
@@ -6,7 +6,7 @@ use swc_core::{
|
|
|
6
6
|
},
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
use swc_plugins_shared::jsx_helpers::{
|
|
9
|
+
use swc_plugins_shared::jsx_helpers::{jsx_is_single_text, jsx_text_to_str};
|
|
10
10
|
|
|
11
11
|
pub struct TextVisitor {}
|
|
12
12
|
|
|
@@ -21,22 +21,27 @@ impl VisitMut for TextVisitor {
|
|
|
21
21
|
// />
|
|
22
22
|
fn visit_mut_jsx_element(&mut self, n: &mut JSXElement) {
|
|
23
23
|
n.visit_mut_children_with(self);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if let JSXElementChild::JSXText(text) = &n.children[0] {
|
|
27
|
-
let text_content = jsx_text_to_str(&text.value);
|
|
28
|
-
n.opening.attrs.push(JSXAttrOrSpread::JSXAttr(JSXAttr {
|
|
29
|
-
span: DUMMY_SP,
|
|
30
|
-
name: JSXAttrName::Ident(IdentName::new("text".into(), DUMMY_SP)),
|
|
31
|
-
value: Some(JSXAttrValue::Str(Str {
|
|
32
|
-
span: DUMMY_SP,
|
|
33
|
-
raw: None,
|
|
34
|
-
value: text_content.into(),
|
|
35
|
-
})),
|
|
36
|
-
}));
|
|
37
|
-
n.children = vec![];
|
|
38
|
-
}
|
|
24
|
+
if !jsx_is_single_text(n) {
|
|
25
|
+
return;
|
|
39
26
|
}
|
|
27
|
+
|
|
28
|
+
let value = match &n.children[0] {
|
|
29
|
+
JSXElementChild::JSXText(text) => JSXAttrValue::Str(Str {
|
|
30
|
+
span: DUMMY_SP,
|
|
31
|
+
raw: None,
|
|
32
|
+
value: jsx_text_to_str(&text.value).into(),
|
|
33
|
+
}),
|
|
34
|
+
// Keep expressions as expressions: JSX attribute strings normalize
|
|
35
|
+
// whitespace differently from JavaScript strings and template literals.
|
|
36
|
+
JSXElementChild::JSXExprContainer(expr) => JSXAttrValue::JSXExprContainer(expr.clone()),
|
|
37
|
+
_ => unreachable!(),
|
|
38
|
+
};
|
|
39
|
+
n.opening.attrs.push(JSXAttrOrSpread::JSXAttr(JSXAttr {
|
|
40
|
+
span: DUMMY_SP,
|
|
41
|
+
name: JSXAttrName::Ident(IdentName::new("text".into(), DUMMY_SP)),
|
|
42
|
+
value: Some(value),
|
|
43
|
+
}));
|
|
44
|
+
n.children.clear();
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
47
|
|
|
@@ -50,6 +55,31 @@ mod tests {
|
|
|
50
55
|
|
|
51
56
|
use super::TextVisitor;
|
|
52
57
|
|
|
58
|
+
test!(
|
|
59
|
+
module,
|
|
60
|
+
Syntax::Es(EsSyntax {
|
|
61
|
+
jsx: true,
|
|
62
|
+
..Default::default()
|
|
63
|
+
}),
|
|
64
|
+
|_t| visit_mut_pass(TextVisitor {}),
|
|
65
|
+
should_transform_string_expressions_to_text_attr,
|
|
66
|
+
r#"
|
|
67
|
+
<>
|
|
68
|
+
<text>{'Hello'}</text>
|
|
69
|
+
<text>{''}</text>
|
|
70
|
+
<text>{' Hello\n\tWorld & '}</text>
|
|
71
|
+
<text>{`Hello`}</text>
|
|
72
|
+
<text>{`Hello ${name}`}</text>
|
|
73
|
+
<text>{`Hello ${getName()} ${count}`}</text>
|
|
74
|
+
<text>{` Hello
|
|
75
|
+
${name}\tWorld `}</text>
|
|
76
|
+
<text class="hello">{'Hello'}</text>
|
|
77
|
+
<text {...attrs}>{`Hello ${name}`}</text>
|
|
78
|
+
<text text="old">{'Hello'}</text>
|
|
79
|
+
</>
|
|
80
|
+
"#
|
|
81
|
+
);
|
|
82
|
+
|
|
53
83
|
test!(
|
|
54
84
|
module,
|
|
55
85
|
Syntax::Es(EsSyntax {
|
|
@@ -87,6 +117,17 @@ mod tests {
|
|
|
87
117
|
<text>ReactLynx</text>
|
|
88
118
|
</text>
|
|
89
119
|
<x-text>Hello, ReactLynx</x-text>
|
|
120
|
+
<x-text>{'Hello'}</x-text>
|
|
121
|
+
<x-text>{`Hello ${name}`}</x-text>
|
|
122
|
+
<text>{42}</text>
|
|
123
|
+
<text>{null}</text>
|
|
124
|
+
<text>{false}</text>
|
|
125
|
+
<text>{['Hello']}</text>
|
|
126
|
+
<text>{tag`Hello ${name}`}</text>
|
|
127
|
+
<text>{'Hello'}{name}</text>
|
|
128
|
+
<text>Hello {`World ${name}`}</text>
|
|
129
|
+
<text>{'Hello'}<text>{name}</text></text>
|
|
130
|
+
<text>{'Hello'}{/* comment */}</text>
|
|
90
131
|
</>
|
|
91
132
|
"#
|
|
92
133
|
);
|
|
@@ -6,4 +6,17 @@
|
|
|
6
6
|
<text text="ReactLynx"></text>
|
|
7
7
|
</text>
|
|
8
8
|
<x-text>Hello, ReactLynx</x-text>
|
|
9
|
+
<x-text>{'Hello'}</x-text>
|
|
10
|
+
<x-text>{`Hello ${name}`}</x-text>
|
|
11
|
+
<text>{42}</text>
|
|
12
|
+
<text>{null}</text>
|
|
13
|
+
<text>{false}</text>
|
|
14
|
+
<text>{[
|
|
15
|
+
'Hello'
|
|
16
|
+
]}</text>
|
|
17
|
+
<text>{tag`Hello ${name}`}</text>
|
|
18
|
+
<text>{'Hello'}{name}</text>
|
|
19
|
+
<text>Hello {`World ${name}`}</text>
|
|
20
|
+
<text>{'Hello'}<text>{name}</text></text>
|
|
21
|
+
<text>{'Hello'}{ /* comment */ }</text>
|
|
9
22
|
</>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<>
|
|
2
|
+
<text text={'Hello'}></text>
|
|
3
|
+
<text text={''}></text>
|
|
4
|
+
<text text={' Hello\n\tWorld & '}></text>
|
|
5
|
+
<text text={`Hello`}></text>
|
|
6
|
+
<text text={`Hello ${name}`}></text>
|
|
7
|
+
<text text={`Hello ${getName()} ${count}`}></text>
|
|
8
|
+
<text text={` Hello
|
|
9
|
+
${name}\tWorld `}></text>
|
|
10
|
+
<text class="hello" text={'Hello'}></text>
|
|
11
|
+
<text {...attrs} text={`Hello ${name}`}></text>
|
|
12
|
+
<text text="old" text={'Hello'}></text>
|
|
13
|
+
</>;
|
|
@@ -119,6 +119,16 @@ impl Visit for BindingCollector {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
fn visit_method_prop(&mut self, node: &MethodProp) {
|
|
123
|
+
if self.should_enter_ctx {
|
|
124
|
+
self.should_enter_ctx = false;
|
|
125
|
+
self.enter_next_block = true;
|
|
126
|
+
// An object method's key is evaluated in the enclosing scope. Only the
|
|
127
|
+
// function parameters and body belong to the method's local scope.
|
|
128
|
+
node.function.visit_with(self);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
122
132
|
fn visit_catch_clause(&mut self, node: &CatchClause) {
|
|
123
133
|
if self.should_enter_ctx {
|
|
124
134
|
self.should_enter_ctx = false;
|
|
@@ -404,6 +404,20 @@ impl VisitMut for ExtractingIdentsCollector {
|
|
|
404
404
|
self.pop_scope();
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
+
fn visit_mut_method_prop(&mut self, n: &mut MethodProp) {
|
|
408
|
+
// Only the outer worklet's key is evaluated at its definition site.
|
|
409
|
+
// Nested method keys execute inside the worklet, in the enclosing scope
|
|
410
|
+
// rather than the nested method's parameter/body scope.
|
|
411
|
+
if !self.scope_env.last().unwrap().is_worklet_fn_scope {
|
|
412
|
+
n.key.visit_mut_with(self);
|
|
413
|
+
}
|
|
414
|
+
self.push_fn_scope(collect_inner_scope_decls(n));
|
|
415
|
+
self.next_block_decls_collected = true;
|
|
416
|
+
n.function.visit_mut_with(self);
|
|
417
|
+
self.next_block_decls_collected = false;
|
|
418
|
+
self.pop_scope();
|
|
419
|
+
}
|
|
420
|
+
|
|
407
421
|
fn visit_mut_class_method(&mut self, n: &mut ClassMethod) {
|
|
408
422
|
self.push_fn_scope(collect_inner_scope_decls(n));
|
|
409
423
|
self.next_block_decls_collected = true;
|