import { transform as swcTransform , transformSync as swcTransformSync , Options as SwcOptions , ReactConfig , Config , JscTarget , } from '@swc/core' ; const DEFAULT_ES_TARGET = 'es2018' ; export interface Options { target ? : JscTarget ; module ? : 'commonjs' | 'umd' | 'amd' | 'es6' ; sourcemap ? : Config [ 'sourceMaps' ] ; jsx ? : boolean ; experimentalDecorators ? : boolean ; emitDecoratorMetadata ? : boolean ; dynamicImport ? : boolean ; esModuleInterop ? : boolean ; keepClassNames ? : boolean ; react ? : Partial < ReactConfig > ; paths ? : { [ from ] : [ string ] ; } ; swc ? : SwcOptions ; } function transformOption ( path , options ? , jest = false ) { const opts = options == null ? { } : options ; opts . esModuleInterop = opts . esModuleInterop ?? true ; const sourceMapDefault = jest ? 'inline' : true ; return { filename : path , jsc : { target : opts . target ?? DEFAULT_ES_TARGET , parser : { syntax : 'typescript' as const , tsx : typeof opts . jsx !== 'undefined' ? opts . jsx : path . endsWith ( '.tsx' ) , decorators : Boolean ( opts . experimentalDecorators ) , dynamicImport : Boolean ( opts . dynamicImport ) , } , transform : { legacyDecorator : Boolean ( opts . experimentalDecorators ) , decoratorMetadata : Boolean ( opts . emitDecoratorMetadata ) , react : options ?. react , hidden : { jest , } , } , keepClassNames : opts . keepClassNames , paths : opts . paths , } , minify : false , isModule : true , module : { type : 'commonjs' , noInterop : ! opts . esModuleInterop , } , sourceMaps : typeof opts . sourcemap === 'undefined' ? sourceMapDefault : opts . sourcemap , inlineSourcesContent : true , swcrc : false , ... ( options ?. swc ?? { } ) , } ; } export function transformSync ( source , path , options ? ) { return swcTransformSync ( source , transformOption ( path , options ) ) ; } export function transformJest ( source , path , options ? ) { return swcTransformSync ( source , transformOption ( path , options , true ) ) ; } export function transform ( source , path , options ? ) { return swcTransform ( source , transformOption ( path , options ) ) ; }