Skip to content

Refactor mixin handling in KDL parser #2082

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

Merged
merged 6 commits into from
Jul 28, 2025
Merged

Conversation

Bashamega
Copy link
Contributor

  • Removed AbstractWorker event definitions from addedTypes.jsonc.
  • Introduced abstractworker.kdl to define AbstractWorker mixin with error event.
  • Updated patches.ts to handle mixin parsing and return mixins in the output.

Related #2053

- Removed AbstractWorker event definitions from addedTypes.jsonc.
- Introduced abstractworker.kdl to define AbstractWorker mixin with error event.
- Updated patches.ts to handle mixin parsing and return mixins in the output.
Copy link
Contributor

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.

@@ -0,0 +1,3 @@
mixin AbstractWorker event {
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

@@ -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 {

@Bashamega
Copy link
Contributor Author

Bashamega commented Jul 25, 2025

Thank you @saschanaz
Can you send me a snippet of how you want the KDL to look?

@saschanaz
Copy link
Contributor

saschanaz commented Jul 25, 2025

Briefly something like in #2053 (comment).

Could change during review in case something is off though.

// This part is done, thank you 🎉
enum Foo {
  foo
  bar
}

interface Foo {
  // Event information should ideally be provided by MDN and @webref/events, this is for edge cases
  event show type=ShowEvent
  event close type=CloseEvent

  method fooOp returns=FooReturnType {
    param arg1 type=ArgType
  }
  property fooAttr type=AttrType
}

interface Foo2 {
  template T1 extends=FooFoo default=FooBar

  operation fooOp override-returns=TemplateType<T1>
}

dictionary Bar {
  template T

  member bar required=#true type=DOMString
  // but all types here are to override the IDL one, perhaps there could be a better word, like ts-type?
  member baz override-type=Foo2<T>
}

- Simplified event array creation using map instead of forEach.
- Improved readability and performance of the event handling logic.
@Bashamega
Copy link
Contributor Author

I have updated it @saschanaz.
I will do the rest in separate PRs

Copy link
Contributor

@saschanaz saschanaz left a comment

Choose a reason for hiding this comment

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

A few nits and then this will be good to go:

* @param node The mixin node to handle.
* @param mixins The record of mixins to update.
*/
export function handleMixin(node: any, mixins: Record<string, any>) {
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
export function handleMixin(node: any, mixins: Record<string, any>) {
function handleMixin(node: Node, mixins: Record<string, any>) {

(Something I missed last time)

@@ -0,0 +1,3 @@
interface-mixin AbstractWorker {
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.

@@ -0,0 +1,3 @@
interface-mixin AbstractWorker {
Copy link
Contributor

Choose a reason for hiding this comment

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

In this specific case, I'd prefer to put all the event things to a single file as events.kdl, so that I can see which events are not covered by automation and can ultimately remove this file.

In this PR just the filename can change, no addition is needed.

(Because all event data technically exists, we don't have a way to track that to assign automatically right now)

@@ -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";

@Bashamega
Copy link
Contributor Author

Thank you for your review @saschanaz
I have updated it

@saschanaz
Copy link
Contributor

LGTM, thanks!

Copy link
Contributor

There was an issue merging, maybe try again saschanaz. Details

@saschanaz
Copy link
Contributor

LGTM

@github-actions github-actions bot merged commit f3e25e8 into microsoft:main Jul 28, 2025
5 checks passed
Copy link
Contributor

Merging because @saschanaz is a code-owner of all the changes - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants