fix(parsing): back to recursive · buehler/node-typescript-parser@1ce22e7
@@ -151,54 +151,46 @@ export class TypescriptParser {
151151 *
152152 * @memberof TsResourceParser
153153 */
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) {
159157case SyntaxKind.ImportDeclaration:
160158case SyntaxKind.ImportEqualsDeclaration:
161-parseImport(resource, <ImportDeclaration | ImportEqualsDeclaration>node);
159+parseImport(resource, <ImportDeclaration | ImportEqualsDeclaration>child);
162160break;
163161case SyntaxKind.ExportDeclaration:
164162case SyntaxKind.ExportAssignment:
165-parseExport(resource, <ExportAssignment | ExportDeclaration>node);
163+parseExport(resource, <ExportAssignment | ExportDeclaration>child);
166164break;
167165case SyntaxKind.EnumDeclaration:
168-parseEnum(resource, <EnumDeclaration>node);
166+parseEnum(resource, <EnumDeclaration>child);
169167break;
170168case SyntaxKind.TypeAliasDeclaration:
171-parseTypeAlias(resource, <TypeAliasDeclaration>node);
169+parseTypeAlias(resource, <TypeAliasDeclaration>child);
172170break;
173171case SyntaxKind.FunctionDeclaration:
174-parseFunction(resource, <FunctionDeclaration>node);
175-[resource, ...resourceQueue] = resourceQueue;
176-[node, ...nodeQueue] = nodeQueue;
172+parseFunction(resource, <FunctionDeclaration>child);
177173continue;
178174case SyntaxKind.VariableStatement:
179-parseVariable(resource, <VariableStatement>node);
175+parseVariable(resource, <VariableStatement>child);
180176break;
181177case SyntaxKind.InterfaceDeclaration:
182-parseInterface(resource, <InterfaceDeclaration>node);
178+parseInterface(resource, <InterfaceDeclaration>child);
183179break;
184180case SyntaxKind.ClassDeclaration:
185-parseClass(resource, <ClassDeclaration>node);
186-[resource, ...resourceQueue] = resourceQueue;
187-[node, ...nodeQueue] = nodeQueue;
181+parseClass(resource, <ClassDeclaration>child);
188182continue;
189183case SyntaxKind.Identifier:
190-parseIdentifier(resource, <Identifier>node);
184+parseIdentifier(resource, <Identifier>child);
191185break;
192186case 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);
196189continue;
197190default:
198191break;
199192}
200-[resource, ...resourceQueue] = [...Array(node.getChildren().length).fill(resource), ...resourceQueue];
201-[node, ...nodeQueue] = [...node.getChildren(), ...nodeQueue];
193+this.parse(resource, child);
202194}
203195}
204196}