File tree Expand file tree Collapse file tree 2 files changed +10
-14
lines changed Expand file tree Collapse file tree 2 files changed +10
-14
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @codeshift/utils ' : patch
3+ ---
4+
5+ InsertImportSpecifier now retains the reference to the original import declaration
Original file line number Diff line number Diff line change @@ -122,18 +122,9 @@ export function insertImportSpecifier(
122122 importSpecifier : ImportSpecifier | ImportDefaultSpecifier ,
123123 sourcePath : string ,
124124) {
125- getImportDeclaration ( j , source , sourcePath ) . replaceWith ( declaration =>
126- j . importDeclaration (
127- [
128- // we are appending to the existing specifiers
129- // We are doing a filter hear because sometimes specifiers can be removed
130- // but they hang around in the declaration
131- ...( declaration . value . specifiers || [ ] ) . filter (
132- item => item . type === 'ImportSpecifier' && item . imported != null ,
133- ) ,
134- importSpecifier ,
135- ] ,
136- j . literal ( sourcePath ) ,
137- ) ,
138- ) ;
125+ const importDeclaration = getImportDeclaration ( j , source , sourcePath ) ;
126+
127+ if ( ! importDeclaration ) return ;
128+
129+ importDeclaration . get ( ) . value . specifiers . push ( importSpecifier ) ;
139130}
You can’t perform that action at this time.
0 commit comments