@@ -36,7 +36,7 @@ import { contextObjectMarker } from './contextObject';
3636
3737export function processIfWorkletFile (
3838 path : NodePath < Program > ,
39- _state : ReanimatedPluginPass
39+ state : ReanimatedPluginPass
4040) : boolean {
4141 if (
4242 ! path . node . directives . some (
@@ -50,18 +50,21 @@ export function processIfWorkletFile(
5050 path . node . directives = path . node . directives . filter (
5151 ( functionDirective ) => functionDirective . value . value !== 'worklet'
5252 ) ;
53- processWorkletFile ( path ) ;
53+ processWorkletFile ( path , state ) ;
5454
5555 return true ;
5656}
5757
5858/** Adds a worklet directive to each viable top-level entity in the file. */
59- function processWorkletFile ( programPath : NodePath < Program > ) {
59+ function processWorkletFile (
60+ programPath : NodePath < Program > ,
61+ state : ReanimatedPluginPass
62+ ) {
6063 const statements = programPath . get ( 'body' ) ;
6164 dehoistCommonJSExports ( programPath . node ) ;
6265 statements . forEach ( ( statement ) => {
6366 const candidatePath = getCandidate ( statement ) ;
64- processWorkletizableEntity ( candidatePath ) ;
67+ processWorkletizableEntity ( candidatePath , state ) ;
6568 } ) ;
6669}
6770
@@ -76,7 +79,10 @@ function getCandidate(statementPath: NodePath<Statement>) {
7679 }
7780}
7881
79- function processWorkletizableEntity ( nodePath : NodePath < unknown > ) {
82+ function processWorkletizableEntity (
83+ nodePath : NodePath < unknown > ,
84+ state : ReanimatedPluginPass
85+ ) {
8086 if ( isWorkletizableFunctionPath ( nodePath ) ) {
8187 if ( nodePath . isArrowFunctionExpression ( ) ) {
8288 replaceImplicitReturnWithBlock ( nodePath . node ) ;
@@ -86,35 +92,46 @@ function processWorkletizableEntity(nodePath: NodePath<unknown>) {
8692 if ( isImplicitContextObject ( nodePath ) ) {
8793 appendWorkletContextObjectMarker ( nodePath . node ) ;
8894 } else {
89- processWorkletAggregator ( nodePath ) ;
95+ processWorkletAggregator ( nodePath , state ) ;
9096 }
9197 } else if ( nodePath . isVariableDeclaration ( ) ) {
92- processVariableDeclaration ( nodePath ) ;
98+ processVariableDeclaration ( nodePath , state ) ;
9399 } else if ( nodePath . isClassDeclaration ( ) ) {
94100 appendWorkletClassMarker ( nodePath . node . body ) ;
101+ if ( nodePath . node . id ?. name ) {
102+ // We don't support unnamed classes yet.
103+ state . classesToWorkletize . push ( {
104+ node : nodePath . node ,
105+ name : nodePath . node . id . name ,
106+ } ) ;
107+ }
95108 }
96109}
97110
98111function processVariableDeclaration (
99- variableDeclarationPath : NodePath < VariableDeclaration >
112+ variableDeclarationPath : NodePath < VariableDeclaration > ,
113+ state : ReanimatedPluginPass
100114) {
101115 const declarations = variableDeclarationPath . get ( 'declarations' ) ;
102116 declarations . forEach ( ( declaration ) => {
103117 const initPath = declaration . get ( 'init' ) ;
104118 if ( initPath . isExpression ( ) ) {
105- processWorkletizableEntity ( initPath ) ;
119+ processWorkletizableEntity ( initPath , state ) ;
106120 }
107121 } ) ;
108122}
109123
110- function processWorkletAggregator ( objectPath : NodePath < ObjectExpression > ) {
124+ function processWorkletAggregator (
125+ objectPath : NodePath < ObjectExpression > ,
126+ state : ReanimatedPluginPass
127+ ) {
111128 const properties = objectPath . get ( 'properties' ) ;
112129 properties . forEach ( ( property ) => {
113130 if ( property . isObjectMethod ( ) ) {
114131 appendWorkletDirective ( property . node . body ) ;
115132 } else if ( property . isObjectProperty ( ) ) {
116133 const valuePath = property . get ( 'value' ) ;
117- processWorkletizableEntity ( valuePath ) ;
134+ processWorkletizableEntity ( valuePath , state ) ;
118135 }
119136 } ) ;
120137}
0 commit comments