Skip to content

Commit 3814299

Browse files
committed
fix(app): multi decorators support
fix #1128 #868 #1130
1 parent 95e4945 commit 3814299

File tree

3 files changed

+106
-75
lines changed

3 files changed

+106
-75
lines changed

src/app/compiler/angular/deps/helpers/class-helper.ts

Lines changed: 99 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,16 @@ export class ClassHelper {
438438
: false;
439439
}
440440

441+
private isControllerDecorator(decorator) {
442+
return decorator.expression.expression
443+
? decorator.expression.expression.text === 'Controller'
444+
: false;
445+
}
446+
441447
private isModuleDecorator(decorator) {
442448
return decorator.expression.expression
443-
? decorator.expression.expression.text === 'NgModule'
449+
? decorator.expression.expression.text === 'NgModule' ||
450+
decorator.expression.expression.text === 'Module'
444451
: false;
445452
}
446453

@@ -522,93 +529,110 @@ export class ClassHelper {
522529
members = this.visitMembers(classDeclaration.members, sourceFile);
523530

524531
if (classDeclaration.decorators) {
525-
for (let i = 0; i < classDeclaration.decorators.length; i++) {
526-
if (this.isDirectiveDecorator(classDeclaration.decorators[i])) {
527-
return {
532+
// Loop and search for official decorators at top-level :
533+
// Angular : @NgModule, @Component, @Directive, @Injectable, @Pipe
534+
// Nestjs : @Controller, @Module, @Injectable
535+
// Stencil : @Component
536+
let isDirective = false;
537+
let isService = false;
538+
let isPipe = false;
539+
let isModule = false;
540+
let isController = false;
541+
for (let a = 0; a < classDeclaration.decorators.length; a++) {
542+
//console.log(classDeclaration.decorators[i].expression);
543+
544+
// RETURN TOO EARLY FOR MANY DECORATORS !!!!
545+
isDirective = this.isDirectiveDecorator(classDeclaration.decorators[a]);
546+
isService = this.isServiceDecorator(classDeclaration.decorators[a]);
547+
isPipe = this.isPipeDecorator(classDeclaration.decorators[a]);
548+
isModule = this.isModuleDecorator(classDeclaration.decorators[a]);
549+
isController = this.isControllerDecorator(classDeclaration.decorators[a]);
550+
}
551+
if (isDirective) {
552+
return {
553+
deprecated,
554+
deprecationMessage,
555+
description,
556+
rawdescription: rawdescription,
557+
inputs: members.inputs,
558+
outputs: members.outputs,
559+
hostBindings: members.hostBindings,
560+
hostListeners: members.hostListeners,
561+
properties: members.properties,
562+
methods: members.methods,
563+
indexSignatures: members.indexSignatures,
564+
kind: members.kind,
565+
constructor: members.constructor,
566+
jsdoctags: jsdoctags,
567+
extends: extendsElement,
568+
implements: implementsElements,
569+
accessors: members.accessors
570+
};
571+
} else if (isService) {
572+
return [
573+
{
574+
fileName,
575+
className,
576+
deprecated,
577+
deprecationMessage,
578+
description,
579+
rawdescription: rawdescription,
580+
methods: members.methods,
581+
indexSignatures: members.indexSignatures,
582+
properties: members.properties,
583+
kind: members.kind,
584+
constructor: members.constructor,
585+
jsdoctags: jsdoctags,
586+
extends: extendsElement,
587+
implements: implementsElements,
588+
accessors: members.accessors
589+
}
590+
];
591+
} else if (isPipe) {
592+
return [
593+
{
594+
fileName,
595+
className,
528596
deprecated,
529597
deprecationMessage,
530598
description,
531599
rawdescription: rawdescription,
532-
inputs: members.inputs,
533-
outputs: members.outputs,
534-
hostBindings: members.hostBindings,
535-
hostListeners: members.hostListeners,
600+
jsdoctags: jsdoctags,
536601
properties: members.properties,
602+
methods: members.methods
603+
}
604+
];
605+
} else if (isModule) {
606+
return [
607+
{
608+
fileName,
609+
className,
610+
deprecated,
611+
deprecationMessage,
612+
description,
613+
rawdescription: rawdescription,
614+
jsdoctags: jsdoctags,
615+
methods: members.methods
616+
}
617+
];
618+
} else {
619+
return [
620+
{
621+
deprecated,
622+
deprecationMessage,
623+
description,
624+
rawdescription: rawdescription,
537625
methods: members.methods,
538626
indexSignatures: members.indexSignatures,
627+
properties: members.properties,
539628
kind: members.kind,
540629
constructor: members.constructor,
541630
jsdoctags: jsdoctags,
542631
extends: extendsElement,
543632
implements: implementsElements,
544633
accessors: members.accessors
545-
};
546-
} else if (this.isServiceDecorator(classDeclaration.decorators[i])) {
547-
return [
548-
{
549-
fileName,
550-
className,
551-
deprecated,
552-
deprecationMessage,
553-
description,
554-
rawdescription: rawdescription,
555-
methods: members.methods,
556-
indexSignatures: members.indexSignatures,
557-
properties: members.properties,
558-
kind: members.kind,
559-
constructor: members.constructor,
560-
jsdoctags: jsdoctags,
561-
extends: extendsElement,
562-
implements: implementsElements,
563-
accessors: members.accessors
564-
}
565-
];
566-
} else if (this.isPipeDecorator(classDeclaration.decorators[i])) {
567-
return [
568-
{
569-
fileName,
570-
className,
571-
deprecated,
572-
deprecationMessage,
573-
description,
574-
rawdescription: rawdescription,
575-
jsdoctags: jsdoctags,
576-
properties: members.properties,
577-
methods: members.methods
578-
}
579-
];
580-
} else if (this.isModuleDecorator(classDeclaration.decorators[i])) {
581-
return [
582-
{
583-
fileName,
584-
className,
585-
deprecated,
586-
deprecationMessage,
587-
description,
588-
rawdescription: rawdescription,
589-
jsdoctags: jsdoctags,
590-
methods: members.methods
591-
}
592-
];
593-
} else {
594-
return [
595-
{
596-
deprecated,
597-
deprecationMessage,
598-
description,
599-
rawdescription: rawdescription,
600-
methods: members.methods,
601-
indexSignatures: members.indexSignatures,
602-
properties: members.properties,
603-
kind: members.kind,
604-
constructor: members.constructor,
605-
jsdoctags: jsdoctags,
606-
extends: extendsElement,
607-
implements: implementsElements,
608-
accessors: members.accessors
609-
}
610-
];
611-
}
634+
}
635+
];
612636
}
613637
} else if (description) {
614638
return [

test/fixtures/todomvc-ng2/src/app/about/about.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { Subscription } from 'rxjs/Subscription';
1717
*
1818
* Display some text with links for details about TodoMVC & Compodoc.
1919
*/
20+
@testDecorator
21+
@UntilDestroy()
2022
@Component({
2123
selector: 'about',
2224
template,

test/src/cli/cli-generation-big-app.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,4 +875,9 @@ describe('CLI simple generation - big app', () => {
875875
let file = read(distFolder + '/components/HeaderComponent.html');
876876
expect(file).to.contain('_fullName <a href="https://compodoc.app/">https://compodoc.app/');
877877
});
878+
879+
it('should support multiple decorators for component for example', () => {
880+
let file = read(distFolder + '/components/AboutComponent.html');
881+
expect(file).to.contain('<code>src/app/about/about.component.ts</code>');
882+
});
878883
});

0 commit comments

Comments
 (0)