@depup/react-native-worklets 0.11.3-depup.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/.worklets/dummy.md +1 -0
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +64 -0
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
- package/Common/cpp/worklets/Compat/Holders.h +25 -0
- package/Common/cpp/worklets/Compat/StableApi.cpp +145 -0
- package/Common/cpp/worklets/Compat/StableApi.h +128 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +729 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +126 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +81 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +76 -0
- package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +95 -0
- package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +44 -0
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +10 -0
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +43 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueue.h +14 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +69 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +48 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.cpp +103 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.h +52 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +60 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.h +29 -0
- package/Common/cpp/worklets/SharedItems/Serializable.cpp +373 -0
- package/Common/cpp/worklets/SharedItems/Serializable.h +413 -0
- package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +172 -0
- package/Common/cpp/worklets/SharedItems/SerializableFactory.h +85 -0
- package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.cpp +71 -0
- package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.h +75 -0
- package/Common/cpp/worklets/SharedItems/Shareable.cpp +84 -0
- package/Common/cpp/worklets/SharedItems/Shareable.h +43 -0
- package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +59 -0
- package/Common/cpp/worklets/SharedItems/Synchronizable.h +57 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +78 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +45 -0
- package/Common/cpp/worklets/SharedItems/UnpackerLoader.h +78 -0
- package/Common/cpp/worklets/Tools/FeatureFlags.cpp +18 -0
- package/Common/cpp/worklets/Tools/FeatureFlags.h +44 -0
- package/Common/cpp/worklets/Tools/JSISerializer.cpp +312 -0
- package/Common/cpp/worklets/Tools/JSISerializer.h +42 -0
- package/Common/cpp/worklets/Tools/JSLogger.cpp +92 -0
- package/Common/cpp/worklets/Tools/JSLogger.h +48 -0
- package/Common/cpp/worklets/Tools/JSScheduler.cpp +21 -0
- package/Common/cpp/worklets/Tools/JSScheduler.h +35 -0
- package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
- package/Common/cpp/worklets/Tools/RNRuntimeStatus.h +27 -0
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +56 -0
- package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +75 -0
- package/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
- package/Common/cpp/worklets/Tools/UIScheduler.cpp +19 -0
- package/Common/cpp/worklets/Tools/UIScheduler.h +22 -0
- package/Common/cpp/worklets/Tools/VersionUtils.cpp +61 -0
- package/Common/cpp/worklets/Tools/VersionUtils.h +24 -0
- package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +34 -0
- package/Common/cpp/worklets/Tools/WorkletEventHandler.h +44 -0
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +30 -0
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +222 -0
- package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +116 -0
- package/Common/cpp/worklets/Tools/WorkletsVersion.cpp +46 -0
- package/Common/cpp/worklets/Tools/WorkletsVersion.h +18 -0
- package/Common/cpp/worklets/WorkletRuntime/BundleModeConfig.h +17 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.cpp +45 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.h +12 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +68 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +24 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +59 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +38 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeHolder.h +19 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +122 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +75 -0
- package/Common/cpp/worklets/WorkletRuntime/ScriptLoader.h +116 -0
- package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +14 -0
- package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +15 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +58 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +100 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +327 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +256 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +320 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +36 -0
- package/LICENSE +20 -0
- package/README.md +43 -0
- package/RNWorklets.podspec +94 -0
- package/android/CMakeLists.txt +108 -0
- package/android/build.gradle.kts +369 -0
- package/android/fix-prefab.gradle.kts +56 -0
- package/android/generate-stub-pch.gradle.kts +84 -0
- package/android/gradle.properties +25 -0
- package/android/proguard-rules.pro +3 -0
- package/android/settings.gradle.kts +21 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/WorkletsPCH.h +26 -0
- package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +66 -0
- package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +38 -0
- package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +30 -0
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.cpp +66 -0
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.h +48 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +51 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +43 -0
- package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +31 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +203 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +75 -0
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +19 -0
- package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.kt +56 -0
- package/android/src/main/java/com/swmansion/worklets/ScriptBufferWrapper.kt +103 -0
- package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.kt +42 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameCallback.kt +14 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +112 -0
- package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +27 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +30 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +187 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +272 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +1124 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +40 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +13 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +98 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +60 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +87 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +181 -0
- package/android/src/no-networking/com/swmansion/worklets/WorkletsModule.kt +143 -0
- package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
- package/apple/worklets/apple/AnimationFrameQueue.mm +145 -0
- package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
- package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +12 -0
- package/apple/worklets/apple/IOSUIScheduler.h +14 -0
- package/apple/worklets/apple/IOSUIScheduler.mm +29 -0
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +25 -0
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +707 -0
- package/apple/worklets/apple/PlatformLogger.mm +31 -0
- package/apple/worklets/apple/SlowAnimations.h +8 -0
- package/apple/worklets/apple/SlowAnimations.mm +45 -0
- package/apple/worklets/apple/WorkletsDisplayLink.h +21 -0
- package/apple/worklets/apple/WorkletsModule.h +28 -0
- package/apple/worklets/apple/WorkletsModule.mm +177 -0
- package/bundleMode/index.d.ts +6 -0
- package/bundleMode/index.js +182 -0
- package/bundleMode/shims/reactNativeShim.js +21 -0
- package/bundleMode/shims/turboModuleRegistryShim.js +47 -0
- package/changes.json +58 -0
- package/compatibility.json +29 -0
- package/jest/pluginTestUtils.ts +16 -0
- package/jest/resolver.js +18 -0
- package/lib/module/WorkletsModule/NativeWorklets.js +4 -0
- package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
- package/lib/module/WorkletsModule/NativeWorklets.native.js +199 -0
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
- package/lib/module/bundleMode/metroOverrides.native.js +26 -0
- package/lib/module/bundleMode/metroOverrides.native.js.map +1 -0
- package/lib/module/bundleMode/network.native.js +44 -0
- package/lib/module/bundleMode/network.native.js.map +1 -0
- package/lib/module/debug/bundleMode.js +6 -0
- package/lib/module/debug/bundleMode.js.map +1 -0
- package/lib/module/debug/bundleMode.native.js +11 -0
- package/lib/module/debug/bundleMode.native.js.map +1 -0
- package/lib/module/debug/checkCppVersion.js +29 -0
- package/lib/module/debug/checkCppVersion.js.map +1 -0
- package/lib/module/debug/errors.native.js +67 -0
- package/lib/module/debug/errors.native.js.map +1 -0
- package/lib/module/debug/jsVersion.js +9 -0
- package/lib/module/debug/jsVersion.js.map +1 -0
- package/lib/module/debug/logger.js +15 -0
- package/lib/module/debug/logger.js.map +1 -0
- package/lib/module/debug/slowAnimations.js +7 -0
- package/lib/module/debug/slowAnimations.js.map +1 -0
- package/lib/module/debug/slowAnimations.native.js +17 -0
- package/lib/module/debug/slowAnimations.native.js.map +1 -0
- package/lib/module/deprecated.js +27 -0
- package/lib/module/deprecated.js.map +1 -0
- package/lib/module/featureFlags/featureFlags.js +12 -0
- package/lib/module/featureFlags/featureFlags.js.map +1 -0
- package/lib/module/featureFlags/featureFlags.native.js +51 -0
- package/lib/module/featureFlags/featureFlags.native.js.map +1 -0
- package/lib/module/featureFlags/staticFlags.json +6 -0
- package/lib/module/featureFlags/types.js +16 -0
- package/lib/module/featureFlags/types.js.map +1 -0
- package/lib/module/guardImplementation.native.js +17 -0
- package/lib/module/guardImplementation.native.js.map +1 -0
- package/lib/module/index.js +26 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/initializers/initializers.js +24 -0
- package/lib/module/initializers/initializers.js.map +1 -0
- package/lib/module/initializers/initializers.native.js +195 -0
- package/lib/module/initializers/initializers.native.js.map +1 -0
- package/lib/module/memory/bundleUnpacker.native.js +38 -0
- package/lib/module/memory/bundleUnpacker.native.js.map +1 -0
- package/lib/module/memory/customSerializableUnpacker.native.js +20 -0
- package/lib/module/memory/customSerializableUnpacker.native.js.map +1 -0
- package/lib/module/memory/isShareable.js +8 -0
- package/lib/module/memory/isShareable.js.map +1 -0
- package/lib/module/memory/isSynchronizable.js +8 -0
- package/lib/module/memory/isSynchronizable.js.map +1 -0
- package/lib/module/memory/remoteFunctionUnpacker.native.js +18 -0
- package/lib/module/memory/remoteFunctionUnpacker.native.js.map +1 -0
- package/lib/module/memory/serializable.js +18 -0
- package/lib/module/memory/serializable.js.map +1 -0
- package/lib/module/memory/serializable.native.js +619 -0
- package/lib/module/memory/serializable.native.js.map +1 -0
- package/lib/module/memory/serializableMappingCache.js +11 -0
- package/lib/module/memory/serializableMappingCache.js.map +1 -0
- package/lib/module/memory/serializableMappingCache.native.js +29 -0
- package/lib/module/memory/serializableMappingCache.native.js.map +1 -0
- package/lib/module/memory/shareable.js +18 -0
- package/lib/module/memory/shareable.js.map +1 -0
- package/lib/module/memory/shareable.native.js +42 -0
- package/lib/module/memory/shareable.native.js.map +1 -0
- package/lib/module/memory/shareableGuestUnpacker.native.js +105 -0
- package/lib/module/memory/shareableGuestUnpacker.native.js.map +1 -0
- package/lib/module/memory/shareableHostUnpacker.native.js +20 -0
- package/lib/module/memory/shareableHostUnpacker.native.js.map +1 -0
- package/lib/module/memory/synchronizable.js +6 -0
- package/lib/module/memory/synchronizable.js.map +1 -0
- package/lib/module/memory/synchronizable.native.js +9 -0
- package/lib/module/memory/synchronizable.native.js.map +1 -0
- package/lib/module/memory/synchronizableUnpacker.native.js +47 -0
- package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -0
- package/lib/module/memory/types.js +12 -0
- package/lib/module/memory/types.js.map +1 -0
- package/lib/module/memory/valueUnpacker.native.js +52 -0
- package/lib/module/memory/valueUnpacker.native.js.map +1 -0
- package/lib/module/mock.js +85 -0
- package/lib/module/mock.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/platformChecker.js +4 -0
- package/lib/module/platformChecker.js.map +1 -0
- package/lib/module/platformChecker.native.js +4 -0
- package/lib/module/platformChecker.native.js.map +1 -0
- package/lib/module/privateGlobals.d.js +7 -0
- package/lib/module/privateGlobals.d.js.map +1 -0
- package/lib/module/runLoop/common/setImmediatePolyfill.js +15 -0
- package/lib/module/runLoop/common/setImmediatePolyfill.js.map +1 -0
- package/lib/module/runLoop/common/setIntervalPolyfill.js +26 -0
- package/lib/module/runLoop/common/setIntervalPolyfill.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +10 -0
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +71 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +32 -0
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/index.js +19 -0
- package/lib/module/runLoop/workletRuntime/index.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js +11 -0
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +48 -0
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/setTimeout.js +28 -0
- package/lib/module/runLoop/workletRuntime/setTimeout.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/taskQueue.js +37 -0
- package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -0
- package/lib/module/runtimeKind.js +92 -0
- package/lib/module/runtimeKind.js.map +1 -0
- package/lib/module/runtimes.js +36 -0
- package/lib/module/runtimes.js.map +1 -0
- package/lib/module/runtimes.native.js +379 -0
- package/lib/module/runtimes.native.js.map +1 -0
- package/lib/module/specs/NativeWorkletsModule.js +5 -0
- package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
- package/lib/module/specs/index.js +10 -0
- package/lib/module/specs/index.js.map +1 -0
- package/lib/module/threads.js +60 -0
- package/lib/module/threads.js.map +1 -0
- package/lib/module/threads.native.js +295 -0
- package/lib/module/threads.native.js.map +1 -0
- package/lib/module/types.js +5 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/workletFunction.js +36 -0
- package/lib/module/workletFunction.js.map +1 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +3 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts +3 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +59 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts +9 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts.map +1 -0
- package/lib/typescript/bundleMode/network.native.d.ts +7 -0
- package/lib/typescript/bundleMode/network.native.d.ts.map +1 -0
- package/lib/typescript/debug/bundleMode.d.ts +2 -0
- package/lib/typescript/debug/bundleMode.d.ts.map +1 -0
- package/lib/typescript/debug/bundleMode.native.d.ts +2 -0
- package/lib/typescript/debug/bundleMode.native.d.ts.map +1 -0
- package/lib/typescript/debug/checkCppVersion.d.ts +3 -0
- package/lib/typescript/debug/checkCppVersion.d.ts.map +1 -0
- package/lib/typescript/debug/errors.native.d.ts +13 -0
- package/lib/typescript/debug/errors.native.d.ts.map +1 -0
- package/lib/typescript/debug/jsVersion.d.ts +7 -0
- package/lib/typescript/debug/jsVersion.d.ts.map +1 -0
- package/lib/typescript/debug/logger.d.ts +5 -0
- package/lib/typescript/debug/logger.d.ts.map +1 -0
- package/lib/typescript/debug/slowAnimations.d.ts +2 -0
- package/lib/typescript/debug/slowAnimations.d.ts.map +1 -0
- package/lib/typescript/debug/slowAnimations.native.d.ts +11 -0
- package/lib/typescript/debug/slowAnimations.native.d.ts.map +1 -0
- package/lib/typescript/deprecated.d.ts +19 -0
- package/lib/typescript/deprecated.d.ts.map +1 -0
- package/lib/typescript/featureFlags/featureFlags.d.ts +5 -0
- package/lib/typescript/featureFlags/featureFlags.d.ts.map +1 -0
- package/lib/typescript/featureFlags/featureFlags.native.d.ts +6 -0
- package/lib/typescript/featureFlags/featureFlags.native.d.ts.map +1 -0
- package/lib/typescript/featureFlags/types.d.ts +23 -0
- package/lib/typescript/featureFlags/types.d.ts.map +1 -0
- package/lib/typescript/guardImplementation.native.d.ts +3 -0
- package/lib/typescript/guardImplementation.native.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +19 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/initializers/initializers.d.ts +2 -0
- package/lib/typescript/initializers/initializers.d.ts.map +1 -0
- package/lib/typescript/initializers/initializers.native.d.ts +19 -0
- package/lib/typescript/initializers/initializers.native.d.ts.map +1 -0
- package/lib/typescript/memory/bundleUnpacker.native.d.ts +7 -0
- package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/customSerializableUnpacker.native.d.ts +3 -0
- package/lib/typescript/memory/customSerializableUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/isShareable.d.ts +3 -0
- package/lib/typescript/memory/isShareable.d.ts.map +1 -0
- package/lib/typescript/memory/isSynchronizable.d.ts +3 -0
- package/lib/typescript/memory/isSynchronizable.d.ts.map +1 -0
- package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts +3 -0
- package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/serializable.d.ts +7 -0
- package/lib/typescript/memory/serializable.d.ts.map +1 -0
- package/lib/typescript/memory/serializable.native.d.ts +37 -0
- package/lib/typescript/memory/serializable.native.d.ts.map +1 -0
- package/lib/typescript/memory/serializableMappingCache.d.ts +6 -0
- package/lib/typescript/memory/serializableMappingCache.d.ts.map +1 -0
- package/lib/typescript/memory/serializableMappingCache.native.d.ts +13 -0
- package/lib/typescript/memory/serializableMappingCache.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareable.d.ts +15 -0
- package/lib/typescript/memory/shareable.d.ts.map +1 -0
- package/lib/typescript/memory/shareable.native.d.ts +15 -0
- package/lib/typescript/memory/shareable.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareableHostUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/shareableHostUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizable.d.ts +3 -0
- package/lib/typescript/memory/synchronizable.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizable.native.d.ts +3 -0
- package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/types.d.ts +136 -0
- package/lib/typescript/memory/types.d.ts.map +1 -0
- package/lib/typescript/memory/valueUnpacker.native.d.ts +7 -0
- package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/mock.d.ts +2 -0
- package/lib/typescript/mock.d.ts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/platformChecker.d.ts +2 -0
- package/lib/typescript/platformChecker.d.ts.map +1 -0
- package/lib/typescript/platformChecker.native.d.ts +2 -0
- package/lib/typescript/platformChecker.native.d.ts.map +1 -0
- package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts +6 -0
- package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts +2 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/index.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/index.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +10 -0
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -0
- package/lib/typescript/runtimeKind.d.ts +56 -0
- package/lib/typescript/runtimeKind.d.ts.map +1 -0
- package/lib/typescript/runtimes.d.ts +15 -0
- package/lib/typescript/runtimes.d.ts.map +1 -0
- package/lib/typescript/runtimes.native.d.ts +155 -0
- package/lib/typescript/runtimes.native.d.ts.map +1 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +9 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
- package/lib/typescript/specs/index.d.ts +3 -0
- package/lib/typescript/specs/index.d.ts.map +1 -0
- package/lib/typescript/threads.d.ts +8 -0
- package/lib/typescript/threads.d.ts.map +1 -0
- package/lib/typescript/threads.native.d.ts +125 -0
- package/lib/typescript/threads.native.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +136 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/workletFunction.d.ts +26 -0
- package/lib/typescript/workletFunction.d.ts.map +1 -0
- package/package.json +220 -0
- package/plugin/index.d.ts +168 -0
- package/plugin/index.js +2188 -0
- package/scripts/validate-react-native-version.js +43 -0
- package/scripts/worklets_utils.rb +94 -0
- package/src/WorkletsModule/NativeWorklets.native.ts +461 -0
- package/src/WorkletsModule/NativeWorklets.ts +5 -0
- package/src/WorkletsModule/workletsModuleProxy.ts +247 -0
- package/src/bundleMode/metroOverrides.native.ts +33 -0
- package/src/bundleMode/network.native.ts +63 -0
- package/src/debug/bundleMode.native.ts +18 -0
- package/src/debug/bundleMode.ts +5 -0
- package/src/debug/checkCppVersion.ts +34 -0
- package/src/debug/errors.native.ts +74 -0
- package/src/debug/jsVersion.ts +8 -0
- package/src/debug/logger.ts +16 -0
- package/src/debug/slowAnimations.native.ts +15 -0
- package/src/debug/slowAnimations.ts +6 -0
- package/src/deprecated.ts +38 -0
- package/src/featureFlags/featureFlags.native.ts +70 -0
- package/src/featureFlags/featureFlags.ts +20 -0
- package/src/featureFlags/staticFlags.json +6 -0
- package/src/featureFlags/types.ts +32 -0
- package/src/guardImplementation.native.ts +26 -0
- package/src/index.ts +95 -0
- package/src/initializers/initializers.native.ts +218 -0
- package/src/initializers/initializers.ts +24 -0
- package/src/memory/bundleUnpacker.native.ts +59 -0
- package/src/memory/customSerializableUnpacker.native.ts +30 -0
- package/src/memory/isShareable.ts +16 -0
- package/src/memory/isSynchronizable.ts +14 -0
- package/src/memory/remoteFunctionUnpacker.native.ts +27 -0
- package/src/memory/serializable.native.ts +889 -0
- package/src/memory/serializable.ts +36 -0
- package/src/memory/serializableMappingCache.native.ts +37 -0
- package/src/memory/serializableMappingCache.ts +12 -0
- package/src/memory/shareable.native.ts +68 -0
- package/src/memory/shareable.ts +27 -0
- package/src/memory/shareableGuestUnpacker.native.ts +168 -0
- package/src/memory/shareableHostUnpacker.native.ts +31 -0
- package/src/memory/synchronizable.native.ts +17 -0
- package/src/memory/synchronizable.ts +9 -0
- package/src/memory/synchronizableUnpacker.native.ts +65 -0
- package/src/memory/types.ts +191 -0
- package/src/memory/valueUnpacker.native.ts +79 -0
- package/src/mock.ts +111 -0
- package/src/platformChecker.native.ts +3 -0
- package/src/platformChecker.ts +4 -0
- package/src/privateGlobals.d.ts +127 -0
- package/src/runLoop/common/setImmediatePolyfill.ts +20 -0
- package/src/runLoop/common/setIntervalPolyfill.ts +38 -0
- package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +11 -0
- package/src/runLoop/uiRuntime/requestAnimationFrame.ts +87 -0
- package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +40 -0
- package/src/runLoop/workletRuntime/index.ts +18 -0
- package/src/runLoop/workletRuntime/queueMicrotask.ts +13 -0
- package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +61 -0
- package/src/runLoop/workletRuntime/setTimeout.ts +37 -0
- package/src/runLoop/workletRuntime/taskQueue.ts +44 -0
- package/src/runtimeKind.ts +85 -0
- package/src/runtimes.native.ts +572 -0
- package/src/runtimes.ts +107 -0
- package/src/specs/NativeWorkletsModule.ts +11 -0
- package/src/specs/index.ts +13 -0
- package/src/threads.native.ts +408 -0
- package/src/threads.ts +110 -0
- package/src/types.ts +164 -0
- package/src/workletFunction.ts +41 -0
package/plugin/index.js
ADDED
|
@@ -0,0 +1,2188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
|
|
28
|
+
// lib/gestureHandlerAutoworkletization.js
|
|
29
|
+
var require_gestureHandlerAutoworkletization = __commonJS({
|
|
30
|
+
"lib/gestureHandlerAutoworkletization.js"(exports2) {
|
|
31
|
+
"use strict";
|
|
32
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
33
|
+
exports2.gestureHandlerObjectHooks = exports2.gestureHandlerBuilderMethods = void 0;
|
|
34
|
+
exports2.isGestureHandlerEventCallback = isGestureHandlerEventCallback;
|
|
35
|
+
exports2.isGestureObjectEventCallbackMethod = isGestureObjectEventCallbackMethod;
|
|
36
|
+
var types_12 = require("@babel/types");
|
|
37
|
+
var gestureHandlerGestureObjects = /* @__PURE__ */ new Set([
|
|
38
|
+
"Tap",
|
|
39
|
+
"Pan",
|
|
40
|
+
"Pinch",
|
|
41
|
+
"Rotation",
|
|
42
|
+
"Fling",
|
|
43
|
+
"LongPress",
|
|
44
|
+
"ForceTouch",
|
|
45
|
+
"Native",
|
|
46
|
+
"Manual",
|
|
47
|
+
"Race",
|
|
48
|
+
"Simultaneous",
|
|
49
|
+
"Exclusive",
|
|
50
|
+
"Hover"
|
|
51
|
+
]);
|
|
52
|
+
exports2.gestureHandlerBuilderMethods = /* @__PURE__ */ new Set([
|
|
53
|
+
"onBegin",
|
|
54
|
+
"onStart",
|
|
55
|
+
"onEnd",
|
|
56
|
+
"onFinalize",
|
|
57
|
+
"onUpdate",
|
|
58
|
+
"onChange",
|
|
59
|
+
"onTouchesDown",
|
|
60
|
+
"onTouchesMove",
|
|
61
|
+
"onTouchesUp",
|
|
62
|
+
"onTouchesCancelled"
|
|
63
|
+
]);
|
|
64
|
+
exports2.gestureHandlerObjectHooks = /* @__PURE__ */ new Set([
|
|
65
|
+
"useTapGesture",
|
|
66
|
+
"usePanGesture",
|
|
67
|
+
"usePinchGesture",
|
|
68
|
+
"useRotationGesture",
|
|
69
|
+
"useFlingGesture",
|
|
70
|
+
"useLongPressGesture",
|
|
71
|
+
"useNativeGesture",
|
|
72
|
+
"useManualGesture",
|
|
73
|
+
"useHoverGesture"
|
|
74
|
+
]);
|
|
75
|
+
function isGestureHandlerEventCallback(path) {
|
|
76
|
+
return (0, types_12.isCallExpression)(path.parent) && (0, types_12.isExpression)(path.parent.callee) && isGestureObjectEventCallbackMethod(path.parent.callee);
|
|
77
|
+
}
|
|
78
|
+
function isGestureObjectEventCallbackMethod(exp) {
|
|
79
|
+
return (0, types_12.isMemberExpression)(exp) && (0, types_12.isIdentifier)(exp.property) && exports2.gestureHandlerBuilderMethods.has(exp.property.name) && containsGestureObject(exp.object);
|
|
80
|
+
}
|
|
81
|
+
function containsGestureObject(exp) {
|
|
82
|
+
if (isGestureObject(exp)) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
if ((0, types_12.isCallExpression)(exp) && (0, types_12.isMemberExpression)(exp.callee) && containsGestureObject(exp.callee.object)) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
function isGestureObject(exp) {
|
|
91
|
+
return (0, types_12.isCallExpression)(exp) && (0, types_12.isMemberExpression)(exp.callee) && (0, types_12.isIdentifier)(exp.callee.object) && exp.callee.object.name === "Gesture" && (0, types_12.isIdentifier)(exp.callee.property) && gestureHandlerGestureObjects.has(exp.callee.property.name);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// lib/layoutAnimationAutoworkletization.js
|
|
97
|
+
var require_layoutAnimationAutoworkletization = __commonJS({
|
|
98
|
+
"lib/layoutAnimationAutoworkletization.js"(exports2) {
|
|
99
|
+
"use strict";
|
|
100
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
101
|
+
exports2.isLayoutAnimationCallback = isLayoutAnimationCallback;
|
|
102
|
+
var types_12 = require("@babel/types");
|
|
103
|
+
var EntryExitAnimations = /* @__PURE__ */ new Set([
|
|
104
|
+
"BounceIn",
|
|
105
|
+
"BounceInDown",
|
|
106
|
+
"BounceInLeft",
|
|
107
|
+
"BounceInRight",
|
|
108
|
+
"BounceInUp",
|
|
109
|
+
"BounceOut",
|
|
110
|
+
"BounceOutDown",
|
|
111
|
+
"BounceOutLeft",
|
|
112
|
+
"BounceOutRight",
|
|
113
|
+
"BounceOutUp",
|
|
114
|
+
"FadeIn",
|
|
115
|
+
"FadeInDown",
|
|
116
|
+
"FadeInLeft",
|
|
117
|
+
"FadeInRight",
|
|
118
|
+
"FadeInUp",
|
|
119
|
+
"FadeOut",
|
|
120
|
+
"FadeOutDown",
|
|
121
|
+
"FadeOutLeft",
|
|
122
|
+
"FadeOutRight",
|
|
123
|
+
"FadeOutUp",
|
|
124
|
+
"FlipInEasyX",
|
|
125
|
+
"FlipInEasyY",
|
|
126
|
+
"FlipInXDown",
|
|
127
|
+
"FlipInXUp",
|
|
128
|
+
"FlipInYLeft",
|
|
129
|
+
"FlipInYRight",
|
|
130
|
+
"FlipOutEasyX",
|
|
131
|
+
"FlipOutEasyY",
|
|
132
|
+
"FlipOutXDown",
|
|
133
|
+
"FlipOutXUp",
|
|
134
|
+
"FlipOutYLeft",
|
|
135
|
+
"FlipOutYRight",
|
|
136
|
+
"LightSpeedInLeft",
|
|
137
|
+
"LightSpeedInRight",
|
|
138
|
+
"LightSpeedOutLeft",
|
|
139
|
+
"LightSpeedOutRight",
|
|
140
|
+
"PinwheelIn",
|
|
141
|
+
"PinwheelOut",
|
|
142
|
+
"RollInLeft",
|
|
143
|
+
"RollInRight",
|
|
144
|
+
"RollOutLeft",
|
|
145
|
+
"RollOutRight",
|
|
146
|
+
"RotateInDownLeft",
|
|
147
|
+
"RotateInDownRight",
|
|
148
|
+
"RotateInUpLeft",
|
|
149
|
+
"RotateInUpRight",
|
|
150
|
+
"RotateOutDownLeft",
|
|
151
|
+
"RotateOutDownRight",
|
|
152
|
+
"RotateOutUpLeft",
|
|
153
|
+
"RotateOutUpRight",
|
|
154
|
+
"SlideInDown",
|
|
155
|
+
"SlideInLeft",
|
|
156
|
+
"SlideInRight",
|
|
157
|
+
"SlideInUp",
|
|
158
|
+
"SlideOutDown",
|
|
159
|
+
"SlideOutLeft",
|
|
160
|
+
"SlideOutRight",
|
|
161
|
+
"SlideOutUp",
|
|
162
|
+
"StretchInX",
|
|
163
|
+
"StretchInY",
|
|
164
|
+
"StretchOutX",
|
|
165
|
+
"StretchOutY",
|
|
166
|
+
"ZoomIn",
|
|
167
|
+
"ZoomInDown",
|
|
168
|
+
"ZoomInEasyDown",
|
|
169
|
+
"ZoomInEasyUp",
|
|
170
|
+
"ZoomInLeft",
|
|
171
|
+
"ZoomInRight",
|
|
172
|
+
"ZoomInRotate",
|
|
173
|
+
"ZoomInUp",
|
|
174
|
+
"ZoomOut",
|
|
175
|
+
"ZoomOutDown",
|
|
176
|
+
"ZoomOutEasyDown",
|
|
177
|
+
"ZoomOutEasyUp",
|
|
178
|
+
"ZoomOutLeft",
|
|
179
|
+
"ZoomOutRight",
|
|
180
|
+
"ZoomOutRotate",
|
|
181
|
+
"ZoomOutUp"
|
|
182
|
+
]);
|
|
183
|
+
var LayoutTransitions = /* @__PURE__ */ new Set([
|
|
184
|
+
"Layout",
|
|
185
|
+
"LinearTransition",
|
|
186
|
+
"SequencedTransition",
|
|
187
|
+
"FadingTransition",
|
|
188
|
+
"JumpingTransition",
|
|
189
|
+
"CurvedTransition",
|
|
190
|
+
"EntryExitTransition"
|
|
191
|
+
]);
|
|
192
|
+
var LayoutAnimations = /* @__PURE__ */ new Set([
|
|
193
|
+
...EntryExitAnimations,
|
|
194
|
+
...LayoutTransitions
|
|
195
|
+
]);
|
|
196
|
+
var BaseAnimationsChainableMethods = /* @__PURE__ */ new Set([
|
|
197
|
+
"build",
|
|
198
|
+
"duration",
|
|
199
|
+
"delay",
|
|
200
|
+
"getDuration",
|
|
201
|
+
"randomDelay",
|
|
202
|
+
"getDelay",
|
|
203
|
+
"getDelayFunction"
|
|
204
|
+
]);
|
|
205
|
+
var ComplexAnimationsChainableMethods = /* @__PURE__ */ new Set([
|
|
206
|
+
"easing",
|
|
207
|
+
"rotate",
|
|
208
|
+
"springify",
|
|
209
|
+
"damping",
|
|
210
|
+
"mass",
|
|
211
|
+
"stiffness",
|
|
212
|
+
"overshootClamping",
|
|
213
|
+
"energyThreshold",
|
|
214
|
+
"restDisplacementThreshold",
|
|
215
|
+
"restSpeedThreshold",
|
|
216
|
+
"withInitialValues",
|
|
217
|
+
"getAnimationAndConfig"
|
|
218
|
+
]);
|
|
219
|
+
var DefaultTransitionChainableMethods = /* @__PURE__ */ new Set([
|
|
220
|
+
"easingX",
|
|
221
|
+
"easingY",
|
|
222
|
+
"easingWidth",
|
|
223
|
+
"easingHeight",
|
|
224
|
+
"entering",
|
|
225
|
+
"exiting",
|
|
226
|
+
"reverse"
|
|
227
|
+
]);
|
|
228
|
+
var LayoutAnimationsChainableMethods = /* @__PURE__ */ new Set([
|
|
229
|
+
...BaseAnimationsChainableMethods,
|
|
230
|
+
...ComplexAnimationsChainableMethods,
|
|
231
|
+
...DefaultTransitionChainableMethods
|
|
232
|
+
]);
|
|
233
|
+
var LayoutAnimationsCallbacks = /* @__PURE__ */ new Set(["withCallback"]);
|
|
234
|
+
function isLayoutAnimationCallback(path) {
|
|
235
|
+
return (0, types_12.isCallExpression)(path.parent) && (0, types_12.isExpression)(path.parent.callee) && isLayoutAnimationCallbackMethod(path.parent.callee);
|
|
236
|
+
}
|
|
237
|
+
function isLayoutAnimationCallbackMethod(exp) {
|
|
238
|
+
return (0, types_12.isMemberExpression)(exp) && (0, types_12.isIdentifier)(exp.property) && LayoutAnimationsCallbacks.has(exp.property.name) && isLayoutAnimationsChainableOrNewOperator(exp.object);
|
|
239
|
+
}
|
|
240
|
+
function isLayoutAnimationsChainableOrNewOperator(exp) {
|
|
241
|
+
if ((0, types_12.isIdentifier)(exp) && LayoutAnimations.has(exp.name)) {
|
|
242
|
+
return true;
|
|
243
|
+
} else if ((0, types_12.isNewExpression)(exp) && (0, types_12.isIdentifier)(exp.callee) && LayoutAnimations.has(exp.callee.name)) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
if ((0, types_12.isCallExpression)(exp) && (0, types_12.isMemberExpression)(exp.callee) && (0, types_12.isIdentifier)(exp.callee.property) && LayoutAnimationsChainableMethods.has(exp.callee.property.name) && isLayoutAnimationsChainableOrNewOperator(exp.callee.object)) {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// lib/types.js
|
|
255
|
+
var require_types = __commonJS({
|
|
256
|
+
"lib/types.js"(exports2) {
|
|
257
|
+
"use strict";
|
|
258
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
259
|
+
exports2.generatedWorkletsDir = exports2.workletClassFactorySuffix = exports2.WorkletizableObject = exports2.WorkletizableFunction = void 0;
|
|
260
|
+
exports2.isWorkletizableFunctionPath = isWorkletizableFunctionPath;
|
|
261
|
+
exports2.isWorkletizableFunctionNode = isWorkletizableFunctionNode;
|
|
262
|
+
exports2.isWorkletizableObjectPath = isWorkletizableObjectPath;
|
|
263
|
+
exports2.isWorkletizableObjectNode = isWorkletizableObjectNode;
|
|
264
|
+
var types_12 = require("@babel/types");
|
|
265
|
+
exports2.WorkletizableFunction = "FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod";
|
|
266
|
+
exports2.WorkletizableObject = "ObjectExpression";
|
|
267
|
+
function isWorkletizableFunctionPath(path) {
|
|
268
|
+
return path.isFunctionDeclaration() || path.isFunctionExpression() || path.isArrowFunctionExpression() || path.isObjectMethod();
|
|
269
|
+
}
|
|
270
|
+
function isWorkletizableFunctionNode(node) {
|
|
271
|
+
return (0, types_12.isFunctionDeclaration)(node) || (0, types_12.isFunctionExpression)(node) || (0, types_12.isArrowFunctionExpression)(node) || (0, types_12.isObjectMethod)(node);
|
|
272
|
+
}
|
|
273
|
+
function isWorkletizableObjectPath(path) {
|
|
274
|
+
return path.isObjectExpression();
|
|
275
|
+
}
|
|
276
|
+
function isWorkletizableObjectNode(node) {
|
|
277
|
+
return (0, types_12.isObjectExpression)(node);
|
|
278
|
+
}
|
|
279
|
+
exports2.workletClassFactorySuffix = "__classFactory";
|
|
280
|
+
exports2.generatedWorkletsDir = ".worklets";
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// lib/referencedWorklets.js
|
|
285
|
+
var require_referencedWorklets = __commonJS({
|
|
286
|
+
"lib/referencedWorklets.js"(exports2) {
|
|
287
|
+
"use strict";
|
|
288
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
289
|
+
exports2.findReferencedWorklet = findReferencedWorklet;
|
|
290
|
+
var types_12 = require("@babel/types");
|
|
291
|
+
var types_2 = require_types();
|
|
292
|
+
function findReferencedWorklet(workletIdentifier, acceptWorkletizableFunction, acceptObject, state) {
|
|
293
|
+
const workletName = workletIdentifier.node.name;
|
|
294
|
+
const scope = workletIdentifier.scope;
|
|
295
|
+
const workletBinding = scope.getBinding(workletName);
|
|
296
|
+
if (!workletBinding) {
|
|
297
|
+
return void 0;
|
|
298
|
+
}
|
|
299
|
+
if (state.opts.bundleMode && bindingIsWorklet(workletBinding)) {
|
|
300
|
+
return void 0;
|
|
301
|
+
}
|
|
302
|
+
if (acceptWorkletizableFunction && workletBinding.path.isFunctionDeclaration()) {
|
|
303
|
+
return workletBinding.path;
|
|
304
|
+
}
|
|
305
|
+
const isConstant = workletBinding.constant;
|
|
306
|
+
if (isConstant) {
|
|
307
|
+
return findReferencedWorkletFromVariableDeclarator(workletBinding, acceptWorkletizableFunction, acceptObject, state);
|
|
308
|
+
}
|
|
309
|
+
return findReferencedWorkletFromAssignmentExpression(workletBinding, acceptWorkletizableFunction, acceptObject, state);
|
|
310
|
+
}
|
|
311
|
+
function findReferencedWorkletFromVariableDeclarator(workletBinding, acceptWorkletizableFunction, acceptObject, state) {
|
|
312
|
+
const workletDeclaration = workletBinding.path;
|
|
313
|
+
if (!workletDeclaration.isVariableDeclarator()) {
|
|
314
|
+
return void 0;
|
|
315
|
+
}
|
|
316
|
+
const worklet = workletDeclaration.get("init");
|
|
317
|
+
if (acceptWorkletizableFunction && (0, types_2.isWorkletizableFunctionPath)(worklet)) {
|
|
318
|
+
return worklet;
|
|
319
|
+
}
|
|
320
|
+
if (acceptObject && (0, types_2.isWorkletizableObjectPath)(worklet)) {
|
|
321
|
+
return worklet;
|
|
322
|
+
}
|
|
323
|
+
if (worklet.isIdentifier() && worklet.isReferencedIdentifier()) {
|
|
324
|
+
return findReferencedWorklet(worklet, acceptWorkletizableFunction, acceptObject, state);
|
|
325
|
+
}
|
|
326
|
+
return void 0;
|
|
327
|
+
}
|
|
328
|
+
function findReferencedWorkletFromAssignmentExpression(workletBinding, acceptWorkletizableFunction, acceptObject, state) {
|
|
329
|
+
const workletDeclaration = workletBinding.constantViolations.reverse().find((constantViolation) => constantViolation.isAssignmentExpression() && (acceptWorkletizableFunction && (0, types_2.isWorkletizableFunctionPath)(constantViolation.get("right")) || acceptObject && (0, types_2.isWorkletizableObjectPath)(constantViolation.get("right"))));
|
|
330
|
+
if (!workletDeclaration || !workletDeclaration.isAssignmentExpression()) {
|
|
331
|
+
return void 0;
|
|
332
|
+
}
|
|
333
|
+
const workletDefinition = workletDeclaration.get("right");
|
|
334
|
+
if (acceptWorkletizableFunction && (0, types_2.isWorkletizableFunctionPath)(workletDefinition)) {
|
|
335
|
+
return workletDefinition;
|
|
336
|
+
}
|
|
337
|
+
if (acceptObject && (0, types_2.isWorkletizableObjectPath)(workletDefinition)) {
|
|
338
|
+
return workletDefinition;
|
|
339
|
+
}
|
|
340
|
+
if (workletDefinition.isIdentifier() && workletDefinition.isReferencedIdentifier()) {
|
|
341
|
+
return findReferencedWorklet(workletDefinition, acceptWorkletizableFunction, acceptObject, state);
|
|
342
|
+
}
|
|
343
|
+
return void 0;
|
|
344
|
+
}
|
|
345
|
+
function bindingIsWorklet(binding) {
|
|
346
|
+
return binding.referencePaths.some((refPath) => !Array.isArray(refPath.container) && (0, types_12.isMemberExpression)(refPath.container) && refPath.container.object === refPath.node && (0, types_12.isIdentifier)(refPath.container.property) && refPath.container.property.name === "__workletHash");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// lib/findWorklet.js
|
|
352
|
+
var require_findWorklet = __commonJS({
|
|
353
|
+
"lib/findWorklet.js"(exports2) {
|
|
354
|
+
"use strict";
|
|
355
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
356
|
+
exports2.findWorklet = findWorklet;
|
|
357
|
+
var referencedWorklets_1 = require_referencedWorklets();
|
|
358
|
+
var types_12 = require_types();
|
|
359
|
+
function findWorklet(nodePath, state, acceptWorkletizableFunction, acceptObject) {
|
|
360
|
+
if (acceptWorkletizableFunction && (0, types_12.isWorkletizableFunctionPath)(nodePath)) {
|
|
361
|
+
return nodePath;
|
|
362
|
+
}
|
|
363
|
+
if (acceptObject && (0, types_12.isWorkletizableObjectPath)(nodePath)) {
|
|
364
|
+
return nodePath;
|
|
365
|
+
}
|
|
366
|
+
if (nodePath.isIdentifier() && nodePath.isReferencedIdentifier()) {
|
|
367
|
+
const worklet = (0, referencedWorklets_1.findReferencedWorklet)(nodePath, acceptWorkletizableFunction, acceptObject, state);
|
|
368
|
+
return worklet;
|
|
369
|
+
}
|
|
370
|
+
return void 0;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// lib/utils.js
|
|
376
|
+
var require_utils = __commonJS({
|
|
377
|
+
"lib/utils.js"(exports2) {
|
|
378
|
+
"use strict";
|
|
379
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
380
|
+
exports2.isRelease = isRelease;
|
|
381
|
+
exports2.replaceWithFactoryCall = replaceWithFactoryCall;
|
|
382
|
+
var types_12 = require("@babel/types");
|
|
383
|
+
function isRelease(state) {
|
|
384
|
+
var _a, _b;
|
|
385
|
+
const releasePattern = /(prod|release|stag[ei])/i;
|
|
386
|
+
const developmentPattern = /dev/i;
|
|
387
|
+
const envName = state.file.opts.envName;
|
|
388
|
+
if (envName) {
|
|
389
|
+
if (envName.match(releasePattern)) {
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
if (envName.match(developmentPattern)) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return !!(((_a = process.env.BABEL_ENV) === null || _a === void 0 ? void 0 : _a.match(releasePattern)) || ((_b = process.env.NODE_ENV) === null || _b === void 0 ? void 0 : _b.match(releasePattern)));
|
|
397
|
+
}
|
|
398
|
+
function replaceWithFactoryCall(toReplace, name, factoryCall) {
|
|
399
|
+
if (!name || !needsDeclaration(toReplace)) {
|
|
400
|
+
toReplace.replaceWith(factoryCall);
|
|
401
|
+
} else {
|
|
402
|
+
const replacement = (0, types_12.variableDeclaration)("const", [
|
|
403
|
+
(0, types_12.variableDeclarator)((0, types_12.identifier)(name), factoryCall)
|
|
404
|
+
]);
|
|
405
|
+
toReplace.replaceWith(replacement);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function needsDeclaration(nodePath) {
|
|
409
|
+
return (0, types_12.isScopable)(nodePath.parent) || (0, types_12.isExportNamedDeclaration)(nodePath.parent);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// lib/globals.js
|
|
415
|
+
var require_globals = __commonJS({
|
|
416
|
+
"lib/globals.js"(exports2) {
|
|
417
|
+
"use strict";
|
|
418
|
+
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
419
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
420
|
+
};
|
|
421
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
422
|
+
exports2.globals = exports2.defaultGlobals = void 0;
|
|
423
|
+
exports2.initializeState = initializeState;
|
|
424
|
+
exports2.isGeneratedWorkletFile = isGeneratedWorkletFile;
|
|
425
|
+
exports2.initializeGlobals = initializeGlobals;
|
|
426
|
+
exports2.addCustomGlobals = addCustomGlobals;
|
|
427
|
+
var assert_1 = require("assert");
|
|
428
|
+
var path_1 = __importDefault(require("path"));
|
|
429
|
+
var autoworkletization_12 = require_autoworkletization();
|
|
430
|
+
var types_12 = require_types();
|
|
431
|
+
var notCapturedIdentifiers = [
|
|
432
|
+
// Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
|
|
433
|
+
// Note that objects' properties don't need to be listed since we always only capture the whole object,
|
|
434
|
+
// e.g. `global.__ErrorUtils` or `Intl.DateTimeFormat`.
|
|
435
|
+
// Value properties
|
|
436
|
+
"globalThis",
|
|
437
|
+
"Infinity",
|
|
438
|
+
"NaN",
|
|
439
|
+
"undefined",
|
|
440
|
+
// Function properties
|
|
441
|
+
"eval",
|
|
442
|
+
"isFinite",
|
|
443
|
+
"isNaN",
|
|
444
|
+
"parseFloat",
|
|
445
|
+
"parseInt",
|
|
446
|
+
"decodeURI",
|
|
447
|
+
"decodeURIComponent",
|
|
448
|
+
"encodeURI",
|
|
449
|
+
"encodeURIComponent",
|
|
450
|
+
"escape",
|
|
451
|
+
"unescape",
|
|
452
|
+
// Fundamental objects
|
|
453
|
+
"Object",
|
|
454
|
+
"Function",
|
|
455
|
+
"Boolean",
|
|
456
|
+
"Symbol",
|
|
457
|
+
// Error objects
|
|
458
|
+
"Error",
|
|
459
|
+
"AggregateError",
|
|
460
|
+
"EvalError",
|
|
461
|
+
"RangeError",
|
|
462
|
+
"ReferenceError",
|
|
463
|
+
"SyntaxError",
|
|
464
|
+
"TypeError",
|
|
465
|
+
"URIError",
|
|
466
|
+
"InternalError",
|
|
467
|
+
// Numbers and dates
|
|
468
|
+
"Number",
|
|
469
|
+
"BigInt",
|
|
470
|
+
"Math",
|
|
471
|
+
"Date",
|
|
472
|
+
// Text processing
|
|
473
|
+
"String",
|
|
474
|
+
"RegExp",
|
|
475
|
+
// Indexed collections
|
|
476
|
+
"Array",
|
|
477
|
+
"Int8Array",
|
|
478
|
+
"Uint8Array",
|
|
479
|
+
"Uint8ClampedArray",
|
|
480
|
+
"Int16Array",
|
|
481
|
+
"Uint16Array",
|
|
482
|
+
"Int32Array",
|
|
483
|
+
"Uint32Array",
|
|
484
|
+
"BigInt64Array",
|
|
485
|
+
"BigUint64Array",
|
|
486
|
+
"Float32Array",
|
|
487
|
+
"Float64Array",
|
|
488
|
+
// Keyed collections
|
|
489
|
+
"Map",
|
|
490
|
+
"Set",
|
|
491
|
+
"WeakMap",
|
|
492
|
+
"WeakSet",
|
|
493
|
+
// Structured data
|
|
494
|
+
"ArrayBuffer",
|
|
495
|
+
"SharedArrayBuffer",
|
|
496
|
+
"DataView",
|
|
497
|
+
"Atomics",
|
|
498
|
+
"JSON",
|
|
499
|
+
// Managing memory
|
|
500
|
+
"WeakRef",
|
|
501
|
+
"FinalizationRegistry",
|
|
502
|
+
// Control abstraction objects
|
|
503
|
+
"Iterator",
|
|
504
|
+
"AsyncIterator",
|
|
505
|
+
"Promise",
|
|
506
|
+
"GeneratorFunction",
|
|
507
|
+
"AsyncGeneratorFunction",
|
|
508
|
+
"Generator",
|
|
509
|
+
"AsyncGenerator",
|
|
510
|
+
"AsyncFunction",
|
|
511
|
+
// Reflection
|
|
512
|
+
"Reflect",
|
|
513
|
+
"Proxy",
|
|
514
|
+
// Internationalization
|
|
515
|
+
"Intl",
|
|
516
|
+
// Other stuff
|
|
517
|
+
"null",
|
|
518
|
+
"this",
|
|
519
|
+
"global",
|
|
520
|
+
"window",
|
|
521
|
+
"globalThis",
|
|
522
|
+
"self",
|
|
523
|
+
"console",
|
|
524
|
+
"performance",
|
|
525
|
+
"arguments",
|
|
526
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
|
|
527
|
+
"require",
|
|
528
|
+
"fetch",
|
|
529
|
+
"XMLHttpRequest",
|
|
530
|
+
"WebSocket",
|
|
531
|
+
// Run loop
|
|
532
|
+
"queueMicrotask",
|
|
533
|
+
"requestAnimationFrame",
|
|
534
|
+
"cancelAnimationFrame",
|
|
535
|
+
"setTimeout",
|
|
536
|
+
"clearTimeout",
|
|
537
|
+
"setImmediate",
|
|
538
|
+
"clearImmediate",
|
|
539
|
+
"setInterval",
|
|
540
|
+
"clearInterval",
|
|
541
|
+
// Hermes
|
|
542
|
+
"HermesInternal",
|
|
543
|
+
// Worklets
|
|
544
|
+
"_WORKLET"
|
|
545
|
+
];
|
|
546
|
+
function initializeState(state) {
|
|
547
|
+
var _a, _b;
|
|
548
|
+
state.skipFile = isGeneratedWorkletFile(state.file.opts.filename);
|
|
549
|
+
if (state.skipFile) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
state.workletNumber = 1;
|
|
553
|
+
state.classesToWorkletize = [];
|
|
554
|
+
state.autoworkletizationPlugin = {
|
|
555
|
+
name: "worklets-autoworkletization",
|
|
556
|
+
visitor: {
|
|
557
|
+
CallExpression: {
|
|
558
|
+
enter(nodePath) {
|
|
559
|
+
(0, autoworkletization_12.processCalleesAutoworkletizableCallbacks)(nodePath, state);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
if (!state.opts.strictGlobal) {
|
|
565
|
+
initializeGlobals();
|
|
566
|
+
addCustomGlobals(state);
|
|
567
|
+
}
|
|
568
|
+
const userImportForwarding = state.opts.importForwarding;
|
|
569
|
+
(0, assert_1.strict)(state.importForwarding === void 0, "state.importForwarding should be undefined at this point");
|
|
570
|
+
state.importForwarding = {
|
|
571
|
+
relativePaths: [
|
|
572
|
+
...defaultAllowedPaths,
|
|
573
|
+
...(_a = userImportForwarding === null || userImportForwarding === void 0 ? void 0 : userImportForwarding.relativePaths) !== null && _a !== void 0 ? _a : []
|
|
574
|
+
],
|
|
575
|
+
moduleNames: [
|
|
576
|
+
...defaultAllowedModules,
|
|
577
|
+
...(_b = userImportForwarding === null || userImportForwarding === void 0 ? void 0 : userImportForwarding.moduleNames) !== null && _b !== void 0 ? _b : []
|
|
578
|
+
]
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function isGeneratedWorkletFile(filename) {
|
|
582
|
+
if (!filename) {
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
const generatedWorkletsDirPath = path_1.default.join("react-native-worklets", types_12.generatedWorkletsDir);
|
|
586
|
+
return filename.includes(generatedWorkletsDirPath);
|
|
587
|
+
}
|
|
588
|
+
exports2.defaultGlobals = new Set(notCapturedIdentifiers);
|
|
589
|
+
function initializeGlobals() {
|
|
590
|
+
exports2.globals = new Set(exports2.defaultGlobals);
|
|
591
|
+
}
|
|
592
|
+
var defaultAllowedPaths = ["react-native-worklets"];
|
|
593
|
+
var defaultAllowedModules = [
|
|
594
|
+
"react-native-worklets",
|
|
595
|
+
"react-native/Libraries/Core/setUpXHR"
|
|
596
|
+
];
|
|
597
|
+
function addCustomGlobals(state) {
|
|
598
|
+
if (state.opts && Array.isArray(state.opts.globals)) {
|
|
599
|
+
state.opts.globals.forEach((name) => {
|
|
600
|
+
exports2.globals.add(name);
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
// lib/imports.js
|
|
608
|
+
var require_imports = __commonJS({
|
|
609
|
+
"lib/imports.js"(exports2) {
|
|
610
|
+
"use strict";
|
|
611
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
612
|
+
exports2.updateRelativeRequires = updateRelativeRequires;
|
|
613
|
+
exports2.isImport = isImport;
|
|
614
|
+
exports2.isImportRelative = isImportRelative;
|
|
615
|
+
exports2.canForwardModuleImport = canForwardModuleImport;
|
|
616
|
+
exports2.canForwardRelativeImport = canForwardRelativeImport;
|
|
617
|
+
exports2.createImportPathLiteral = createImportPathLiteral;
|
|
618
|
+
var core_1 = require("@babel/core");
|
|
619
|
+
var types_12 = require("@babel/types");
|
|
620
|
+
var path_1 = require("path");
|
|
621
|
+
var types_2 = require_types();
|
|
622
|
+
function updateRelativeRequires(node, state) {
|
|
623
|
+
(0, core_1.traverse)(node, {
|
|
624
|
+
noScope: true,
|
|
625
|
+
CallExpression(nodePath) {
|
|
626
|
+
var _a;
|
|
627
|
+
if (nodePath.get("callee").isIdentifier({ name: "require" }) && ((_a = nodePath.get("arguments")[0]) === null || _a === void 0 ? void 0 : _a.isStringLiteral())) {
|
|
628
|
+
const requiredModule = nodePath.get("arguments")[0];
|
|
629
|
+
if (requiredModule.node.value.startsWith(".") && canForwardRelativeImport(state.file.opts.filename || "", state.importForwarding.relativePaths)) {
|
|
630
|
+
requiredModule.replaceWith(createImportPathLiteral(requiredModule.node.value, state));
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
function isImport(binding) {
|
|
637
|
+
return binding.kind === "module" && binding.constant && (binding.path.isImportSpecifier() || binding.path.isImportDefaultSpecifier()) && binding.path.parentPath.isImportDeclaration();
|
|
638
|
+
}
|
|
639
|
+
function isImportRelative(imported) {
|
|
640
|
+
return imported.path.parentPath.node.source.value.startsWith(".");
|
|
641
|
+
}
|
|
642
|
+
function canForwardModuleImport(moduleName, forwardableModuleNames) {
|
|
643
|
+
return forwardableModuleNames.some((forwardableModuleName) => moduleName === forwardableModuleName || moduleName.startsWith(forwardableModuleName + "/"));
|
|
644
|
+
}
|
|
645
|
+
function canForwardRelativeImport(modulePath, relativePaths) {
|
|
646
|
+
return !!modulePath && relativePaths.some((relativePath) => matchesFilenameSegment(modulePath, relativePath));
|
|
647
|
+
}
|
|
648
|
+
function matchesFilenameSegment(filename, allowedPath) {
|
|
649
|
+
const pkgSegments = allowedPath.split(path_1.posix.sep);
|
|
650
|
+
let fileSegments = filename.split(path_1.sep);
|
|
651
|
+
const lastNodeModules = fileSegments.lastIndexOf("node_modules");
|
|
652
|
+
if (lastNodeModules !== -1) {
|
|
653
|
+
fileSegments = fileSegments.slice(lastNodeModules + 1);
|
|
654
|
+
}
|
|
655
|
+
for (let i = 0; i <= fileSegments.length - pkgSegments.length; i++) {
|
|
656
|
+
if (pkgSegments.every((segment, segmentIndex) => fileSegments[i + segmentIndex] === segment)) {
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
function createImportPathLiteral(originalPath, state) {
|
|
663
|
+
const generatedWorkletsDirPath = (0, path_1.resolve)((0, path_1.dirname)(require.resolve("react-native-worklets/package.json")), types_2.generatedWorkletsDir);
|
|
664
|
+
const resolved = (0, path_1.resolve)((0, path_1.dirname)(state.file.opts.filename), originalPath);
|
|
665
|
+
const relativePath = (0, path_1.relative)(generatedWorkletsDirPath, resolved);
|
|
666
|
+
return (0, types_12.stringLiteral)(path_1.sep === "/" ? relativePath : relativePath.split(path_1.sep).join("/"));
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
// lib/closure.js
|
|
672
|
+
var require_closure = __commonJS({
|
|
673
|
+
"lib/closure.js"(exports2) {
|
|
674
|
+
"use strict";
|
|
675
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
676
|
+
exports2.getClosure = getClosure;
|
|
677
|
+
var types_12 = require("@babel/types");
|
|
678
|
+
var globals_12 = require_globals();
|
|
679
|
+
var imports_1 = require_imports();
|
|
680
|
+
function getClosure(funPath, state) {
|
|
681
|
+
const capturedNames = /* @__PURE__ */ new Set();
|
|
682
|
+
const closureVariables = new Array();
|
|
683
|
+
const moduleBindingsToImport = /* @__PURE__ */ new Set();
|
|
684
|
+
const relativeBindingsToImport = /* @__PURE__ */ new Set();
|
|
685
|
+
let recrawled = false;
|
|
686
|
+
funPath.traverse({
|
|
687
|
+
"TSType|TSTypeAliasDeclaration|TSInterfaceDeclaration"(typePath) {
|
|
688
|
+
typePath.skip();
|
|
689
|
+
},
|
|
690
|
+
ReferencedIdentifier(idPath) {
|
|
691
|
+
if (idPath.isJSXIdentifier() && !state.opts.bundleMode) {
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
const name = idPath.node.name;
|
|
695
|
+
if (capturedNames.has(name)) {
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
let binding = idPath.scope.getBinding(name);
|
|
699
|
+
if (!binding && !recrawled) {
|
|
700
|
+
recrawled = true;
|
|
701
|
+
idPath.scope.crawl();
|
|
702
|
+
binding = idPath.scope.getBinding(name);
|
|
703
|
+
}
|
|
704
|
+
if (!binding) {
|
|
705
|
+
if (state.opts.strictGlobal || globals_12.globals.has(name)) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
capturedNames.add(name);
|
|
709
|
+
closureVariables.push((0, types_12.cloneNode)(idPath.node, true));
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
if ("id" in funPath.node) {
|
|
713
|
+
const id = idPath.scope.getBindingIdentifier(name);
|
|
714
|
+
if (id && id === funPath.node.id) {
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
let scope = idPath.scope;
|
|
719
|
+
while (scope !== funPath.scope.parent) {
|
|
720
|
+
if (scope.hasOwnBinding(name)) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
scope = scope.parent;
|
|
724
|
+
}
|
|
725
|
+
if (state.opts.bundleMode && (0, imports_1.isImport)(binding)) {
|
|
726
|
+
if ((0, imports_1.isImportRelative)(binding) && (0, imports_1.canForwardRelativeImport)(state.filename, state.importForwarding.relativePaths)) {
|
|
727
|
+
capturedNames.add(name);
|
|
728
|
+
relativeBindingsToImport.add(binding);
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const source = binding.path.parentPath.node.source.value;
|
|
732
|
+
if ((0, imports_1.canForwardModuleImport)(source, state.importForwarding.moduleNames)) {
|
|
733
|
+
capturedNames.add(name);
|
|
734
|
+
moduleBindingsToImport.add(binding);
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
capturedNames.add(name);
|
|
739
|
+
closureVariables.push((0, types_12.cloneNode)(idPath.node, true));
|
|
740
|
+
}
|
|
741
|
+
}, state);
|
|
742
|
+
return {
|
|
743
|
+
closureVariables,
|
|
744
|
+
moduleBindingsToImport,
|
|
745
|
+
relativeBindingsToImport
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
// lib/generate.js
|
|
752
|
+
var require_generate = __commonJS({
|
|
753
|
+
"lib/generate.js"(exports2) {
|
|
754
|
+
"use strict";
|
|
755
|
+
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
756
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
757
|
+
};
|
|
758
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
759
|
+
exports2.generateWorkletFile = generateWorkletFile;
|
|
760
|
+
var core_1 = require("@babel/core");
|
|
761
|
+
var types_12 = require("@babel/types");
|
|
762
|
+
var assert_1 = __importDefault(require("assert"));
|
|
763
|
+
var fs_1 = require("fs");
|
|
764
|
+
var path_1 = require("path");
|
|
765
|
+
var imports_1 = require_imports();
|
|
766
|
+
var types_2 = require_types();
|
|
767
|
+
function generateWorkletFile(moduleBindingsToImport, relativeBindingsToImport, factory, workletHash, state) {
|
|
768
|
+
var _a;
|
|
769
|
+
const libraryImports = Array.from(moduleBindingsToImport).filter((binding) => (binding.path.isImportSpecifier() || binding.path.isImportDefaultSpecifier()) && binding.path.parentPath.isImportDeclaration()).map((binding) => (0, types_12.importDeclaration)([(0, types_12.cloneNode)(binding.path.node, true)], (0, types_12.stringLiteral)(binding.path.parentPath.node.source.value)));
|
|
770
|
+
const filesDirPath = (0, path_1.resolve)((0, path_1.dirname)(require.resolve("react-native-worklets/package.json")), types_2.generatedWorkletsDir);
|
|
771
|
+
const relativeImports = Array.from(relativeBindingsToImport).filter((binding) => binding.path.isImportSpecifier() && binding.path.parentPath.isImportDeclaration()).map((binding) => (0, types_12.importDeclaration)([(0, types_12.cloneNode)(binding.path.node, true)], (0, imports_1.createImportPathLiteral)(binding.path.parentPath.node.source.value, state)));
|
|
772
|
+
const imports = [...libraryImports, ...relativeImports];
|
|
773
|
+
const newProg = (0, types_12.program)([...imports, (0, types_12.exportDefaultDeclaration)(factory)]);
|
|
774
|
+
const transformedProg = (_a = (0, core_1.transformFromAstSync)(newProg, void 0, {
|
|
775
|
+
filename: state.file.opts.filename,
|
|
776
|
+
presets: [resolvePresetTypescript()],
|
|
777
|
+
plugins: [state.autoworkletizationPlugin, stripJsxDevAttributesPlugin],
|
|
778
|
+
ast: false,
|
|
779
|
+
babelrc: false,
|
|
780
|
+
configFile: false,
|
|
781
|
+
comments: false
|
|
782
|
+
})) === null || _a === void 0 ? void 0 : _a.code;
|
|
783
|
+
(0, assert_1.default)(transformedProg, "[Worklets] `transformedProg` is undefined.");
|
|
784
|
+
const dedicatedFilePath = (0, path_1.resolve)(filesDirPath, `${workletHash}.js`);
|
|
785
|
+
(0, fs_1.writeFileSync)(dedicatedFilePath, transformedProg);
|
|
786
|
+
}
|
|
787
|
+
function resolvePresetTypescript() {
|
|
788
|
+
try {
|
|
789
|
+
return require.resolve("@babel/preset-typescript");
|
|
790
|
+
} catch (_a) {
|
|
791
|
+
return require.resolve("@babel/preset-typescript", {
|
|
792
|
+
paths: [(0, path_1.dirname)(require.resolve("react-native-worklets/package.json"))]
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
var stripJsxDevAttributesPlugin = {
|
|
797
|
+
name: "worklets-strip-jsx-dev-attributes",
|
|
798
|
+
visitor: {
|
|
799
|
+
JSXAttribute(path) {
|
|
800
|
+
const name = path.node.name;
|
|
801
|
+
if (name.type !== "JSXIdentifier") {
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
if (name.name !== "__self" && name.name !== "__source") {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
path.remove();
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// lib/hermesBytecode.js
|
|
815
|
+
var require_hermesBytecode = __commonJS({
|
|
816
|
+
"lib/hermesBytecode.js"(exports2) {
|
|
817
|
+
"use strict";
|
|
818
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
819
|
+
exports2.compileWorkletToHbc = compileWorkletToHbc;
|
|
820
|
+
var core_1 = require("@babel/core");
|
|
821
|
+
var child_process_1 = require("child_process");
|
|
822
|
+
function compileWorkletToHbc(funString, workletHash, state) {
|
|
823
|
+
if (compilationCache.has(workletHash)) {
|
|
824
|
+
return compilationCache.get(workletHash);
|
|
825
|
+
}
|
|
826
|
+
const result = compile(funString, state);
|
|
827
|
+
compilationCache.set(workletHash, result);
|
|
828
|
+
return result;
|
|
829
|
+
}
|
|
830
|
+
function compile(funString, state) {
|
|
831
|
+
const hermesc = resolveHbcBinary(state);
|
|
832
|
+
if (!hermesc) {
|
|
833
|
+
return null;
|
|
834
|
+
}
|
|
835
|
+
try {
|
|
836
|
+
return runHermesc(hermesc, funString);
|
|
837
|
+
} catch (error) {
|
|
838
|
+
if (getErrorOutput(error).includes("JSX")) {
|
|
839
|
+
const transformed = transformJsx(funString);
|
|
840
|
+
if (transformed !== null) {
|
|
841
|
+
try {
|
|
842
|
+
return runHermesc(hermesc, transformed);
|
|
843
|
+
} catch (retryError) {
|
|
844
|
+
return warnFallback(retryError);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return warnFallback(error);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
var MAX_BYTECODE_BYTES = 256 * 1024 * 1024;
|
|
852
|
+
var compilationCache = /* @__PURE__ */ new Map();
|
|
853
|
+
var warnedMessages = /* @__PURE__ */ new Set();
|
|
854
|
+
function warnOnce(message) {
|
|
855
|
+
if (warnedMessages.has(message)) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
warnedMessages.add(message);
|
|
859
|
+
console.warn(`[Worklets] ${message}`);
|
|
860
|
+
}
|
|
861
|
+
function resolveHbcBinary(state) {
|
|
862
|
+
const { getHBCBinary } = state.opts;
|
|
863
|
+
if (!getHBCBinary) {
|
|
864
|
+
warnOnce("The `getHBCBinary` plugin option is required to compile worklets to Hermes bytecode. Falling back to shipping worklets as source strings.");
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
867
|
+
try {
|
|
868
|
+
const binary = getHBCBinary();
|
|
869
|
+
if (!binary) {
|
|
870
|
+
throw new Error("`getHBCBinary` returned an empty path.");
|
|
871
|
+
}
|
|
872
|
+
return binary;
|
|
873
|
+
} catch (error) {
|
|
874
|
+
warnOnce(`Calling \`getHBCBinary\` failed, falling back to a source string. ${error instanceof Error ? error.message : String(error)}`);
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
function runHermesc(hermesc, source) {
|
|
879
|
+
return (0, child_process_1.execFileSync)(hermesc, ["-g0", "-emit-binary", "-O", "-w", "-"], {
|
|
880
|
+
input: source,
|
|
881
|
+
maxBuffer: MAX_BYTECODE_BYTES,
|
|
882
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
function getErrorOutput(error) {
|
|
886
|
+
const stderr = error === null || error === void 0 ? void 0 : error.stderr;
|
|
887
|
+
if (stderr) {
|
|
888
|
+
return stderr.toString();
|
|
889
|
+
}
|
|
890
|
+
return error instanceof Error ? error.message : String(error);
|
|
891
|
+
}
|
|
892
|
+
function warnFallback(error) {
|
|
893
|
+
const reason = getErrorOutput(error).trim().split("\n")[0];
|
|
894
|
+
warnOnce(`Could not compile a worklet to Hermes bytecode, falling back to a source string. ${reason}`);
|
|
895
|
+
return null;
|
|
896
|
+
}
|
|
897
|
+
var jsxPluginPath;
|
|
898
|
+
function resolveJsxPlugin() {
|
|
899
|
+
if (jsxPluginPath === void 0) {
|
|
900
|
+
try {
|
|
901
|
+
jsxPluginPath = require.resolve("@babel/plugin-transform-react-jsx");
|
|
902
|
+
} catch (_a) {
|
|
903
|
+
jsxPluginPath = null;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return jsxPluginPath;
|
|
907
|
+
}
|
|
908
|
+
function transformJsx(source) {
|
|
909
|
+
var _a;
|
|
910
|
+
const plugin = resolveJsxPlugin();
|
|
911
|
+
if (!plugin) {
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
try {
|
|
915
|
+
const result = (0, core_1.transformSync)(source, {
|
|
916
|
+
babelrc: false,
|
|
917
|
+
configFile: false,
|
|
918
|
+
compact: true,
|
|
919
|
+
plugins: [plugin]
|
|
920
|
+
});
|
|
921
|
+
return (_a = result === null || result === void 0 ? void 0 : result.code) !== null && _a !== void 0 ? _a : null;
|
|
922
|
+
} catch (_b) {
|
|
923
|
+
return null;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
// lib/transform.js
|
|
930
|
+
var require_transform = __commonJS({
|
|
931
|
+
"lib/transform.js"(exports2) {
|
|
932
|
+
"use strict";
|
|
933
|
+
var __rest = exports2 && exports2.__rest || function(s, e) {
|
|
934
|
+
var t = {};
|
|
935
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
936
|
+
t[p] = s[p];
|
|
937
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
938
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
939
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
940
|
+
t[p[i]] = s[p[i]];
|
|
941
|
+
}
|
|
942
|
+
return t;
|
|
943
|
+
};
|
|
944
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
945
|
+
exports2.workletTransformSync = workletTransformSync;
|
|
946
|
+
var core_1 = require("@babel/core");
|
|
947
|
+
function workletTransformSync(code, opts) {
|
|
948
|
+
const { extraPlugins = [], extraPresets = [] } = opts, rest = __rest(opts, ["extraPlugins", "extraPresets"]);
|
|
949
|
+
return (0, core_1.transformSync)(code, Object.assign(Object.assign({}, rest), { plugins: [...defaultPlugins, ...extraPlugins], presets: [...defaultPresets, ...extraPresets] }));
|
|
950
|
+
}
|
|
951
|
+
var defaultPresets = [
|
|
952
|
+
require.resolve("@babel/preset-typescript")
|
|
953
|
+
];
|
|
954
|
+
var defaultPlugins = [];
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
// lib/workletStringCode.js
|
|
959
|
+
var require_workletStringCode = __commonJS({
|
|
960
|
+
"lib/workletStringCode.js"(exports2) {
|
|
961
|
+
"use strict";
|
|
962
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
963
|
+
if (k2 === void 0) k2 = k;
|
|
964
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
965
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
966
|
+
desc = { enumerable: true, get: function() {
|
|
967
|
+
return m[k];
|
|
968
|
+
} };
|
|
969
|
+
}
|
|
970
|
+
Object.defineProperty(o, k2, desc);
|
|
971
|
+
}) : (function(o, m, k, k2) {
|
|
972
|
+
if (k2 === void 0) k2 = k;
|
|
973
|
+
o[k2] = m[k];
|
|
974
|
+
}));
|
|
975
|
+
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
976
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
977
|
+
}) : function(o, v) {
|
|
978
|
+
o["default"] = v;
|
|
979
|
+
});
|
|
980
|
+
var __importStar = exports2 && exports2.__importStar || /* @__PURE__ */ (function() {
|
|
981
|
+
var ownKeys = function(o) {
|
|
982
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
983
|
+
var ar = [];
|
|
984
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
985
|
+
return ar;
|
|
986
|
+
};
|
|
987
|
+
return ownKeys(o);
|
|
988
|
+
};
|
|
989
|
+
return function(mod) {
|
|
990
|
+
if (mod && mod.__esModule) return mod;
|
|
991
|
+
var result = {};
|
|
992
|
+
if (mod != null) {
|
|
993
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
994
|
+
}
|
|
995
|
+
__setModuleDefault(result, mod);
|
|
996
|
+
return result;
|
|
997
|
+
};
|
|
998
|
+
})();
|
|
999
|
+
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
1000
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1001
|
+
};
|
|
1002
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1003
|
+
exports2.buildWorkletString = buildWorkletString;
|
|
1004
|
+
var core_1 = require("@babel/core");
|
|
1005
|
+
var generator_1 = __importDefault(require("@babel/generator"));
|
|
1006
|
+
var types_12 = require("@babel/types");
|
|
1007
|
+
var assert_1 = require("assert");
|
|
1008
|
+
var convertSourceMap = __importStar(require("convert-source-map"));
|
|
1009
|
+
var fs = __importStar(require("fs"));
|
|
1010
|
+
var transform_1 = require_transform();
|
|
1011
|
+
var types_2 = require_types();
|
|
1012
|
+
var utils_1 = require_utils();
|
|
1013
|
+
var MOCK_SOURCE_MAP = "mock source map";
|
|
1014
|
+
var querySuffixRE = /[?#].*$/;
|
|
1015
|
+
function buildWorkletString(fun, state, closureVariables, workletName, inputMap) {
|
|
1016
|
+
var _a;
|
|
1017
|
+
restoreRecursiveCalls(fun, workletName);
|
|
1018
|
+
const draftExpression = fun.program.body.find((obj) => (0, types_12.isFunctionDeclaration)(obj)) || fun.program.body.find((obj) => (0, types_12.isExpressionStatement)(obj));
|
|
1019
|
+
(0, assert_1.strict)(draftExpression, "`draftExpression` is undefined.");
|
|
1020
|
+
const expression = (0, types_12.isFunctionDeclaration)(draftExpression) ? draftExpression : draftExpression.expression;
|
|
1021
|
+
(0, assert_1.strict)("params" in expression, "'params' property is undefined in 'expression'");
|
|
1022
|
+
(0, assert_1.strict)((0, types_12.isBlockStatement)(expression.body), "`expression.body` is not a `BlockStatement`");
|
|
1023
|
+
const parsedClasses = /* @__PURE__ */ new Set();
|
|
1024
|
+
if (!state.opts.disableWorkletClasses) {
|
|
1025
|
+
(0, core_1.traverse)(fun, {
|
|
1026
|
+
NewExpression(path) {
|
|
1027
|
+
if (!(0, types_12.isIdentifier)(path.node.callee)) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
const constructorName = path.node.callee.name;
|
|
1031
|
+
if (!closureVariables.some((variable) => variable.name === constructorName) || parsedClasses.has(constructorName)) {
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
const index = closureVariables.findIndex((variable) => variable.name === constructorName);
|
|
1035
|
+
closureVariables.splice(index, 1);
|
|
1036
|
+
const workletClassFactoryName = constructorName + types_2.workletClassFactorySuffix;
|
|
1037
|
+
closureVariables.push((0, types_12.identifier)(workletClassFactoryName));
|
|
1038
|
+
(0, types_12.assertBlockStatement)(expression.body);
|
|
1039
|
+
expression.body.body.unshift((0, types_12.variableDeclaration)("const", [
|
|
1040
|
+
(0, types_12.variableDeclarator)((0, types_12.identifier)(constructorName), (0, types_12.callExpression)((0, types_12.identifier)(workletClassFactoryName), []))
|
|
1041
|
+
]));
|
|
1042
|
+
parsedClasses.add(constructorName);
|
|
1043
|
+
}
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
const workletFunction = (0, types_12.functionExpression)((0, types_12.identifier)(workletName), expression.params, expression.body, expression.generator, expression.async);
|
|
1047
|
+
const code = (0, generator_1.default)(workletFunction).code;
|
|
1048
|
+
(0, assert_1.strict)(inputMap, "`inputMap` is undefined.");
|
|
1049
|
+
const includeSourceMap = !((0, utils_1.isRelease)(state) || state.opts.disableSourceMaps);
|
|
1050
|
+
if (includeSourceMap) {
|
|
1051
|
+
inputMap.sourcesContent = [];
|
|
1052
|
+
for (const sourceFile of inputMap.sources) {
|
|
1053
|
+
inputMap.sourcesContent.push(fs.readFileSync(sourceFile.replace(querySuffixRE, "")).toString("utf-8"));
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
const transformed = (0, transform_1.workletTransformSync)(code, {
|
|
1057
|
+
filename: state.file.opts.filename,
|
|
1058
|
+
extraPlugins: [
|
|
1059
|
+
getClosurePlugin(closureVariables),
|
|
1060
|
+
...(_a = state.opts.extraPlugins) !== null && _a !== void 0 ? _a : []
|
|
1061
|
+
],
|
|
1062
|
+
extraPresets: state.opts.extraPresets,
|
|
1063
|
+
compact: true,
|
|
1064
|
+
sourceMaps: includeSourceMap,
|
|
1065
|
+
inputSourceMap: inputMap,
|
|
1066
|
+
ast: false,
|
|
1067
|
+
babelrc: false,
|
|
1068
|
+
configFile: false,
|
|
1069
|
+
comments: false
|
|
1070
|
+
});
|
|
1071
|
+
(0, assert_1.strict)(transformed, "`transformed` is null.");
|
|
1072
|
+
let sourceMap;
|
|
1073
|
+
if (includeSourceMap) {
|
|
1074
|
+
if (shouldMockSourceMap()) {
|
|
1075
|
+
sourceMap = MOCK_SOURCE_MAP;
|
|
1076
|
+
} else {
|
|
1077
|
+
sourceMap = convertSourceMap.fromObject(transformed.map).toObject();
|
|
1078
|
+
delete sourceMap.sourcesContent;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
const wrappedCode = `(${transformed.code})`;
|
|
1082
|
+
return [wrappedCode, JSON.stringify(sourceMap)];
|
|
1083
|
+
}
|
|
1084
|
+
function restoreRecursiveCalls(file, newName) {
|
|
1085
|
+
(0, core_1.traverse)(file, {
|
|
1086
|
+
FunctionExpression(path) {
|
|
1087
|
+
if (!path.node.id) {
|
|
1088
|
+
path.stop();
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
const oldName = path.node.id.name;
|
|
1092
|
+
const scope = path.scope;
|
|
1093
|
+
scope.rename(oldName, newName);
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
function shouldMockSourceMap() {
|
|
1098
|
+
return process.env.WORKLETS_JEST_SHOULD_MOCK_SOURCE_MAP === "1";
|
|
1099
|
+
}
|
|
1100
|
+
function prependClosure(path, closureVariables, closureDeclaration) {
|
|
1101
|
+
if (closureVariables.length === 0 || !(0, types_12.isProgram)(path.parent)) {
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
if (!(0, types_12.isExpression)(path.node.body)) {
|
|
1105
|
+
path.node.body.body.unshift(closureDeclaration);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
function prependRecursiveDeclaration(path) {
|
|
1109
|
+
var _a;
|
|
1110
|
+
if ((0, types_12.isProgram)(path.parent) && !(0, types_12.isArrowFunctionExpression)(path.node) && !(0, types_12.isObjectMethod)(path.node) && path.node.id && path.scope.parent) {
|
|
1111
|
+
const hasRecursiveCalls = ((_a = path.scope.parent.bindings[path.node.id.name]) === null || _a === void 0 ? void 0 : _a.references) > 0;
|
|
1112
|
+
if (hasRecursiveCalls) {
|
|
1113
|
+
path.node.body.body.unshift((0, types_12.variableDeclaration)("const", [
|
|
1114
|
+
(0, types_12.variableDeclarator)((0, types_12.identifier)(path.node.id.name), (0, types_12.memberExpression)((0, types_12.thisExpression)(), (0, types_12.identifier)("_recur")))
|
|
1115
|
+
]));
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
function getClosurePlugin(closureVariables) {
|
|
1120
|
+
const closureDeclaration = (0, types_12.variableDeclaration)("const", [
|
|
1121
|
+
(0, types_12.variableDeclarator)((0, types_12.objectPattern)(closureVariables.map((variable) => (0, types_12.objectProperty)((0, types_12.identifier)(variable.name), (0, types_12.identifier)(variable.name), false, true))), (0, types_12.memberExpression)((0, types_12.thisExpression)(), (0, types_12.identifier)("__closure")))
|
|
1122
|
+
]);
|
|
1123
|
+
return {
|
|
1124
|
+
visitor: {
|
|
1125
|
+
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod": (path) => {
|
|
1126
|
+
prependClosure(path, closureVariables, closureDeclaration);
|
|
1127
|
+
prependRecursiveDeclaration(path);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
// lib/workletFactory.js
|
|
1136
|
+
var require_workletFactory = __commonJS({
|
|
1137
|
+
"lib/workletFactory.js"(exports2) {
|
|
1138
|
+
"use strict";
|
|
1139
|
+
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
1140
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1141
|
+
};
|
|
1142
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1143
|
+
exports2.makeWorkletFactory = makeWorkletFactory;
|
|
1144
|
+
var generator_1 = __importDefault(require("@babel/generator"));
|
|
1145
|
+
var types_12 = require("@babel/types");
|
|
1146
|
+
var assert_1 = require("assert");
|
|
1147
|
+
var path_1 = require("path");
|
|
1148
|
+
var closure_1 = require_closure();
|
|
1149
|
+
var generate_1 = require_generate();
|
|
1150
|
+
var hermesBytecode_1 = require_hermesBytecode();
|
|
1151
|
+
var imports_1 = require_imports();
|
|
1152
|
+
var transform_1 = require_transform();
|
|
1153
|
+
var types_2 = require_types();
|
|
1154
|
+
var utils_1 = require_utils();
|
|
1155
|
+
var workletStringCode_1 = require_workletStringCode();
|
|
1156
|
+
var REAL_VERSION = require("../package.json").version;
|
|
1157
|
+
var MOCK_VERSION = "x.y.z";
|
|
1158
|
+
function makeWorkletFactory(fun, state) {
|
|
1159
|
+
var _a;
|
|
1160
|
+
const includeClosure = state.opts.bundleMode || !hasDirective(fun, "no-worklet-closure");
|
|
1161
|
+
const limitInitDataHoisting = hasDirective(fun, "limit-init-data-hoisting");
|
|
1162
|
+
stripWorkletDirectives(fun);
|
|
1163
|
+
(0, assert_1.strict)(state.file.opts.filename, "`state.file.opts.filename` is undefined.");
|
|
1164
|
+
const codeObject = (0, generator_1.default)(fun.node, {
|
|
1165
|
+
sourceMaps: true,
|
|
1166
|
+
sourceFileName: state.file.opts.filename
|
|
1167
|
+
});
|
|
1168
|
+
codeObject.code = "(" + (fun.isObjectMethod() ? "function " : "") + codeObject.code + "\n)";
|
|
1169
|
+
const transformed = (0, transform_1.workletTransformSync)(codeObject.code, {
|
|
1170
|
+
extraPlugins: [...extraPlugins, ...(_a = state.opts.extraPlugins) !== null && _a !== void 0 ? _a : []],
|
|
1171
|
+
extraPresets: state.opts.extraPresets,
|
|
1172
|
+
filename: state.file.opts.filename,
|
|
1173
|
+
ast: true,
|
|
1174
|
+
babelrc: false,
|
|
1175
|
+
configFile: false,
|
|
1176
|
+
inputSourceMap: codeObject.map
|
|
1177
|
+
});
|
|
1178
|
+
(0, assert_1.strict)(transformed, "`transformed` is undefined.");
|
|
1179
|
+
(0, assert_1.strict)(transformed.ast, "`transformed.ast` is undefined.");
|
|
1180
|
+
const { closureVariables, moduleBindingsToImport, relativeBindingsToImport } = includeClosure ? (0, closure_1.getClosure)(fun, state) : {
|
|
1181
|
+
closureVariables: [],
|
|
1182
|
+
moduleBindingsToImport: /* @__PURE__ */ new Set(),
|
|
1183
|
+
relativeBindingsToImport: /* @__PURE__ */ new Set()
|
|
1184
|
+
};
|
|
1185
|
+
const clone = (0, types_12.cloneNode)(fun.node);
|
|
1186
|
+
const funExpression = (0, types_12.isBlockStatement)(clone.body) ? (0, types_12.functionExpression)(null, clone.params, clone.body, clone.generator, clone.async) : clone;
|
|
1187
|
+
const { workletName, reactName } = makeWorkletName(fun, state);
|
|
1188
|
+
let mutatedClosureVariables;
|
|
1189
|
+
if (state.opts.bundleMode) {
|
|
1190
|
+
mutatedClosureVariables = closureVariables.map((variable) => (0, types_12.cloneNode)(variable, true));
|
|
1191
|
+
} else {
|
|
1192
|
+
mutatedClosureVariables = closureVariables;
|
|
1193
|
+
}
|
|
1194
|
+
let [funString, sourceMapString] = (0, workletStringCode_1.buildWorkletString)(transformed.ast, state, mutatedClosureVariables, workletName, transformed.map);
|
|
1195
|
+
(0, assert_1.strict)(funString, "`funString` is undefined.");
|
|
1196
|
+
const workletHash = hash(funString);
|
|
1197
|
+
let lineOffset = 1;
|
|
1198
|
+
if (closureVariables.length > 0) {
|
|
1199
|
+
lineOffset -= closureVariables.length + 2;
|
|
1200
|
+
}
|
|
1201
|
+
const pathForStringDefinitions = fun.parentPath.isProgram() ? fun : fun.findParent((path) => {
|
|
1202
|
+
var _a2, _b;
|
|
1203
|
+
return (_b = (_a2 = path.parentPath) === null || _a2 === void 0 ? void 0 : _a2.isProgram()) !== null && _b !== void 0 ? _b : false;
|
|
1204
|
+
});
|
|
1205
|
+
(0, assert_1.strict)(pathForStringDefinitions, "`pathForStringDefinitions` is null.");
|
|
1206
|
+
(0, assert_1.strict)(pathForStringDefinitions.parentPath, "`pathForStringDefinitions.parentPath` is null.");
|
|
1207
|
+
const initDataId = pathForStringDefinitions.parentPath.scope.generateUidIdentifier(`worklet_${workletHash}_init_data`);
|
|
1208
|
+
const shouldIncludeInitData = !state.opts.omitNativeOnlyData && !state.opts.bundleMode;
|
|
1209
|
+
const shouldEmitBytecode = !!state.opts.hermesBytecode && (0, utils_1.isRelease)(state) && shouldIncludeInitData;
|
|
1210
|
+
const bytecode = shouldEmitBytecode ? (0, hermesBytecode_1.compileWorkletToHbc)(funString, workletHash, state) : null;
|
|
1211
|
+
const initDataObjectExpression = (0, types_12.objectExpression)(bytecode ? [
|
|
1212
|
+
(0, types_12.objectProperty)((0, types_12.identifier)("bytecode"), (0, types_12.memberExpression)((0, types_12.newExpression)((0, types_12.identifier)("Uint8Array"), [
|
|
1213
|
+
(0, types_12.arrayExpression)(Array.from(bytecode, (byte) => (0, types_12.numericLiteral)(byte)))
|
|
1214
|
+
]), (0, types_12.identifier)("buffer")))
|
|
1215
|
+
] : [(0, types_12.objectProperty)((0, types_12.identifier)("code"), (0, types_12.stringLiteral)(funString))]);
|
|
1216
|
+
const shouldInjectLocation = !(0, utils_1.isRelease)(state);
|
|
1217
|
+
if (shouldInjectLocation) {
|
|
1218
|
+
let location = state.file.opts.filename;
|
|
1219
|
+
if (state.opts.relativeSourceLocation) {
|
|
1220
|
+
location = (0, path_1.relative)(state.cwd, location);
|
|
1221
|
+
sourceMapString = sourceMapString === null || sourceMapString === void 0 ? void 0 : sourceMapString.replace(toPosix(state.file.opts.filename), toPosix(location));
|
|
1222
|
+
}
|
|
1223
|
+
location = toPosix(location);
|
|
1224
|
+
initDataObjectExpression.properties.push((0, types_12.objectProperty)((0, types_12.identifier)("location"), (0, types_12.stringLiteral)(location)));
|
|
1225
|
+
}
|
|
1226
|
+
if (!bytecode && sourceMapString) {
|
|
1227
|
+
initDataObjectExpression.properties.push((0, types_12.objectProperty)((0, types_12.identifier)("sourceMap"), (0, types_12.stringLiteral)(sourceMapString)));
|
|
1228
|
+
}
|
|
1229
|
+
if (shouldIncludeInitData) {
|
|
1230
|
+
const initDataDeclaration = (0, types_12.variableDeclaration)("const", [
|
|
1231
|
+
(0, types_12.variableDeclarator)(initDataId, initDataObjectExpression)
|
|
1232
|
+
]);
|
|
1233
|
+
if (limitInitDataHoisting) {
|
|
1234
|
+
fun.getFunctionParent().node.body.body.unshift(initDataDeclaration);
|
|
1235
|
+
} else {
|
|
1236
|
+
pathForStringDefinitions.insertBefore(initDataDeclaration);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
(0, assert_1.strict)(!(0, types_12.isFunctionDeclaration)(funExpression), "`funExpression` is a `FunctionDeclaration`.");
|
|
1240
|
+
(0, assert_1.strict)(!(0, types_12.isObjectMethod)(funExpression), "`funExpression` is an `ObjectMethod`.");
|
|
1241
|
+
const statements = [
|
|
1242
|
+
(0, types_12.variableDeclaration)("const", [
|
|
1243
|
+
(0, types_12.variableDeclarator)((0, types_12.identifier)(reactName), funExpression)
|
|
1244
|
+
]),
|
|
1245
|
+
(0, types_12.expressionStatement)((0, types_12.assignmentExpression)("=", (0, types_12.memberExpression)((0, types_12.identifier)(reactName), (0, types_12.identifier)("__closure"), false), (0, types_12.objectExpression)(closureVariables.map((variable) => !state.opts.bundleMode && variable.name.endsWith(types_2.workletClassFactorySuffix) ? (0, types_12.objectProperty)((0, types_12.identifier)(variable.name), (0, types_12.memberExpression)((0, types_12.identifier)(variable.name.slice(0, variable.name.length - types_2.workletClassFactorySuffix.length)), (0, types_12.identifier)(variable.name))) : (0, types_12.objectProperty)((0, types_12.cloneNode)(variable, true), (0, types_12.cloneNode)(variable, true), false, true))))),
|
|
1246
|
+
(0, types_12.expressionStatement)((0, types_12.assignmentExpression)("=", (0, types_12.memberExpression)((0, types_12.identifier)(reactName), (0, types_12.identifier)("__workletHash"), false), (0, types_12.numericLiteral)(workletHash)))
|
|
1247
|
+
];
|
|
1248
|
+
const shouldInjectVersion = !(0, utils_1.isRelease)(state);
|
|
1249
|
+
if (shouldInjectVersion) {
|
|
1250
|
+
statements.push((0, types_12.expressionStatement)((0, types_12.assignmentExpression)("=", (0, types_12.memberExpression)((0, types_12.identifier)(reactName), (0, types_12.identifier)("__pluginVersion")), (0, types_12.stringLiteral)(shouldMockVersion() ? MOCK_VERSION : REAL_VERSION))));
|
|
1251
|
+
}
|
|
1252
|
+
if (shouldIncludeInitData) {
|
|
1253
|
+
statements.push((0, types_12.expressionStatement)((0, types_12.assignmentExpression)("=", (0, types_12.memberExpression)((0, types_12.identifier)(reactName), (0, types_12.identifier)("__initData"), false), (0, types_12.cloneNode)(initDataId, true))));
|
|
1254
|
+
}
|
|
1255
|
+
if (!(0, utils_1.isRelease)(state) && !state.opts.bundleMode) {
|
|
1256
|
+
statements.unshift((0, types_12.variableDeclaration)("const", [
|
|
1257
|
+
(0, types_12.variableDeclarator)((0, types_12.identifier)("_e"), (0, types_12.arrayExpression)([
|
|
1258
|
+
(0, types_12.newExpression)((0, types_12.memberExpression)((0, types_12.identifier)("global"), (0, types_12.identifier)("Error")), []),
|
|
1259
|
+
(0, types_12.numericLiteral)(lineOffset),
|
|
1260
|
+
(0, types_12.numericLiteral)(-27)
|
|
1261
|
+
// the placement of opening bracket after Exception in line that defined '_e' variable
|
|
1262
|
+
]))
|
|
1263
|
+
]));
|
|
1264
|
+
statements.push((0, types_12.expressionStatement)((0, types_12.assignmentExpression)("=", (0, types_12.memberExpression)((0, types_12.identifier)(reactName), (0, types_12.identifier)("__stackDetails"), false), (0, types_12.identifier)("_e"))));
|
|
1265
|
+
}
|
|
1266
|
+
statements.push((0, types_12.returnStatement)((0, types_12.identifier)(reactName)));
|
|
1267
|
+
const factoryParams = closureVariables.map((variableId) => {
|
|
1268
|
+
const clonedId = (0, types_12.cloneNode)(variableId, true);
|
|
1269
|
+
if (!state.opts.bundleMode && clonedId.name.endsWith(types_2.workletClassFactorySuffix)) {
|
|
1270
|
+
clonedId.name = clonedId.name.slice(0, clonedId.name.length - types_2.workletClassFactorySuffix.length);
|
|
1271
|
+
}
|
|
1272
|
+
return clonedId;
|
|
1273
|
+
});
|
|
1274
|
+
if (shouldIncludeInitData) {
|
|
1275
|
+
factoryParams.unshift((0, types_12.cloneNode)(initDataId, true));
|
|
1276
|
+
}
|
|
1277
|
+
const factoryParamObjectPattern = (0, types_12.objectPattern)(factoryParams.map((param) => (0, types_12.objectProperty)((0, types_12.cloneNode)(param, true), (0, types_12.cloneNode)(param, true), false, true)));
|
|
1278
|
+
const factory = (0, types_12.functionExpression)((0, types_12.identifier)(workletName + "Factory"), [factoryParamObjectPattern], (0, types_12.blockStatement)(statements));
|
|
1279
|
+
const factoryCallArgs = factoryParams.map((param) => (0, types_12.cloneNode)(param, true));
|
|
1280
|
+
const factoryCallParamPack = (0, types_12.objectExpression)(factoryCallArgs.map((param) => (0, types_12.objectProperty)((0, types_12.cloneNode)(param, true), (0, types_12.cloneNode)(param, true), false, true)));
|
|
1281
|
+
if (state.opts.bundleMode) {
|
|
1282
|
+
(0, imports_1.updateRelativeRequires)(factory, state);
|
|
1283
|
+
(0, generate_1.generateWorkletFile)(moduleBindingsToImport, relativeBindingsToImport, factory, workletHash, state);
|
|
1284
|
+
}
|
|
1285
|
+
factory.workletized = true;
|
|
1286
|
+
return { factory, factoryCallParamPack, workletHash };
|
|
1287
|
+
}
|
|
1288
|
+
function hasDirective(path, directiveText) {
|
|
1289
|
+
if (!path.node.body) {
|
|
1290
|
+
return false;
|
|
1291
|
+
}
|
|
1292
|
+
const bodyPath = path.get("body");
|
|
1293
|
+
let has = false;
|
|
1294
|
+
if (bodyPath.isBlockStatement()) {
|
|
1295
|
+
has = bodyPath.get("directives").some((directivePath) => {
|
|
1296
|
+
if (directivePath.isDirective() && directivePath.node.value.value === directiveText) {
|
|
1297
|
+
return true;
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
return has;
|
|
1302
|
+
}
|
|
1303
|
+
function stripWorkletDirectives(fun) {
|
|
1304
|
+
fun.traverse({
|
|
1305
|
+
DirectiveLiteral(nodePath) {
|
|
1306
|
+
if ((nodePath.node.value === "worklet" || nodePath.node.value === "no-worklet-closure" || nodePath.node.value === "limit-init-data-hoisting") && nodePath.getFunctionParent() === fun) {
|
|
1307
|
+
nodePath.parentPath.remove();
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
function shouldMockVersion() {
|
|
1313
|
+
return process.env.WORKLETS_JEST_SHOULD_MOCK_VERSION === "1";
|
|
1314
|
+
}
|
|
1315
|
+
function hash(str) {
|
|
1316
|
+
let i = str.length;
|
|
1317
|
+
let hash1 = 5381;
|
|
1318
|
+
let hash2 = 52711;
|
|
1319
|
+
while (i--) {
|
|
1320
|
+
const char = str.charCodeAt(i);
|
|
1321
|
+
hash1 = hash1 * 33 ^ char;
|
|
1322
|
+
hash2 = hash2 * 33 ^ char;
|
|
1323
|
+
}
|
|
1324
|
+
return (hash1 >>> 0) * 4096 + (hash2 >>> 0);
|
|
1325
|
+
}
|
|
1326
|
+
function makeWorkletName(fun, state) {
|
|
1327
|
+
let source = "unknownFile";
|
|
1328
|
+
if (state.file.opts.filename) {
|
|
1329
|
+
const filepath = state.file.opts.filename;
|
|
1330
|
+
source = (0, path_1.basename)(filepath);
|
|
1331
|
+
const splitFilepath = filepath.split(/[\\/]/);
|
|
1332
|
+
const nodeModulesIndex = splitFilepath.indexOf("node_modules");
|
|
1333
|
+
if (nodeModulesIndex !== -1) {
|
|
1334
|
+
const libraryName = splitFilepath[nodeModulesIndex + 1];
|
|
1335
|
+
source = `${libraryName}_${source}`;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
const suffix = `${source}${state.workletNumber++}`;
|
|
1339
|
+
let reactName = "";
|
|
1340
|
+
if ((0, types_12.isObjectMethod)(fun.node) && (0, types_12.isIdentifier)(fun.node.key)) {
|
|
1341
|
+
reactName = fun.node.key.name;
|
|
1342
|
+
} else if (((0, types_12.isFunctionDeclaration)(fun.node) || (0, types_12.isFunctionExpression)(fun.node)) && (0, types_12.isIdentifier)(fun.node.id)) {
|
|
1343
|
+
reactName = fun.node.id.name;
|
|
1344
|
+
}
|
|
1345
|
+
const workletName = reactName ? (0, types_12.toIdentifier)(`${reactName}_${suffix}`) : (0, types_12.toIdentifier)(suffix);
|
|
1346
|
+
reactName = reactName || (0, types_12.toIdentifier)(suffix);
|
|
1347
|
+
return { workletName, reactName };
|
|
1348
|
+
}
|
|
1349
|
+
function toPosix(p) {
|
|
1350
|
+
return path_1.sep === "/" ? p : p.split(path_1.sep).join("/");
|
|
1351
|
+
}
|
|
1352
|
+
var extraPlugins = [
|
|
1353
|
+
require.resolve("@babel/plugin-transform-shorthand-properties"),
|
|
1354
|
+
require.resolve("@babel/plugin-transform-arrow-functions"),
|
|
1355
|
+
require.resolve("@babel/plugin-transform-optional-chaining"),
|
|
1356
|
+
require.resolve("@babel/plugin-transform-nullish-coalescing-operator"),
|
|
1357
|
+
[
|
|
1358
|
+
require.resolve("@babel/plugin-transform-template-literals"),
|
|
1359
|
+
{ loose: true }
|
|
1360
|
+
]
|
|
1361
|
+
];
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
|
|
1365
|
+
// lib/workletFactoryCall.js
|
|
1366
|
+
var require_workletFactoryCall = __commonJS({
|
|
1367
|
+
"lib/workletFactoryCall.js"(exports2) {
|
|
1368
|
+
"use strict";
|
|
1369
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1370
|
+
exports2.makeWorkletFactoryCall = makeWorkletFactoryCall;
|
|
1371
|
+
var types_12 = require("@babel/types");
|
|
1372
|
+
var types_2 = require_types();
|
|
1373
|
+
var workletFactory_1 = require_workletFactory();
|
|
1374
|
+
function makeWorkletFactoryCall(path, state) {
|
|
1375
|
+
const { factory, factoryCallParamPack, workletHash } = (0, workletFactory_1.makeWorkletFactory)(path, state);
|
|
1376
|
+
let factoryCall;
|
|
1377
|
+
if (state.opts.bundleMode) {
|
|
1378
|
+
factoryCall = (0, types_12.callExpression)((0, types_12.memberExpression)((0, types_12.callExpression)((0, types_12.identifier)("require"), [
|
|
1379
|
+
(0, types_12.stringLiteral)(`react-native-worklets/${types_2.generatedWorkletsDir}/${workletHash}.js`)
|
|
1380
|
+
]), (0, types_12.identifier)("default")), [factoryCallParamPack]);
|
|
1381
|
+
} else {
|
|
1382
|
+
factoryCall = (0, types_12.callExpression)(factory, [factoryCallParamPack]);
|
|
1383
|
+
}
|
|
1384
|
+
addStackTraceDataToWorkletFactory(path, factoryCall);
|
|
1385
|
+
const replacement = factoryCall;
|
|
1386
|
+
return replacement;
|
|
1387
|
+
}
|
|
1388
|
+
function addStackTraceDataToWorkletFactory(path, workletFactoryCall) {
|
|
1389
|
+
const originalWorkletLocation = path.node.loc;
|
|
1390
|
+
if (originalWorkletLocation) {
|
|
1391
|
+
workletFactoryCall.callee.loc = {
|
|
1392
|
+
filename: originalWorkletLocation.filename,
|
|
1393
|
+
identifierName: originalWorkletLocation.identifierName,
|
|
1394
|
+
start: originalWorkletLocation.start,
|
|
1395
|
+
end: originalWorkletLocation.start
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
});
|
|
1401
|
+
|
|
1402
|
+
// lib/workletSubstitution.js
|
|
1403
|
+
var require_workletSubstitution = __commonJS({
|
|
1404
|
+
"lib/workletSubstitution.js"(exports2) {
|
|
1405
|
+
"use strict";
|
|
1406
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1407
|
+
exports2.processIfWithWorkletDirective = processIfWithWorkletDirective;
|
|
1408
|
+
exports2.processWorklet = processWorklet;
|
|
1409
|
+
exports2.substituteObjectMethodWithObjectProperty = substituteObjectMethodWithObjectProperty;
|
|
1410
|
+
var types_12 = require("@babel/types");
|
|
1411
|
+
var types_2 = require_types();
|
|
1412
|
+
var utils_1 = require_utils();
|
|
1413
|
+
var workletFactoryCall_1 = require_workletFactoryCall();
|
|
1414
|
+
function processIfWithWorkletDirective(path, state) {
|
|
1415
|
+
if (!(0, types_12.isBlockStatement)(path.node.body)) {
|
|
1416
|
+
return false;
|
|
1417
|
+
}
|
|
1418
|
+
if (!hasWorkletDirective(path.node.body.directives)) {
|
|
1419
|
+
return false;
|
|
1420
|
+
}
|
|
1421
|
+
processWorklet(path, state);
|
|
1422
|
+
return true;
|
|
1423
|
+
}
|
|
1424
|
+
function processWorklet(path, state) {
|
|
1425
|
+
path.traverse({
|
|
1426
|
+
// @ts-expect-error TypeScript doesn't like this syntax here.
|
|
1427
|
+
[types_2.WorkletizableFunction](subPath, passedState) {
|
|
1428
|
+
processIfWithWorkletDirective(subPath, passedState);
|
|
1429
|
+
}
|
|
1430
|
+
}, state);
|
|
1431
|
+
const workletFactoryCall = (0, workletFactoryCall_1.makeWorkletFactoryCall)(path, state);
|
|
1432
|
+
substituteWorkletWithWorkletFactoryCall(path, workletFactoryCall);
|
|
1433
|
+
path.scope.getProgramParent().crawl();
|
|
1434
|
+
}
|
|
1435
|
+
function hasWorkletDirective(directives) {
|
|
1436
|
+
return directives.some((directive) => (0, types_12.isDirectiveLiteral)(directive.value) && directive.value.value === "worklet");
|
|
1437
|
+
}
|
|
1438
|
+
function substituteWorkletWithWorkletFactoryCall(path, workletFactoryCall) {
|
|
1439
|
+
var _a;
|
|
1440
|
+
if (path.isObjectMethod()) {
|
|
1441
|
+
substituteObjectMethodWithObjectProperty(path, workletFactoryCall);
|
|
1442
|
+
} else {
|
|
1443
|
+
const name = "id" in path.node ? (_a = path.node.id) === null || _a === void 0 ? void 0 : _a.name : void 0;
|
|
1444
|
+
(0, utils_1.replaceWithFactoryCall)(path, name, workletFactoryCall);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
function substituteObjectMethodWithObjectProperty(path, workletFactoryCall) {
|
|
1448
|
+
const replacement = (0, types_12.objectProperty)(path.node.key, workletFactoryCall);
|
|
1449
|
+
path.replaceWith(replacement);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
});
|
|
1453
|
+
|
|
1454
|
+
// lib/objectWorklets.js
|
|
1455
|
+
var require_objectWorklets = __commonJS({
|
|
1456
|
+
"lib/objectWorklets.js"(exports2) {
|
|
1457
|
+
"use strict";
|
|
1458
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1459
|
+
exports2.tryProcessingNode = tryProcessingNode;
|
|
1460
|
+
exports2.processWorkletizableObject = processWorkletizableObject;
|
|
1461
|
+
var findWorklet_1 = require_findWorklet();
|
|
1462
|
+
var types_12 = require_types();
|
|
1463
|
+
var workletSubstitution_12 = require_workletSubstitution();
|
|
1464
|
+
function tryProcessingNode(arg, state, acceptWorkletizableFunction, acceptObject) {
|
|
1465
|
+
var _a;
|
|
1466
|
+
const maybeWorklet = (0, findWorklet_1.findWorklet)(arg, state, acceptWorkletizableFunction, acceptObject);
|
|
1467
|
+
if (!maybeWorklet || ((_a = maybeWorklet.getFunctionParent()) === null || _a === void 0 ? void 0 : _a.node.workletized)) {
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
if ((0, types_12.isWorkletizableFunctionPath)(maybeWorklet)) {
|
|
1471
|
+
(0, workletSubstitution_12.processWorklet)(maybeWorklet, state);
|
|
1472
|
+
} else if ((0, types_12.isWorkletizableObjectPath)(maybeWorklet)) {
|
|
1473
|
+
processWorkletizableObject(maybeWorklet, state);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
function processWorkletizableObject(path, state) {
|
|
1477
|
+
const properties = path.get("properties");
|
|
1478
|
+
for (const property of properties) {
|
|
1479
|
+
if (property.isObjectMethod()) {
|
|
1480
|
+
(0, workletSubstitution_12.processWorklet)(property, state);
|
|
1481
|
+
} else if (property.isObjectProperty()) {
|
|
1482
|
+
const value = property.get("value");
|
|
1483
|
+
tryProcessingNode(
|
|
1484
|
+
value,
|
|
1485
|
+
state,
|
|
1486
|
+
true,
|
|
1487
|
+
// acceptWorkletizableFunction
|
|
1488
|
+
false
|
|
1489
|
+
// acceptObject
|
|
1490
|
+
);
|
|
1491
|
+
} else {
|
|
1492
|
+
throw new Error(`'${property.type}' as to-be workletized argument is not supported for object hooks.`);
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
});
|
|
1498
|
+
|
|
1499
|
+
// lib/autoworkletization.js
|
|
1500
|
+
var require_autoworkletization = __commonJS({
|
|
1501
|
+
"lib/autoworkletization.js"(exports2) {
|
|
1502
|
+
"use strict";
|
|
1503
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1504
|
+
exports2.processIfAutoworkletizableCallback = processIfAutoworkletizableCallback;
|
|
1505
|
+
exports2.processCalleesAutoworkletizableCallbacks = processCalleesAutoworkletizableCallbacks;
|
|
1506
|
+
var types_12 = require("@babel/types");
|
|
1507
|
+
var gestureHandlerAutoworkletization_1 = require_gestureHandlerAutoworkletization();
|
|
1508
|
+
var layoutAnimationAutoworkletization_1 = require_layoutAnimationAutoworkletization();
|
|
1509
|
+
var objectWorklets_1 = require_objectWorklets();
|
|
1510
|
+
var workletSubstitution_12 = require_workletSubstitution();
|
|
1511
|
+
var reanimatedObjectHooks = /* @__PURE__ */ new Set([
|
|
1512
|
+
"useAnimatedScrollHandler",
|
|
1513
|
+
...Array.from(gestureHandlerAutoworkletization_1.gestureHandlerObjectHooks)
|
|
1514
|
+
]);
|
|
1515
|
+
var reanimatedFunctionHooks = /* @__PURE__ */ new Set([
|
|
1516
|
+
"useFrameCallback",
|
|
1517
|
+
"useAnimatedStyle",
|
|
1518
|
+
"useAnimatedProps",
|
|
1519
|
+
"createAnimatedPropAdapter",
|
|
1520
|
+
"useDerivedValue",
|
|
1521
|
+
"useAnimatedScrollHandler",
|
|
1522
|
+
"useAnimatedReaction",
|
|
1523
|
+
// animations' callbacks
|
|
1524
|
+
"withTiming",
|
|
1525
|
+
"withSpring",
|
|
1526
|
+
"withDecay",
|
|
1527
|
+
"withRepeat",
|
|
1528
|
+
// scheduling functions
|
|
1529
|
+
"runOnUI",
|
|
1530
|
+
"executeOnUIRuntimeSync",
|
|
1531
|
+
"scheduleOnUI",
|
|
1532
|
+
"runOnUISync",
|
|
1533
|
+
"runOnUIAsync",
|
|
1534
|
+
"runOnRuntime",
|
|
1535
|
+
"runOnRuntimeSync",
|
|
1536
|
+
"runOnRuntimeAsync",
|
|
1537
|
+
"scheduleOnRuntime",
|
|
1538
|
+
"runOnRuntimeSyncWithId",
|
|
1539
|
+
"scheduleOnRuntimeWithId"
|
|
1540
|
+
]);
|
|
1541
|
+
var reanimatedFunctionArgsToWorkletize = new Map([
|
|
1542
|
+
["useFrameCallback", [0]],
|
|
1543
|
+
["useAnimatedStyle", [0]],
|
|
1544
|
+
["useAnimatedProps", [0]],
|
|
1545
|
+
["createAnimatedPropAdapter", [0]],
|
|
1546
|
+
["useDerivedValue", [0]],
|
|
1547
|
+
["useAnimatedScrollHandler", [0]],
|
|
1548
|
+
["useAnimatedReaction", [0, 1]],
|
|
1549
|
+
["withTiming", [2]],
|
|
1550
|
+
["withSpring", [2]],
|
|
1551
|
+
["withDecay", [1]],
|
|
1552
|
+
["withRepeat", [3]],
|
|
1553
|
+
["runOnUI", [0]],
|
|
1554
|
+
["executeOnUIRuntimeSync", [0]],
|
|
1555
|
+
["scheduleOnUI", [0]],
|
|
1556
|
+
["runOnUISync", [0]],
|
|
1557
|
+
["runOnUIAsync", [0]],
|
|
1558
|
+
["runOnRuntime", [1]],
|
|
1559
|
+
["runOnRuntimeSync", [1]],
|
|
1560
|
+
["runOnRuntimeAsync", [1]],
|
|
1561
|
+
["scheduleOnRuntime", [1]],
|
|
1562
|
+
["runOnRuntimeSyncWithId", [1]],
|
|
1563
|
+
["scheduleOnRuntimeWithId", [1]],
|
|
1564
|
+
...Array.from(gestureHandlerAutoworkletization_1.gestureHandlerObjectHooks).map((name) => [name, [0]]),
|
|
1565
|
+
...Array.from(gestureHandlerAutoworkletization_1.gestureHandlerBuilderMethods).map((name) => [name, [0]])
|
|
1566
|
+
]);
|
|
1567
|
+
function processIfAutoworkletizableCallback(path, state) {
|
|
1568
|
+
if ((0, gestureHandlerAutoworkletization_1.isGestureHandlerEventCallback)(path) || (0, layoutAnimationAutoworkletization_1.isLayoutAnimationCallback)(path)) {
|
|
1569
|
+
(0, workletSubstitution_12.processWorklet)(path, state);
|
|
1570
|
+
return true;
|
|
1571
|
+
}
|
|
1572
|
+
return false;
|
|
1573
|
+
}
|
|
1574
|
+
function processCalleesAutoworkletizableCallbacks(path, state) {
|
|
1575
|
+
const callee = (0, types_12.isSequenceExpression)(path.node.callee) ? path.node.callee.expressions[path.node.callee.expressions.length - 1] : path.node.callee;
|
|
1576
|
+
const name = "name" in callee ? callee.name : "property" in callee && "name" in callee.property ? callee.property.name : void 0;
|
|
1577
|
+
if (name === void 0) {
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
if (reanimatedFunctionHooks.has(name) || reanimatedObjectHooks.has(name)) {
|
|
1581
|
+
const acceptWorkletizableFunction = reanimatedFunctionHooks.has(name);
|
|
1582
|
+
const acceptObject = reanimatedObjectHooks.has(name);
|
|
1583
|
+
const argIndices = reanimatedFunctionArgsToWorkletize.get(name);
|
|
1584
|
+
const args = path.get("arguments").filter((_, index) => argIndices.includes(index));
|
|
1585
|
+
processArgs(args, state, acceptWorkletizableFunction, acceptObject);
|
|
1586
|
+
} else if (!(0, types_12.isV8IntrinsicIdentifier)(callee) && (0, gestureHandlerAutoworkletization_1.isGestureObjectEventCallbackMethod)(callee)) {
|
|
1587
|
+
const args = path.get("arguments");
|
|
1588
|
+
processArgs(args, state, true, true);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
function processArgs(args, state, acceptWorkletizableFunction, acceptObject) {
|
|
1592
|
+
args.forEach((arg) => {
|
|
1593
|
+
(0, objectWorklets_1.tryProcessingNode)(arg, state, acceptWorkletizableFunction, acceptObject);
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
});
|
|
1598
|
+
|
|
1599
|
+
// lib/bundleMode.js
|
|
1600
|
+
var require_bundleMode = __commonJS({
|
|
1601
|
+
"lib/bundleMode.js"(exports2) {
|
|
1602
|
+
"use strict";
|
|
1603
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1604
|
+
exports2.toggleBundleMode = toggleBundleMode;
|
|
1605
|
+
var types_12 = require("@babel/types");
|
|
1606
|
+
var path_1 = require("path");
|
|
1607
|
+
var WORKLETS_PACKAGE = "react-native-worklets";
|
|
1608
|
+
var WORKLETS_SRC_DIR = (0, path_1.join)(WORKLETS_PACKAGE, "src");
|
|
1609
|
+
var WORKLETS_LIB_DIR = (0, path_1.join)(WORKLETS_PACKAGE, "lib", "module");
|
|
1610
|
+
var togglePaths = [
|
|
1611
|
+
(0, path_1.join)(WORKLETS_SRC_DIR, "index.ts"),
|
|
1612
|
+
(0, path_1.join)(WORKLETS_SRC_DIR, "debug", "bundleMode.native.ts"),
|
|
1613
|
+
(0, path_1.join)(WORKLETS_LIB_DIR, "index.js"),
|
|
1614
|
+
(0, path_1.join)(WORKLETS_LIB_DIR, "debug", "bundleMode.native.js")
|
|
1615
|
+
];
|
|
1616
|
+
function toggleBundleMode(path, state) {
|
|
1617
|
+
if (!state.opts.bundleMode || !togglePaths.some((togglePath) => {
|
|
1618
|
+
var _a;
|
|
1619
|
+
return (_a = state.filename) === null || _a === void 0 ? void 0 : _a.endsWith(togglePath);
|
|
1620
|
+
})) {
|
|
1621
|
+
return;
|
|
1622
|
+
}
|
|
1623
|
+
const expressionPath = path.get("expression");
|
|
1624
|
+
if (!expressionPath.isAssignmentExpression()) {
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
const left = expressionPath.get("left");
|
|
1628
|
+
if (!left.isMemberExpression()) {
|
|
1629
|
+
return;
|
|
1630
|
+
}
|
|
1631
|
+
const object = left.get("object");
|
|
1632
|
+
const property = left.get("property");
|
|
1633
|
+
if (!object.isIdentifier() || object.node.name !== "globalThis" || !property.isIdentifier() || property.node.name !== "_WORKLETS_BUNDLE_MODE_ENABLED") {
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
const right = expressionPath.get("right");
|
|
1637
|
+
right.replaceWith((0, types_12.booleanLiteral)(true));
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
|
|
1642
|
+
// lib/class.js
|
|
1643
|
+
var require_class = __commonJS({
|
|
1644
|
+
"lib/class.js"(exports2) {
|
|
1645
|
+
"use strict";
|
|
1646
|
+
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
1647
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1648
|
+
};
|
|
1649
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1650
|
+
exports2.processIfWorkletClass = processIfWorkletClass;
|
|
1651
|
+
var generator_1 = __importDefault(require("@babel/generator"));
|
|
1652
|
+
var traverse_1 = __importDefault(require("@babel/traverse"));
|
|
1653
|
+
var types_12 = require("@babel/types");
|
|
1654
|
+
var assert_1 = require("assert");
|
|
1655
|
+
var transform_1 = require_transform();
|
|
1656
|
+
var types_2 = require_types();
|
|
1657
|
+
var utils_1 = require_utils();
|
|
1658
|
+
var classWorkletMarker = "__workletClass";
|
|
1659
|
+
function processIfWorkletClass(classPath, state) {
|
|
1660
|
+
if (!isWorkletizableClass(classPath, state) || state.opts.bundleMode) {
|
|
1661
|
+
return false;
|
|
1662
|
+
}
|
|
1663
|
+
removeWorkletClassMarker(classPath.node.body);
|
|
1664
|
+
processClass(classPath, state);
|
|
1665
|
+
return true;
|
|
1666
|
+
}
|
|
1667
|
+
function processClass(classPath, state) {
|
|
1668
|
+
(0, assert_1.strict)(classPath.node.id);
|
|
1669
|
+
const className = classPath.node.id.name;
|
|
1670
|
+
const polyfilledClassAst = getPolyfilledAst(classPath.node, state);
|
|
1671
|
+
sortPolyfills(polyfilledClassAst);
|
|
1672
|
+
appendWorkletDirectiveToPolyfills(polyfilledClassAst.program.body);
|
|
1673
|
+
replaceClassDeclarationWithFactoryAndCall(polyfilledClassAst.program.body, className);
|
|
1674
|
+
polyfilledClassAst.program.body.push((0, types_12.returnStatement)((0, types_12.identifier)(className)));
|
|
1675
|
+
const factoryFactory = (0, types_12.functionExpression)(null, [], (0, types_12.blockStatement)([...polyfilledClassAst.program.body]));
|
|
1676
|
+
const factoryCall = (0, types_12.callExpression)(factoryFactory, []);
|
|
1677
|
+
(0, utils_1.replaceWithFactoryCall)(classPath, className, factoryCall);
|
|
1678
|
+
}
|
|
1679
|
+
function getPolyfilledAst(classNode, state) {
|
|
1680
|
+
var _a;
|
|
1681
|
+
const classCode = (0, generator_1.default)(classNode).code;
|
|
1682
|
+
const classWithPolyfills = (0, transform_1.workletTransformSync)(classCode, {
|
|
1683
|
+
extraPlugins: [
|
|
1684
|
+
"@babel/plugin-transform-class-properties",
|
|
1685
|
+
"@babel/plugin-transform-classes",
|
|
1686
|
+
"@babel/plugin-transform-unicode-regex",
|
|
1687
|
+
...(_a = state.opts.extraPlugins) !== null && _a !== void 0 ? _a : []
|
|
1688
|
+
],
|
|
1689
|
+
extraPresets: state.opts.extraPresets,
|
|
1690
|
+
filename: state.file.opts.filename,
|
|
1691
|
+
ast: true,
|
|
1692
|
+
babelrc: false,
|
|
1693
|
+
configFile: false
|
|
1694
|
+
});
|
|
1695
|
+
(0, assert_1.strict)(classWithPolyfills && classWithPolyfills.ast);
|
|
1696
|
+
return classWithPolyfills.ast;
|
|
1697
|
+
}
|
|
1698
|
+
function appendWorkletDirectiveToPolyfills(statements) {
|
|
1699
|
+
statements.forEach((statement) => {
|
|
1700
|
+
if ((0, types_12.isFunctionDeclaration)(statement)) {
|
|
1701
|
+
const workletDirective = (0, types_12.directive)((0, types_12.directiveLiteral)("worklet"));
|
|
1702
|
+
statement.body.directives.push(workletDirective);
|
|
1703
|
+
}
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
function replaceClassDeclarationWithFactoryAndCall(statements, className) {
|
|
1707
|
+
const classFactoryName = className + types_2.workletClassFactorySuffix;
|
|
1708
|
+
const classDeclarationIndex = getPolyfilledClassDeclarationIndex(statements, className);
|
|
1709
|
+
const classDeclarationToReplace = statements[classDeclarationIndex];
|
|
1710
|
+
const classDeclarationInit = classDeclarationToReplace.declarations[0].init;
|
|
1711
|
+
const classFactoryDeclaration = (0, types_12.functionDeclaration)((0, types_12.identifier)(classFactoryName), [], (0, types_12.blockStatement)([
|
|
1712
|
+
(0, types_12.variableDeclaration)("const", [
|
|
1713
|
+
(0, types_12.variableDeclarator)((0, types_12.identifier)(className), classDeclarationInit)
|
|
1714
|
+
]),
|
|
1715
|
+
(0, types_12.expressionStatement)((0, types_12.assignmentExpression)("=", (0, types_12.memberExpression)((0, types_12.identifier)(className), (0, types_12.identifier)(classFactoryName)), (0, types_12.identifier)(classFactoryName))),
|
|
1716
|
+
(0, types_12.returnStatement)((0, types_12.identifier)(className))
|
|
1717
|
+
], [(0, types_12.directive)((0, types_12.directiveLiteral)("worklet"))]));
|
|
1718
|
+
const newClassDeclaration = (0, types_12.variableDeclaration)("const", [
|
|
1719
|
+
(0, types_12.variableDeclarator)((0, types_12.identifier)(className), (0, types_12.callExpression)((0, types_12.identifier)(classFactoryName), []))
|
|
1720
|
+
]);
|
|
1721
|
+
statements.splice(classDeclarationIndex, 1, classFactoryDeclaration, newClassDeclaration);
|
|
1722
|
+
}
|
|
1723
|
+
function getPolyfilledClassDeclarationIndex(statements, className) {
|
|
1724
|
+
const index = statements.findIndex((statement) => (0, types_12.isVariableDeclaration)(statement) && statement.declarations.some((declaration) => (0, types_12.isIdentifier)(declaration.id) && declaration.id.name === className));
|
|
1725
|
+
(0, assert_1.strict)(index >= 0);
|
|
1726
|
+
return index;
|
|
1727
|
+
}
|
|
1728
|
+
function hasWorkletClassMarker(classBody) {
|
|
1729
|
+
return classBody.body.some((statement) => (0, types_12.isClassProperty)(statement) && (0, types_12.isIdentifier)(statement.key) && statement.key.name === classWorkletMarker);
|
|
1730
|
+
}
|
|
1731
|
+
function removeWorkletClassMarker(classBody) {
|
|
1732
|
+
classBody.body = classBody.body.filter((statement) => !(0, types_12.isClassProperty)(statement) || !(0, types_12.isIdentifier)(statement.key) || statement.key.name !== classWorkletMarker);
|
|
1733
|
+
}
|
|
1734
|
+
function sortPolyfills(ast) {
|
|
1735
|
+
const toSort = getPolyfillsToSort(ast);
|
|
1736
|
+
const sorted = topoSort(toSort);
|
|
1737
|
+
const toSortIndices = toSort.map((element) => element.index);
|
|
1738
|
+
const sortedIndices = sorted.map((element) => element.index);
|
|
1739
|
+
const statements = ast.program.body;
|
|
1740
|
+
const oldStatements = [...statements];
|
|
1741
|
+
for (let i = 0; i < toSort.length; i++) {
|
|
1742
|
+
const sourceIndex = sortedIndices[i];
|
|
1743
|
+
const targetIndex = toSortIndices[i];
|
|
1744
|
+
const source = oldStatements[sourceIndex];
|
|
1745
|
+
statements[targetIndex] = source;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
function getPolyfillsToSort(ast) {
|
|
1749
|
+
const polyfills = [];
|
|
1750
|
+
(0, traverse_1.default)(ast, {
|
|
1751
|
+
Program: {
|
|
1752
|
+
enter: (functionPath) => {
|
|
1753
|
+
const statements = functionPath.get("body");
|
|
1754
|
+
statements.forEach((statement, index) => {
|
|
1755
|
+
var _a;
|
|
1756
|
+
const bindingIdentifiers = statement.getBindingIdentifiers();
|
|
1757
|
+
if (!statement.isFunctionDeclaration() || !((_a = statement.node.id) === null || _a === void 0 ? void 0 : _a.name)) {
|
|
1758
|
+
return;
|
|
1759
|
+
}
|
|
1760
|
+
const element = {
|
|
1761
|
+
name: statement.node.id.name,
|
|
1762
|
+
index,
|
|
1763
|
+
dependencies: /* @__PURE__ */ new Set()
|
|
1764
|
+
};
|
|
1765
|
+
polyfills.push(element);
|
|
1766
|
+
statement.traverse({
|
|
1767
|
+
Identifier(path) {
|
|
1768
|
+
if (isOutsideDependency(path, bindingIdentifiers, statement)) {
|
|
1769
|
+
element.dependencies.add(path.node.name);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
});
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
});
|
|
1777
|
+
return polyfills;
|
|
1778
|
+
}
|
|
1779
|
+
function topoSort(toSort) {
|
|
1780
|
+
const sorted = [];
|
|
1781
|
+
const stack = /* @__PURE__ */ new Set();
|
|
1782
|
+
for (const element of toSort) {
|
|
1783
|
+
recursiveTopoSort(element, toSort, sorted, stack);
|
|
1784
|
+
}
|
|
1785
|
+
return sorted;
|
|
1786
|
+
}
|
|
1787
|
+
function recursiveTopoSort(current, toSort, sorted, stack) {
|
|
1788
|
+
if (stack.has(current.name)) {
|
|
1789
|
+
throw new Error("Cycle detected. This should never happen.");
|
|
1790
|
+
}
|
|
1791
|
+
if (sorted.find((element) => element.name === current.name)) {
|
|
1792
|
+
return;
|
|
1793
|
+
}
|
|
1794
|
+
stack.add(current.name);
|
|
1795
|
+
for (const dependency of current.dependencies) {
|
|
1796
|
+
if (!sorted.find((element) => element.name === dependency)) {
|
|
1797
|
+
const next = toSort.find((element) => element.name === dependency);
|
|
1798
|
+
(0, assert_1.strict)(next);
|
|
1799
|
+
recursiveTopoSort(next, toSort, sorted, stack);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
sorted.push(current);
|
|
1803
|
+
stack.delete(current.name);
|
|
1804
|
+
}
|
|
1805
|
+
function isOutsideDependency(identifierPath, bindingIdentifiers, functionPath) {
|
|
1806
|
+
return (
|
|
1807
|
+
// We don't care about identifiers that were just declared.
|
|
1808
|
+
identifierPath.isReferencedIdentifier() && // We don't care about identifiers that are bound in the scope.
|
|
1809
|
+
!(identifierPath.node.name in bindingIdentifiers) && // This I don't exactly understand, but the function identifier itself isn't in `bindingIdentifiers`,
|
|
1810
|
+
// but it return true on `hasOwnBinding`.
|
|
1811
|
+
!functionPath.scope.hasOwnBinding(identifierPath.node.name) && // `hasReference` returns true for global identifiers, like `Object`,
|
|
1812
|
+
// we don't want to include those.
|
|
1813
|
+
functionPath.scope.hasReference(identifierPath.node.name)
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
function isWorkletizableClass(classPath, state) {
|
|
1817
|
+
var _a;
|
|
1818
|
+
const className = (_a = classPath.node.id) === null || _a === void 0 ? void 0 : _a.name;
|
|
1819
|
+
const classNode = classPath.node;
|
|
1820
|
+
if (!className) {
|
|
1821
|
+
return false;
|
|
1822
|
+
}
|
|
1823
|
+
const isMarked = hasWorkletClassMarker(classNode.body);
|
|
1824
|
+
const isMemoizedNode = state.classesToWorkletize.some((record) => record.node === classNode);
|
|
1825
|
+
const isTopLevelMemoizedName = classPath.parentPath.isProgram() && state.classesToWorkletize.some((record) => record.name === className);
|
|
1826
|
+
state.classesToWorkletize = state.classesToWorkletize.filter((record) => record.node !== classNode && record.name !== className);
|
|
1827
|
+
const result = isMarked || isMemoizedNode || isTopLevelMemoizedName;
|
|
1828
|
+
return result;
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
});
|
|
1832
|
+
|
|
1833
|
+
// lib/contextObject.js
|
|
1834
|
+
var require_contextObject = __commonJS({
|
|
1835
|
+
"lib/contextObject.js"(exports2) {
|
|
1836
|
+
"use strict";
|
|
1837
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1838
|
+
exports2.contextObjectMarker = void 0;
|
|
1839
|
+
exports2.processIfWorkletContextObject = processIfWorkletContextObject;
|
|
1840
|
+
exports2.isContextObject = isContextObject;
|
|
1841
|
+
var types_12 = require("@babel/types");
|
|
1842
|
+
exports2.contextObjectMarker = "__workletContextObject";
|
|
1843
|
+
function processIfWorkletContextObject(path, _state) {
|
|
1844
|
+
if (!isContextObject(path.node)) {
|
|
1845
|
+
return false;
|
|
1846
|
+
}
|
|
1847
|
+
removeContextObjectMarker(path.node);
|
|
1848
|
+
processWorkletContextObject(path.node);
|
|
1849
|
+
return true;
|
|
1850
|
+
}
|
|
1851
|
+
function isContextObject(objectExpression) {
|
|
1852
|
+
return objectExpression.properties.some((property) => (0, types_12.isObjectProperty)(property) && (0, types_12.isIdentifier)(property.key) && property.key.name === exports2.contextObjectMarker);
|
|
1853
|
+
}
|
|
1854
|
+
function processWorkletContextObject(objectExpression) {
|
|
1855
|
+
const workletObjectFactory = (0, types_12.functionExpression)(null, [], (0, types_12.blockStatement)([(0, types_12.returnStatement)((0, types_12.cloneNode)(objectExpression))], [(0, types_12.directive)((0, types_12.directiveLiteral)("worklet"))]));
|
|
1856
|
+
objectExpression.properties.push((0, types_12.objectProperty)((0, types_12.identifier)(`${exports2.contextObjectMarker}Factory`), workletObjectFactory));
|
|
1857
|
+
}
|
|
1858
|
+
function removeContextObjectMarker(objectExpression) {
|
|
1859
|
+
objectExpression.properties = objectExpression.properties.filter((property) => !((0, types_12.isObjectProperty)(property) && (0, types_12.isIdentifier)(property.key) && property.key.name === exports2.contextObjectMarker));
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
});
|
|
1863
|
+
|
|
1864
|
+
// lib/file.js
|
|
1865
|
+
var require_file = __commonJS({
|
|
1866
|
+
"lib/file.js"(exports2) {
|
|
1867
|
+
"use strict";
|
|
1868
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1869
|
+
exports2.processIfWorkletFile = processIfWorkletFile;
|
|
1870
|
+
exports2.isImplicitContextObject = isImplicitContextObject;
|
|
1871
|
+
var types_12 = require("@babel/types");
|
|
1872
|
+
var contextObject_12 = require_contextObject();
|
|
1873
|
+
var types_2 = require_types();
|
|
1874
|
+
function processIfWorkletFile(path, state) {
|
|
1875
|
+
if (!path.node.directives.some((functionDirective) => functionDirective.value.value === "worklet")) {
|
|
1876
|
+
return false;
|
|
1877
|
+
}
|
|
1878
|
+
path.node.directives = path.node.directives.filter((functionDirective) => functionDirective.value.value !== "worklet");
|
|
1879
|
+
processWorkletFile(path, state);
|
|
1880
|
+
return true;
|
|
1881
|
+
}
|
|
1882
|
+
function processWorkletFile(programPath, state) {
|
|
1883
|
+
const statements = programPath.get("body");
|
|
1884
|
+
dehoistCommonJSExports(programPath.node);
|
|
1885
|
+
statements.forEach((statement) => {
|
|
1886
|
+
const candidatePath = getCandidate(statement);
|
|
1887
|
+
processWorkletizableEntity(candidatePath, state);
|
|
1888
|
+
});
|
|
1889
|
+
}
|
|
1890
|
+
function getCandidate(statementPath) {
|
|
1891
|
+
if (statementPath.isExportNamedDeclaration() || statementPath.isExportDefaultDeclaration()) {
|
|
1892
|
+
return statementPath.get("declaration");
|
|
1893
|
+
} else {
|
|
1894
|
+
return statementPath;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
function processWorkletizableEntity(nodePath, state) {
|
|
1898
|
+
var _a;
|
|
1899
|
+
if ((0, types_2.isWorkletizableFunctionPath)(nodePath)) {
|
|
1900
|
+
if (nodePath.isArrowFunctionExpression()) {
|
|
1901
|
+
replaceImplicitReturnWithBlock(nodePath.node);
|
|
1902
|
+
}
|
|
1903
|
+
appendWorkletDirective(nodePath.node.body);
|
|
1904
|
+
} else if ((0, types_2.isWorkletizableObjectPath)(nodePath)) {
|
|
1905
|
+
if (isImplicitContextObject(nodePath)) {
|
|
1906
|
+
appendWorkletContextObjectMarker(nodePath.node);
|
|
1907
|
+
} else {
|
|
1908
|
+
processWorkletAggregator(nodePath, state);
|
|
1909
|
+
}
|
|
1910
|
+
} else if (nodePath.isVariableDeclaration()) {
|
|
1911
|
+
processVariableDeclaration(nodePath, state);
|
|
1912
|
+
} else if (nodePath.isClassDeclaration()) {
|
|
1913
|
+
appendWorkletClassMarker(nodePath.node.body);
|
|
1914
|
+
if ((_a = nodePath.node.id) === null || _a === void 0 ? void 0 : _a.name) {
|
|
1915
|
+
state.classesToWorkletize.push({
|
|
1916
|
+
node: nodePath.node,
|
|
1917
|
+
name: nodePath.node.id.name
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
function processVariableDeclaration(variableDeclarationPath, state) {
|
|
1923
|
+
const declarations = variableDeclarationPath.get("declarations");
|
|
1924
|
+
declarations.forEach((declaration) => {
|
|
1925
|
+
const initPath = declaration.get("init");
|
|
1926
|
+
if (initPath.isExpression()) {
|
|
1927
|
+
processWorkletizableEntity(initPath, state);
|
|
1928
|
+
}
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
function processWorkletAggregator(objectPath, state) {
|
|
1932
|
+
const properties = objectPath.get("properties");
|
|
1933
|
+
properties.forEach((property) => {
|
|
1934
|
+
if (property.isObjectMethod()) {
|
|
1935
|
+
appendWorkletDirective(property.node.body);
|
|
1936
|
+
} else if (property.isObjectProperty()) {
|
|
1937
|
+
const valuePath = property.get("value");
|
|
1938
|
+
processWorkletizableEntity(valuePath, state);
|
|
1939
|
+
}
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
function replaceImplicitReturnWithBlock(path) {
|
|
1943
|
+
if (!(0, types_12.isBlockStatement)(path.body)) {
|
|
1944
|
+
path.body = (0, types_12.blockStatement)([(0, types_12.returnStatement)(path.body)]);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
function appendWorkletDirective(node) {
|
|
1948
|
+
if (!node.directives.some((functionDirective) => functionDirective.value.value === "worklet")) {
|
|
1949
|
+
node.directives.push((0, types_12.directive)((0, types_12.directiveLiteral)("worklet")));
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
function appendWorkletContextObjectMarker(objectExpression) {
|
|
1953
|
+
if (objectExpression.properties.some((value) => (0, types_12.isObjectProperty)(value) && (0, types_12.isIdentifier)(value.key) && value.key.name === contextObject_12.contextObjectMarker)) {
|
|
1954
|
+
return;
|
|
1955
|
+
}
|
|
1956
|
+
objectExpression.properties.push((0, types_12.objectProperty)((0, types_12.identifier)(`${contextObject_12.contextObjectMarker}`), (0, types_12.booleanLiteral)(true)));
|
|
1957
|
+
}
|
|
1958
|
+
function isImplicitContextObject(path) {
|
|
1959
|
+
const propertyPaths = path.get("properties");
|
|
1960
|
+
return propertyPaths.some((propertyPath) => {
|
|
1961
|
+
if (!propertyPath.isObjectMethod()) {
|
|
1962
|
+
return false;
|
|
1963
|
+
}
|
|
1964
|
+
return hasThisExpression(propertyPath);
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
function hasThisExpression(path) {
|
|
1968
|
+
let result = false;
|
|
1969
|
+
path.traverse({
|
|
1970
|
+
ThisExpression(thisPath) {
|
|
1971
|
+
result = true;
|
|
1972
|
+
thisPath.stop();
|
|
1973
|
+
}
|
|
1974
|
+
});
|
|
1975
|
+
return result;
|
|
1976
|
+
}
|
|
1977
|
+
function appendWorkletClassMarker(classBody) {
|
|
1978
|
+
classBody.body.push((0, types_12.classProperty)((0, types_12.identifier)("__workletClass"), (0, types_12.booleanLiteral)(true)));
|
|
1979
|
+
}
|
|
1980
|
+
function dehoistCommonJSExports(program) {
|
|
1981
|
+
const statements = program.body;
|
|
1982
|
+
let end = statements.length;
|
|
1983
|
+
let current = 0;
|
|
1984
|
+
while (current < end) {
|
|
1985
|
+
const statement = statements[current];
|
|
1986
|
+
if (!isCommonJSExport(statement)) {
|
|
1987
|
+
current++;
|
|
1988
|
+
continue;
|
|
1989
|
+
}
|
|
1990
|
+
const exportStatement = statements.splice(current, 1);
|
|
1991
|
+
statements.push(...exportStatement);
|
|
1992
|
+
end--;
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
function isCommonJSExport(statement) {
|
|
1996
|
+
return (0, types_12.isExpressionStatement)(statement) && (0, types_12.isAssignmentExpression)(statement.expression) && (0, types_12.isMemberExpression)(statement.expression.left) && (0, types_12.isIdentifier)(statement.expression.left.object) && statement.expression.left.object.name === "exports";
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
2000
|
+
|
|
2001
|
+
// lib/inlineStylesWarning.js
|
|
2002
|
+
var require_inlineStylesWarning = __commonJS({
|
|
2003
|
+
"lib/inlineStylesWarning.js"(exports2) {
|
|
2004
|
+
"use strict";
|
|
2005
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2006
|
+
exports2.processInlineStylesWarning = processInlineStylesWarning;
|
|
2007
|
+
var types_12 = require("@babel/types");
|
|
2008
|
+
var assert_1 = require("assert");
|
|
2009
|
+
var utils_1 = require_utils();
|
|
2010
|
+
function generateInlineStylesWarning(path) {
|
|
2011
|
+
return (0, types_12.callExpression)((0, types_12.arrowFunctionExpression)([], (0, types_12.blockStatement)([
|
|
2012
|
+
(0, types_12.expressionStatement)((0, types_12.callExpression)((0, types_12.memberExpression)((0, types_12.identifier)("console"), (0, types_12.identifier)("warn")), [
|
|
2013
|
+
(0, types_12.callExpression)((0, types_12.memberExpression)((0, types_12.callExpression)((0, types_12.identifier)("require"), [
|
|
2014
|
+
(0, types_12.stringLiteral)("react-native-reanimated")
|
|
2015
|
+
]), (0, types_12.identifier)("getUseOfValueInStyleWarning")), [])
|
|
2016
|
+
])),
|
|
2017
|
+
(0, types_12.returnStatement)(path.node)
|
|
2018
|
+
])), []);
|
|
2019
|
+
}
|
|
2020
|
+
function processPropertyValueForInlineStylesWarning(path) {
|
|
2021
|
+
if (path.isMemberExpression() && (0, types_12.isIdentifier)(path.node.property)) {
|
|
2022
|
+
if (!path.node.computed && path.node.property.name === "value") {
|
|
2023
|
+
path.replaceWith(generateInlineStylesWarning(path));
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
function processTransformPropertyForInlineStylesWarning(path) {
|
|
2028
|
+
if ((0, types_12.isArrayExpression)(path.node)) {
|
|
2029
|
+
const elements = path.get("elements");
|
|
2030
|
+
(0, assert_1.strict)(Array.isArray(elements), "`elements` should be an array.");
|
|
2031
|
+
for (const element of elements) {
|
|
2032
|
+
if (element.isObjectExpression()) {
|
|
2033
|
+
processStyleObjectForInlineStylesWarning(element);
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
function processStyleObjectForInlineStylesWarning(path) {
|
|
2039
|
+
const properties = path.get("properties");
|
|
2040
|
+
for (const property of properties) {
|
|
2041
|
+
if (property.isObjectProperty()) {
|
|
2042
|
+
const value = property.get("value");
|
|
2043
|
+
if ((0, types_12.isIdentifier)(property.node.key) && property.node.key.name === "transform") {
|
|
2044
|
+
processTransformPropertyForInlineStylesWarning(value);
|
|
2045
|
+
} else {
|
|
2046
|
+
processPropertyValueForInlineStylesWarning(value);
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
function processInlineStylesWarning(path, state) {
|
|
2052
|
+
if ((0, utils_1.isRelease)(state)) {
|
|
2053
|
+
return;
|
|
2054
|
+
}
|
|
2055
|
+
if (state.opts.disableInlineStylesWarning) {
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
if (path.node.name.name !== "style") {
|
|
2059
|
+
return;
|
|
2060
|
+
}
|
|
2061
|
+
if (!(0, types_12.isJSXExpressionContainer)(path.node.value)) {
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
const expression = path.get("value").get("expression");
|
|
2065
|
+
(0, assert_1.strict)(!Array.isArray(expression), "`expression` should not be an array.");
|
|
2066
|
+
if (expression.isArrayExpression()) {
|
|
2067
|
+
const elements = expression.get("elements");
|
|
2068
|
+
(0, assert_1.strict)(Array.isArray(elements), "`elements` should be an array.");
|
|
2069
|
+
for (const element of elements) {
|
|
2070
|
+
if (element.isObjectExpression()) {
|
|
2071
|
+
processStyleObjectForInlineStylesWarning(element);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
} else if (expression.isObjectExpression()) {
|
|
2075
|
+
processStyleObjectForInlineStylesWarning(expression);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
});
|
|
2080
|
+
|
|
2081
|
+
// lib/webOptimization.js
|
|
2082
|
+
var require_webOptimization = __commonJS({
|
|
2083
|
+
"lib/webOptimization.js"(exports2) {
|
|
2084
|
+
"use strict";
|
|
2085
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2086
|
+
exports2.substituteWebCallExpression = substituteWebCallExpression;
|
|
2087
|
+
var types_12 = require("@babel/types");
|
|
2088
|
+
function substituteWebCallExpression(path) {
|
|
2089
|
+
const callee = path.node.callee;
|
|
2090
|
+
if ((0, types_12.isIdentifier)(callee)) {
|
|
2091
|
+
const name = callee.name;
|
|
2092
|
+
if (name === "isWeb" || name === "shouldBeUseWeb") {
|
|
2093
|
+
path.replaceWith((0, types_12.booleanLiteral)(true));
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
});
|
|
2099
|
+
|
|
2100
|
+
// lib/plugin.js
|
|
2101
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2102
|
+
var autoworkletization_1 = require_autoworkletization();
|
|
2103
|
+
var bundleMode_1 = require_bundleMode();
|
|
2104
|
+
var class_1 = require_class();
|
|
2105
|
+
var contextObject_1 = require_contextObject();
|
|
2106
|
+
var file_1 = require_file();
|
|
2107
|
+
var globals_1 = require_globals();
|
|
2108
|
+
var inlineStylesWarning_1 = require_inlineStylesWarning();
|
|
2109
|
+
var types_1 = require_types();
|
|
2110
|
+
var webOptimization_1 = require_webOptimization();
|
|
2111
|
+
var workletSubstitution_1 = require_workletSubstitution();
|
|
2112
|
+
module.exports = function WorkletsBabelPlugin() {
|
|
2113
|
+
function runWithTaggedExceptions(state, fun) {
|
|
2114
|
+
if (state.skipFile) {
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
try {
|
|
2118
|
+
fun();
|
|
2119
|
+
} catch (e) {
|
|
2120
|
+
const error = e;
|
|
2121
|
+
error.message = `[Worklets] Babel plugin exception: ${error.message}`;
|
|
2122
|
+
error.name = "WorkletsBabelPluginError";
|
|
2123
|
+
throw error;
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
return {
|
|
2127
|
+
name: "worklets",
|
|
2128
|
+
pre() {
|
|
2129
|
+
runWithTaggedExceptions(this, () => {
|
|
2130
|
+
(0, globals_1.initializeState)(this);
|
|
2131
|
+
});
|
|
2132
|
+
},
|
|
2133
|
+
visitor: {
|
|
2134
|
+
CallExpression: {
|
|
2135
|
+
enter(path, state) {
|
|
2136
|
+
runWithTaggedExceptions(state, () => {
|
|
2137
|
+
(0, autoworkletization_1.processCalleesAutoworkletizableCallbacks)(path, state);
|
|
2138
|
+
if (state.opts.substituteWebPlatformChecks) {
|
|
2139
|
+
(0, webOptimization_1.substituteWebCallExpression)(path);
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
},
|
|
2144
|
+
[types_1.WorkletizableFunction]: {
|
|
2145
|
+
enter(path, state) {
|
|
2146
|
+
runWithTaggedExceptions(state, () => (0, workletSubstitution_1.processIfWithWorkletDirective)(path, state) || (0, autoworkletization_1.processIfAutoworkletizableCallback)(path, state));
|
|
2147
|
+
}
|
|
2148
|
+
},
|
|
2149
|
+
ObjectExpression: {
|
|
2150
|
+
enter(path, state) {
|
|
2151
|
+
runWithTaggedExceptions(state, () => {
|
|
2152
|
+
(0, contextObject_1.processIfWorkletContextObject)(path, state);
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
},
|
|
2156
|
+
ClassDeclaration: {
|
|
2157
|
+
enter(path, state) {
|
|
2158
|
+
runWithTaggedExceptions(state, () => {
|
|
2159
|
+
if (state.opts.disableWorkletClasses) {
|
|
2160
|
+
return;
|
|
2161
|
+
}
|
|
2162
|
+
(0, class_1.processIfWorkletClass)(path, state);
|
|
2163
|
+
});
|
|
2164
|
+
}
|
|
2165
|
+
},
|
|
2166
|
+
Program: {
|
|
2167
|
+
enter(path, state) {
|
|
2168
|
+
runWithTaggedExceptions(state, () => {
|
|
2169
|
+
(0, file_1.processIfWorkletFile)(path, state);
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
},
|
|
2173
|
+
ExpressionStatement: {
|
|
2174
|
+
enter(path, state) {
|
|
2175
|
+
runWithTaggedExceptions(state, () => {
|
|
2176
|
+
(0, bundleMode_1.toggleBundleMode)(path, state);
|
|
2177
|
+
});
|
|
2178
|
+
}
|
|
2179
|
+
},
|
|
2180
|
+
JSXAttribute: {
|
|
2181
|
+
enter(path, state) {
|
|
2182
|
+
runWithTaggedExceptions(state, () => (0, inlineStylesWarning_1.processInlineStylesWarning)(path, state));
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
};
|
|
2187
|
+
};
|
|
2188
|
+
//# sourceMappingURL=index.js.map
|