diff --git a/packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-apis/async-component-access-api-prop-07.input.tsx b/packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-apis/async-component-access-api-prop-07.input.tsx new file mode 100644 index 00000000000000..5fca48fb6a3170 --- /dev/null +++ b/packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-apis/async-component-access-api-prop-07.input.tsx @@ -0,0 +1,6 @@ +import { draftMode, type DangerouslyUnwrapDraftMode } from 'next/headers'; + +export function MyComponent2() { + draftMode().enable() +} + diff --git a/packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-apis/async-component-access-api-prop-07.output.tsx b/packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-apis/async-component-access-api-prop-07.output.tsx new file mode 100644 index 00000000000000..e608d18f5acf1e --- /dev/null +++ b/packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-apis/async-component-access-api-prop-07.output.tsx @@ -0,0 +1,5 @@ +import { draftMode, type DangerouslyUnwrapDraftMode } from 'next/headers'; + +export function MyComponent2() { + (draftMode() as unknown as DangerouslyUnwrapDraftMode).enable() +} diff --git a/packages/next-codemod/transforms/async-request-api/next-async-dynamic-api.ts b/packages/next-codemod/transforms/async-request-api/next-async-dynamic-api.ts index ff63cbbab349d3..951ba31c3ecf3f 100644 --- a/packages/next-codemod/transforms/async-request-api/next-async-dynamic-api.ts +++ b/packages/next-codemod/transforms/async-request-api/next-async-dynamic-api.ts @@ -332,6 +332,11 @@ function castTypesOrAddComment( .find(j.TSTypeAliasDeclaration, { id: { name: targetType }, }) + .size() > 0 || + importDeclaration + .find(j.ImportSpecifier, { + imported: { name: targetType }, + }) .size() > 0 if (!hasImportedType) {