Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
10 changes: 0 additions & 10 deletions inputfiles/addedTypes.jsonc
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
{
"mixins": {
"mixin": {
"AbstractWorker": {
"events": {
"event": [
{
"name": "error",
"type": "ErrorEvent"
}
]
}
},
"DocumentAndElementEventHandlers": {
"events": {
"event": [
Expand Down
3 changes: 3 additions & 0 deletions inputfiles/patches/abstractworker.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mixin AbstractWorker event {
Copy link
Contributor

@saschanaz saschanaz Jul 25, 2025

Choose a reason for hiding this comment

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

Suggested change
mixin AbstractWorker event {
interface-mixin AbstractWorker {

error ErrorEvent
Copy link
Contributor

@saschanaz saschanaz Jul 25, 2025

Choose a reason for hiding this comment

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

Suggested change
error ErrorEvent
event error type=ErrorEvent

}
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 have a final newline - if you use VSCode then "Files: Insert Final Newline" should do it for you.

41 changes: 37 additions & 4 deletions src/build/patches.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse } from "kdljs";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { parse } from "kdljs";
import { parse, type Node } from "kdljs";

import type { Enum } from "./types";
import type { Enum, Event } from "./types";
import { readdir, readFile } from "fs/promises";
import { merge } from "./helpers.js";

Expand All @@ -15,14 +15,22 @@ function parseKDL(kdlText: string) {

const nodes = output!;
const enums: Record<string, Enum> = {};
const mixins: Record<string, any> = {};

for (const node of nodes) {
if (node.name === "enum") {
handleEnum(node, enums);
switch (node.name) {
case "enum":
handleEnum(node, enums);
break;
case "mixin":
handelMixin(node, mixins);
break;
default:
throw new Error(`Unknown node name: ${node.name}`);
}
}

return { enums: { enum: enums } };
return { enums: { enum: enums }, mixins: { mixin: mixins } };
}

/**
Expand All @@ -45,6 +53,31 @@ function handleEnum(node: any, enums: Record<string, Enum>) {
enums[name] = { name, value: values };
}

/**
* Handles a mixin node by extracting its name and associated events.
* Throws an error if the mixin name is missing.
* If the mixin node specifies "event" as its second value, it collects all child nodes as events,
* each with a name and type, and adds them to the mixins record under the mixin's name.
* @param node The mixin node to handle.
* @param mixins The record of mixins to update.
*/
export function handelMixin(node: any, mixins: Record<string, any>) {
const name = node.values[0];
if (typeof name !== "string") {
throw new Error("Missing mixin name");
}
const event: Event[] = [];
if (node.values[1] == "event") {
node.children?.forEach((child: any) => {
event.push({
name: child.name,
type: child.values[0],
});
});
}
mixins[name] = { name, events: { event } };
}

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