Skip to content

Commit

Permalink
search from program.directives
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Oct 1, 2024
1 parent 1c66699 commit cc37d27
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions packages/next-codemod/transforms/lib/async-request-api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>) {
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'
}
Expand Down

0 comments on commit cc37d27

Please sign in to comment.