@@ -28,7 +28,7 @@ import {
2828 getVNodeHelper ,
2929 locStub ,
3030} from './ast'
31- import { type RawSourceMap , SourceMapGenerator } from 'source-map-js'
31+ import { SourceMapGenerator } from 'source-map-js'
3232import {
3333 advancePositionWithMutation ,
3434 assert ,
@@ -56,6 +56,45 @@ import {
5656} from './runtimeHelpers'
5757import type { ImportItem } from './transform'
5858
59+ /**
60+ * The `SourceMapGenerator` type from `source-map-js` is a bit incomplete as it
61+ * misses `toJSON()`. We also need to add types for internal properties which we
62+ * need to access for better performance.
63+ *
64+ * Since TS 5.3, dts generation starts to strangely include broken triple slash
65+ * references for source-map-js, so we are inlining all source map related types
66+ * here to to workaround that.
67+ */
68+ export interface CodegenSourceMapGenerator {
69+ setSourceContent ( sourceFile : string , sourceContent : string ) : void
70+ // SourceMapGenerator has this method but the types do not include it
71+ toJSON ( ) : RawSourceMap
72+ _sources : Set < string >
73+ _names : Set < string >
74+ _mappings : {
75+ add ( mapping : MappingItem ) : void
76+ }
77+ }
78+
79+ export interface RawSourceMap {
80+ file ?: string
81+ sourceRoot ?: string
82+ version : string
83+ sources : string [ ]
84+ names : string [ ]
85+ sourcesContent ?: string [ ]
86+ mappings : string
87+ }
88+
89+ interface MappingItem {
90+ source : string
91+ generatedLine : number
92+ generatedColumn : number
93+ originalLine : number
94+ originalColumn : number
95+ name : string | null
96+ }
97+
5998const PURE_ANNOTATION = `/*#__PURE__*/`
6099
61100const aliasHelper = ( s : symbol ) => `${ helperNameMap [ s ] } : _${ helperNameMap [ s ] } `
@@ -85,7 +124,7 @@ export interface CodegenContext
85124 offset : number
86125 indentLevel : number
87126 pure : boolean
88- map ?: SourceMapGenerator
127+ map ?: CodegenSourceMapGenerator
89128 helper ( key : symbol ) : string
90129 push ( code : string , newlineIndex ?: number , node ?: CodegenNode ) : void
91130 indent ( ) : void
@@ -218,14 +257,14 @@ function createCodegenContext(
218257 generatedLine : context . line ,
219258 generatedColumn : context . column - 1 ,
220259 source : filename ,
221- // @ts -expect-error it is possible to be null
222260 name,
223261 } )
224262 }
225263
226264 if ( ! __BROWSER__ && sourceMap ) {
227265 // lazy require source-map implementation, only in non-browser builds
228- context . map = new SourceMapGenerator ( )
266+ context . map =
267+ new SourceMapGenerator ( ) as unknown as CodegenSourceMapGenerator
229268 context . map . setSourceContent ( filename , context . source )
230269 context . map . _sources . add ( filename )
231270 }
0 commit comments