Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse Components before Modules to get all the Components metadata #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/modules/compiler/dist/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@ var Compiler = /** @class */ (function () {
if (filePath.lastIndexOf('.d.ts') === -1 && filePath.lastIndexOf('spec.ts') === -1) {
ngd_core_1.logger.info('parsing', filePath);
try {
_this.getSourceFileDecorators(file, deps);
_this.getSourceFileDecorators(file, deps, 'Component');
}
catch (e) {
ngd_core_1.logger.trace(e, file.fileName);
}
}
}
return deps;
});
sourceFiles.map(function (file) {
var filePath = file.fileName;
if (path.extname(filePath) === '.ts') {
if (filePath.lastIndexOf('.d.ts') === -1 && filePath.lastIndexOf('spec.ts') === -1) {
ngd_core_1.logger.info('parsing', filePath);
try {
_this.getSourceFileDecorators(file, deps, ', NgModule');
}
catch (e) {
ngd_core_1.logger.trace(e, file.fileName);
Expand All @@ -39,7 +54,7 @@ var Compiler = /** @class */ (function () {
});
return deps;
};
Compiler.prototype.getSourceFileDecorators = function (srcFile, outputSymbols) {
Compiler.prototype.getSourceFileDecorators = function (srcFile, outputSymbols, parseType) {
var _this = this;
ts.forEachChild(srcFile, function (node) {
if (node.decorators) {
Expand Down Expand Up @@ -77,7 +92,7 @@ var Compiler = /** @class */ (function () {
};
var filterByDecorators = function (node) {
if (node.expression && node.expression.expression) {
return /(NgModule|Component)/.test(node.expression.expression.text);
return new RegExp('(' + parseType + ')').test(node.expression.expression.text);
}
return false;
};
Expand Down
30 changes: 26 additions & 4 deletions src/modules/compiler/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Compiler {
module: ts.ModuleKind.CommonJS,
tsconfigDirectory: options.tsconfigDirectory
};
this.program = ts.createProgram(this.files, transpileOptions, compilerHost(transpileOptions));
this.program = ts.createProgram(this.files, transpileOptions, <any>compilerHost(transpileOptions));

// silent this instance of the logger
logger.setVerbose(options.silent);
Expand All @@ -81,7 +81,29 @@ export class Compiler {
logger.info('parsing', filePath);

try {
this.getSourceFileDecorators(file, deps);
this.getSourceFileDecorators(file, deps, 'Component');
}
catch (e) {
logger.trace(e, file.fileName);
}
}

}

return deps;

});
sourceFiles.map((file: ts.SourceFile) => {

let filePath = file.fileName;

if (path.extname(filePath) === '.ts') {

if (filePath.lastIndexOf('.d.ts') === -1 && filePath.lastIndexOf('spec.ts') === -1) {
logger.info('parsing', filePath);

try {
this.getSourceFileDecorators(file, deps, ', NgModule');
}
catch (e) {
logger.trace(e, file.fileName);
Expand All @@ -98,7 +120,7 @@ export class Compiler {
}


private getSourceFileDecorators(srcFile: ts.SourceFile, outputSymbols: Dependencies[]): void {
private getSourceFileDecorators(srcFile: ts.SourceFile, outputSymbols: Dependencies[], parseType): void {

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

Expand Down Expand Up @@ -145,7 +167,7 @@ export class Compiler {

let filterByDecorators = (node) => {
if (node.expression && node.expression.expression) {
return /(NgModule|Component)/.test(node.expression.expression.text)
return new RegExp('(' + parseType + ')').test(node.expression.expression.text);
}
return false;
};
Expand Down