@@ -7,11 +7,25 @@ import { Logger } from './tsLogger';
77import { TSLanguageService } from './tsPlugin/TSLanguageService' ;
88
99export const IG_PACKAGE_NAME = 'igniteui-angular' ;
10+ export const IG_LICENSED_PACKAGE_NAME = '@infragistics/igniteui-angular' ;
1011export const NG_LANG_SERVICE_PACKAGE_NAME = '@angular/language-service' ;
1112export const NG_CORE_PACKAGE_NAME = '@angular/core' ;
1213export const CUSTOM_TS_PLUGIN_PATH = './tsPlugin' ;
1314export const CUSTOM_TS_PLUGIN_NAME = 'igx-ts-plugin' ;
1415
16+ /**
17+ * Checks if the given import path is from igniteui-angular package.
18+ * Handles both OSS (igniteui-angular) and licensed (@infragistics/igniteui-angular) versions,
19+ * as well as subpaths (e.g., igniteui-angular/core, @infragistics/igniteui-angular/grids).
20+ * @param importPath The module specifier text to check
21+ * @returns true if the import path is from igniteui-angular package
22+ */
23+ export const isIgniteuiImport = ( importPath : string ) : boolean =>
24+ importPath === IG_PACKAGE_NAME ||
25+ importPath === IG_LICENSED_PACKAGE_NAME ||
26+ importPath . startsWith ( `${ IG_PACKAGE_NAME } /` ) ||
27+ importPath . startsWith ( `${ IG_LICENSED_PACKAGE_NAME } /` ) ;
28+
1529enum SyntaxTokens {
1630 ClosingParenthesis = ')' ,
1731 MemberAccess = '.' ,
@@ -83,13 +97,13 @@ export const getImportModulePositions = (sourceText: string, startsWith: string)
8397 return positions ;
8498} ;
8599
86- /** Filters out statements to named imports (e.g. `import {x, y}`) from PACKAGE_IMPORT */
87- export const namedImportFilter = ( statement : ts . Statement ) => {
88- if ( statement . kind === ts . SyntaxKind . ImportDeclaration &&
89- ( ( statement as ts . ImportDeclaration ) . moduleSpecifier as ts . StringLiteral ) . text . endsWith ( IG_PACKAGE_NAME ) ) {
90-
91- const clause = ( statement as ts . ImportDeclaration ) . importClause ;
92- return clause && clause . namedBindings && clause . namedBindings . kind === ts . SyntaxKind . NamedImports ;
100+ /** Filters out statements to named imports (e.g. `import {x, y}`) from IG_PACKAGE_NAME */
101+ export const igNamedImportFilter = (
102+ statement : ts . Statement ,
103+ ) : statement is ts . ImportDeclaration & { moduleSpecifier : ts . StringLiteral } & { importClause : { namedBindings : ts . NamedImports } } => {
104+ if ( ts . isImportDeclaration ( statement ) && ts . isStringLiteral ( statement . moduleSpecifier ) && isIgniteuiImport ( statement . moduleSpecifier . text ) ) {
105+ const clause = statement . importClause ;
106+ return clause ? .namedBindings && clause . namedBindings . kind === ts . SyntaxKind . NamedImports ;
93107 }
94108 return false ;
95109} ;
@@ -100,14 +114,13 @@ export const getRenamePositions = (sourcePath: string, name: string, service: ts
100114 const source = service . getProgram ( ) . getSourceFile ( sourcePath ) ;
101115 const positions = [ ] ;
102116
103- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
104- const imports = source . statements . filter ( < ( a : ts . Statement ) => a is ts . ImportDeclaration > namedImportFilter ) ;
117+ const imports = source . statements . filter ( igNamedImportFilter ) ;
105118 if ( ! imports . length ) {
106119 return positions ;
107120 }
108121 const elements : ts . NodeArray < ts . ImportSpecifier > =
109122 imports
110- . map ( x => ( x . importClause . namedBindings as ts . NamedImports ) . elements )
123+ . map ( x => x . importClause . namedBindings . elements )
111124 . reduce ( ( prev , current ) => prev . concat ( current ) as unknown as ts . NodeArray < ts . ImportSpecifier > ) ;
112125
113126 for ( const elem of elements ) {
0 commit comments