Skip to content

Commit 765f496

Browse files
committed
fix(app): Directive class inheritance
fix #1140
1 parent 0a15cf6 commit 765f496

File tree

6 files changed

+88
-6
lines changed

6 files changed

+88
-6
lines changed

src/app/compiler/angular/deps/directive-dep.factory.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export class DirectiveDepFactory {
99
constructor(private helper: ComponentHelper) {}
1010

1111
public create(file: any, srcFile: any, name: any, props: any, IO: any): IDirectiveDep {
12-
let sourceCode = srcFile.getText();
13-
let hash = crypto.createHash('sha512').update(sourceCode).digest('hex');
14-
let directiveDeps: IDirectiveDep = {
12+
const sourceCode = srcFile.getText();
13+
const hash = crypto.createHash('sha512').update(sourceCode).digest('hex');
14+
const directiveDeps: IDirectiveDep = {
1515
name,
1616
id: 'directive-' + name + '-' + hash,
1717
file: file,
@@ -41,6 +41,9 @@ export class DirectiveDepFactory {
4141
if (IO.jsdoctags && IO.jsdoctags.length > 0) {
4242
directiveDeps.jsdoctags = IO.jsdoctags[0].tags;
4343
}
44+
if (IO.extends) {
45+
directiveDeps.extends = IO.extends;
46+
}
4447
if (IO.implements && IO.implements.length > 0) {
4548
directiveDeps.implements = IO.implements;
4649
}
@@ -80,4 +83,5 @@ export interface IDirectiveDep extends IDep {
8083
jsdoctags?: Array<string>;
8184
implements?: any;
8285
accessors?: Object;
86+
extends?: any;
8387
}

src/templates/partials/directive.hbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
</p>
4242
{{/if}}
4343

44+
{{#if directive.extends}}
45+
<p class="comment">
46+
<h3>{{t "extends" }}</h3>
47+
</p>
48+
<p class="comment">
49+
{{> link-type type=directive.extends }}
50+
</p>
51+
{{/if}}
52+
4453
{{#if directive.implements}}
4554
<p class="comment">
4655
<h3>{{t "implements" }}</h3>

src/utils/extends-merger.util.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ExtendsMerger {
2424
this.injectables = deps.injectables;
2525
this.directives = deps.directives;
2626

27-
this.components.forEach(component => {
27+
const mergeExtendedProperties = component => {
2828
let ext;
2929
if (typeof component.extends !== 'undefined') {
3030
ext = this.findInDependencies(component.extends);
@@ -117,7 +117,10 @@ export class ExtendsMerger {
117117
recursiveScanWithInheritance(ext);
118118
}
119119
}
120-
});
120+
};
121+
122+
this.components.forEach(mergeExtendedProperties);
123+
this.directives.forEach(mergeExtendedProperties);
121124

122125
const mergeExtendedClasses = el => {
123126
let ext;
@@ -151,6 +154,7 @@ export class ExtendsMerger {
151154

152155
this.classes.forEach(mergeExtendedClasses);
153156
this.injectables.forEach(mergeExtendedClasses);
157+
this.directives.forEach(mergeExtendedClasses);
154158

155159
return deps;
156160
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Directive, HostBinding, HostListener, Input } from '@angular/core';
2+
3+
/**
4+
* The a directive
5+
*/
6+
@Directive({
7+
selector: '[a]',
8+
})
9+
export class ADirective {
10+
title: string;
11+
12+
/**
13+
* constructor description
14+
*/
15+
constructor() {}
16+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Directive, HostBinding, HostListener, Input } from '@angular/core';
2+
import { ADirective } from './a.directive';
3+
4+
/**
5+
* This directive does nothing !
6+
*/
7+
@Directive({
8+
selector: '[donothing]',
9+
})
10+
export class DoNothingDirective extends ADirective {
11+
protected popover: string;
12+
13+
/**
14+
* constructor description
15+
*/
16+
constructor() {
17+
console.log('Do nothing directive');
18+
}
19+
20+
/**
21+
* HostBinding description
22+
*/
23+
@HostBinding('style.color') color: string;
24+
25+
/**
26+
* HostListener description 1
27+
*/
28+
@HostListener('mouseup', ['$event.clientX', '$event.clientY'])
29+
onMouseup(mouseX: number, mouseY: number): void {}
30+
/**
31+
* HostListener description 2
32+
*/
33+
@HostListener('mousedown', ['$event.clientX', '$event.clientY'])
34+
onMousedown(mouseX: number, mouseY: number): void {}
35+
/**
36+
* HostListener description 3
37+
*/
38+
@HostListener('focus', ['$event'])
39+
@HostListener('click', ['$event'])
40+
onClick(e: Event): void {}
41+
}

test/src/cli/cli-extends.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ describe('CLI simple generation - extends app', () => {
3939
expect(appComponentFile).to.contain('itisme');
4040
});
4141

42+
it('DoNothingDirective extends ADirective', () => {
43+
const file = read(distFolder + '/directives/DoNothingDirective.html');
44+
expect(file).to.contain('Extends');
45+
expect(file).to.contain(
46+
'code><a href="../directives/ADirective.html" target="_self" >ADirective'
47+
);
48+
});
49+
4250
it('MyInitialClass extends SubClassA', () => {
4351
expect(myInitialClassFile).to.contain('meh');
4452
expect(myInitialClassFile).to.contain('myproperty');
@@ -51,7 +59,7 @@ describe('CLI simple generation - extends app', () => {
5159
});
5260

5361
it('CharactersService extends AbstractService', () => {
54-
let file = read(distFolder + '/injectables/CharactersService.html');
62+
const file = read(distFolder + '/injectables/CharactersService.html');
5563
expect(file).to.contain(
5664
'code><a href="../injectables/AbstractService.html" target="_self" >AbstractService'
5765
);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy