-
Couldn't load subscription status.
- Fork 452
Handle Properties in kdl #2088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle Properties in kdl #2088
Changes from 6 commits
f7c15b7
4c5d916
7570cf8
0156114
23965c3
a263457
e707e51
de05586
9dce3c9
8cfd4dc
812b211
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| interface-mixin WebGLRenderingContextBase { | ||
| property canvas exposed=Window | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import { parse, type Node } from "kdljs"; | ||
| import type { Enum, Event } from "./types"; | ||
| import type { Enum, Event, Property } from "./types"; | ||
| import { readdir, readFile } from "fs/promises"; | ||
| import { merge } from "./helpers.js"; | ||
| type Properties = Record<string, Omit<Property, "type">>; | ||
|
|
||
| /** | ||
| * Converts patch files in KDL to match the [types](types.d.ts). | ||
|
|
@@ -54,10 +55,10 @@ function handleEnum(node: Node, enums: Record<string, Enum>) { | |
| } | ||
|
|
||
| /** | ||
| * Handles a mixin node by extracting its name and associated events. | ||
| * Handles a mixin node by extracting its name and associated events and properties. | ||
Bashamega marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * 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. | ||
| * Uses helper functions to collect events and properties. | ||
Bashamega marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * 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. | ||
| */ | ||
|
|
@@ -66,14 +67,49 @@ function handleMixin(node: Node, mixins: Record<string, any>) { | |
| if (typeof name !== "string") { | ||
| throw new Error("Missing mixin name"); | ||
| } | ||
| const rawEvents = node.children.filter( | ||
| (child: any) => child.name === "event", | ||
| ); | ||
| const event: Event[] = rawEvents.map((child: any) => ({ | ||
| name: child.values[0], | ||
| type: child.properties.type, | ||
| })); | ||
| mixins[name] = { name, events: { event } }; | ||
|
|
||
| const event: Event[] = []; | ||
| const property: Properties = {}; | ||
|
|
||
| for (const child of node.children) { | ||
| const name = child.values[0] as string; | ||
| switch (child.name) { | ||
| case "event": | ||
| handleEvent(child, event, name); | ||
| break; | ||
| case "property": | ||
| handleProperty(child, property, name); | ||
| break; | ||
| default: | ||
| throw new Error(`Unknown node name: ${child.name}`); | ||
| } | ||
| } | ||
|
|
||
| mixins[name] = { name, events: { event }, properties: { property } }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 handleEvent(child: Node, event: Event[], name: string) { | ||
| event.push({ | ||
|
||
| 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 handleProperty(child: Node, property: Properties, name: string) { | ||
| property[name] = { | ||
| name, | ||
| exposed: child.properties?.exposed as string, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.