@@ -151,54 +151,46 @@ export class TypescriptParser {
151
151
*
152
152
* @memberof TsResourceParser
153
153
*/
154
- private parse ( rootResource : Resource , rootNode : Node ) : void {
155
- let [ resource , ...resourceQueue ] : Resource [ ] = Array ( rootNode . getChildren ( ) . length ) . fill ( rootResource ) ;
156
- let [ node , ...nodeQueue ] : Node [ ] = [ ...rootNode . getChildren ( ) ] ;
157
- while ( node ) {
158
- switch ( node . kind ) {
154
+ private parse ( resource : Resource , node : Node ) : void {
155
+ for ( const child of node . getChildren ( ) ) {
156
+ switch ( child . kind ) {
159
157
case SyntaxKind . ImportDeclaration :
160
158
case SyntaxKind . ImportEqualsDeclaration :
161
- parseImport ( resource , < ImportDeclaration | ImportEqualsDeclaration > node ) ;
159
+ parseImport ( resource , < ImportDeclaration | ImportEqualsDeclaration > child ) ;
162
160
break ;
163
161
case SyntaxKind . ExportDeclaration :
164
162
case SyntaxKind . ExportAssignment :
165
- parseExport ( resource , < ExportAssignment | ExportDeclaration > node ) ;
163
+ parseExport ( resource , < ExportAssignment | ExportDeclaration > child ) ;
166
164
break ;
167
165
case SyntaxKind . EnumDeclaration :
168
- parseEnum ( resource , < EnumDeclaration > node ) ;
166
+ parseEnum ( resource , < EnumDeclaration > child ) ;
169
167
break ;
170
168
case SyntaxKind . TypeAliasDeclaration :
171
- parseTypeAlias ( resource , < TypeAliasDeclaration > node ) ;
169
+ parseTypeAlias ( resource , < TypeAliasDeclaration > child ) ;
172
170
break ;
173
171
case SyntaxKind . FunctionDeclaration :
174
- parseFunction ( resource , < FunctionDeclaration > node ) ;
175
- [ resource , ...resourceQueue ] = resourceQueue ;
176
- [ node , ...nodeQueue ] = nodeQueue ;
172
+ parseFunction ( resource , < FunctionDeclaration > child ) ;
177
173
continue ;
178
174
case SyntaxKind . VariableStatement :
179
- parseVariable ( resource , < VariableStatement > node ) ;
175
+ parseVariable ( resource , < VariableStatement > child ) ;
180
176
break ;
181
177
case SyntaxKind . InterfaceDeclaration :
182
- parseInterface ( resource , < InterfaceDeclaration > node ) ;
178
+ parseInterface ( resource , < InterfaceDeclaration > child ) ;
183
179
break ;
184
180
case SyntaxKind . ClassDeclaration :
185
- parseClass ( resource , < ClassDeclaration > node ) ;
186
- [ resource , ...resourceQueue ] = resourceQueue ;
187
- [ node , ...nodeQueue ] = nodeQueue ;
181
+ parseClass ( resource , < ClassDeclaration > child ) ;
188
182
continue ;
189
183
case SyntaxKind . Identifier :
190
- parseIdentifier ( resource , < Identifier > node ) ;
184
+ parseIdentifier ( resource , < Identifier > child ) ;
191
185
break ;
192
186
case SyntaxKind . ModuleDeclaration :
193
- const newResource = parseModule ( resource , < ModuleDeclaration > node ) ;
194
- [ resource , ...resourceQueue ] = [ ...Array ( node . getChildren ( ) . length ) . fill ( newResource ) , ...resourceQueue ] ;
195
- [ node , ...nodeQueue ] = [ ...node . getChildren ( ) , ...nodeQueue ] ;
187
+ const newResource = parseModule ( resource , < ModuleDeclaration > child ) ;
188
+ this . parse ( newResource , child ) ;
196
189
continue ;
197
190
default :
198
191
break ;
199
192
}
200
- [ resource , ...resourceQueue ] = [ ...Array ( node . getChildren ( ) . length ) . fill ( resource ) , ...resourceQueue ] ;
201
- [ node , ...nodeQueue ] = [ ...node . getChildren ( ) , ...nodeQueue ] ;
193
+ this . parse ( resource , child ) ;
202
194
}
203
195
}
204
196
}
0 commit comments