Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ts language server rule metadata should allow null #74704

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
24 changes: 12 additions & 12 deletions packages/next/src/server/typescript/rules/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {

import type tsModule from 'typescript/lib/tsserverlibrary'

const TYPE_ANOTATION = ': Metadata'
const TYPE_ANOTATION_ASYNC = ': Promise<Metadata>'
const TYPE_ANNOTATION = ': Metadata | null'
const TYPE_ANNOTATION_ASYNC = ': Promise<Metadata | null>'
const TYPE_IMPORT = `\n\nimport type { Metadata } from 'next'`

// Find the `export const metadata = ...` node.
Expand Down Expand Up @@ -152,7 +152,7 @@ function updateVirtualFileWithType(
const source = getSource(fileName)
if (!source) return

// We annotate with the type in a vritual language service
// We annotate with the type in a virtual language service
const sourceText = source.getFullText()
let nodeEnd: number
let annotation: string
Expand All @@ -164,13 +164,13 @@ function updateVirtualFileWithType(
const isAsync = node.modifiers?.some(
(m) => m.kind === ts.SyntaxKind.AsyncKeyword
)
annotation = isAsync ? TYPE_ANOTATION_ASYNC : TYPE_ANOTATION
annotation = isAsync ? TYPE_ANNOTATION_ASYNC : TYPE_ANNOTATION
} else {
return
}
} else {
nodeEnd = node.name.getFullStart() + node.name.getFullWidth()
annotation = TYPE_ANOTATION
annotation = TYPE_ANNOTATION
}

const newSource =
Expand Down Expand Up @@ -234,7 +234,7 @@ const metadata = {

const ts = getTs()

// We annotate with the type in a vritual language service
// We annotate with the type in a virtual language service
const pos = updateVirtualFileWithType(fileName, node)
if (pos === undefined) return prior

Expand Down Expand Up @@ -335,7 +335,7 @@ const metadata = {
if (node.name?.getText() === 'generateMetadata') {
if (isTyped(node)) return []

// We annotate with the type in a vritual language service
// We annotate with the type in a virtual language service
const pos = updateVirtualFileWithType(fileName, node, true)
if (!pos) return []

Expand All @@ -346,7 +346,7 @@ const metadata = {
if (declaration.name.getText() === 'metadata') {
if (isTyped(declaration)) break

// We annotate with the type in a vritual language service
// We annotate with the type in a virtual language service
const pos = updateVirtualFileWithType(fileName, declaration)
if (!pos) break

Expand Down Expand Up @@ -409,7 +409,7 @@ const metadata = {
declaration.getSourceFile().fileName
const isSameFile = declarationFileName === fileName

// We annotate with the type in a vritual language service
// We annotate with the type in a virtual language service
const pos = updateVirtualFileWithType(
declarationFileName,
declaration
Expand Down Expand Up @@ -461,7 +461,7 @@ const metadata = {
if (!node) return
if (isTyped(node)) return

// We annotate with the type in a vritual language service
// We annotate with the type in a virtual language service
const pos = updateVirtualFileWithType(fileName, node)
if (pos === undefined) return

Expand All @@ -485,7 +485,7 @@ const metadata = {
if (!node) return
if (isTyped(node)) return

// We annotate with the type in a vritual language service
// We annotate with the type in a virtual language service
const pos = updateVirtualFileWithType(fileName, node)
if (pos === undefined) return

Expand All @@ -500,7 +500,7 @@ const metadata = {
if (!node) return
if (isTyped(node)) return
if (!isPositionInsideNode(position, node)) return
// We annotate with the type in a vritual language service
// We annotate with the type in a virtual language service
const pos = updateVirtualFileWithType(fileName, node)
if (pos === undefined) return
const { languageService } = getProxiedLanguageService()
Expand Down
Loading