Skip to content

Commit

Permalink
fix(migration): add line break before UntilDestroy decorator (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
FFKL authored Jul 15, 2020
1 parent f2a59eb commit 4fc708a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
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', () => {
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

0 comments on commit 4fc708a

Please sign in to comment.