-
Notifications
You must be signed in to change notification settings - Fork 448
Feature: Add method handling to mixin processing in KDL #2100
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR! This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged. |
inputfiles/patches/dom.kdl
Outdated
@@ -0,0 +1,12 @@ | |||
// Manually moved from Document |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cssom-view.kdl
src/build/patches.ts
Outdated
function handleMethod(child: Node): Partial<Method> { | ||
const name = child.values[0] as string; | ||
// Build the overrideSignatures array with the method signature string | ||
const overrideSignatures = [ |
There was a problem hiding this comment.
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)
TypeScript-DOM-lib-generator/src/build/widlprocess.ts
Lines 192 to 204 in 23819c7
} 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); | |
} |
Co-authored-by: Kagami Sascha Rosylight <[email protected]>
Co-authored-by: Kagami Sascha Rosylight <[email protected]>
…meters and update return types for elementFromPoint and elementsFromPoint methods. Enhance method handling in patches.ts to accommodate nullable return types and array signatures.
I've updated it, @saschanaz. |
inputfiles/patches/cssom-view.kd
Outdated
@@ -0,0 +1,12 @@ | |||
// Manually moved from Document |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.kdl, not .kd 😛
Also maybe 2-space indent to be consistent with the rest of the code 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed the name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but not the indent 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot, I have updated them
inputfiles/patches/cssom-view.kd
Outdated
param x type=long | ||
param y type=long | ||
} | ||
method elementsFromPoint returns="Element" array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to follow the syntax of
TypeScript-DOM-lib-generator/src/build/types.d.ts
Lines 1 to 8 in 23819c7
export interface Typed { | |
type: string | Typed[]; | |
subtype?: Typed | Typed[]; | |
nullable?: boolean; | |
overrideType?: string; | |
additionalTypes?: string[]; | |
allowShared?: boolean; | |
} |
But that doesn't seem possible as a property. Perhaps we should allow (but not force) type as a member for complex cases like this.
method elementsFromPoint {
type sequence {
type Element
}
param x type=long
param y type=long
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
I have updated it @saschanaz |
Hello @saschanaz |
inputfiles/patches/cssom-view.kdl
Outdated
// Manually moved from Document | ||
// 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 nullable=#true { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullable
is logically a property of the return type rather than the method, so in this case it would be also nicer to use separate type node as below.
src/build/patches.ts
Outdated
|
||
const signature: Method["signature"] = [ | ||
{ | ||
type: type.name == "type" ? (type.values[0] as string) : returnType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll probably get similar situation on other things than methods, this should probably be done in a helper function so that others can reuse it, something like handleTyped
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made it a helper function
src/build/patches.ts
Outdated
const nullable = child.properties.nullable as boolean; | ||
|
||
const params = child.children | ||
.filter((c) => c.values[0] != "sequence") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should filter in based on the type param
, not filter out based on name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I have updated it @saschanaz |
Hello @saschanaz |
Welcome back from vacation, @saschanaz! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long delay!
src/build/patches.ts
Outdated
* @param child The child node to handle. | ||
*/ | ||
function handleMethod(child: Node): Partial<Method> { | ||
const name = child.values[0] as string; |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/build/patches.ts
Outdated
*/ | ||
function handleMethod(child: Node): Partial<Method> { | ||
const name = child.values[0] as string; | ||
const type = child.children[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should iterate and check types than assuming a position or using filter()
, otherwise we can't throw on unexpected child. Just like line 120.
@@ -105,6 +127,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); |
There was a problem hiding this comment.
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)
src/build/patches.ts
Outdated
const name = isTyped ? (type.values[0] as string) : returnType; | ||
const subType = | ||
type.children.length > 0 | ||
? { type: type.children[0].values[0] as string } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a recursive call to handleTyped
No problem :) |
I have updated it @saschanaz 😃 |
related #2053