Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions transforms/helpers/import-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'))],
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -272,7 +272,7 @@ export function createDecoratorImportDeclarations(
root,
decoratorsToImport,
decoratorPathsImported,
options
userOptions
);
}

Expand Down
52 changes: 26 additions & 26 deletions transforms/helpers/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -44,15 +39,15 @@ 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);
}

function _maybeTransformEmberObjects(
root: AST.Collection,
filePath: string,
options: Options
userOptions: UserOptions
): {
results: TransformResult[];
decoratorImportSpecs: DecoratorImportSpecs;
Expand All @@ -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 };
}
Expand Down