11import type { NodePath } from '@babel/core' ;
22import type { Binding } from '@babel/traverse' ;
33import type { AssignmentExpression , Identifier } from '@babel/types' ;
4+ import { isIdentifier , isMemberExpression } from '@babel/types' ;
45
5- import type { WorkletizableFunction , WorkletizableObject } from './types' ;
6+ import type {
7+ ReanimatedPluginPass ,
8+ WorkletizableFunction ,
9+ WorkletizableObject ,
10+ } from './types' ;
611import {
712 isWorkletizableFunctionPath ,
813 isWorkletizableObjectPath ,
@@ -11,7 +16,8 @@ import {
1116export function findReferencedWorklet (
1217 workletIdentifier : NodePath < Identifier > ,
1318 acceptWorkletizableFunction : boolean ,
14- acceptObject : boolean
19+ acceptObject : boolean ,
20+ state : ReanimatedPluginPass
1521) : NodePath < WorkletizableFunction > | NodePath < WorkletizableObject > | undefined {
1622 const workletName = workletIdentifier . node . name ;
1723 const scope = workletIdentifier . scope ;
@@ -21,6 +27,10 @@ export function findReferencedWorklet(
2127 return undefined ;
2228 }
2329
30+ if ( state . opts . bundleMode && bindingIsWorklet ( workletBinding ) ) {
31+ return undefined ;
32+ }
33+
2434 if (
2535 acceptWorkletizableFunction &&
2636 workletBinding . path . isFunctionDeclaration ( )
@@ -33,20 +43,23 @@ export function findReferencedWorklet(
3343 return findReferencedWorkletFromVariableDeclarator (
3444 workletBinding ,
3545 acceptWorkletizableFunction ,
36- acceptObject
46+ acceptObject ,
47+ state
3748 ) ;
3849 }
3950 return findReferencedWorkletFromAssignmentExpression (
4051 workletBinding ,
4152 acceptWorkletizableFunction ,
42- acceptObject
53+ acceptObject ,
54+ state
4355 ) ;
4456}
4557
4658function findReferencedWorkletFromVariableDeclarator (
4759 workletBinding : Binding ,
4860 acceptWorkletizableFunction : boolean ,
49- acceptObject : boolean
61+ acceptObject : boolean ,
62+ state : ReanimatedPluginPass
5063) : NodePath < WorkletizableFunction > | NodePath < WorkletizableObject > | undefined {
5164 const workletDeclaration = workletBinding . path ;
5265 if ( ! workletDeclaration . isVariableDeclarator ( ) ) {
@@ -64,7 +77,8 @@ function findReferencedWorkletFromVariableDeclarator(
6477 return findReferencedWorklet (
6578 worklet ,
6679 acceptWorkletizableFunction ,
67- acceptObject
80+ acceptObject ,
81+ state
6882 ) ;
6983 }
7084 return undefined ;
@@ -73,7 +87,8 @@ function findReferencedWorkletFromVariableDeclarator(
7387function findReferencedWorkletFromAssignmentExpression (
7488 workletBinding : Binding ,
7589 acceptWorkletizableFunction : boolean ,
76- acceptObject : boolean
90+ acceptObject : boolean ,
91+ state : ReanimatedPluginPass
7792) : NodePath < WorkletizableFunction > | NodePath < WorkletizableObject > | undefined {
7893 const workletDeclaration = workletBinding . constantViolations
7994 . reverse ( )
@@ -108,8 +123,20 @@ function findReferencedWorkletFromAssignmentExpression(
108123 return findReferencedWorklet (
109124 workletDefinition ,
110125 acceptWorkletizableFunction ,
111- acceptObject
126+ acceptObject ,
127+ state
112128 ) ;
113129 }
114130 return undefined ;
115131}
132+
133+ function bindingIsWorklet ( binding : Binding ) {
134+ return binding . referencePaths . some (
135+ ( refPath ) =>
136+ ! Array . isArray ( refPath . container ) &&
137+ isMemberExpression ( refPath . container ) &&
138+ refPath . container . object === refPath . node &&
139+ isIdentifier ( refPath . container . property ) &&
140+ refPath . container . property . name === '__workletHash'
141+ ) ;
142+ }
0 commit comments