Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
e204a30a
Commit
e204a30a
authored
Jan 09, 2025
by
Jiachi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: ts language server rule metadata should allow null (#74704)
parent
7666d2ef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
metadata.ts
packages/next/src/server/typescript/rules/metadata.ts
+12
-12
No files found.
packages/next/src/server/typescript/rules/metadata.ts
View file @
e204a30a
...
...
@@ -9,8 +9,8 @@ import {
import
type
tsModule
from
'typescript/lib/tsserverlibrary'
const
TYPE_AN
OTATION
=
': Metadata
'
const
TYPE_AN
OTATION_ASYNC
=
': Promise<Metadata
>'
const
TYPE_AN
NOTATION
=
': Metadata | null
'
const
TYPE_AN
NOTATION_ASYNC
=
': Promise<Metadata | null
>'
const
TYPE_IMPORT
=
`\n\nimport type { Metadata } from 'next'`
// Find the `export const metadata = ...` node.
...
...
@@ -152,7 +152,7 @@ function updateVirtualFileWithType(
const
source
=
getSource
(
fileName
)
if
(
!
source
)
return
// We annotate with the type in a v
ri
tual language service
// We annotate with the type in a v
ir
tual language service
const
sourceText
=
source
.
getFullText
()
let
nodeEnd
:
number
let
annotation
:
string
...
...
@@ -164,13 +164,13 @@ function updateVirtualFileWithType(
const
isAsync
=
node
.
modifiers
?.
some
(
(
m
)
=>
m
.
kind
===
ts
.
SyntaxKind
.
AsyncKeyword
)
annotation
=
isAsync
?
TYPE_AN
OTATION_ASYNC
:
TYPE_A
NOTATION
annotation
=
isAsync
?
TYPE_AN
NOTATION_ASYNC
:
TYPE_AN
NOTATION
}
else
{
return
}
}
else
{
nodeEnd
=
node
.
name
.
getFullStart
()
+
node
.
name
.
getFullWidth
()
annotation
=
TYPE_ANOTATION
annotation
=
TYPE_AN
N
OTATION
}
const
newSource
=
...
...
@@ -234,7 +234,7 @@ const metadata = {
const
ts
=
getTs
()
// We annotate with the type in a v
ri
tual language service
// We annotate with the type in a v
ir
tual language service
const
pos
=
updateVirtualFileWithType
(
fileName
,
node
)
if
(
pos
===
undefined
)
return
prior
...
...
@@ -335,7 +335,7 @@ const metadata = {
if
(
node
.
name
?.
getText
()
===
'generateMetadata'
)
{
if
(
isTyped
(
node
))
return
[]
// We annotate with the type in a v
ri
tual language service
// We annotate with the type in a v
ir
tual language service
const
pos
=
updateVirtualFileWithType
(
fileName
,
node
,
true
)
if
(
!
pos
)
return
[]
...
...
@@ -346,7 +346,7 @@ const metadata = {
if
(
declaration
.
name
.
getText
()
===
'metadata'
)
{
if
(
isTyped
(
declaration
))
break
// We annotate with the type in a v
ri
tual language service
// We annotate with the type in a v
ir
tual language service
const
pos
=
updateVirtualFileWithType
(
fileName
,
declaration
)
if
(
!
pos
)
break
...
...
@@ -409,7 +409,7 @@ const metadata = {
declaration
.
getSourceFile
().
fileName
const
isSameFile
=
declarationFileName
===
fileName
// We annotate with the type in a v
ri
tual language service
// We annotate with the type in a v
ir
tual language service
const
pos
=
updateVirtualFileWithType
(
declarationFileName
,
declaration
...
...
@@ -461,7 +461,7 @@ const metadata = {
if
(
!
node
)
return
if
(
isTyped
(
node
))
return
// We annotate with the type in a v
ri
tual language service
// We annotate with the type in a v
ir
tual language service
const
pos
=
updateVirtualFileWithType
(
fileName
,
node
)
if
(
pos
===
undefined
)
return
...
...
@@ -485,7 +485,7 @@ const metadata = {
if
(
!
node
)
return
if
(
isTyped
(
node
))
return
// We annotate with the type in a v
ri
tual language service
// We annotate with the type in a v
ir
tual language service
const
pos
=
updateVirtualFileWithType
(
fileName
,
node
)
if
(
pos
===
undefined
)
return
...
...
@@ -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 v
ri
tual language service
// We annotate with the type in a v
ir
tual language service
const
pos
=
updateVirtualFileWithType
(
fileName
,
node
)
if
(
pos
===
undefined
)
return
const
{
languageService
}
=
getProxiedLanguageService
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment