Skip to content

Commit 059b3c9

Browse files
committed
fix(deps): support class with custom decorator
fix #245
1 parent d468ee8 commit 059b3c9

File tree

6 files changed

+429
-432
lines changed

6 files changed

+429
-432
lines changed

dist/index-cli.js

Lines changed: 67 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 67 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/compiler/dependencies.ts

Lines changed: 67 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,44 @@ export class Dependencies {
241241
return deps;
242242
}
243243

244+
private processClass(node, file, srcFile, deps, outputSymbols) {
245+
let name = this.getSymboleName(node);
246+
let IO = this.getClassIO(file, srcFile, node);
247+
deps = {
248+
name,
249+
id: 'class-' + name + '-' + Date.now(),
250+
file: file,
251+
type: 'class',
252+
sourceCode: srcFile.getText()
253+
};
254+
if(IO.constructor) {
255+
deps.constructorObj = IO.constructor;
256+
}
257+
if(IO.properties) {
258+
deps.properties = IO.properties;
259+
}
260+
if(IO.description) {
261+
deps.description = IO.description;
262+
}
263+
if(IO.methods) {
264+
deps.methods = IO.methods;
265+
}
266+
if(IO.indexSignatures) {
267+
deps.indexSignatures = IO.indexSignatures;
268+
}
269+
if (IO.extends) {
270+
deps.extends = IO.extends;
271+
}
272+
if (IO.jsdoctags && IO.jsdoctags.length > 0) {
273+
deps.jsdoctags = IO.jsdoctags[0].tags
274+
}
275+
if (IO.implements && IO.implements.length > 0) {
276+
deps.implements = IO.implements;
277+
}
278+
this.debug(deps);
279+
outputSymbols['classes'].push(deps);
280+
}
281+
244282
private getSourceFileDecorators(srcFile: ts.SourceFile, outputSymbols: Object): void {
245283

246284
let cleaner = (process.cwd() + path.sep).replace(/\\/g, '/'),
@@ -253,6 +291,7 @@ export class Dependencies {
253291
if (this.hasJSDocInternalTag(file, srcFile, node) && this.configuration.mainData.disablePrivateOrInternalSupport) { return; }
254292

255293
if (node.decorators) {
294+
let classWithCustomDecorator = false;
256295
let visitNode = (visitedNode, index) => {
257296

258297
let metadata = node.decorators;
@@ -395,16 +434,25 @@ export class Dependencies {
395434
deps.constructorObj = IO.constructor;
396435
}
397436
outputSymbols['directives'].push(deps);
437+
} else {
438+
//Just a class
439+
if (!classWithCustomDecorator) {
440+
classWithCustomDecorator = true;
441+
this.processClass(node, file, srcFile, deps, outputSymbols);
442+
}
398443
}
399444

400445
this.debug(deps);
401446

402447
this.__cache[name] = deps;
403448
}
404449

405-
let filterByDecorators = (node) => {
406-
if (node.expression && node.expression.expression) {
407-
return /(NgModule|Component|Injectable|Pipe|Directive)/.test(node.expression.expression.text)
450+
let filterByDecorators = (filteredNode) => {
451+
if (filteredNode.expression && filteredNode.expression.expression) {
452+
return /(NgModule|Component|Injectable|Pipe|Directive)/.test(filteredNode.expression.expression.text)
453+
}
454+
if (node.kind === ts.SyntaxKind.ClassDeclaration) {
455+
return true;
408456
}
409457
return false;
410458
};
@@ -415,41 +463,7 @@ export class Dependencies {
415463
}
416464
else if (node.symbol) {
417465
if(node.symbol.flags === ts.SymbolFlags.Class) {
418-
let name = this.getSymboleName(node);
419-
let IO = this.getClassIO(file, srcFile, node);
420-
deps = {
421-
name,
422-
id: 'class-' + name + '-' + Date.now(),
423-
file: file,
424-
type: 'class',
425-
sourceCode: srcFile.getText()
426-
};
427-
if(IO.constructor) {
428-
deps.constructorObj = IO.constructor;
429-
}
430-
if(IO.properties) {
431-
deps.properties = IO.properties;
432-
}
433-
if(IO.description) {
434-
deps.description = IO.description;
435-
}
436-
if(IO.methods) {
437-
deps.methods = IO.methods;
438-
}
439-
if(IO.indexSignatures) {
440-
deps.indexSignatures = IO.indexSignatures;
441-
}
442-
if (IO.extends) {
443-
deps.extends = IO.extends;
444-
}
445-
if (IO.jsdoctags && IO.jsdoctags.length > 0) {
446-
deps.jsdoctags = IO.jsdoctags[0].tags
447-
}
448-
if (IO.implements && IO.implements.length > 0) {
449-
deps.implements = IO.implements;
450-
}
451-
this.debug(deps);
452-
outputSymbols['classes'].push(deps);
466+
this.processClass(node, file, srcFile, deps, outputSymbols);
453467
} else if(node.symbol.flags === ts.SymbolFlags.Interface) {
454468
let name = this.getSymboleName(node);
455469
let IO = this.getInterfaceIO(file, srcFile, node);
@@ -541,41 +555,7 @@ export class Dependencies {
541555
outputSymbols['routes'] = [...outputSymbols['routes'], ...newRoutes];
542556
}
543557
if (node.kind === ts.SyntaxKind.ClassDeclaration) {
544-
let name = this.getSymboleName(node);
545-
let IO = this.getClassIO(file, srcFile, node);
546-
deps = {
547-
name,
548-
id: 'class-' + name + '-' + Date.now(),
549-
file: file,
550-
type: 'class',
551-
sourceCode: srcFile.getText()
552-
};
553-
if(IO.constructor) {
554-
deps.constructorObj = IO.constructor;
555-
}
556-
if(IO.properties) {
557-
deps.properties = IO.properties;
558-
}
559-
if(IO.indexSignatures) {
560-
deps.indexSignatures = IO.indexSignatures;
561-
}
562-
if(IO.description) {
563-
deps.description = IO.description;
564-
}
565-
if(IO.methods) {
566-
deps.methods = IO.methods;
567-
}
568-
if (IO.extends) {
569-
deps.extends = IO.extends;
570-
}
571-
if (IO.implements && IO.implements.length > 0) {
572-
deps.implements = IO.implements;
573-
}
574-
if (IO.jsdoctags && IO.jsdoctags.length > 0) {
575-
deps.jsdoctags = IO.jsdoctags[0].tags
576-
}
577-
this.debug(deps);
578-
outputSymbols['classes'].push(deps);
558+
this.processClass(node, file, srcFile, deps, outputSymbols);
579559
}
580560
if (node.kind === ts.SyntaxKind.ExpressionStatement) {
581561
let bootstrapModuleReference = 'bootstrapModule';
@@ -858,7 +838,7 @@ export class Dependencies {
858838
}
859839

860840
private findProps(visitedNode) {
861-
if(visitedNode.expression.arguments.length > 0) {
841+
if(visitedNode.expression.arguments && visitedNode.expression.arguments.length > 0) {
862842
return visitedNode.expression.arguments.pop().properties;
863843
} else {
864844
return '';
@@ -1570,7 +1550,19 @@ export class Dependencies {
15701550
jsdoctags: jsdoctags
15711551
}];
15721552
} else {
1573-
//console.log('custom decorator');
1553+
members = this.visitMembers(classDeclaration.members, sourceFile);
1554+
1555+
return [{
1556+
description,
1557+
methods: members.methods,
1558+
indexSignatures: members.indexSignatures,
1559+
properties: members.properties,
1560+
kind: members.kind,
1561+
constructor: members.constructor,
1562+
jsdoctags: jsdoctags,
1563+
extends: extendsElement,
1564+
implements: implementsElements
1565+
}];
15741566
}
15751567
}
15761568
} else if (description) {

0 commit comments

Comments
 (0)