Skip to content

Commit 1ce22e7

Browse files
author
Christoph Bühler
committed
fix(parsing): back to recursive
1 parent 7bf013e commit 1ce22e7

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

src/TypescriptParser.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
159157
case SyntaxKind.ImportDeclaration:
160158
case SyntaxKind.ImportEqualsDeclaration:
161-
parseImport(resource, <ImportDeclaration | ImportEqualsDeclaration>node);
159+
parseImport(resource, <ImportDeclaration | ImportEqualsDeclaration>child);
162160
break;
163161
case SyntaxKind.ExportDeclaration:
164162
case SyntaxKind.ExportAssignment:
165-
parseExport(resource, <ExportAssignment | ExportDeclaration>node);
163+
parseExport(resource, <ExportAssignment | ExportDeclaration>child);
166164
break;
167165
case SyntaxKind.EnumDeclaration:
168-
parseEnum(resource, <EnumDeclaration>node);
166+
parseEnum(resource, <EnumDeclaration>child);
169167
break;
170168
case SyntaxKind.TypeAliasDeclaration:
171-
parseTypeAlias(resource, <TypeAliasDeclaration>node);
169+
parseTypeAlias(resource, <TypeAliasDeclaration>child);
172170
break;
173171
case SyntaxKind.FunctionDeclaration:
174-
parseFunction(resource, <FunctionDeclaration>node);
175-
[resource, ...resourceQueue] = resourceQueue;
176-
[node, ...nodeQueue] = nodeQueue;
172+
parseFunction(resource, <FunctionDeclaration>child);
177173
continue;
178174
case SyntaxKind.VariableStatement:
179-
parseVariable(resource, <VariableStatement>node);
175+
parseVariable(resource, <VariableStatement>child);
180176
break;
181177
case SyntaxKind.InterfaceDeclaration:
182-
parseInterface(resource, <InterfaceDeclaration>node);
178+
parseInterface(resource, <InterfaceDeclaration>child);
183179
break;
184180
case SyntaxKind.ClassDeclaration:
185-
parseClass(resource, <ClassDeclaration>node);
186-
[resource, ...resourceQueue] = resourceQueue;
187-
[node, ...nodeQueue] = nodeQueue;
181+
parseClass(resource, <ClassDeclaration>child);
188182
continue;
189183
case SyntaxKind.Identifier:
190-
parseIdentifier(resource, <Identifier>node);
184+
parseIdentifier(resource, <Identifier>child);
191185
break;
192186
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);
196189
continue;
197190
default:
198191
break;
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
}

0 commit comments

Comments
 (0)