This repository was archived by the owner on May 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -150,6 +150,9 @@ class Annotator {
150150 this . visitTypeAlias ( < ts . TypeAliasDeclaration > node ) ;
151151 this . writeNode ( node ) ;
152152 break ;
153+ case ts . SyntaxKind . EnumDeclaration :
154+ this . visitEnum ( < ts . EnumDeclaration > node ) ;
155+ break ;
153156 default :
154157 this . writeNode ( node ) ;
155158 break ;
@@ -263,6 +266,24 @@ class Annotator {
263266 this . emit ( ': void;\n' ) ;
264267 }
265268
269+ private visitEnum ( node : ts . EnumDeclaration ) {
270+ this . emit ( '/** @typedef {number} */\n' ) ;
271+ this . writeNode ( node ) ;
272+ this . emit ( '\n' ) ;
273+ let i = 0 ;
274+ for ( let member of node . members ) {
275+ this . emit ( `/** @type {${ node . name . getText ( ) } } */\n` ) ;
276+ this . emit ( `(<any>${ node . name . getText ( ) } ).${ member . name . getText ( ) } = ` ) ;
277+ if ( member . initializer ) {
278+ this . visit ( member . initializer ) ;
279+ } else {
280+ this . emit ( String ( i ) ) ;
281+ i ++ ;
282+ }
283+ this . emit ( ';\n' ) ;
284+ }
285+ }
286+
266287 private writeNode ( node : ts . Node , skipComments : boolean = false ) {
267288 if ( node . getChildCount ( ) == 0 ) {
268289 // Directly write complete tokens.
Original file line number Diff line number Diff line change 1+ enum FooEnum { XYZ , PI = 3.14159 }
Original file line number Diff line number Diff line change 1+ /** @typedef {number } */
2+ var FooEnum ;
3+ ( function ( FooEnum ) {
4+ FooEnum [ FooEnum [ "XYZ" ] = 0 ] = "XYZ" ;
5+ FooEnum [ FooEnum [ "PI" ] = 3.14159 ] = "PI" ;
6+ } ) ( FooEnum || ( FooEnum = { } ) ) ;
7+ /** @type {FooEnum } */
8+ FooEnum . XYZ = 0 ;
9+ /** @type {FooEnum } */
10+ FooEnum . PI = 3.14159 ;
Original file line number Diff line number Diff line change 1+ /** @typedef {number } */
2+ enum FooEnum { XYZ , PI = 3.14159 }
3+ /** @type {FooEnum } */
4+ ( < any > FooEnum ) . XYZ = 0 ;
5+ /** @type {FooEnum } */
6+ ( < any > FooEnum ) . PI = 3.14159 ;
You can’t perform that action at this time.
0 commit comments