Skip to content

Commit 753b74d

Browse files
committed
fix(app): disableLifeCycleHooks for pipes and services
fix #1369
1 parent 791f421 commit 753b74d

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/app/compiler/angular-dependencies.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ export class AngularDependencies extends FrameworkDependencies {
468468
if (IO.extends) {
469469
injectableDeps.extends = IO.extends;
470470
}
471+
if (Configuration.mainData.disableLifeCycleHooks) {
472+
injectableDeps.methods = cleanLifecycleHooksFromMethods(
473+
injectableDeps.methods
474+
);
475+
}
471476
deps = injectableDeps;
472477
if (typeof IO.ignore === 'undefined') {
473478
if (_.includes(IO.implements, 'HttpInterceptor')) {
@@ -509,6 +514,9 @@ export class AngularDependencies extends FrameworkDependencies {
509514
srcFile.getText()
510515
)
511516
};
517+
if (Configuration.mainData.disableLifeCycleHooks) {
518+
pipeDeps.methods = cleanLifecycleHooksFromMethods(pipeDeps.methods);
519+
}
512520
if (IO.jsdoctags && IO.jsdoctags.length > 0) {
513521
pipeDeps.jsdoctags = IO.jsdoctags[0].tags;
514522
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { PipeTransform, Pipe, OnDestroy } from '@angular/core';
2+
3+
@Pipe({
4+
name: 'bar',
5+
standalone: true
6+
})
7+
export class BarPipe implements PipeTransform, OnDestroy {
8+
transform(value, args) {
9+
return 'StandAlone Pipe ;)';
10+
}
11+
12+
ngOnDestroy(): void {}
13+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Injectable } from '@angular/core';
22

33
@Injectable()
4-
export class BarService {}
4+
export class BarService implements OnDestroy {
5+
ngOnDestroy(): void {}
6+
}

test/src/cli/cli-disable-options.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ describe('CLI disable flags', () => {
167167
expect(componentFile).not.to.contain('<code>ngOnInit');
168168
const directiveFile = read(`${distFolder}/directives/BarDirective.html`);
169169
expect(directiveFile).not.to.contain('<code>ngOnInit');
170+
const pipeFile = read(`${distFolder}/pipes/BarPipe.html`);
171+
expect(pipeFile).not.to.contain('<code>ngOnDestroy');
172+
const serviceFile = read(`${distFolder}/injectables/BarService.html`);
173+
expect(serviceFile).not.to.contain('<code>ngOnDestroy');
170174
});
171175

172176
it('should include methods marked as private', () => {

0 commit comments

Comments
 (0)