@@ -20,8 +20,10 @@ import {
2020 getImportedDecoratedProps ,
2121} from './import-helper' ;
2222import logger from './log-helper' ;
23+ import type { Options } from './options' ;
2324import { DEFAULT_OPTIONS } from './options' ;
2425import type { RuntimeData } from './runtime-data' ;
26+ import { isRuntimeData } from './runtime-data' ;
2527import { createClass , withComments } from './transform-helper' ;
2628import { capitalizeFirstLetter , dig , startsWithUpperCaseLetter } from './util' ;
2729import {
@@ -274,10 +276,7 @@ export function replaceEmberObjectExpressions(
274276) : boolean | undefined {
275277 options . runtimeData = verified (
276278 getTelemetryFor ( path . resolve ( filePath ) ) ,
277- // FIXME: move to runtime-data.ts
278- function isRuntimeData ( v : unknown ) : v is RuntimeData | undefined {
279- return v === undefined || isRecord ( v ) ;
280- }
279+ isRuntimeData
281280 ) ;
282281
283282 if ( ! options . runtimeData ) {
@@ -303,6 +302,40 @@ export function replaceEmberObjectExpressions(
303302 let transformed = false ;
304303 let decoratorsToImportMap : Partial < DecoratorsToImportMap > = { } ;
305304
305+ ( { transformed, decoratorsToImportMap } = transform (
306+ j ,
307+ root ,
308+ importedDecoratedProps ,
309+ options ,
310+ filePath ,
311+ transformed ,
312+ decoratorsToImportMap
313+ ) ) ;
314+
315+ // Need to find another way, as there might be a case where
316+ // one object from a file is transformed and other is not
317+ if ( transformed ) {
318+ const decoratorsToImport = Object . keys ( decoratorsToImportMap ) . filter (
319+ ( key ) => decoratorsToImportMap [ key as keyof DecoratorsToImportMap ]
320+ ) ;
321+ createDecoratorImportDeclarations ( j , root , decoratorsToImport , options ) ;
322+ logger . info ( `[${ filePath } ]: SUCCESS` ) ;
323+ }
324+ return transformed ;
325+ }
326+
327+ function transform (
328+ j : JSCodeshift ,
329+ root : Collection < unknown > ,
330+ importedDecoratedProps : ImportPropDecoratorMap ,
331+ options : Options ,
332+ filePath : string ,
333+ transformed : boolean ,
334+ decoratorsToImportMap : Partial < DecoratorsToImportMap >
335+ ) : {
336+ transformed : boolean ;
337+ decoratorsToImportMap : Partial < DecoratorsToImportMap > ;
338+ } {
306339 // eslint-disable-next-line unicorn/no-array-for-each
307340 getEmberObjectCallExpressions ( j , root ) . forEach ( ( eoCallExpression ) => {
308341 const { eoExpression, mixins } =
@@ -373,16 +406,5 @@ export function replaceEmberObjectExpressions(
373406 ) ;
374407 } ) ;
375408
376- // Need to find another way, as there might be a case where
377- // one object from a file is transformed and other is not
378- // FIXME: Is this always falsy?
379- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
380- if ( transformed ) {
381- const decoratorsToImport = Object . keys ( decoratorsToImportMap ) . filter (
382- ( key ) => decoratorsToImportMap [ key as keyof DecoratorsToImportMap ]
383- ) ;
384- createDecoratorImportDeclarations ( j , root , decoratorsToImport , options ) ;
385- logger . info ( `[${ filePath } ]: SUCCESS` ) ;
386- }
387- return transformed ;
409+ return { transformed, decoratorsToImportMap } ;
388410}
0 commit comments