Skip to content

Commit 42f0d4c

Browse files
authored
Merge pull request #9417 from IgniteUI/dpetev/migration-event-prop
fix(migrations): resolve property type from definition file path first
2 parents 257d28e + e953621 commit 42f0d4c

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

projects/igniteui-angular/migrations/common/UpdateChanges.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,4 +856,51 @@ export class AppModule { }`);
856856
}
857857
});
858858
});
859+
860+
describe('Language Service migrations', () => {
861+
862+
it('Should be able to replace property of an event', () => {
863+
pending('set up tests for migrations through lang service');
864+
const membersConfig = {
865+
member: 'onGridKeydown',
866+
replaceWith: 'gridKeydown',
867+
definedIn: [
868+
'IgxGridComponent',
869+
'IgxTreeGridComponent',
870+
'IgxHierarchicalGridComponent',
871+
'IgxRowIslandComponent'
872+
]
873+
};
874+
const fileContent =
875+
`import { Component } from '@angular/core';
876+
import { IGridCreatedEventArgs } from 'igniteui-angular';
877+
@Component({
878+
selector: 'app-custom-grid',
879+
template: ''
880+
})
881+
export class CustomGridComponent {
882+
public childGridCreated(event: IGridCreatedEventArgs) {
883+
event.grid.onGridKeydown.subscribe(() => {});
884+
}
885+
}
886+
`;
887+
appTree.create('test.component.ts', fileContent);
888+
const expectedFileContent =
889+
`import { Component } from '@angular/core';
890+
import { IGridCreatedEventArgs } from 'igniteui-angular';
891+
@Component({
892+
selector: 'app-custom-grid',
893+
template: ''
894+
})
895+
export class CustomGridComponent {
896+
public childGridCreated(event: IGridCreatedEventArgs) {
897+
event.grid.gridKeydown.subscribe(() => {});
898+
}
899+
}
900+
`;
901+
const update = new UnitUpdateChanges(__dirname, appTree);
902+
update.applyChanges();
903+
expect(appTree.readContent('test.component.ts')).toEqual(expectedFileContent);
904+
});
905+
});
859906
});

projects/igniteui-angular/migrations/common/tsUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export const getTypeDefinitionAtPosition =
267267
definition.name = maybeReturnType.kind === 'className' ? maybeReturnType.text : '';
268268
return definition;
269269
}
270-
let typeDefs = getTypeDefinitions(langServ, entryPath, definition.textSpan.start);
270+
let typeDefs = getTypeDefinitions(langServ, definition.fileName || entryPath, definition.textSpan.start);
271271
// if there are no type definitions found, the identifier is a ts property, referred in an internal/external template
272272
// or is a reference in a decorator
273273
if (!typeDefs) {

0 commit comments

Comments
 (0)