Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(migration): add line break before UntilDestroy decorator #114

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions migration/fixtures/single-import.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { of } from 'rxjs';
import { untilDestroyed } from 'ngx-take-until-destroy';
import { OnDestroy } from '@angular/core';

// test comment
@Component({ template: '' })
export class SingleImportComponent extends BaseComponent implements OnDestroy {
create() {
Expand Down
5 changes: 5 additions & 0 deletions migration/run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ describe('Migration script', () => {
expect(result).not.toContain('ngOnDestroy()');
});

it('should place @UntilDestroy decorator to a new line after the comment', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case for an existing class with multiple decorators.

Copy link
Contributor Author

@FFKL FFKL Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NetanelBasal what do you mean? This case - \n@UntilDestroy\n@Component?

const result = transformCode(code, 'single-import.component.ts', true);
expect(result).toContain(`// test comment\n@UntilDestroy()`);
});

it('should remove class implements', () => {
const result = transformCode(code, 'single-import.component.ts', true);
expect(result).toContain(`export class SingleImportComponent extends BaseComponent {`);
Expand Down
7 changes: 1 addition & 6 deletions migration/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ function replaceOldImport(sourceFile: SourceFile) {
}

function addUntilDestroyDecorator(classDeclaration: ClassDeclaration) {
const decorators = [
{ name: 'UntilDestroy', arguments: [] },
...(classDeclaration.getStructure().decorators || [])
];
classDeclaration.getDecorators().forEach(d => d.remove());
classDeclaration.addDecorators(decorators);
classDeclaration.insertDecorator(0, { name: 'UntilDestroy', arguments: [] });
}

function removeOnDestroyImplements(classDeclaration: ClassDeclaration) {
Expand Down