Skip to content

Commit

Permalink
Merge pull request #54 from buehler/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
buehler authored Mar 6, 2018
2 parents 57a14a5 + 851513a commit 3cf2a6c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"AST",
"parsing"
],
"release": {
"success": false,
"fail": false
},
"author": "Christoph Bühler <christoph.buehler@bluewin.ch>",
"license": "MIT",
"bugs": {
Expand Down
38 changes: 15 additions & 23 deletions src/TypescriptParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,54 +151,46 @@ export class TypescriptParser {
*
* @memberof TsResourceParser
*/
private parse(rootResource: Resource, rootNode: Node): void {
let [resource, ...resourceQueue]: Resource[] = Array(rootNode.getChildren().length).fill(rootResource);
let [node, ...nodeQueue]: Node[] = [...rootNode.getChildren()];
while (node) {
switch (node.kind) {
private parse(resource: Resource, node: Node): void {
for (const child of node.getChildren()) {
switch (child.kind) {
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
parseImport(resource, <ImportDeclaration | ImportEqualsDeclaration>node);
parseImport(resource, <ImportDeclaration | ImportEqualsDeclaration>child);
break;
case SyntaxKind.ExportDeclaration:
case SyntaxKind.ExportAssignment:
parseExport(resource, <ExportAssignment | ExportDeclaration>node);
parseExport(resource, <ExportAssignment | ExportDeclaration>child);
break;
case SyntaxKind.EnumDeclaration:
parseEnum(resource, <EnumDeclaration>node);
parseEnum(resource, <EnumDeclaration>child);
break;
case SyntaxKind.TypeAliasDeclaration:
parseTypeAlias(resource, <TypeAliasDeclaration>node);
parseTypeAlias(resource, <TypeAliasDeclaration>child);
break;
case SyntaxKind.FunctionDeclaration:
parseFunction(resource, <FunctionDeclaration>node);
[resource, ...resourceQueue] = resourceQueue;
[node, ...nodeQueue] = nodeQueue;
parseFunction(resource, <FunctionDeclaration>child);
continue;
case SyntaxKind.VariableStatement:
parseVariable(resource, <VariableStatement>node);
parseVariable(resource, <VariableStatement>child);
break;
case SyntaxKind.InterfaceDeclaration:
parseInterface(resource, <InterfaceDeclaration>node);
parseInterface(resource, <InterfaceDeclaration>child);
break;
case SyntaxKind.ClassDeclaration:
parseClass(resource, <ClassDeclaration>node);
[resource, ...resourceQueue] = resourceQueue;
[node, ...nodeQueue] = nodeQueue;
parseClass(resource, <ClassDeclaration>child);
continue;
case SyntaxKind.Identifier:
parseIdentifier(resource, <Identifier>node);
parseIdentifier(resource, <Identifier>child);
break;
case SyntaxKind.ModuleDeclaration:
const newResource = parseModule(resource, <ModuleDeclaration>node);
[resource, ...resourceQueue] = [...Array(node.getChildren().length).fill(newResource), ...resourceQueue];
[node, ...nodeQueue] = [...node.getChildren(), ...nodeQueue];
const newResource = parseModule(resource, <ModuleDeclaration>child);
this.parse(newResource, child);
continue;
default:
break;
}
[resource, ...resourceQueue] = [...Array(node.getChildren().length).fill(resource), ...resourceQueue];
[node, ...nodeQueue] = [...node.getChildren(), ...nodeQueue];
this.parse(resource, child);
}
}
}

0 comments on commit 3cf2a6c

Please sign in to comment.