Skip to content

Commit

Permalink
check if directives are top level
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Aug 21, 2023
1 parent 873cd2f commit 25405c3
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions packages/next/src/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,26 @@ function checkExports(
let generateStaticParams = false
let extraProperties = new Set<string>()
let directives = new Set<string>()
let hasNonExpressionStatementNode = false

for (const node of swcAST.body) {
// There should be no non-string literals nodes before directives
if (
node.type === 'ExpressionStatement' &&
node.expression.type === 'StringLiteral'
) {
if (!hasNonExpressionStatementNode) {
const directive = node.expression.value
if (CLIENT_DIRECTIVE === directive) {
directives.add('client')
}
if (SERVER_ACTION_DIRECTIVE === directive) {
directives.add('server')
}
}
} else {
hasNonExpressionStatementNode = true
}
if (
node.type === 'ExportDeclaration' &&
node.declaration?.type === 'VariableDeclaration'
Expand Down Expand Up @@ -233,18 +251,6 @@ function checkExports(
)
}
}

if (node.type === 'ExpressionStatement') {
if (node.expression.type === 'StringLiteral') {
const directive = node.expression.value
if (CLIENT_DIRECTIVE === directive) {
directives.add('client')
}
if (SERVER_ACTION_DIRECTIVE === directive) {
directives.add('server')
}
}
}
}

return {
Expand Down

0 comments on commit 25405c3

Please sign in to comment.