Skip to content

Commit 0156114

Browse files
committed
-
1 parent 7570cf8 commit 0156114

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

src/build/patches.ts

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,42 +54,6 @@ function handleEnum(node: Node, enums: Record<string, Enum>) {
5454
enums[name] = { name, value: values };
5555
}
5656

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-
9357
/**
9458
* Handles a mixin node by extracting its name and associated events and properties.
9559
* Throws an error if the mixin name is missing.
@@ -104,8 +68,28 @@ function handleMixin(node: Node, mixins: Record<string, any>) {
10468
throw new Error("Missing mixin name");
10569
}
10670

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+
}
10993

11094
mixins[name] = { name, events: { event }, properties: { property } };
11195
}

0 commit comments

Comments
 (0)