@@ -54,42 +54,6 @@ function handleEnum(node: Node, enums: Record<string, Enum>) {
54
54
enums [ name ] = { name, value : values } ;
55
55
}
56
56
57
- /**
58
- * Extracts all event child nodes from a mixin node and returns them as an array of Event objects.
59
- * Each event object contains the event's name and type.
60
- * @param node The mixin node to extract events from.
61
- * @returns An array of Event objects.
62
- */
63
- function extractMixinEvents ( node : Node ) : Event [ ] {
64
- const rawEvents = node . children . filter (
65
- ( child : any ) => child . name === "event" ,
66
- ) ;
67
- return rawEvents . map ( ( child : any ) => ( {
68
- name : child . values [ 0 ] ,
69
- type : child . properties . type ,
70
- } ) ) ;
71
- }
72
-
73
- /**
74
- * Extracts all property child nodes from a mixin node and returns them as a Properties object.
75
- * Each property is keyed by its name and contains its name and exposed value.
76
- * @param node The mixin node to extract properties from.
77
- * @returns A Properties object mapping property names to property details.
78
- */
79
- function extractMixinProperties ( node : Node ) : Properties {
80
- const rawProperties = node . children . filter (
81
- ( child : any ) => child . name === "property" ,
82
- ) ;
83
- return rawProperties . reduce ( ( acc : Properties , child : any ) => {
84
- const name = child . values [ 0 ] ;
85
- acc [ name ] = {
86
- name,
87
- exposed : child . properties ?. exposed ,
88
- } ;
89
- return acc ;
90
- } , { } ) ;
91
- }
92
-
93
57
/**
94
58
* Handles a mixin node by extracting its name and associated events and properties.
95
59
* Throws an error if the mixin name is missing.
@@ -104,8 +68,28 @@ function handleMixin(node: Node, mixins: Record<string, any>) {
104
68
throw new Error ( "Missing mixin name" ) ;
105
69
}
106
70
107
- const event : Event [ ] = extractMixinEvents ( node ) ;
108
- const property : Properties = extractMixinProperties ( node ) ;
71
+ const event : Event [ ] = [ ] ;
72
+ const property : Properties = { } ;
73
+
74
+ for ( const child of node . children ) {
75
+ const name = child . values [ 0 ] as string ;
76
+ switch ( child . name ) {
77
+ case "event" :
78
+ event . push ( {
79
+ name,
80
+ type : child . properties . type as string ,
81
+ } ) ;
82
+ break ;
83
+ case "property" :
84
+ property [ name ] = {
85
+ name,
86
+ exposed : child . properties ?. exposed as string ,
87
+ } ;
88
+ break ;
89
+ default :
90
+ throw new Error ( `Unknown node name: ${ child . name } ` ) ;
91
+ }
92
+ }
109
93
110
94
mixins [ name ] = { name, events : { event } , properties : { property } } ;
111
95
}
0 commit comments