@@ -251,6 +251,26 @@ function getDecoratorPathSpecifiers(j, root, decoratorsToImport = []) {
251251 ) ;
252252}
253253
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+
254274/**
255275 * Create the import statements for decorators
256276 *
@@ -276,9 +296,20 @@ function createDecoratorImportDeclarations(j, root, decoratorsToImport = []) {
276296 // Create import statement replacing the existing ones with specifiers importing from ember-decorators namespace
277297 decoratorPathsImported . forEach ( decoratorPath => {
278298 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+ }
282313 } ) ;
283314
284315 // Create new import declarations
0 commit comments