1
- /** @import { ClassBody, Identifier, Literal, MethodDefinition, PrivateIdentifier, PropertyDefinition } from 'estree' */
2
- /** @import { Context, StateField } from '../types' */
3
- import { regex_invalid_identifier_chars } from '../../../patterns.js' ;
4
- import { ClassAnalysis } from './shared/class-analysis.js' ;
1
+ /** @import { ClassBody } from 'estree' */
2
+ /** @import { Context } from '../types' */
3
+ import { create_client_class_analysis } from './shared/client-class-analysis.js' ;
5
4
6
5
/**
7
6
* @param {ClassBody } node
@@ -13,46 +12,8 @@ export function ClassBody(node, context) {
13
12
return ;
14
13
}
15
14
16
- const class_analysis = new ClassAnalysis ( ) ;
17
-
18
- for ( const definition of node . body ) {
19
- class_analysis . register_body_definition ( definition , context . state . scope ) ;
20
- }
21
-
22
- class_analysis . finalize_property_definitions ( ) ;
23
-
24
- /** @type {Array<MethodDefinition | PropertyDefinition> } */
25
- const body = [ ] ;
26
-
27
- const child_state = {
28
- ...context . state ,
29
- class_analysis
30
- } ;
31
-
32
- // we need to visit the constructor first so that it can add to the field maps.
33
- const constructor_node = node . body . find (
34
- ( child ) => child . type === 'MethodDefinition' && child . kind === 'constructor'
35
- ) ;
36
- const constructor = constructor_node && context . visit ( constructor_node , child_state ) ;
37
-
38
- // Replace parts of the class body
39
- for ( const definition of node . body ) {
40
- if ( definition === constructor_node ) {
41
- body . push ( /** @type {MethodDefinition } */ ( constructor ) ) ;
42
- continue ;
43
- }
44
-
45
- const state_field = class_analysis . build_state_field_from_body_definition ( definition , context ) ;
46
-
47
- if ( state_field ) {
48
- body . push ( ...state_field ) ;
49
- continue ;
50
- }
51
-
52
- body . push ( /** @type {MethodDefinition } **/ ( context . visit ( definition , child_state ) ) ) ;
53
- }
54
-
55
- body . push ( ...class_analysis . constructor_state_fields ) ;
15
+ const class_analysis = create_client_class_analysis ( node . body ) ;
16
+ const body = class_analysis . generate_body ( context ) ;
56
17
57
18
return { ...node , body } ;
58
19
}
0 commit comments