From cc37d272cd1d5030339163bfc774d7fded9e3137 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 1 Oct 2024 12:04:14 +0200 Subject: [PATCH] search from program.directives --- .../transforms/lib/async-request-api/utils.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/next-codemod/transforms/lib/async-request-api/utils.ts b/packages/next-codemod/transforms/lib/async-request-api/utils.ts index ae0bb191b89ef..8777e412d5d28 100644 --- a/packages/next-codemod/transforms/lib/async-request-api/utils.ts +++ b/packages/next-codemod/transforms/lib/async-request-api/utils.ts @@ -105,20 +105,10 @@ export function isMatchedFunctionExported( // directive is not parsed into AST, so we need to manually find it // by going through the tokens. Use the 1st string token as the directive export function determineClientDirective(root: Collection) { - const { tokens } = root.get().node + const { program } = root.get().node let directive = undefined - for (const token of tokens) { - if (token.type === 'CommentBlock') { - continue - } else if (token.type?.label === 'string') { - // Skip 'use strict' directive - if (token.value === 'use strict') continue - directive = token.value - break - } else { - break - } - } + + directive = program.directives[0].value return directive === 'use client' }