diff --git a/transforms/helpers/import-helper.ts b/transforms/helpers/import-helper.ts index cb879a9..dc62696 100644 --- a/transforms/helpers/import-helper.ts +++ b/transforms/helpers/import-helper.ts @@ -2,7 +2,7 @@ import { default as j } from 'jscodeshift'; import * as AST from '../helpers/ast'; import type { DecoratorImportInfoMap } from './decorator-info'; import { getDecoratorImportInfo } from './decorator-info'; -import type { Options } from './options'; +import type { UserOptions } from './options'; import { createEmberDecoratorSpecifiers, createImportDeclaration, @@ -87,11 +87,11 @@ function createNewImportDeclarations( decoratorsToImport: string[], /** Already imported paths */ decoratorPathsToIgnore: string[], - options: Options + userOptions: UserOptions ): void { const firstDeclaration = AST.getFirstDeclaration(root); - if (options.classicDecorator) { + if (userOptions.classicDecorator) { firstDeclaration.insertBefore( createImportDeclaration( [j.importDefaultSpecifier(j.identifier('classic'))], @@ -236,7 +236,7 @@ function getExistingImportForPath( export function createDecoratorImportDeclarations( root: AST.Collection, decoratorsToImport: string[], - options: Options + userOptions: UserOptions ): void { // Iterate through existing imports, extract the already imported specifiers const decoratorPathSpecifierMap = getDecoratorPathSpecifiers( @@ -272,7 +272,7 @@ export function createDecoratorImportDeclarations( root, decoratorsToImport, decoratorPathsImported, - options + userOptions ); } diff --git a/transforms/helpers/transform.ts b/transforms/helpers/transform.ts index a24f1df..1f38831 100644 --- a/transforms/helpers/transform.ts +++ b/transforms/helpers/transform.ts @@ -20,15 +20,10 @@ export default function maybeTransformEmberObjects( filePath: string, userOptions: UserOptions ): boolean { - const options: Options = { - ...userOptions, - runtimeData: getRuntimeData(filePath), - }; - const { results, decoratorImportSpecs } = _maybeTransformEmberObjects( root, filePath, - options + userOptions ); for (const result of results) { @@ -44,7 +39,7 @@ export default function maybeTransformEmberObjects( const decoratorsToImport = Object.keys(decoratorImportSpecs).filter( (key) => decoratorImportSpecs[key as keyof DecoratorImportSpecs] ); - createDecoratorImportDeclarations(root, decoratorsToImport, options); + createDecoratorImportDeclarations(root, decoratorsToImport, userOptions); return results.length > 0 && results.every((r) => r.success); } @@ -52,7 +47,7 @@ export default function maybeTransformEmberObjects( function _maybeTransformEmberObjects( root: AST.Collection, filePath: string, - options: Options + userOptions: UserOptions ): { results: TransformResult[]; decoratorImportSpecs: DecoratorImportSpecs; @@ -79,27 +74,32 @@ function _maybeTransformEmberObjects( filePath, info: "UNMODIFIED: Did not find any 'EmberObject.extend()' expressions", }); - } + } else { + const options: Options = { + ...userOptions, + runtimeData: getRuntimeData(filePath), + }; - // eslint-disable-next-line unicorn/no-array-for-each - eoExtendExpressionPaths.forEach((eoExtendExpressionPath) => { - const extendExpression = new EOExtendExpression( - eoExtendExpressionPath, - filePath, - existingDecoratorImportInfos, - options - ); + // eslint-disable-next-line unicorn/no-array-for-each + eoExtendExpressionPaths.forEach((eoExtendExpressionPath) => { + const extendExpression = new EOExtendExpression( + eoExtendExpressionPath, + filePath, + existingDecoratorImportInfos, + options + ); - const result = extendExpression.transform(); - results.push(result); + const result = extendExpression.transform(); + results.push(result); - if (result.success) { - decoratorImportSpecs = mergeDecoratorImportSpecs( - extendExpression.decoratorImportSpecs, - decoratorImportSpecs - ); - } - }); + if (result.success) { + decoratorImportSpecs = mergeDecoratorImportSpecs( + extendExpression.decoratorImportSpecs, + decoratorImportSpecs + ); + } + }); + } return { results, decoratorImportSpecs }; }