Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions src/build/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,10 @@ function handleMixin(node: Node, mixins: Record<string, any>) {
const name = child.values[0] as string;
switch (child.name) {
case "event":
event.push({
name,
type: child.properties.type as string,
});
handleEventChild(child, event, name);
break;
case "property":
property[name] = {
name,
exposed: child.properties?.exposed as string,
};
handlePropertyChild(child, property, name);
break;
default:
throw new Error(`Unknown node name: ${child.name}`);
Expand All @@ -94,6 +88,30 @@ function handleMixin(node: Node, mixins: Record<string, any>) {
mixins[name] = { name, events: { event }, properties: { property } };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to return a value as handleProperty now does. But as handleEnum already does this, this can be done in a separate PR.

}

/**
* Handles a child node of type "event" and adds it to the event array.
* @param child The child node to handle.
* @param event The event array to update.
*/
function handleEventChild(child: Node, event: Event[], name: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every event will be child so no need to have Child in the name. Same for property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have renamed it @saschanaz

event.push({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we return Event here and do event.push in the caller? Like event.push(handleEvent(child)).

Also probably better to get the name in each function, as I think not all members will have a name, e.g. constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated it for events and properties

name,
type: child.properties.type as string,
});
}

/**
* Handles a child node of type "property" and adds it to the property object.
* @param child The child node to handle.
* @param property The property object to update.
*/
function handlePropertyChild(child: Node, property: Properties, name: string) {
property[name] = {
name,
exposed: child.properties?.exposed as string,
};
}

/**
* Collect all file URLs in a directory.
*/
Expand Down