9
9
10
10
import type tsModule from 'typescript/lib/tsserverlibrary'
11
11
12
- const TYPE_ANOTATION = ': Metadata'
13
- const TYPE_ANOTATION_ASYNC = ': Promise<Metadata>'
12
+ const TYPE_ANNOTATION = ': Metadata | null '
13
+ const TYPE_ANNOTATION_ASYNC = ': Promise<Metadata | null >'
14
14
const TYPE_IMPORT = `\n\nimport type { Metadata } from 'next'`
15
15
16
16
// Find the `export const metadata = ...` node.
@@ -152,7 +152,7 @@ function updateVirtualFileWithType(
152
152
const source = getSource ( fileName )
153
153
if ( ! source ) return
154
154
155
- // We annotate with the type in a vritual language service
155
+ // We annotate with the type in a virtual language service
156
156
const sourceText = source . getFullText ( )
157
157
let nodeEnd : number
158
158
let annotation : string
@@ -164,13 +164,13 @@ function updateVirtualFileWithType(
164
164
const isAsync = node . modifiers ?. some (
165
165
( m ) => m . kind === ts . SyntaxKind . AsyncKeyword
166
166
)
167
- annotation = isAsync ? TYPE_ANOTATION_ASYNC : TYPE_ANOTATION
167
+ annotation = isAsync ? TYPE_ANNOTATION_ASYNC : TYPE_ANNOTATION
168
168
} else {
169
169
return
170
170
}
171
171
} else {
172
172
nodeEnd = node . name . getFullStart ( ) + node . name . getFullWidth ( )
173
- annotation = TYPE_ANOTATION
173
+ annotation = TYPE_ANNOTATION
174
174
}
175
175
176
176
const newSource =
@@ -234,7 +234,7 @@ const metadata = {
234
234
235
235
const ts = getTs ( )
236
236
237
- // We annotate with the type in a vritual language service
237
+ // We annotate with the type in a virtual language service
238
238
const pos = updateVirtualFileWithType ( fileName , node )
239
239
if ( pos === undefined ) return prior
240
240
@@ -335,7 +335,7 @@ const metadata = {
335
335
if ( node . name ?. getText ( ) === 'generateMetadata' ) {
336
336
if ( isTyped ( node ) ) return [ ]
337
337
338
- // We annotate with the type in a vritual language service
338
+ // We annotate with the type in a virtual language service
339
339
const pos = updateVirtualFileWithType ( fileName , node , true )
340
340
if ( ! pos ) return [ ]
341
341
@@ -346,7 +346,7 @@ const metadata = {
346
346
if ( declaration . name . getText ( ) === 'metadata' ) {
347
347
if ( isTyped ( declaration ) ) break
348
348
349
- // We annotate with the type in a vritual language service
349
+ // We annotate with the type in a virtual language service
350
350
const pos = updateVirtualFileWithType ( fileName , declaration )
351
351
if ( ! pos ) break
352
352
@@ -409,7 +409,7 @@ const metadata = {
409
409
declaration . getSourceFile ( ) . fileName
410
410
const isSameFile = declarationFileName === fileName
411
411
412
- // We annotate with the type in a vritual language service
412
+ // We annotate with the type in a virtual language service
413
413
const pos = updateVirtualFileWithType (
414
414
declarationFileName ,
415
415
declaration
@@ -461,7 +461,7 @@ const metadata = {
461
461
if ( ! node ) return
462
462
if ( isTyped ( node ) ) return
463
463
464
- // We annotate with the type in a vritual language service
464
+ // We annotate with the type in a virtual language service
465
465
const pos = updateVirtualFileWithType ( fileName , node )
466
466
if ( pos === undefined ) return
467
467
@@ -485,7 +485,7 @@ const metadata = {
485
485
if ( ! node ) return
486
486
if ( isTyped ( node ) ) return
487
487
488
- // We annotate with the type in a vritual language service
488
+ // We annotate with the type in a virtual language service
489
489
const pos = updateVirtualFileWithType ( fileName , node )
490
490
if ( pos === undefined ) return
491
491
@@ -500,7 +500,7 @@ const metadata = {
500
500
if ( ! node ) return
501
501
if ( isTyped ( node ) ) return
502
502
if ( ! isPositionInsideNode ( position , node ) ) return
503
- // We annotate with the type in a vritual language service
503
+ // We annotate with the type in a virtual language service
504
504
const pos = updateVirtualFileWithType ( fileName , node )
505
505
if ( pos === undefined ) return
506
506
const { languageService } = getProxiedLanguageService ( )
0 commit comments