Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/sxzz/rolldown-plugin-dts. A Rolldown plugin to generate and bundle dts files.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import { isolatedDeclarationSync, type IsolatedDeclarationsOptions,} from 'rolldown/experimental'import type { LanguageContext } from '../custom-language.ts'import type { Generator, GeneratorResult } from './index.ts'import type { SourceMapInput } from 'rolldown'
export class OxcGenerator implements Generator { private options: IsolatedDeclarationsOptions private languageContext: LanguageContext
constructor( options: IsolatedDeclarationsOptions, languageContext: LanguageContext, ) { this.options = options this.languageContext = languageContext }
emit(code: string, fileName: string): GeneratorResult { // Volar-based custom languages force the `tsc` generator, so any custom // language file reaching here is plain TS with a custom extension; map the // filename so oxc parses it as TS. const result = isolatedDeclarationSync( this.languageContext.toTsFilename(fileName), code, this.options, ) if (result.errors.length) { const [error] = result.errors return { error: { message: error.message, frame: error.codeframe || undefined, }, } }
let map: SourceMapInput | undefined if (result.map) { map = { ...result.map, // Point back to the original file, not the mapped TS filename. sources: [fileName], sourcesContent: undefined, } }
return { code: result.code, map } }}