Skip to content

Commit 333fb26

Browse files
committed
chore: split function
1 parent 7338aab commit 333fb26

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/build/patches.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { parse, type Value, type Node } from "kdljs";
2-
import type { Enum, Event, Property, Interface, WebIdl, Method } from "./types.js";
2+
import type {
3+
Enum,
4+
Event,
5+
Property,
6+
Interface,
7+
WebIdl,
8+
Method,
9+
} from "./types.js";
310
import { readdir, readFile } from "fs/promises";
411
import { merge } from "./helpers.js";
512

@@ -25,6 +32,18 @@ function optionalMember<const T>(prop: string, type: T, value?: Value) {
2532
};
2633
}
2734

35+
function handleTyped(type: Node, returnType: string) {
36+
const isTyped = type.name == "type";
37+
const name = isTyped ? (type.values[0] as string) : returnType;
38+
const subType = isTyped
39+
? { type: type.children[0].values[0] as string }
40+
: undefined;
41+
return {
42+
type: name,
43+
subtype: subType,
44+
};
45+
}
46+
2847
/**
2948
* Converts patch files in KDL to match the [types](types.d.ts).
3049
*/
@@ -168,13 +187,9 @@ function handleMethod(child: Node): Partial<Method> {
168187

169188
const signature: Method["signature"] = [
170189
{
171-
type: type.name == "type" ? (type.values[0] as string) : returnType,
172190
param: params,
173191
nullable,
174-
subtype:
175-
type.name == "type"
176-
? { type: type.children[0].values[0] as string }
177-
: undefined,
192+
...handleTyped(type, returnType),
178193
},
179194
];
180195
return { name, signature };

0 commit comments

Comments
 (0)