Skip to content

Commit

Permalink
fix(app): disableLifeCycleHooks for pipes and services
Browse files Browse the repository at this point in the history
fix #1369
  • Loading branch information
vogloblinsky committed Aug 16, 2023
1 parent 791f421 commit 753b74d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/app/compiler/angular-dependencies.ts
Expand Up @@ -468,6 +468,11 @@ export class AngularDependencies extends FrameworkDependencies {
if (IO.extends) {
injectableDeps.extends = IO.extends;
}
if (Configuration.mainData.disableLifeCycleHooks) {
injectableDeps.methods = cleanLifecycleHooksFromMethods(
injectableDeps.methods
);
}
deps = injectableDeps;
if (typeof IO.ignore === 'undefined') {
if (_.includes(IO.implements, 'HttpInterceptor')) {
Expand Down Expand Up @@ -509,6 +514,9 @@ export class AngularDependencies extends FrameworkDependencies {
srcFile.getText()
)
};
if (Configuration.mainData.disableLifeCycleHooks) {
pipeDeps.methods = cleanLifecycleHooksFromMethods(pipeDeps.methods);
}
if (IO.jsdoctags && IO.jsdoctags.length > 0) {
pipeDeps.jsdoctags = IO.jsdoctags[0].tags;
}
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/sample-files/bar.pipe.ts
@@ -0,0 +1,13 @@
import { PipeTransform, Pipe, OnDestroy } from '@angular/core';

@Pipe({
name: 'bar',
standalone: true
})
export class BarPipe implements PipeTransform, OnDestroy {
transform(value, args) {
return 'StandAlone Pipe ;)';
}

ngOnDestroy(): void {}
}
4 changes: 3 additions & 1 deletion test/fixtures/sample-files/bar.service.ts
@@ -1,4 +1,6 @@
import { Injectable } from '@angular/core';

@Injectable()
export class BarService {}
export class BarService implements OnDestroy {
ngOnDestroy(): void {}
}
4 changes: 4 additions & 0 deletions test/src/cli/cli-disable-options.spec.ts
Expand Up @@ -167,6 +167,10 @@ describe('CLI disable flags', () => {
expect(componentFile).not.to.contain('<code>ngOnInit');
const directiveFile = read(`${distFolder}/directives/BarDirective.html`);
expect(directiveFile).not.to.contain('<code>ngOnInit');
const pipeFile = read(`${distFolder}/pipes/BarPipe.html`);
expect(pipeFile).not.to.contain('<code>ngOnDestroy');
const serviceFile = read(`${distFolder}/injectables/BarService.html`);
expect(serviceFile).not.to.contain('<code>ngOnDestroy');
});

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

0 comments on commit 753b74d

Please sign in to comment.