Skip to content

Commit

Permalink
refactor(parsing): don't create ts program for each child on a file, …
Browse files Browse the repository at this point in the history
…300% boost !
  • Loading branch information
vogloblinsky committed Nov 16, 2016
1 parent 1e70f88 commit 9f754cd
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/app/compiler/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,23 @@ export class Dependencies {

private getSourceFileDecorators(srcFile: ts.SourceFile, outputSymbols: Object): void {

let cleaner = (process.cwd() + path.sep).replace(/\\/g, '/');
let file = srcFile.fileName.replace(cleaner, '');

this.programComponent = ts.createProgram([file], {});
let sourceFile = this.programComponent.getSourceFile(file);
this.typeCheckerComponent = this.programComponent.getTypeChecker(true);

ts.forEachChild(srcFile, (node: ts.Node) => {

let deps: Deps = <Deps>{};
let cleaner = (process.cwd() + path.sep).replace(/\\/g, '/');
let file = srcFile.fileName.replace(cleaner, '');
if (node.decorators) {
let visitNode = (visitedNode, index) => {

let metadata = node.decorators.pop();
let name = this.getSymboleName(node);
let props = this.findProps(visitedNode);
let IO = this.getComponentIO(file);
let IO = this.getComponentIO(file, sourceFile);

if (this.isModule(metadata)) {
deps = {
Expand Down Expand Up @@ -252,7 +257,7 @@ export class Dependencies {
else if (node.symbol) {
if(node.symbol.flags === ts.SymbolFlags.Class) {
let name = this.getSymboleName(node);
let IO = this.getComponentIO(file);
let IO = this.getComponentIO(file, sourceFile);
deps = {
name,
file: file,
Expand All @@ -270,7 +275,7 @@ export class Dependencies {
outputSymbols['classes'].push(deps);
}
} else {
let IO = this.getRouteIO(file);
let IO = this.getRouteIO(file, sourceFile);
if(IO.routes) {
let newRoutes;
try {
Expand Down Expand Up @@ -695,14 +700,10 @@ export class Dependencies {
return [];
}

private getRouteIO(filename: string) {
private getRouteIO(filename, sourceFile) {
/**
* Copyright https://github.com/ng-bootstrap/ng-bootstrap
*/
this.programComponent = ts.createProgram([filename], {});
let sourceFile = this.programComponent.getSourceFile(filename);
this.typeCheckerComponent = this.programComponent.getTypeChecker(true);

var res = sourceFile.statements.reduce((directive, statement) => {

if (statement.kind === ts.SyntaxKind.VariableStatement) {
Expand All @@ -715,14 +716,10 @@ export class Dependencies {
return res[0] || {};
}

private getComponentIO(filename: string) {
private getComponentIO(filename: string, sourceFile) {
/**
* Copyright https://github.com/ng-bootstrap/ng-bootstrap
*/
this.programComponent = ts.createProgram([filename], {});
let sourceFile = this.programComponent.getSourceFile(filename);
this.typeCheckerComponent = this.programComponent.getTypeChecker(true);

var res = sourceFile.statements.reduce((directive, statement) => {

if (statement.kind === ts.SyntaxKind.ClassDeclaration) {
Expand Down

0 comments on commit 9f754cd

Please sign in to comment.