@@ -16,6 +16,7 @@ import type {
1616 Dictionary ,
1717 Member ,
1818 Signature ,
19+ TypeDef ,
1920} from "./types.js" ;
2021import { readdir , readFile } from "fs/promises" ;
2122import { merge } from "./helpers.js" ;
@@ -120,6 +121,7 @@ function convertKDLNodes(nodes: Node[]): DeepPartial<WebIdl> {
120121 const mixin : Record < string , DeepPartial < Interface > > = { } ;
121122 const interfaces : Record < string , DeepPartial < Interface > > = { } ;
122123 const dictionary : Record < string , DeepPartial < Dictionary > > = { } ;
124+ const typedefs : DeepPartial < TypeDef > [ ] = [ ] ;
123125
124126 for ( const node of nodes ) {
125127 // Note: no "removals" handling here; caller is responsible for splitting
@@ -143,6 +145,9 @@ function convertKDLNodes(nodes: Node[]): DeepPartial<WebIdl> {
143145 case "dictionary" :
144146 dictionary [ name ] = merge ( dictionary [ name ] , handleDictionary ( node ) ) ;
145147 break ;
148+ case "typedef" :
149+ typedefs . push ( handleTypedef ( node ) ) ;
150+ break ;
146151 default :
147152 throw new Error ( `Unknown node name: ${ node . name } ` ) ;
148153 }
@@ -155,6 +160,7 @@ function convertKDLNodes(nodes: Node[]): DeepPartial<WebIdl> {
155160 interface : interfaces ,
156161 } ) ,
157162 ...optionalNestedMember ( "dictionaries" , dictionary , { dictionary } ) ,
163+ ...optionalNestedMember ( "typedefs" , typedefs , { typedef : typedefs } ) ,
158164 } ;
159165}
160166
@@ -432,6 +438,23 @@ function handleMember(c: Node): DeepPartial<Member> {
432438 } ;
433439}
434440
441+ /**
442+ * Handles typedef nodes
443+ * @param node The typedef node to handle.
444+ */
445+ function handleTypedef ( node : Node ) : DeepPartial < TypeDef > {
446+ const typeNodes = node . children . filter ( ( c ) => c . name === "type" ) ;
447+ return {
448+ name : string ( node . values [ 0 ] ) ,
449+ ...handleTyped ( typeNodes ) ,
450+ ...optionalMember (
451+ "legacyNamespace" ,
452+ "string" ,
453+ node . properties ?. legacyNamespace ,
454+ ) ,
455+ } ;
456+ }
457+
435458/**
436459 * Collect all file URLs in a directory.
437460 */
0 commit comments