-
Notifications
You must be signed in to change notification settings - Fork 458
KDL support for removals #2250
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
KDL support for removals #2250
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. |
|
What do you think @saschanaz |
|
A bit busy... hopefully this weekend. |
|
No problem |
src/build/patches.ts
Outdated
| */ | ||
| export default async function readPatches(): Promise<any> { | ||
| const patchDirectory = new URL("../../inputfiles/patches/", import.meta.url); | ||
| export default async function readPatches( |
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 would be sad to put removal files separately. Would be nice if we can:
// ... somenormal patches ...
// and then removals in the same file
removals {
enum foo { bar }
}We can extract all removals node from the result of readPatch and then separately return all extracted removals.
Co-authored-by: Kagami Sascha Rosylight <[email protected]>
Co-authored-by: Kagami Sascha Rosylight <[email protected]>
src/build/patches.ts
Outdated
| if (node.name === "removals") { | ||
| removals = parseKDL(node.children); | ||
| continue; |
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 think the logic change should rather happen in readPatches.
parse(kdl)can happen inreadPatchesreadPatchesthen extractsremovalsfrom the resultingDocument.- Now
readPatcheshas two Document for each file - the normal and the removals. - Pass that to
parseKDL()(which maybe a new name, because it doesn't parse anymore). - Return the results as
{ patches, removalPatches }. (Then the call can happen once rather than twice.)
src/build/patches.ts
Outdated
| */ | ||
| function parseKDL(kdlText: string): DeepPartial<WebIdl> { | ||
| const { output, errors } = parse(kdlText); | ||
| function convertKDLNodes(nodes: Node[] | Document): DeepPartial<WebIdl> { |
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.
Hmm? Document is equivalent to Node[], this shouldn't be needed.
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
| mixins: { mixin }, | ||
| interfaces: { interface: interfaces }, | ||
| dictionaries: { dictionary }, | ||
| ...optionalMember("enums.enum", "object", enums), |
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.
Do we need this? Why?
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 still don't understand why this change is needed
src/build/patches.ts
Outdated
| const newObj: { [key: string]: unknown } = {}; | ||
| for (const [key, value] of Object.entries(obj as Record<string, unknown>)) { | ||
| if (key !== "name") { | ||
| newObj[key] = removeNamesDeep(value); |
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.
Do you have a plan how to make nulls work to remove other things than enum values?
|
I have fixed it, and added support for dictionaries @saschanaz |
src/build/patches.ts
Outdated
| mixins: { mixin }, | ||
| interfaces: { interface: interfaces }, | ||
| dictionaries: { dictionary }, | ||
| ...optionalMember("enums.enum", "object", enums), |
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 still don't understand why this change is needed
src/build/patches.ts
Outdated
| // Accept either Document or array of nodes | ||
| const actualNodes: Node[] = Array.isArray(nodes) | ||
| ? nodes | ||
| : nodes; |
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.
nodes or nodes is just nodes
src/build/patches.ts
Outdated
| return result.length === 0 ? null : result; | ||
| } | ||
| if (obj && typeof obj === "object") { | ||
| const newObj: { [key: string]: unknown } = {}; |
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.
Can use Record here
Co-authored-by: Kagami Sascha Rosylight <[email protected]>
|
Done @saschanaz |
src/build/patches.ts
Outdated
| dictionaries: { | ||
| dictionary, | ||
| }, | ||
| ...optionalMember("mixins.mixin", "object", mixin), |
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.
Same for this and below, and generally the dot accessor thing as a whole.
|
Is it better now @saschanaz |
| interface OverridableMethod extends Omit<Method, "signature"> { | ||
| signature: DeepPartial<Signature>[] | Record<number, DeepPartial<Signature>>; | ||
| } | ||
|
|
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 restored)
src/build/patches.ts
Outdated
| // Only because we don't use them | ||
| removalPatches.mixins = undefined; | ||
| removalPatches.interfaces = undefined; |
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.
Does this matter - if we omit this does the test fail?
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.
Yes without it the tests fail
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.
Yes without it the tests fail
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.
Yes without it the tests fail
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.
Ah because interface: {} becomes interface: null. Hmmmmm I think this may be a footgun later when some patches become redundant and are removed...
src/build/patches.ts
Outdated
| * Recursively remove all 'name' fields from the object and its children, and | ||
| * replace any empty objects ({} or []) with null. | ||
| */ | ||
| function sanitizeRemovals(obj: unknown): unknown { |
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.
convertForRemovals? It's not really sanitizing - normalizing random user input, but rather converting into a different format.
Co-authored-by: Kagami Sascha Rosylight <[email protected]>
Co-authored-by: Kagami Sascha Rosylight <[email protected]>
|
Thanks @saschanaz |
|
LGTM, thanks! |
|
Merging because @saschanaz is a code-owner of all the changes - thanks! |
#2053
Added support for removing items using KDL