Skip to content

Commit

Permalink
fix: ts language server rule metadata should allow null (#74704)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Jan 9, 2025
1 parent fa422ce commit eb96a53
Showing 1 changed file with 12 additions and 12 deletions.
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

0 comments on commit eb96a53

Please sign in to comment.