@@ -251,6 +251,26 @@ function getDecoratorPathSpecifiers(j, root, decoratorsToImport = []) {
251
251
) ;
252
252
}
253
253
254
+ /**
255
+ * Get existing import statement matching the import path
256
+ *
257
+ * @param {Object } j - jscodeshift lib reference
258
+ * @param {File } root
259
+ * @param {String } importPath
260
+ * @returns {Object }
261
+ */
262
+ function getExistingImportForPath ( j , root , importPath ) {
263
+ const decoratorImports = root . find ( j . ImportDeclaration , {
264
+ source : {
265
+ value : importPath
266
+ }
267
+ } ) ;
268
+
269
+ if ( decoratorImports . length ) {
270
+ return decoratorImports . get ( ) ;
271
+ }
272
+ }
273
+
254
274
/**
255
275
* Create the import statements for decorators
256
276
*
@@ -276,9 +296,20 @@ function createDecoratorImportDeclarations(j, root, decoratorsToImport = []) {
276
296
// Create import statement replacing the existing ones with specifiers importing from ember-decorators namespace
277
297
decoratorPathsImported . forEach ( decoratorPath => {
278
298
const specifiers = decoratorPathSpecifierMap [ decoratorPath ] ;
279
- firstDeclaration . insertBefore (
280
- createImportDeclaration ( j , specifiers , decoratorPath )
281
- ) ;
299
+ const existingImport = getExistingImportForPath ( j , root , decoratorPath ) ;
300
+ if ( existingImport ) {
301
+ let existingSpecifiers = get ( existingImport , "value.specifiers" ) ;
302
+ if ( existingSpecifiers ) {
303
+ existingImport . value . specifiers = [ ] . concat (
304
+ existingSpecifiers ,
305
+ specifiers
306
+ ) ;
307
+ }
308
+ } else {
309
+ firstDeclaration . insertBefore (
310
+ createImportDeclaration ( j , specifiers , decoratorPath )
311
+ ) ;
312
+ }
282
313
} ) ;
283
314
284
315
// Create new import declarations
0 commit comments