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