@@ -65,7 +65,7 @@ class Parser {
6565
6666 if (
6767 attributes . length > 0 || this . isText ( "public" ) || this . isText ( "partial" ) || this . isText ( "class" ) ||
68- this . isText ( "enum" )
68+ this . isText ( "interface" ) || this . isText ( " enum")
6969 ) {
7070 declarations . push ( ...this . parseDeclaration ( undefined , attributes ) ) ;
7171 continue ;
@@ -83,7 +83,11 @@ class Parser {
8383 this . matchText ( "partial" ) ;
8484
8585 if ( this . matchText ( "class" ) ) {
86- return [ this . parseClass ( namespaceName , attributes , leadingComments ) ] ;
86+ return [ this . parseClass ( namespaceName , attributes , leadingComments , "class" ) ] ;
87+ }
88+
89+ if ( this . matchText ( "interface" ) ) {
90+ return [ this . parseClass ( namespaceName , attributes , leadingComments , "interface" ) ] ;
8791 }
8892
8993 if ( this . matchText ( "enum" ) ) {
@@ -99,11 +103,11 @@ class Parser {
99103 namespaceName : string | undefined ,
100104 attributes : AttributeNode [ ] ,
101105 leadingComments : CommentTrivia [ ] ,
106+ declarationKind : "class" | "interface" ,
102107 ) : ClassNode {
103- const name = this . expectIdentifier ( " Expected class name" ) . text ;
108+ const name = this . expectIdentifier ( ` Expected ${ declarationKind } name` ) . text ;
104109 const typeParameters = this . parseTypeParameters ( ) ;
105- let baseType : TypeReferenceNode | undefined ;
106- if ( this . matchText ( ":" ) ) baseType = this . parseTypeReference ( ) ;
110+ const baseTypes = this . parseBaseTypes ( ) ;
107111 this . expectText ( "{" ) ;
108112 const properties : PropertyNode [ ] = [ ] ;
109113
@@ -115,7 +119,7 @@ class Parser {
115119 continue ;
116120 }
117121
118- if ( this . isText ( "class" ) || this . isText ( "enum" ) ) {
122+ if ( this . isText ( "class" ) || this . isText ( "interface" ) || this . isText ( " enum") ) {
119123 this . skipUnsupportedMember ( "Nested type declarations are not supported" ) ;
120124 continue ;
121125 }
@@ -150,14 +154,22 @@ class Parser {
150154 name,
151155 namespaceName,
152156 typeParameters,
153- baseType,
157+ baseType : baseTypes [ 0 ] ,
158+ baseTypes,
154159 properties,
155160 attributes,
156161 leadingComments,
157162 trailingComments : this . previous ( ) . trailingComments ,
158163 } ;
159164 }
160165
166+ private parseBaseTypes ( ) : TypeReferenceNode [ ] {
167+ const baseTypes : TypeReferenceNode [ ] = [ ] ;
168+ if ( ! this . matchText ( ":" ) ) return baseTypes ;
169+ do baseTypes . push ( this . parseTypeReference ( ) ) ; while ( this . matchText ( "," ) ) ;
170+ return baseTypes ;
171+ }
172+
161173 private parseEnum (
162174 namespaceName : string | undefined ,
163175 attributes : AttributeNode [ ] ,
@@ -172,8 +184,7 @@ class Parser {
172184 const token = this . expectIdentifier ( "Expected enum member name" ) ;
173185 let value : number | undefined ;
174186 if ( this . matchText ( "=" ) ) {
175- const valueToken = this . expect ( "number" , "Expected enum member numeric value" ) ;
176- value = Number ( valueToken . text ) ;
187+ value = this . parseEnumNumericValue ( ) ;
177188 nextImplicitValue = value + 1 ;
178189 } else {
179190 value = nextImplicitValue ++ ;
@@ -198,6 +209,12 @@ class Parser {
198209 } ;
199210 }
200211
212+ private parseEnumNumericValue ( ) : number {
213+ const sign = this . matchText ( "-" ) ? - 1 : this . matchText ( "+" ) ? 1 : 1 ;
214+ const valueToken = this . expect ( "number" , "Expected enum member numeric value" ) ;
215+ return sign * Number ( valueToken . text ) ;
216+ }
217+
201218 private parseAttributes ( ) : AttributeNode [ ] {
202219 const attributes : AttributeNode [ ] = [ ] ;
203220 while ( this . matchText ( "[" ) ) {
0 commit comments