Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
24 changes: 0 additions & 24 deletions inputfiles/addedTypes.jsonc
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
{
"mixins": {
"mixin": {
"DocumentOrShadowRoot": {
// Manually moved from Document
// See https://github.com/w3c/csswg-drafts/issues/5886 and https://github.com/w3c/csswg-drafts/issues/556
"methods": {
"method": {
"elementFromPoint": {
"name": "elementFromPoint",
"overrideSignatures": [
"elementFromPoint(x: number, y: number): Element | null"
]
},
"elementsFromPoint": {
"name": "elementsFromPoint",
"overrideSignatures": [
"elementsFromPoint(x: number, y: number): Element[]"
]
}
}
}
}
}
},
"callbackInterfaces": {
"interface": {}
},
Expand Down
12 changes: 12 additions & 0 deletions inputfiles/patches/dom.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Manually moved from Document
Copy link
Contributor

Choose a reason for hiding this comment

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

cssom-view.kdl

// See https://github.com/w3c/csswg-drafts/issues/5886 and https://github.com/w3c/csswg-drafts/issues/556
interface-mixin DocumentOrShadowRoot {
method elementFromPoint returns="Element | null" {
param x type=number
param y type=number
}
method elementsFromPoint returns="Element[]" {
param x type=number
param y type=number
}
}
22 changes: 21 additions & 1 deletion src/build/patches.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse, type Node } from "kdljs";
import type { Enum, Event, Property, Interface, WebIdl } from "./types";
import type { Enum, Event, Property, Interface, WebIdl, Method } from "./types";
import { readdir, readFile } from "fs/promises";
import { merge } from "./helpers.js";

Expand Down Expand Up @@ -76,6 +76,7 @@ function handleMixin(node: Node): DeepPartial<Interface> {

const event: Event[] = [];
const property: Record<string, Partial<Property>> = {};
const method: Record<string, Partial<Method>> = {};

for (const child of node.children) {
switch (child.name) {
Expand All @@ -87,6 +88,11 @@ function handleMixin(node: Node): DeepPartial<Interface> {
property[propName] = handleProperty(child);
break;
}
case "method": {
const methodName = child.values[0] as string;
method[methodName] = handleMethod(child);
Copy link
Contributor

Choose a reason for hiding this comment

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

(Fine for now but eventually this will need to change to support overloads)

break;
}
default:
throw new Error(`Unknown node name: ${child.name}`);
}
Expand All @@ -96,6 +102,7 @@ function handleMixin(node: Node): DeepPartial<Interface> {
name,
events: { event },
properties: { property },
methods: { method },
} as DeepPartial<Interface>;
if (node.properties.extends) {
result.extends = node.properties.extends as string;
Expand Down Expand Up @@ -125,6 +132,19 @@ function handleProperty(child: Node): Partial<Property> {
};
}

/**
* Handles a child node of type "method" and adds it to the method object.
* @param child The child node to handle.
*/
function handleMethod(child: Node): Partial<Method> {
const name = child.values[0] as string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Too many as string, would be nice to have something like

function string(arg: unknown): string {
  if (typeof arg !== "string") {
    throw new Error(`Expected a string but found ${typeof arg}`);
  }
  return arg;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// Build the overrideSignatures array with the method signature string
const overrideSignatures = [
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not use overrideSignatures unless it's explicitly used. Take a look at widlprocess.ts to see how to proceed: (this PR does not need to cover everything in that file)

} else if (member.type === "operation") {
const operation = convertOperation(member, result.exposed);
const { method } = result.methods;
if (!member.name) {
result.anonymousMethods!.method.push(operation);
} else if (method.hasOwnProperty(member.name)) {
method[member.name].signature.push(...operation.signature);
} else {
method[member.name] = operation as Browser.Method;
}
if (member.name) {
addComments(method[member.name], commentMap, i.name, member.name);
}

`${name}(${child.children.map((c) => `${c.values[0]}: ${c.properties.type}`).join(", ")}): ${child.properties.returns || "void"}`,
];
return { name, overrideSignatures };
}

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